diff --git a/docs/conf.py b/docs/conf.py index 5cc4091..bcc87b8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,8 @@ # import os import sys +import inspect +import joblib package_path = os.path.abspath('../') sys.path.insert(0, package_path) @@ -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) diff --git a/iris/sg/_spectrograph.py b/iris/sg/_spectrograph.py index 5ed8bb3..c3b5e5f 100644 --- a/iris/sg/_spectrograph.py +++ b/iris/sg/_spectrograph.py @@ -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.""" @@ -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, @@ -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, @@ -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 @@ -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( @@ -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, @@ -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 @@ -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, @@ -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 @@ -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, diff --git a/iris/sg/_spectrograph_test.py b/iris/sg/_spectrograph_test.py index 6acdfad..54ae867 100644 --- a/iris/sg/_spectrograph_test.py +++ b/iris/sg/_spectrograph_test.py @@ -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) diff --git a/iris/sg/background/_background.py b/iris/sg/background/_background.py index ee59c18..c03c40a 100644 --- a/iris/sg/background/_background.py +++ b/iris/sg/background/_background.py @@ -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), @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index d3ddd73..28c18b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dependencies = [ "requests", "joblib", "irispy-lmsal", - "named-arrays>=0.17.1", + "named-arrays~=1.3", ] dynamic = ["version"]