From 65bcf2baeca9a88049108e7b55b09a392fc4998a Mon Sep 17 00:00:00 2001 From: "Timothy P. Ellsworth Bowers" Date: Wed, 5 Nov 2025 12:32:21 -0700 Subject: [PATCH 1/5] Modernize modified: obstools/scrub_deveny_pickup.py modified: obstools/utils.py --- obstools/scrub_deveny_pickup.py | 4 ++-- obstools/utils.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/obstools/scrub_deveny_pickup.py b/obstools/scrub_deveny_pickup.py index 2b50d2c..30ee0ac 100644 --- a/obstools/scrub_deveny_pickup.py +++ b/obstools/scrub_deveny_pickup.py @@ -127,7 +127,7 @@ def iterative_pypeit_clean( try: # Look for the spec2d file - spec2d_file = utils.flatten_comprehension( + spec2d_file = utils.flatten_itertools( [ sorted(d.joinpath("Science").glob(f"spec2d_{filename.stem}-*.fits")) for d in pyp_dir @@ -1012,7 +1012,7 @@ 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/utils.py b/obstools/utils.py index 8bfc394..8cca85d 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 [itertools.chain.from_iterable(nested_list)] + + def gaussfit( x: np.ndarray, y: np.ndarray, From 131619718497b5d4c21b1e5d67c19f092e985a97 Mon Sep 17 00:00:00 2001 From: "Timothy P. Ellsworth Bowers" Date: Tue, 3 Feb 2026 11:56:48 -0700 Subject: [PATCH 2/5] Remove pypeit.msgs --- obstools/scrub_deveny_pickup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/obstools/scrub_deveny_pickup.py b/obstools/scrub_deveny_pickup.py index 30ee0ac..348bc06 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 msgs import pypeit.spec2dobj import scipy.fft import scipy.ndimage @@ -135,10 +135,10 @@ def iterative_pypeit_clean( )[0] except (StopIteration, IndexError): # And... fail. - msgs.warn( - f"File {filename.name} does not have a corresponding PypeIt-processed 2D spectrum. " - "Check the image type and whether you have `run_pypeit`." - ) + # msgs.warn( + # f"File {filename.name} does not have a corresponding PypeIt-processed 2D spectrum. " + # "Check the image type and whether you have `run_pypeit`." + # ) return # Define (and create, if needed) the QA directory for these plots qa_dir = spec2d_file.parents[1] / "QA" / "PDFs" From 103cf4d3b471537c41f4cfe2483b9f1e4ca2cb42 Mon Sep 17 00:00:00 2001 From: "Timothy P. Ellsworth Bowers" Date: Tue, 3 Feb 2026 12:15:56 -0700 Subject: [PATCH 3/5] Fix typo in scrubber --- obstools/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obstools/utils.py b/obstools/utils.py index 8cca85d..7c8227c 100644 --- a/obstools/utils.py +++ b/obstools/utils.py @@ -153,7 +153,7 @@ def flatten_itertools(nested_list: list[list]) -> list: :obj:`list` The flattened list """ - return [itertools.chain.from_iterable(nested_list)] + return [item for item in itertools.chain.from_iterable(nested_list)] def gaussfit( From ccd25daecfe9b3e4a0f817cd78543cc4cc833e75 Mon Sep 17 00:00:00 2001 From: "Timothy P. Ellsworth Bowers" Date: Tue, 3 Feb 2026 12:22:19 -0700 Subject: [PATCH 4/5] Add test / Blacked things --- obstools/__init__.py | 3 +-- obstools/neocp_ephem.py | 2 +- obstools/scrub_deveny_pickup.py | 5 ++++- obstools/tests/test_celestial_time.py | 3 +-- obstools/tests/test_deveny_grangle.py | 3 +-- obstools/tests/test_lmi_etc.py | 3 +-- obstools/tests/test_utils.py | 9 +++++++-- 7 files changed, 16 insertions(+), 12 deletions(-) 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 348bc06..288a2b6 100644 --- a/obstools/scrub_deveny_pickup.py +++ b/obstools/scrub_deveny_pickup.py @@ -60,6 +60,7 @@ import ccdproc.utils.slices import matplotlib.pyplot as plt import numpy as np + # from pypeit import msgs import pypeit.spec2dobj import scipy.fft @@ -1012,7 +1013,9 @@ def package_into_fits( suffix (Default: False) """ # Add a little history - time_str = datetime.datetime.now(datetime.UTC).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..ebd1677 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 @@ -40,6 +39,12 @@ def test_flatten_comprehension(): pass +def test_flatten_itertools(): + nested_str = [["a", "b", "c"], ["d"], ["e"], ["f"], ["g"]] + flat_str = utils.flatten_itertools(nested_str) + assert flat_str == ["a", "b", "c", "d", "e", "f", "g"] + # Add other types of tests here... + def test_gaussfit(): pass From ddd48b2463eda5f49314c494d29d2a0e24f649c1 Mon Sep 17 00:00:00 2001 From: "Timothy P. Ellsworth Bowers" Date: Tue, 3 Feb 2026 12:35:58 -0700 Subject: [PATCH 5/5] Trying to debug... --- obstools/scrub_deveny_pickup.py | 13 ++++++------- obstools/tests/test_utils.py | 10 +++++++--- setup.cfg | 3 ++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/obstools/scrub_deveny_pickup.py b/obstools/scrub_deveny_pickup.py index 288a2b6..b8a2ec0 100644 --- a/obstools/scrub_deveny_pickup.py +++ b/obstools/scrub_deveny_pickup.py @@ -60,8 +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 @@ -128,7 +127,7 @@ def iterative_pypeit_clean( try: # Look for the spec2d file - spec2d_file = utils.flatten_itertools( + spec2d_file = utils.flatten_comprehension( [ sorted(d.joinpath("Science").glob(f"spec2d_{filename.stem}-*.fits")) for d in pyp_dir @@ -136,10 +135,10 @@ def iterative_pypeit_clean( )[0] except (StopIteration, IndexError): # And... fail. - # msgs.warn( - # f"File {filename.name} does not have a corresponding PypeIt-processed 2D spectrum. " - # "Check the image type and whether you have `run_pypeit`." - # ) + 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`." + ) return # Define (and create, if needed) the QA directory for these plots qa_dir = spec2d_file.parents[1] / "QA" / "PDFs" diff --git a/obstools/tests/test_utils.py b/obstools/tests/test_utils.py index ebd1677..4b538ca 100644 --- a/obstools/tests/test_utils.py +++ b/obstools/tests/test_utils.py @@ -36,15 +36,19 @@ 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"]] + 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"] + assert flat_str == ["a", "b", "c", "d", "e", "f", "g", "h", "i"] # Add other types of tests here... + def test_gaussfit(): pass 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