Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image data handling refactor #228

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
12eb705
fix input for background.traces, raise error in FlatTrace for negativ…
cshanahan1 Feb 20, 2024
d4d528d
rtd fixes
cshanahan1 Sep 18, 2024
9d20d12
Changed `_ImageParser._mask_and_nonfinite_data_handling` into a stati…
hpparvi Nov 3, 2024
ca9d9aa
Fixed a minor typo in mask_treatment docstring.
hpparvi Nov 3, 2024
4fed07d
Added a mask treatment method as an optional argument to `_ImageParse…
hpparvi Nov 3, 2024
6ccb457
Updated image parsing method in BoxcarExtract.
hpparvi Nov 3, 2024
340d866
Fixed too long lines.
hpparvi Nov 3, 2024
6f2dbd3
Updated _InmageParser._parse_image method call to include disp_axis a…
hpparvi Nov 4, 2024
c115357
Added a small comment to '_ImageParser' about 'implemented_mask_treat…
hpparvi Nov 4, 2024
a7553ee
Updated _InmageParser._parse_image method call to include disp_axis a…
hpparvi Nov 4, 2024
1cb42aa
Changed 'TestMaskTracing.test_array_trace_masking' to use 'pytest.war…
hpparvi Nov 4, 2024
039faf4
MNT: Use hash for Action workflow versions and update if needed
pllim Sep 27, 2024
20b8466
Create dependabot.yml
pllim Sep 27, 2024
6e61444
Created a 'specreduce.image.Image' class that can replace the 'specre…
hpparvi Nov 5, 2024
7ca476d
Added some sanity checks to the Image class.
hpparvi Nov 5, 2024
d2f4645
Renamed Image class to SRImage and enhanced axis handling.
hpparvi Nov 6, 2024
a314aa2
Renamed some SRImage properties.
hpparvi Nov 6, 2024
ebf0cd6
Refactored SRImage initialization and axis handling.
hpparvi Nov 7, 2024
9a7d869
Added the first SRImage tests.
hpparvi Nov 7, 2024
e5bc07b
Refactored `Background` class to use `SRImage` for image handling
hpparvi Nov 8, 2024
67ac821
Refactored the Tracing classes to use the `SRImage` class instead of …
hpparvi Nov 9, 2024
6363128
Added `size_disp_axis` and `size_crossdisp_axis` properties to the `S…
hpparvi Nov 10, 2024
3d6cf89
Finalising the image handling refactoring for the Trace and Extract c…
hpparvi Nov 11, 2024
b768d0c
Improved the 'SRImage' class uncertainty handling.
hpparvi Nov 11, 2024
eace0ae
Refactored the image handling logic to further use the SRImage class,…
hpparvi Nov 11, 2024
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
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: ".github/workflows" # Location of package manifests
schedule:
interval: "monthly"
groups:
actions:
patterns:
- "*"
2 changes: 1 addition & 1 deletion .github/workflows/cron-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrency:
jobs:
tests:
if: (github.repository == 'astropy/specreduce' && (github.event_name == 'schedule' || github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'Extra CI')))
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@924441154cf3053034c6513d5e06c69d262fb9a6 # v1.13.0
with:
submodules: false
coverage: ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
publish:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@924441154cf3053034c6513d5e06c69d262fb9a6 # v1.13.0
# NOTE: Uncomment "if" if you do not want this to run for every PR.
# if: ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) || contains(github.event.pull_request.labels.*.name, 'Build wheels'))
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:

jobs:
tests:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@924441154cf3053034c6513d5e06c69d262fb9a6 # v1.13.0
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV }}
with:
Expand Down
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ Bug Fixes
peaks. Previously for Gaussian, the entire fit failed. [#205, #206]

- Fixed input of `traces` in `Background`. Added a condition to 'FlatTrace' that
trace position must be a positive number. [#211]

- Fix in FitTrace to set fully-masked column bin peaks to NaN. Previously, for
peak_method='max' these were set to 0.0, and for peak_method='centroid' they
were set to the number of rows in the image, biasing the final fit to all bin
peaks. [#206]


Other changes
^^^^^^^^^^^^^
Expand Down
179 changes: 106 additions & 73 deletions specreduce/background.py

Large diffs are not rendered by default.

83 changes: 2 additions & 81 deletions specreduce/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from copy import deepcopy
import inspect
from dataclasses import dataclass

Expand All @@ -11,88 +12,8 @@
__all__ = ['SpecreduceOperation']


class _ImageParser:
"""
Coerces images from accepted formats to Spectrum1D objects for
internal use in specreduce's operation classes.

Fills any and all of uncertainty, mask, units, and spectral axis
that are missing in the provided image with generic values.
Accepted image types are:

- `~specutils.spectra.spectrum1d.Spectrum1D` (preferred)
- `~astropy.nddata.ccddata.CCDData`
- `~astropy.nddata.ndddata.NDDData`
- `~astropy.units.quantity.Quantity`
- `~numpy.ndarray`
"""

def _parse_image(self, image, disp_axis=1):
"""
Convert all accepted image types to a consistently formatted
Spectrum1D object.

Parameters
----------
image : `~astropy.nddata.NDData`-like or array-like, required
The image to be parsed. If None, defaults to class' own
image attribute.
disp_axis : int, optional
The index of the image's dispersion axis. Should not be
changed until operations can handle variable image
orientations. [default: 1]
"""

# would be nice to handle (cross)disp_axis consistently across
# operations (public attribute? private attribute? argument only?) so
# it can be called from self instead of via kwargs...

if image is None:
# useful for Background's instance methods
return self.image

img = self._get_data_from_image(image, disp_axis=disp_axis)

return img

@staticmethod
def _get_data_from_image(image, disp_axis=1):
"""Extract data array from various input types for `image`.
Retruns `np.ndarray` of image data."""

if isinstance(image, u.quantity.Quantity):
img = image.value
elif isinstance(image, np.ndarray):
img = image
else: # NDData, including CCDData and Spectrum1D
img = image.data

# mask and uncertainty are set as None when they aren't specified upon
# creating a Spectrum1D object, so we must check whether these
# attributes are absent *and* whether they are present but set as None
if getattr(image, 'mask', None) is not None:
mask = image.mask
else:
mask = ~np.isfinite(img)

if getattr(image, 'uncertainty', None) is not None:
uncertainty = image.uncertainty
else:
uncertainty = VarianceUncertainty(np.ones(img.shape))

unit = getattr(image, 'unit', u.Unit('DN'))

spectral_axis = getattr(image, 'spectral_axis',
np.arange(img.shape[disp_axis]) * u.pix)

return Spectrum1D(img * unit, spectral_axis=spectral_axis,
uncertainty=uncertainty, mask=mask)

return img


@dataclass
class SpecreduceOperation(_ImageParser):
class SpecreduceOperation:
"""
An operation to perform as part of a spectroscopic reduction pipeline.

Expand Down
Loading
Loading