nebius/SWE-bench-extra huggingface dataset:
Repository: spacetelescope/gwcs

Issue:
APE 14 array_shape and pixel_shape should map to same private attribute
Currently WCS properties `array_shape` and `pixel_shape` set and retrieve independent private attributes.

https://github.com/spacetelescope/gwcs/blob/145778108aa6d7d0a220c96a179dc55d0a818e95/gwcs/api.py#L175-L177

and

https://github.com/spacetelescope/gwcs/blob/145778108aa6d7d0a220c96a179dc55d0a818e95/gwcs/api.py#L226-L237

But they are related:

```python
array_shape == pixel_shape[::-1]
```

for 2D images.  So really they should be setting the same underlying private attribute with the same validation.  Currently validation only happens for setting `pixel_shape`.

Finally, neither of these serializes when written out to ASDF.  We should probably add one or the other (both?) to the schema.

Brought about via discussion with @mcara.

Comments:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index bfd8523..4c17f4a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,10 @@
 Bug Fixes
 ^^^^^^^^^
 
+- Synchronize ``array_shape`` and ``pixel_shape`` attributes of WCS
+  objects. [#439]
+
+
 0.18.3 (2022-12-23)
 -------------------
 Bug Fixes
diff --git a/gwcs/api.py b/gwcs/api.py
index 9e5012f..e4fd19a 100644
--- a/gwcs/api.py
+++ b/gwcs/api.py
@@ -170,11 +170,17 @@ class GWCSAPIMixin(BaseHighLevelWCS, BaseLowLevelWCS):
         The shape should be given in ``(row, column)`` order (the convention
         for arrays in Python).
         """
-        return self._array_shape
+        if self._pixel_shape is None:
+            return None
+        else:
+            return self._pixel_shape[::-1]
 
     @array_shape.setter
     def array_shape(self, value):
-        self._array_shape = value
+        if value is None:
+            self._pixel_shape = None
+        else:
+            self._pixel_shape = value[::-1]
 
     @property
     def pixel_bounds(self):
diff --git a/gwcs/wcs.py b/gwcs/wcs.py
index 92a635c..3d09a34 100644
--- a/gwcs/wcs.py
+++ b/gwcs/wcs.py
@@ -141,7 +141,6 @@ class WCS(GWCSAPIMixin):
         self._available_frames = []
         self._pipeline = []
         self._name = name
-        self._array_shape = None
         self._initialize_wcs(forward_transform, input_frame, output_frame)
         self._pixel_shape = None
 


Test patch:
diff --git a/gwcs/tests/test_api.py b/gwcs/tests/test_api.py
index cae9bdd..5d1fa6c 100644
--- a/gwcs/tests/test_api.py
+++ b/gwcs/tests/test_api.py
@@ -327,6 +327,11 @@ def test_array_shape(wcsobj):
     wcsobj.array_shape = (2040, 1020)
     assert_array_equal(wcsobj.array_shape, (2040, 1020))
 
+    assert wcsobj.array_shape == wcsobj.pixel_shape[::-1]
+
+    wcsobj.pixel_shape = (1111, 2222)
+    assert wcsobj.array_shape == (2222, 1111)
+
 
 @wcs_objs
 def test_pixel_bounds(wcsobj):
Repository: spacetelescope/tweakwcs

Issue:
Peak measurement of 2d histogram can find unrealistic positions for the peak
Processing the singleton 'ibbr02c5q' triggers a logical error when determining the position of the peak of the 2d histogram.  

Specifically, Line 489 of `matchutils.py` in the `_find_peak()` function can return a solution that ends up outside the range of values defined by the slice being used for the fit defined by (x1, x2), (y1,y2).  Logic needs to be added to look for this situation and trigger the failure mode to revert to simply reporting the position of the max value instead as currently happens now when the 'det <= 0' in Line 513.  The current logic does not prevent this function from returning values outside of the slice defined for the peak.

Comments:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index ebe60f5..2dde896 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -8,9 +8,12 @@ Release Notes
    ==================
 
 
-0.7.2 (06-May-2021)
+0.7.2 (07-May-2021)
 ===================
 
+- Fixed a bug in ``matchutils._find_peak()`` due to which it could return
+  coordinates of the peak that were outside of the image. [#136]
+
 - Fixed a bug in how re-projection was computed when ``center`` of the
   transformations was provided. [#135]
 
diff --git a/tweakwcs/matchutils.py b/tweakwcs/matchutils.py
index 9fd05e9..6def57b 100644
--- a/tweakwcs/matchutils.py
+++ b/tweakwcs/matchutils.py
@@ -518,12 +518,12 @@ def _find_peak(data, peak_fit_box=5, mask=None):
     ym = (c10 * c11 - 2.0 * c01 * c20) / det
 
     if 0.0 <= xm <= (nx - 1.0) and 0.0 <= ym <= (ny - 1.0):
-        coord = (xm, ym)
         fit_status = 'SUCCESS'
-
     else:
         xm = 0.0 if xm < 0.0 else min(xm, nx - 1.0)
         ym = 0.0 if ym < 0.0 else min(ym, ny - 1.0)
         fit_status = 'WARNING:EDGE'
 
+    coord = (xm, ym)
+
     return coord, fit_status, np.s_[y1:y2, x1:x2]


Test patch:
diff --git a/tweakwcs/tests/test_matchutils.py b/tweakwcs/tests/test_matchutils.py
index a390812..59d6dd3 100644
--- a/tweakwcs/tests/test_matchutils.py
+++ b/tweakwcs/tests/test_matchutils.py
@@ -189,7 +189,7 @@ def test_find_peak_fit_over_edge():
     data[:, 0] = 0.0
     coord, fit_status, fit_box = _find_peak(data, peak_fit_box=7)
     assert fit_status == 'WARNING:EDGE'
-    assert np.allclose(coord, (1, 11), rtol=0, atol=1e-6)
+    assert np.allclose(coord, (0, 11), rtol=0, atol=1e-6)
 
 
 @pytest.mark.parametrize('shift', [100, 2])