From c6bb62cc1e3bf196d2497f20c2a5e8a95efa6bcc Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 05:39:36 -0400 Subject: [PATCH 01/12] Error handling implemented on CubeFactory --- astrocut/make_cube.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index e8374275..5224ee06 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -85,7 +85,10 @@ def _configure_cube(self, file_list, **extra_keywords): # Working out the block size and number of blocks needed for writing the cube # without using too much memory - slice_size = image_shape[1] * len(self.file_list) * 2 * 4 # in bytes (float32) + try: + slice_size = image_shape[1] * len(self.file_list) * 2 * 4 # in bytes (float32) + except IndexError: + raise ValueError("One or more TICA FFIs were input. Please use ``TicaCubeFactory`` class to process TICA FFIs.") max_block_size = int((self.max_memory * 1e9)//slice_size) self.num_blocks = int(image_shape[0]/max_block_size + 1) @@ -310,7 +313,7 @@ def make_cube(self, file_list, cube_file="img-cube.fits", sector=None, max_memor # Set up the basic cube parameters sector = (sector, "Observing sector") - + self._configure_cube(file_list, sector=sector) if verbose: From bdeacb6249d86b6d593d01b674d5cfccff024344 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 05:52:12 -0400 Subject: [PATCH 02/12] Error handling for TicaCubeFactory --- astrocut/make_cube.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index 5224ee06..8f4d9da5 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -88,7 +88,7 @@ def _configure_cube(self, file_list, **extra_keywords): try: slice_size = image_shape[1] * len(self.file_list) * 2 * 4 # in bytes (float32) except IndexError: - raise ValueError("One or more TICA FFIs were input. Please use ``TicaCubeFactory`` class to process TICA FFIs.") + raise ValueError("One or more TICA FFIs were input. Please use ``TicaCubeFactory`` to process TICA FFIs.") max_block_size = int((self.max_memory * 1e9)//slice_size) self.num_blocks = int(image_shape[0]/max_block_size + 1) @@ -408,7 +408,10 @@ def _configure_cube(self, file_list, **extra_keywords): start_times[i] = ffi_data[0].header.get(self.time_keyword) if image_shape is None: # Only need to fill this once - image_shape = ffi_data[0].data.shape + try: + image_shape = ffi_data[0].data.shape + except AttributeError: + raise ValueError("One or more SPOC FFIs were input. Please use ``CubeFactory`` to process SPOC FFIs.") if self.template_file is None: # Only check this if we don't already have it From fb76eca9274fac9354ed075e2b0b8f0bd9e7c05c Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 06:00:09 -0400 Subject: [PATCH 03/12] codestyle --- astrocut/make_cube.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index 8f4d9da5..40102d77 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -411,7 +411,8 @@ def _configure_cube(self, file_list, **extra_keywords): try: image_shape = ffi_data[0].data.shape except AttributeError: - raise ValueError("One or more SPOC FFIs were input. Please use ``CubeFactory`` to process SPOC FFIs.") + raise ValueError("One or more SPOC FFIs were input. Please use ``CubeFactory``\ + to process SPOC FFIs.") if self.template_file is None: # Only check this if we don't already have it From 07c8173e313586eb08bde50dd3643b8cfceb5c17 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 13:57:15 -0400 Subject: [PATCH 04/12] New unit tests to verify error handling --- astrocut/make_cube.py | 4 ++-- astrocut/tests/test_make_cube.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index 40102d77..607b7b61 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -407,12 +407,12 @@ def _configure_cube(self, file_list, **extra_keywords): start_times[i] = ffi_data[0].header.get(self.time_keyword) + error_msg = "One or more SPOC FFIs were input. Please use ``CubeFactory`` to process SPOC FFIs." if image_shape is None: # Only need to fill this once try: image_shape = ffi_data[0].data.shape except AttributeError: - raise ValueError("One or more SPOC FFIs were input. Please use ``CubeFactory``\ - to process SPOC FFIs.") + raise ValueError(error_msg) if self.template_file is None: # Only check this if we don't already have it diff --git a/astrocut/tests/test_make_cube.py b/astrocut/tests/test_make_cube.py index 15dc54c7..5dddcaad 100644 --- a/astrocut/tests/test_make_cube.py +++ b/astrocut/tests/test_make_cube.py @@ -1,8 +1,11 @@ import numpy as np import os +import pytest +from astropy.coordinates import SkyCoord from astropy.io import fits from astropy.table import Table +from astroquery.mast import Observations from re import findall from os import path @@ -167,7 +170,37 @@ def test_iteration(tmpdir, capsys): assert np.alltrue(cube_1 == ecube), "Cube values do not match expected values" + +@pytest.mark.parametrize("ffi_type", ["TICA", "SPOC"]) +def test_invalid_inputs(tmpdir, ffi_type): + + coordinates = SkyCoord(289.0979, -29.3370, unit="deg") + + # Assigning some variables + target_name = "TICA FFI" if ffi_type == "TICA" else "TESS FFI" + class_name = "``TicaCubeFactory``" if ffi_type == "TICA" else "``CubeFactory``" + value_error = f"One or more {ffi_type} FFIs were input. Please use {class_name} to process {ffi_type} FFIs." + + # Getting TESS sector 27 observations for the given coordinate + observations = Observations.query_criteria(coordinates=coordinates, + target_name=target_name, + dataproduct_type="image", + sequence_number=27) + # Getting a list of products. Keeping it small so we don't have to download so many. + products = Observations.get_product_list(observations[0])[:2] + + manifest = Observations.download_products(products, download_dir=tmpdir) + + if ffi_type == "TICA": + cube_maker = CubeFactory() + elif ffi_type == "SPOC": + cube_maker = TicaCubeFactory() + + with pytest.raises(ValueError) as error_msg: + cube_maker.make_cube(manifest["Local Path"]) + assert value_error in str(error_msg.value) + From ab4eff08c048e661a56cbc005e9cc73dc7637355 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 14:29:54 -0400 Subject: [PATCH 05/12] Adding astroquery as a dependency --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index cb71838c..56bdd7de 100644 --- a/tox.ini +++ b/tox.ini @@ -38,6 +38,7 @@ description = astropy52: with astropy 5.2.* numpy120: with numpy 1.20.* numpy123: with numpy 1.23.* + astroquery04: with astroquery 0.4.* # The following provides some specific pinnings for key packages deps = @@ -46,6 +47,8 @@ deps = astropy52: astropy==5.2.* + astroquery04: astroquery==0.4.* + devdeps: git+https://github.com/numpy/numpy.git#egg=numpy devdeps: git+https://github.com/astropy/astropy.git#egg=astropy From 9182656dde8cd0f9e9dca6b551ac9c40343815dc Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 14:35:09 -0400 Subject: [PATCH 06/12] . --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index fa077354..708f8c23 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,6 +17,7 @@ python_requires = >=3.6 setup_requires = setuptools_scm install_requires = astropy>=5.2 # astropy with s3fs support + astroquery>=0.4.6 # for testing fsspec[http]>=2022.8.2 # for remote cutouts s3fs>=2022.8.2 # for remote cutouts scipy From fa24b2675f3ddd7999f3c904ac60d81671cb3343 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 14:54:19 -0400 Subject: [PATCH 07/12] . --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 56bdd7de..23fdfe53 100644 --- a/tox.ini +++ b/tox.ini @@ -51,6 +51,7 @@ deps = devdeps: git+https://github.com/numpy/numpy.git#egg=numpy devdeps: git+https://github.com/astropy/astropy.git#egg=astropy + devdeps: git+https://github.com/astropy/astroquery.git # The following indicates which extras_require from setup.cfg will be installed extras = From 520c57fbca7fccb97d697ae1e2bc0d055a8259ee Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 15:16:45 -0400 Subject: [PATCH 08/12] . --- astrocut/tests/test_make_cube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrocut/tests/test_make_cube.py b/astrocut/tests/test_make_cube.py index 5dddcaad..52cb4f1c 100644 --- a/astrocut/tests/test_make_cube.py +++ b/astrocut/tests/test_make_cube.py @@ -190,7 +190,7 @@ def test_invalid_inputs(tmpdir, ffi_type): # Getting a list of products. Keeping it small so we don't have to download so many. products = Observations.get_product_list(observations[0])[:2] - manifest = Observations.download_products(products, download_dir=tmpdir) + manifest = Observations.download_products(products, download_dir=str(tmpdir)) if ffi_type == "TICA": cube_maker = CubeFactory() From b94cad6e409c142ea358f07ff48cfa878a347b9f Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Fri, 14 Jul 2023 15:31:45 -0400 Subject: [PATCH 09/12] Astroquery is a dependency required only for testing --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 708f8c23..63bbd98b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,7 +17,6 @@ python_requires = >=3.6 setup_requires = setuptools_scm install_requires = astropy>=5.2 # astropy with s3fs support - astroquery>=0.4.6 # for testing fsspec[http]>=2022.8.2 # for remote cutouts s3fs>=2022.8.2 # for remote cutouts scipy @@ -30,6 +29,7 @@ console_scripts = [options.extras_require] test = pytest-astropy + astroquery>=0.4.6 docs = sphinx != 4.1.0 docutils == 0.16 From b24cd8f7f804244f12694c42776e3004e3040f1e Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Sat, 15 Jul 2023 14:34:15 -0400 Subject: [PATCH 10/12] Making error message more general, and a global variable --- astrocut/make_cube.py | 8 ++++---- astrocut/tests/test_make_cube.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index 607b7b61..d39ad0eb 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -19,7 +19,8 @@ from mmap import MADV_SEQUENTIAL __all__ = ['CubeFactory', 'TicaCubeFactory'] - +ERROR_MSG = "One or more incorrect file types were input. Please input TICA FFI files when using\ + ``TicaCubeFactory``, and SPOC FFI files when using ``CubeFactory``." class CubeFactory(): """ @@ -88,7 +89,7 @@ def _configure_cube(self, file_list, **extra_keywords): try: slice_size = image_shape[1] * len(self.file_list) * 2 * 4 # in bytes (float32) except IndexError: - raise ValueError("One or more TICA FFIs were input. Please use ``TicaCubeFactory`` to process TICA FFIs.") + raise ValueError(ERROR_MSG) max_block_size = int((self.max_memory * 1e9)//slice_size) self.num_blocks = int(image_shape[0]/max_block_size + 1) @@ -407,12 +408,11 @@ def _configure_cube(self, file_list, **extra_keywords): start_times[i] = ffi_data[0].header.get(self.time_keyword) - error_msg = "One or more SPOC FFIs were input. Please use ``CubeFactory`` to process SPOC FFIs." if image_shape is None: # Only need to fill this once try: image_shape = ffi_data[0].data.shape except AttributeError: - raise ValueError(error_msg) + raise ValueError(ERROR_MSG) if self.template_file is None: # Only check this if we don't already have it diff --git a/astrocut/tests/test_make_cube.py b/astrocut/tests/test_make_cube.py index 52cb4f1c..756ee516 100644 --- a/astrocut/tests/test_make_cube.py +++ b/astrocut/tests/test_make_cube.py @@ -178,8 +178,8 @@ def test_invalid_inputs(tmpdir, ffi_type): # Assigning some variables target_name = "TICA FFI" if ffi_type == "TICA" else "TESS FFI" - class_name = "``TicaCubeFactory``" if ffi_type == "TICA" else "``CubeFactory``" - value_error = f"One or more {ffi_type} FFIs were input. Please use {class_name} to process {ffi_type} FFIs." + value_error = "One or more incorrect file types were input. Please input TICA FFI files when using\ + ``TicaCubeFactory``, and SPOC FFI files when using ``CubeFactory``." # Getting TESS sector 27 observations for the given coordinate observations = Observations.query_criteria(coordinates=coordinates, From b2106dbd5a893b192a34bf7c8f723c490794e860 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Sat, 15 Jul 2023 14:36:39 -0400 Subject: [PATCH 11/12] Making error msg even more general --- astrocut/make_cube.py | 3 +-- astrocut/tests/test_make_cube.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index d39ad0eb..457ac49c 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -19,8 +19,7 @@ from mmap import MADV_SEQUENTIAL __all__ = ['CubeFactory', 'TicaCubeFactory'] -ERROR_MSG = "One or more incorrect file types were input. Please input TICA FFI files when using\ - ``TicaCubeFactory``, and SPOC FFI files when using ``CubeFactory``." +ERROR_MSG = "One or more incorrect file types were input." class CubeFactory(): """ diff --git a/astrocut/tests/test_make_cube.py b/astrocut/tests/test_make_cube.py index 756ee516..79d10e83 100644 --- a/astrocut/tests/test_make_cube.py +++ b/astrocut/tests/test_make_cube.py @@ -178,8 +178,7 @@ def test_invalid_inputs(tmpdir, ffi_type): # Assigning some variables target_name = "TICA FFI" if ffi_type == "TICA" else "TESS FFI" - value_error = "One or more incorrect file types were input. Please input TICA FFI files when using\ - ``TicaCubeFactory``, and SPOC FFI files when using ``CubeFactory``." + value_error = "One or more incorrect file types were input." # Getting TESS sector 27 observations for the given coordinate observations = Observations.query_criteria(coordinates=coordinates, From fe010326a76b7a55506c1f8dcb1671feda19b938 Mon Sep 17 00:00:00 2001 From: Jennifer Medina Date: Sat, 15 Jul 2023 14:38:31 -0400 Subject: [PATCH 12/12] . --- astrocut/make_cube.py | 4 +++- astrocut/tests/test_make_cube.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index 457ac49c..f622ea6f 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -19,7 +19,9 @@ from mmap import MADV_SEQUENTIAL __all__ = ['CubeFactory', 'TicaCubeFactory'] -ERROR_MSG = "One or more incorrect file types were input." +ERROR_MSG = "One or more incorrect file types were input. Please input TICA FFI files when using\ + ``TicaCubeFactory``, and SPOC FFI files when using ``CubeFactory``." + class CubeFactory(): """ diff --git a/astrocut/tests/test_make_cube.py b/astrocut/tests/test_make_cube.py index 79d10e83..756ee516 100644 --- a/astrocut/tests/test_make_cube.py +++ b/astrocut/tests/test_make_cube.py @@ -178,7 +178,8 @@ def test_invalid_inputs(tmpdir, ffi_type): # Assigning some variables target_name = "TICA FFI" if ffi_type == "TICA" else "TESS FFI" - value_error = "One or more incorrect file types were input." + value_error = "One or more incorrect file types were input. Please input TICA FFI files when using\ + ``TicaCubeFactory``, and SPOC FFI files when using ``CubeFactory``." # Getting TESS sector 27 observations for the given coordinate observations = Observations.query_criteria(coordinates=coordinates,