Ordering and defects in artificial magnetic square ice: thermodynamic and field-driven processes