From f9b607e020448fe5b8456fa2706d5affadad0404 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Thu, 7 Dec 2023 14:06:34 -0500 Subject: [PATCH 1/8] update min version of photutils --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index deff8ef7..c5642263 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "scipy>=1.5.0", "matplotlib>=3.2.0", "astropy>=5.1.0", - "photutils>=1.0.0", + "photutils>=1.10.0", "poppy>=1.0.0", "pysiaf>=0.19.1", "soc_roman_tools>=0.1.0", diff --git a/requirements.txt b/requirements.txt index 33754585..e47a5514 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ astropy==5.3.4 ipython==8.17.2 matplotlib==3.8.1 numpy==1.26.1 -photutils==1.9.0 +photutils==1.10.0 poppy>=1.0.0 pysiaf==0.21.0 scipy==1.11.3 From b3fdf34894379b1e7e5eb8a0dc456600cee58b01 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Thu, 7 Dec 2023 14:33:24 -0500 Subject: [PATCH 2/8] bump versions to newest --- requirements.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index e47a5514..c280f922 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -astropy==5.3.4 -ipython==8.17.2 -matplotlib==3.8.1 -numpy==1.26.1 +astropy==6.0.0 +ipython==8.18.1 +matplotlib==3.8.2 +numpy==1.26.2 photutils==1.10.0 poppy>=1.0.0 pysiaf==0.21.0 -scipy==1.11.3 -synphot==1.2.1 +scipy==1.11.4 +synphot==1.3.post0 astroquery==0.4.6 From 78f45731948499418beafa914bd7c93de665971c Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Fri, 8 Dec 2023 14:08:43 -0500 Subject: [PATCH 3/8] update test_psfgrid for most tests --- webbpsf/tests/test_psfgrid.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/webbpsf/tests/test_psfgrid.py b/webbpsf/tests/test_psfgrid.py index a41f1800..e53cad0e 100644 --- a/webbpsf/tests/test_psfgrid.py +++ b/webbpsf/tests/test_psfgrid.py @@ -5,11 +5,11 @@ import numpy as np import pytest -from .. import gridded_library -from .. import webbpsf_core -from .. import roman -from .. import utils -from .. import detectors +from webbpsf import gridded_library +from webbpsf import webbpsf_core +from webbpsf import roman +from webbpsf import utils +from webbpsf import detectors def test_compare_to_calc_psf_oversampled(): @@ -33,7 +33,7 @@ def test_compare_to_calc_psf_oversampled(): # Pull one of the PSFs out of the grid psfnum = 1 - loc = grid.meta["grid_xypos"][psfnum] + loc = grid.grid_xypos[psfnum] locy = int(float(loc[1]) - 0.5) locx = int(float(loc[0]) - 0.5) gridpsf = grid.data[psfnum, :, :] @@ -68,7 +68,7 @@ def test_compare_to_calc_psf_detsampled(): # Pull one of the PSFs out of the grid psfnum = 1 - loc = grid.meta["grid_xypos"][psfnum] + loc = grid.grid_xypos[psfnum] locy = int(float(loc[1])) locx = int(float(loc[0])) gridpsf = grid.data[psfnum, :, :] @@ -142,8 +142,8 @@ def test_one_psf(): scalefactor = oversample**2 # normalization as used internally in GriddedPSFModel; see #302 - assert grid1.meta["grid_xypos"] == [(1023, 1023)], "Center position not as expected" # the default is the center of the NIS aperture - assert grid2.meta["grid_xypos"] == [(10, 0)], "Corner position not as expected" # it's in (x,y) + assert np.all(grid1.grid_xypos == [[1023, 1023]]), "Center position not as expected" # the default is the center of the NIS aperture + assert np.all(grid2.grid_xypos == [(10, 0)]), "Corner position not as expected" # it's in (x,y) # check for near-equality of the PSFs computed both ways, # but ignore the outer few pixels rows and columns, for which boundary wrapping leads to imperfect equality # depending on the order of the convolutions. Ignore 2 rows/cols on either side based on oversample value @@ -209,7 +209,7 @@ def test_saving(tmpdir): # Check meta data model = utils.to_griddedpsfmodel(infile) assert model.meta.keys() == grid.meta.keys() - assert model.meta["grid_xypos"] == grid.meta["grid_xypos"] + assert np.all(model.grid_xypos == grid.grid_xypos) assert model.meta["oversampling"] == grid.meta["oversampling"] # Remove temporary directory @@ -249,7 +249,7 @@ def test_wfi(): # Pull one of the PSFs out of the grid psfnum = 1 - loc = grid.meta["grid_xypos"][psfnum] + loc = grid.grid_xypos[psfnum] locy = int(float(loc[1])-0.5) locx = int(float(loc[0])-0.5) gridpsf = grid.data[psfnum, :, :] @@ -266,3 +266,4 @@ def test_wfi(): assert np.allclose(gridpsf, convpsf*scalefactor), "Data values not as expected" +test_saving('/Users/bsappington/tmp/') \ No newline at end of file From d79feeafaa597aca3505dc4502a765485af50ecb Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Fri, 8 Dec 2023 14:12:08 -0500 Subject: [PATCH 4/8] remove temp local test code --- webbpsf/tests/test_psfgrid.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/webbpsf/tests/test_psfgrid.py b/webbpsf/tests/test_psfgrid.py index e53cad0e..da43fe80 100644 --- a/webbpsf/tests/test_psfgrid.py +++ b/webbpsf/tests/test_psfgrid.py @@ -263,7 +263,4 @@ def test_wfi(): # Compare to make sure they are in fact the same PSF assert gridpsf.shape == calcpsf.shape, "Shape mismatch" - assert np.allclose(gridpsf, convpsf*scalefactor), "Data values not as expected" - - -test_saving('/Users/bsappington/tmp/') \ No newline at end of file + assert np.allclose(gridpsf, convpsf*scalefactor), "Data values not as expected" \ No newline at end of file From f629e65decea4b02f298ae4c3ed7c66c4b9ff548 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Mon, 11 Dec 2023 13:58:46 -0500 Subject: [PATCH 5/8] store sorted data when saving to file --- webbpsf/gridded_library.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webbpsf/gridded_library.py b/webbpsf/gridded_library.py index 6a852797..138a2e81 100644 --- a/webbpsf/gridded_library.py +++ b/webbpsf/gridded_library.py @@ -399,7 +399,8 @@ def create_grid(self): model_list.append(model) if self.save is True: - self.writeto(psf_arr, meta, det) + # model.data is sorted with xygrid, psf_arr is not. Store the sorted data + self.writeto(model.data, meta, det) # If only 1 detector, only return that 1 object. Else, return list of objects if len(self.detector_list) == 1: @@ -435,6 +436,8 @@ def to_model(data, meta): raise ImportError("This method requires photutils >= 0.6") ndd = NDData(data, meta=meta, copy=True) + print("TO_MODEL - NDD DATA: ") + print (ndd.data) ndd.meta['grid_xypos'] = [((float(ndd.meta[key][0].split(',')[1].split(')')[0])), (float(ndd.meta[key][0].split(',')[0].split('(')[1]))) @@ -444,6 +447,8 @@ def to_model(data, meta): ndd.meta = {key.lower(): ndd.meta[key] for key in ndd.meta} model = GriddedPSFModel(ndd) + print ("TO_MODEL - MODEL DATA: ") + print (model.data) return model From 30328e9d8256a43b070333a8bc1464dae3d84a75 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Mon, 11 Dec 2023 14:04:32 -0500 Subject: [PATCH 6/8] remove debug statements --- webbpsf/gridded_library.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/webbpsf/gridded_library.py b/webbpsf/gridded_library.py index 138a2e81..08eec1a8 100644 --- a/webbpsf/gridded_library.py +++ b/webbpsf/gridded_library.py @@ -436,8 +436,6 @@ def to_model(data, meta): raise ImportError("This method requires photutils >= 0.6") ndd = NDData(data, meta=meta, copy=True) - print("TO_MODEL - NDD DATA: ") - print (ndd.data) ndd.meta['grid_xypos'] = [((float(ndd.meta[key][0].split(',')[1].split(')')[0])), (float(ndd.meta[key][0].split(',')[0].split('(')[1]))) @@ -447,9 +445,7 @@ def to_model(data, meta): ndd.meta = {key.lower(): ndd.meta[key] for key in ndd.meta} model = GriddedPSFModel(ndd) - print ("TO_MODEL - MODEL DATA: ") - print (model.data) - + return model def writeto(self, data, meta, detector): From a33e19d4ac778ac53d30d52711acf9c2fdc24b00 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Mon, 11 Dec 2023 14:06:08 -0500 Subject: [PATCH 7/8] went back to relative dir --- webbpsf/tests/test_psfgrid.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webbpsf/tests/test_psfgrid.py b/webbpsf/tests/test_psfgrid.py index da43fe80..013d62b4 100644 --- a/webbpsf/tests/test_psfgrid.py +++ b/webbpsf/tests/test_psfgrid.py @@ -5,11 +5,11 @@ import numpy as np import pytest -from webbpsf import gridded_library -from webbpsf import webbpsf_core -from webbpsf import roman -from webbpsf import utils -from webbpsf import detectors +from .. import gridded_library +from .. import webbpsf_core +from .. import roman +from .. import utils +from .. import detectors def test_compare_to_calc_psf_oversampled(): From b99e0d0279a93d39967e7f208c68fa4b6f020248 Mon Sep 17 00:00:00 2001 From: Bradley Sappington Date: Mon, 11 Dec 2023 14:11:46 -0500 Subject: [PATCH 8/8] ruff formatting --- webbpsf/gridded_library.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webbpsf/gridded_library.py b/webbpsf/gridded_library.py index 08eec1a8..d1b95040 100644 --- a/webbpsf/gridded_library.py +++ b/webbpsf/gridded_library.py @@ -1,13 +1,13 @@ -from collections import OrderedDict import itertools import os +from collections import OrderedDict import astropy.convolution +import numpy as np from astropy.io import fits from astropy.nddata import NDData -import numpy as np -import poppy +import poppy import webbpsf.detectors @@ -445,7 +445,7 @@ def to_model(data, meta): ndd.meta = {key.lower(): ndd.meta[key] for key in ndd.meta} model = GriddedPSFModel(ndd) - + return model def writeto(self, data, meta, detector):