diff --git a/obstools/__init__.py b/obstools/__init__.py index e84a32b..c2af11c 100644 --- a/obstools/__init__.py +++ b/obstools/__init__.py @@ -8,8 +8,7 @@ # # @author: tbowers -"""Init File -""" +"""Init File""" # Imports for signal and log handling diff --git a/obstools/neocp_ephem.py b/obstools/neocp_ephem.py index a90bf77..29c4d67 100644 --- a/obstools/neocp_ephem.py +++ b/obstools/neocp_ephem.py @@ -87,7 +87,7 @@ .. warning:: This module is not yet functional! - + """ # Built-In Libraries diff --git a/obstools/scrub_deveny_pickup.py b/obstools/scrub_deveny_pickup.py index 2b50d2c..b8a2ec0 100644 --- a/obstools/scrub_deveny_pickup.py +++ b/obstools/scrub_deveny_pickup.py @@ -60,7 +60,7 @@ import ccdproc.utils.slices import matplotlib.pyplot as plt import numpy as np -from pypeit import msgs +from pypeit import log import pypeit.spec2dobj import scipy.fft import scipy.ndimage @@ -135,7 +135,7 @@ def iterative_pypeit_clean( )[0] except (StopIteration, IndexError): # And... fail. - msgs.warn( + log.warning( f"File {filename.name} does not have a corresponding PypeIt-processed 2D spectrum. " "Check the image type and whether you have `run_pypeit`." ) @@ -1012,7 +1012,9 @@ def package_into_fits( suffix (Default: False) """ # Add a little history - time_str = datetime.datetime.utcnow().isoformat(sep=" ", timespec="seconds") + time_str = datetime.datetime.now(datetime.UTC).isoformat( + sep=" ", timespec="seconds" + ) history_str = f"Written by package obstools: {time_str} UTC" # For the image HDUs, include a basic header img_hdr = astropy.io.fits.Header({"BUNIT": "ADU", "HISTORY": history_str}) diff --git a/obstools/tests/test_celestial_time.py b/obstools/tests/test_celestial_time.py index 2f712aa..d508107 100644 --- a/obstools/tests/test_celestial_time.py +++ b/obstools/tests/test_celestial_time.py @@ -11,8 +11,7 @@ # @author: tbowers # pylint: disable=missing-function-docstring -"""Celestial Time Utilities TEST Module -""" +"""Celestial Time Utilities TEST Module""" import numpy as np import pytest diff --git a/obstools/tests/test_deveny_grangle.py b/obstools/tests/test_deveny_grangle.py index 5dbdb6f..3206cf7 100644 --- a/obstools/tests/test_deveny_grangle.py +++ b/obstools/tests/test_deveny_grangle.py @@ -11,8 +11,7 @@ # @author: tbowers # pylint: disable=missing-function-docstring -"""DeVeny Grating Angle Calculator TEST Module -""" +"""DeVeny Grating Angle Calculator TEST Module""" import numpy as np diff --git a/obstools/tests/test_lmi_etc.py b/obstools/tests/test_lmi_etc.py index 66d4722..8d24c67 100644 --- a/obstools/tests/test_lmi_etc.py +++ b/obstools/tests/test_lmi_etc.py @@ -11,8 +11,7 @@ # @author: tbowers # pylint: disable=missing-function-docstring -"""LMI Exposure Time Calculator TEST Module -""" +"""LMI Exposure Time Calculator TEST Module""" import numpy as np import pytest diff --git a/obstools/tests/test_utils.py b/obstools/tests/test_utils.py index 52b18b0..4b538ca 100644 --- a/obstools/tests/test_utils.py +++ b/obstools/tests/test_utils.py @@ -11,8 +11,7 @@ # @author: tbowers # pylint: disable=missing-function-docstring -"""Utility TEST Module -""" +"""Utility TEST Module""" from obstools import utils @@ -37,7 +36,17 @@ def test_first_moment_1d(): def test_flatten_comprehension(): - pass + nested_str = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]] + flat_str = utils.flatten_comprehension(nested_str) + assert flat_str == ["a", "b", "c", "d", "e", "f", "g", "h", "i"] + # Add other types of tests here... + + +def test_flatten_itertools(): + nested_str = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]] + flat_str = utils.flatten_itertools(nested_str) + assert flat_str == ["a", "b", "c", "d", "e", "f", "g", "h", "i"] + # Add other types of tests here... def test_gaussfit(): diff --git a/obstools/utils.py b/obstools/utils.py index 8bfc394..7c8227c 100644 --- a/obstools/utils.py +++ b/obstools/utils.py @@ -25,6 +25,7 @@ import argparse from functools import reduce from importlib import resources +import itertools import pathlib import textwrap import sys @@ -139,6 +140,22 @@ def flatten_comprehension(nested_list: list[list]) -> list: return [item for row in nested_list for item in row] +def flatten_itertools(nested_list: list[list]) -> list: + """Flatten a single-depth nested list via itertools + + Parameters + ---------- + nested_list : :obj:`list` + The single-depth nested list to flatten + + Returns + ------- + :obj:`list` + The flattened list + """ + return [item for item in itertools.chain.from_iterable(nested_list)] + + def gaussfit( x: np.ndarray, y: np.ndarray, diff --git a/setup.cfg b/setup.cfg index ecb27ba..e7bb080 100644 --- a/setup.cfg +++ b/setup.cfg @@ -73,7 +73,8 @@ dev = sphinx_rtd_theme<3 pylint black - pypeit[specutils]>=1.15.0 + # pypeit[specutils]>=1.15.0 + pypeit[specutils] @ git+https://github.com/pypeit/PypeIt.git@develop pyyaml stomp.py xmltodict