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
23 changes: 23 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#
import os
import sys
import inspect
import joblib

package_path = os.path.abspath('../')
sys.path.insert(0, package_path)
Expand Down Expand Up @@ -120,3 +122,24 @@
'irispy': ('https://irispy.readthedocs.io/en/stable/', None),
'named_arrays': ('https://named-arrays.readthedocs.io/en/stable/', None)
}


class MemorizedFunc(
joblib.memory.MemorizedFunc,
):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
f = self.func
self.__code__ = f.__code__
self.__name__ = f.__name__
self.__doc__ = f.__doc__
self.__annotations__ = f.__annotations__
self.__defaults__ = f.__defaults__
self.__kwdefaults__ = f.__kwdefaults__


joblib.memory.MemorizedFunc = MemorizedFunc

f = inspect.isfunction
inspect.isfunction = lambda x: f(x) or isinstance(x, joblib.memory.MemorizedFunc)
35 changes: 9 additions & 26 deletions iris/sg/_spectrograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ class SpectrographObservation(
The exposure time for each frame in the observation.
"""

wavelength_center: None | u.Quantity | na.AbstractScalar = None
"""
TThe rest wavelength of the dominant spectral line in the observation.
"""

axis_time: str = "time"
"""The logical axis corresponding to changes in time."""

Expand All @@ -71,16 +66,6 @@ class SpectrographObservation(
axis_detector_y: str = "detector_y"
"""The logical axis corresponding to changes in detector :math:`y`-coordinate."""

@property
def velocity_doppler(self):
"""
The Doppler velocity of each wavelength bin in the observation.
"""
return self.inputs.wavelength.to(
unit=u.km / u.s,
equivalencies=u.doppler_radio(self.wavelength_center),
)

@classmethod
def from_time_range(
cls,
Expand Down Expand Up @@ -317,7 +302,7 @@ def from_fits(
pc.position.y.components[axis_detector_y][index] = wcs.pc[~iy, ~iy]

key_center = f"TWAVE{index_window}"
self.wavelength_center[index] = hdul[0].header[key_center] * u.AA
self.inputs.wavelength_rest[index] = hdul[0].header[key_center] * u.AA

t = astropy.time.Time(
val=self.inputs.time.ndarray,
Expand All @@ -329,14 +314,14 @@ def from_fits(
where_invalid = self.outputs == -200 * u.DN
self.outputs[where_invalid] = np.nan

w0 = self.wavelength_center
w0 = self.inputs.wavelength_rest
if np.all(w0[{self.axis_time: 0}] == w0):
w0 = w0[{self.axis_time: 0}]

if not w0.shape:
w0 = w0.ndarray

self.wavelength_center = w0
self.inputs.wavelength_rest = w0

return self

Expand Down Expand Up @@ -374,8 +359,9 @@ def empty(
shape_time = shape_base | {axis_detector_x: shape_wcs[axis_detector_x]}
vshape_time = shape_base | {axis_detector_x: vshape_wcs[axis_detector_x]}

inputs = na.ExplicitTemporalWcsSpectralPositionalVectorArray(
inputs = na.ExplicitTemporalWcsDopplerPositionalVectorArray(
time=na.ScalarArray.zeros(vshape_time),
wavelength_rest=na.ScalarArray.zeros(shape_base) << u.AA,
crval=na.SpectralPositionalVectorArray(
wavelength=na.ScalarArray.zeros(shape_base) << u.AA,
position=na.Cartesian2dVectorArray(
Expand Down Expand Up @@ -430,13 +416,10 @@ def empty(

timedelta = na.ScalarArray.zeros(shape_time) * u.s

wavelength_center = na.ScalarArray.zeros(shape_base) << u.AA

return cls(
inputs=inputs,
outputs=outputs,
timedelta=timedelta,
wavelength_center=wavelength_center,
axis_time=axis_time,
axis_wavelength=axis_wavelength,
axis_detector_x=axis_detector_x,
Expand Down Expand Up @@ -529,7 +512,7 @@ def show(
if self.axis_time in self.shape:
a = a[{self.axis_time: index_time}]

wavelength_center = a.wavelength_center
wavelength_center = na.as_named_array(a.inputs.wavelength_rest).ndarray

axis_wavelength = self.axis_wavelength
axis_x = self.axis_detector_x
Expand Down Expand Up @@ -562,7 +545,7 @@ def show(
with astropy.visualization.quantity_support():
cax_twin = cax.twinx()
colorbar = na.plt.rgbmesh(
a.velocity_doppler,
a.inputs.velocity,
a.inputs.position.x,
a.inputs.position.y,
C=a.outputs,
Expand Down Expand Up @@ -632,7 +615,7 @@ def _animate(
cbar_fraction
The fraction of the space to use for the colorbar axes.
"""
wavelength_center = self.wavelength_center
wavelength_center = self.inputs.wavelength_rest

axis_time = self.axis_time
axis_wavelength = self.axis_wavelength
Expand Down Expand Up @@ -665,7 +648,7 @@ def _animate(
y = self.inputs.position.y
ani, colorbar = na.plt.rgbmovie(
self.inputs.time.mean(axis_x),
self.velocity_doppler,
self.inputs.velocity,
x,
y,
C=self.outputs,
Expand Down
3 changes: 0 additions & 3 deletions iris/sg/_spectrograph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def test_axis_detector_x(self, array: iris.sg.SpectrographObservation):
def test_axis_detector_y(self, array: iris.sg.SpectrographObservation):
assert isinstance(array.axis_detector_y, str)

def test_velocity_doppler(self, array: iris.sg.SpectrographObservation):
assert np.all(array.velocity_doppler != 0 * u.km / u.s)

def test_radiance(self, array: iris.sg.SpectrographObservation):
result = array.radiance
assert isinstance(result, iris.sg.SpectrographObservation)
Expand Down
6 changes: 3 additions & 3 deletions iris/sg/background/_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def average(
"""
obs = obs.copy_shallow()
shape = obs.inputs.shape
obs.inputs = na.TemporalSpectralPositionalVectorArray(
obs.inputs = obs.inputs.explicit.replace(
time=obs.inputs.time.ndarray.jd.mean(),
wavelength=obs.inputs.wavelength.broadcast_to(shape).mean(axis),
position=obs.inputs.position.broadcast_to(shape).mean(axis),
Expand Down Expand Up @@ -311,7 +311,7 @@ def fit(
data = avg.outputs[where_crop]

# Convert wavelength to velocity units
velocity = avg.velocity_doppler.cell_centers()
velocity = avg.inputs.velocity.cell_centers()
velocity = velocity[where_crop]

# Fit the data within +/- 150 km/s of line center
Expand Down Expand Up @@ -490,7 +490,7 @@ def subtract_spectral_line(

where_crop = np.isfinite(obs.outputs).mean(obs.axis_wavelength) > 0.7

velocity = obs.velocity_doppler.cell_centers()
velocity = obs.inputs.velocity.cell_centers()
velocity = velocity[where_crop]

where = np.abs(velocity) < 150 * u.km / u.s
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"requests",
"joblib",
"irispy-lmsal",
"named-arrays>=0.17.1",
"named-arrays~=1.3",
]
dynamic = ["version"]

Expand Down
Loading