From a1e1d0d1e09ba070ea81b49f0a199bc23ef3e9b4 Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 15:04:46 -0400 Subject: [PATCH 01/10] Remove .DS_Store files --- docs/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 docs/.DS_Store diff --git a/docs/.DS_Store b/docs/.DS_Store deleted file mode 100644 index cd3a2cf86a516c8064df523e3cb54a7528c4c45a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOKQU~5S>X)F?8c)mbyZ2AcAuOU!aACP{;>bnzdIsSC7^=pN;Ew=WfCq7(Hn; zPeO0u@ra0SKVLT@ortt>L%G>7H`_O#*(xIngyW38d|Ze3^YL;%%(8zE823@$ Date: Tue, 24 Sep 2024 15:10:56 -0400 Subject: [PATCH 02/10] Update version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6514e8b..fa95b9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "lkprf" -version = "1.1.0dev" +version = "1.1.0" description = "" authors = ["TESS Science Support Center , Christina Hedges "] license = "MIT" From 29ab4266ec19059aee1bd590382c14106a930f99 Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 15:11:38 -0400 Subject: [PATCH 03/10] Update version number --- src/lkprf/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lkprf/version.py b/src/lkprf/version.py index b55f4df..d56e88c 100644 --- a/src/lkprf/version.py +++ b/src/lkprf/version.py @@ -1,3 +1,3 @@ # It is important to store the version number in a separate file # so that we can read it without importing the package -__version__ = "1.1.0dev" +__version__ = "1.1.0" From 3d8fe6b4edcd1defdbe029276d7f2e8e35a11488 Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 15:12:43 -0400 Subject: [PATCH 04/10] Update version number --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9bc00e2..1549e08 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -1.1.0dev (2024-09-18) +1.1.0 (2024-09-24) ===================== - Added the option to use the initial TESS commissioning PRF files [#9] From 3e3e0225679febf3047b372f5b344683f441fc9b Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 15:19:21 -0400 Subject: [PATCH 05/10] black formatting --- src/lkprf/data.py | 13 ++++++++----- src/lkprf/keplerprf.py | 27 +++++++++++++------------- src/lkprf/prfmodel.py | 13 +++++-------- src/lkprf/tessprf.py | 43 +++++++++++++++++++++++++----------------- 4 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/lkprf/data.py b/src/lkprf/data.py index 0a11621..571cc75 100644 --- a/src/lkprf/data.py +++ b/src/lkprf/data.py @@ -7,7 +7,8 @@ from scipy.ndimage import label, uniform_filter from . import logger, PACKAGEDIR -CACHEDIR = PACKAGEDIR + '/data/' + +CACHEDIR = PACKAGEDIR + "/data/" __all__ = [ "download_kepler_prf_file", @@ -138,7 +139,7 @@ def open_file(url: str): ) prefix = _tess_prefixes[camera][ccd] filename = f"tess-prf-cam{camera}-ccd{ccd}-sec4.fits" - + file_path = f"{cache_dir}{filename}" # ensure the file_path exists if not os.path.exists(file_path): @@ -170,12 +171,14 @@ def get_kepler_prf_file(module: int, output: int, cache_dir: str = CACHEDIR): f"No local files found, building Kepler PRF for Module {module}, output {output}." ) download_kepler_prf_file(module=module, output=output, cache_dir=cache_dir) - + hdulist = fitsio.FITS(file_path) return hdulist -def get_tess_prf_file(camera: int, ccd: int, sector: int = 4, cache_dir: str = CACHEDIR): +def get_tess_prf_file( + camera: int, ccd: int, sector: int = 4, cache_dir: str = CACHEDIR +): """Get a PRF file for a given camera/ccd/sector""" if sector <= 3: filename = f"tess-prf-cam{camera}-ccd{ccd}-sec1.fits" @@ -187,7 +190,7 @@ def get_tess_prf_file(camera: int, ccd: int, sector: int = 4, cache_dir: str = C f"No local files found, building TESS PRF for Camera {camera}, CCD {ccd}." ) build_tess_prf_file(camera=camera, ccd=ccd, sector=sector, cache_dir=cache_dir) - + hdulist = fitsio.FITS(file_path) return hdulist diff --git a/src/lkprf/keplerprf.py b/src/lkprf/keplerprf.py index 89304f0..5551204 100644 --- a/src/lkprf/keplerprf.py +++ b/src/lkprf/keplerprf.py @@ -23,20 +23,21 @@ class KeplerPRF(PRF): https://archive.stsci.edu/missions/kepler/commissioning_prfs/ """ - def __init__(self, channel: int, cache_dir: str = PACKAGEDIR + '/data/'): + def __init__(self, channel: int, cache_dir: str = PACKAGEDIR + "/data/"): super().__init__() self.channel = channel self.mission = "Kepler" self.cache_dir = cache_dir self._prepare_prf() - def __repr__(self): return f"KeplerPRF Object [Channel {self.channel}]" def _get_prf_data(self): module, output = channel_to_module_output(self.channel) - return get_kepler_prf_file(module=module, output=output, cache_dir = self.cache_dir) + return get_kepler_prf_file( + module=module, output=output, cache_dir=self.cache_dir + ) def check_coordinates(self, targets: List[Tuple], shape: Tuple): row, column = self._unpack_targets(targets) @@ -63,7 +64,7 @@ def check_coordinates(self, targets: List[Tuple], shape: Tuple): LKPRFWarning, ) return - + def _prepare_supersamp_prf(self, targets: List[Tuple], shape: Tuple): row, column = self._unpack_targets(targets) # Set the row and column for the model @@ -86,9 +87,10 @@ def _prepare_supersamp_prf(self, targets: List[Tuple], shape: Tuple): # Kepler has 5 measurements, so nearest 3 triangulates the measurement prf_weights = [ np.sqrt( - (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2) - for i in range(self.PRFdata.shape[0]) - ] + (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2 + ) + for i in range(self.PRFdata.shape[0]) + ] idx = np.argpartition(prf_weights, 3)[:3] for i in idx: @@ -96,13 +98,12 @@ def _prepare_supersamp_prf(self, targets: List[Tuple], shape: Tuple): prf_weights[i] = min_prf_weight supersamp_prf += self.PRFdata[i] / prf_weights[i] - supersamp_prf /= np.nansum(supersamp_prf) * self.cdelt1p[0] * self.cdelt2p[0] # Set up the interpolation function self.interpolate = RectBivariateSpline(self.PRFrow, self.PRFcol, supersamp_prf) return - + def _update_coordinates(self, targets: List[Tuple], shape: Tuple): row, column = self._unpack_targets(targets) # Set the row and column for the model @@ -123,9 +124,10 @@ def _update_coordinates(self, targets: List[Tuple], shape: Tuple): # Kepler has 5 measurements, so nearest 3 triangulates the measurement prf_weights = [ np.sqrt( - (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2) - for i in range(self.PRFdata.shape[0]) - ] + (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2 + ) + for i in range(self.PRFdata.shape[0]) + ] idx = np.argpartition(prf_weights, 3)[:3] for i in idx: @@ -133,7 +135,6 @@ def _update_coordinates(self, targets: List[Tuple], shape: Tuple): prf_weights[i] = min_prf_weight supersamp_prf += self.PRFdata[i] / prf_weights[i] - supersamp_prf /= np.nansum(supersamp_prf) * self.cdelt1p[0] * self.cdelt2p[0] self.interpolate = RectBivariateSpline(self.PRFrow, self.PRFcol, supersamp_prf) return diff --git a/src/lkprf/prfmodel.py b/src/lkprf/prfmodel.py index 8c8d7d0..946e6b9 100644 --- a/src/lkprf/prfmodel.py +++ b/src/lkprf/prfmodel.py @@ -67,7 +67,7 @@ def _evaluate( The (row, column) origin of the image in pixels. Combined with shape this sets the extent of the image. shape : Tuple - The (N_row, N_col) shape of the image. + The (N_row, N_col) shape of the image. Combined with the origin this sets the extent of the image. Returns @@ -76,8 +76,8 @@ def _evaluate( Three dimensional array representing the PRF values parametrized by flux and centroids. Has shape (ntargets, shape[0], shape[1]) """ - - #self.update_coordinates(targets=targets, shape=shape) + + # self.update_coordinates(targets=targets, shape=shape) target_row, target_column = self._unpack_targets(targets) # Integer extent from the PRF model @@ -197,7 +197,7 @@ def _prepare_prf(self): """ hdulist = self._get_prf_data() - self.date = hdulist[0].read_header()['DATE'] + self.date = hdulist[0].read_header()["DATE"] PRFdata, crval1p, crval2p, cdelt1p, cdelt2p = [], [], [], [], [] for hdu in hdulist[1:]: PRFdata.append(hdu.read()) @@ -223,7 +223,6 @@ def _prepare_prf(self): PRFcol = (PRFcol - np.size(PRFcol) / 2) * cdelt1p[0] PRFrow = (PRFrow - np.size(PRFrow) / 2) * cdelt2p[0] - ( self.PRFrow, self.PRFcol, @@ -234,8 +233,6 @@ def _prepare_prf(self): self.cdelt2p, ) = (PRFrow, PRFcol, PRFdata, crval1p, crval2p, cdelt1p, cdelt2p) - - @abstractmethod def check_coordinates(self, targets, shape): """Method to check if selected pxels contain collatoral pixels @@ -251,4 +248,4 @@ def _prepare_supersamp_prf(self, targets, shape): This method sets up the RectBivariateSpline function to interpolate the supersampled PRF """ - pass \ No newline at end of file + pass diff --git a/src/lkprf/tessprf.py b/src/lkprf/tessprf.py index 0d7ca8c..96eddc1 100644 --- a/src/lkprf/tessprf.py +++ b/src/lkprf/tessprf.py @@ -14,9 +14,15 @@ class TESSPRF(PRF): """A TESSPRF class. The TESS PRF measurements are supersampled by a factor of 9. - Two PRF models were produced, one for sectors 1-3 and a second set for sectors 4+ """ - - def __init__(self, camera: int, ccd: int, sector: int = 4, cache_dir: str = PACKAGEDIR + '/data/'): + Two PRF models were produced, one for sectors 1-3 and a second set for sectors 4+""" + + def __init__( + self, + camera: int, + ccd: int, + sector: int = 4, + cache_dir: str = PACKAGEDIR + "/data/", + ): super().__init__() self.camera = camera self.ccd = ccd @@ -29,7 +35,12 @@ def __repr__(self): return f"TESSPRF Object [Camera {self.camera}, CCD {self.ccd}, Sector {self.sector}]" def _get_prf_data(self): - return get_tess_prf_file(camera=self.camera, ccd=self.ccd, sector=self.sector, cache_dir=self.cache_dir) + return get_tess_prf_file( + camera=self.camera, + ccd=self.ccd, + sector=self.sector, + cache_dir=self.cache_dir, + ) def check_coordinates(self, targets: List[Tuple], shape: Tuple): row, column = self._unpack_targets(targets) @@ -54,11 +65,10 @@ def check_coordinates(self, targets: List[Tuple], shape: Tuple): ) return - def _prepare_supersamp_prf(self, targets: List[Tuple], shape: Tuple): row, column = self._unpack_targets(targets) - # Set the row and column for the model. + # Set the row and column for the model. # Create one supersampled PRF for each image, used for all targets in the image row, column = np.atleast_1d(row), np.atleast_1d(column) @@ -77,9 +87,10 @@ def _prepare_supersamp_prf(self, targets: List[Tuple], shape: Tuple): # Find the 4 measured PRF models nearest the target location prf_weights = [ np.sqrt( - (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2) - for i in range(self.PRFdata.shape[0]) - ] + (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2 + ) + for i in range(self.PRFdata.shape[0]) + ] idx = np.argpartition(prf_weights, 4)[:4] for i in idx: @@ -87,17 +98,15 @@ def _prepare_supersamp_prf(self, targets: List[Tuple], shape: Tuple): prf_weights[i] = min_prf_weight supersamp_prf += self.PRFdata[i] / prf_weights[i] - supersamp_prf /= np.nansum(supersamp_prf) * self.cdelt1p[0] * self.cdelt2p[0] - + # Set up the interpolation function self.interpolate = RectBivariateSpline(self.PRFrow, self.PRFcol, supersamp_prf) return - def _update_coordinates(self, targets: List[Tuple], shape: Tuple): row, column = self._unpack_targets(targets) - # Set the row and column for the model. + # Set the row and column for the model. # Disallows models in the collateral pixels row, column = np.atleast_1d(row), np.atleast_1d(column) row = np.min([np.max([row, row**0 * 0], axis=0), row**0 * 2048], axis=0).mean() @@ -115,9 +124,10 @@ def _update_coordinates(self, targets: List[Tuple], shape: Tuple): # Find the 4 measurements nearest the desired locations prf_weights = [ np.sqrt( - (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2) - for i in range(self.PRFdata.shape[0]) - ] + (ref_column - self.crval1p[i]) ** 2 + (ref_row - self.crval2p[i]) ** 2 + ) + for i in range(self.PRFdata.shape[0]) + ] idx = np.argpartition(prf_weights, 4)[:4] for i in idx: @@ -125,7 +135,6 @@ def _update_coordinates(self, targets: List[Tuple], shape: Tuple): prf_weights[i] = min_prf_weight supersamp_prf += self.PRFdata[i] / prf_weights[i] - supersamp_prf /= np.nansum(supersamp_prf) * self.cdelt1p[0] * self.cdelt2p[0] self.interpolate = RectBivariateSpline(self.PRFrow, self.PRFcol, supersamp_prf) return From 8c84481c41723340393945231af2a4d843bff17f Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 16:27:01 -0400 Subject: [PATCH 06/10] Change numpy requirement --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index fa95b9c..6f45d5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ packages = [{include = "lkprf", from = "src"}] [tool.poetry.dependencies] python = ">=3.8.1,<4.0" scipy = ">=1.8.0" +numpy = ">=1.20.0,<2.0.0" fitsio = "^1.2.4" requests = "^2.32.3" From 4eb1960630bd3c27c30acad1ad071279641983b8 Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 16:27:51 -0400 Subject: [PATCH 07/10] Update minor version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6f45d5c..f95508d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "lkprf" -version = "1.1.0" +version = "1.1.1" description = "" authors = ["TESS Science Support Center , Christina Hedges "] license = "MIT" From b6df7daeccc47895b520062de597b04ec874f793 Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 16:28:58 -0400 Subject: [PATCH 08/10] Update requirements --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1549e08..b3cde5a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,7 @@ +1.1.1 (2024-09-24) +===================== +- Updated pyproject.toml + 1.1.0 (2024-09-24) ===================== From 831b9974161c4099dd415c2901bf7b7c362d20ad Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 16:29:20 -0400 Subject: [PATCH 09/10] Update minor version --- src/lkprf/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lkprf/version.py b/src/lkprf/version.py index d56e88c..9d71a96 100644 --- a/src/lkprf/version.py +++ b/src/lkprf/version.py @@ -1,3 +1,3 @@ # It is important to store the version number in a separate file # so that we can read it without importing the package -__version__ = "1.1.0" +__version__ = "1.1.1" From 681e523bace2d6adfe82485ed016f640989b421e Mon Sep 17 00:00:00 2001 From: Nschanche Date: Tue, 24 Sep 2024 16:55:55 -0400 Subject: [PATCH 10/10] Update README.md --- docs/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/README.md b/docs/README.md index d282231..23e9147 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,6 +20,8 @@ You can install lkprf using pip: pip install lkprf --upgrade ``` +> :question: **Note**: If installing in a new environment you may run into issues with the fitsio build that causes an installation error. If so, you can pip install numpy< 2.0.0 first, then pip install lkprf. + ## Usage > :question: **Note**: `lkprf` uses tuples to specify positions and uses the Python convention of `(row, column)`.