Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions obstools/scrub_deveny_pickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -127,18 +127,18 @@ 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
]
)[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"
Expand Down Expand Up @@ -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})
Expand Down
17 changes: 17 additions & 0 deletions obstools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import argparse
from functools import reduce
from importlib import resources
import itertools
import pathlib
import textwrap
import sys
Expand Down Expand Up @@ -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,
Expand Down