diff --git a/astrocut/make_cube.py b/astrocut/make_cube.py index e8374275..f622ea6f 100644 --- a/astrocut/make_cube.py +++ b/astrocut/make_cube.py @@ -19,6 +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(): @@ -85,7 +87,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(ERROR_MSG) max_block_size = int((self.max_memory * 1e9)//slice_size) self.num_blocks = int(image_shape[0]/max_block_size + 1) @@ -310,7 +315,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: @@ -405,7 +410,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(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..756ee516 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" + 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, + 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=str(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) + diff --git a/setup.cfg b/setup.cfg index fa077354..63bbd98b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,6 +29,7 @@ console_scripts = [options.extras_require] test = pytest-astropy + astroquery>=0.4.6 docs = sphinx != 4.1.0 docutils == 0.16 diff --git a/tox.ini b/tox.ini index cb71838c..23fdfe53 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,8 +47,11 @@ 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 + devdeps: git+https://github.com/astropy/astroquery.git # The following indicates which extras_require from setup.cfg will be installed extras =