1212import named_arrays as na
1313import msfc_ccd
1414import esis
15+ from .. import abc
1516
1617__all__ = [
1718 "Level_0" ,
2122@dataclasses .dataclass (eq = False , repr = False )
2223class Level_0 (
2324 msfc_ccd .SensorData ,
25+ abc .AbstractChannelData ,
2426):
2527 """
2628 Representation of ESIS Level-0 images, the raw data gathered by the instrument.
@@ -33,12 +35,6 @@ class Level_0(
3335 timeline : None | esis .nsroc .Timeline = None
3436 """The sequence of NSROC events associated with these images."""
3537
36- axis_time : str = dataclasses .field (default = "time" , kw_only = True )
37- """The name of the logical axis corresponding to changing time."""
38-
39- axis_channel : str = dataclasses .field (default = "channel" , kw_only = True )
40- """The name of the logical axis corresponding to the different channels."""
41-
4238 @classmethod
4339 def from_fits (
4440 cls ,
@@ -193,164 +189,3 @@ def dark(self) -> Self:
193189 def dark_subtracted (self ):
194190 """Subtract the master :attr:`dark` from each image in the sequence."""
195191 return self - self .dark .outputs
196-
197- def animate (
198- self ,
199- ax : None | matplotlib .axes .Axes | na .AbstractArray = None ,
200- cmap : None | str | matplotlib .colors .Colormap = None ,
201- norm : None | str | matplotlib .colors .Normalize = None ,
202- vmin : None | na .ArrayLike = None ,
203- vmax : None | na .ArrayLike = None ,
204- cbar_fraction : float = 0.1 ,
205- ) -> matplotlib .animation .FuncAnimation :
206- """
207- Create an animation using the frames in this dataset.
208-
209- Parameters
210- ----------
211- ax
212- The :class:`~matplotlib.axes.Axes` instance(s) to use.
213- If :obj:`None`, a new set of axes will be created.
214- cmap
215- The colormap used to map scalar data to colors.
216- norm
217- The normalization method used to scale data into the range [0, 1] before
218- mapping to colors.
219- vmin
220- The minimum value of the data range.
221- If `norm` is :obj:`None`, this parameter will be ignored.
222- vmax
223- The maximum value of the data range.
224- If `norm` is :obj:`None`, this parameter will be ignored.
225- cbar_fraction
226- The fraction of the space to use for the colorbar axes.
227- """
228- axis_time = self .axis_time
229- axis_channel = self .axis_channel
230-
231- if ax is None :
232- figwidth = plt .rcParams ["figure.figsize" ][0 ]
233- figwidth_eff = figwidth * (1 - 2 * cbar_fraction )
234- shape = self .shape
235- num_channel = shape [axis_channel ]
236- num_x = shape [self .axis_x ]
237- num_y = shape [self .axis_y ]
238- figheight = num_channel * figwidth_eff * num_y / num_x
239- fig , ax = na .plt .subplots (
240- axis_rows = axis_channel ,
241- nrows = num_channel ,
242- sharex = True ,
243- sharey = True ,
244- constrained_layout = True ,
245- figsize = (figwidth , figheight ),
246- origin = "upper" ,
247- )
248- na .plt .set_xlabel ("detector $x$ (pix)" , ax = ax [{axis_channel : ~ 0 }])
249- na .plt .set_ylabel ("detector $y$ (pix)" , ax = ax )
250-
251- data = self .outputs
252- unit = na .unit (data )
253-
254- if norm is None :
255- if vmin is None :
256- vmin = data .percentile (1 ).ndarray
257- if vmax is None :
258- vmax = data .percentile (99 ).ndarray
259-
260- if unit is not None :
261- vmin = vmin .to (unit ).value
262- vmax = vmax .to (unit ).value
263-
264- norm = plt .Normalize (
265- vmin = vmin ,
266- vmax = vmax ,
267- )
268-
269- colorizer = plt .Colorizer (
270- cmap = cmap ,
271- norm = norm ,
272- )
273-
274- pixel = self .inputs .pixel
275-
276- ani = na .plt .pcolormovie (
277- self .inputs .time .mean (axis_channel ),
278- pixel .x ,
279- pixel .y ,
280- C = data ,
281- axis_time = axis_time ,
282- ax = ax ,
283- kwargs_pcolormesh = dict (
284- colorizer = colorizer ,
285- ),
286- )
287- na .plt .text (
288- x = 0.5 ,
289- y = 1.01 ,
290- s = self .channel ,
291- transform = na .plt .transAxes (ax ),
292- ax = ax ,
293- ha = "center" ,
294- va = "bottom" ,
295- )
296- na .plt .set_aspect ("equal" , ax = ax )
297-
298- plt .colorbar (
299- mappable = plt .cm .ScalarMappable (colorizer = colorizer ),
300- ax = ax .ndarray ,
301- label = f"signal ({ unit :latex_inline} )" ,
302- fraction = cbar_fraction ,
303- )
304-
305- return ani
306-
307- def to_jshtml (
308- self ,
309- ax : None | matplotlib .axes .Axes | na .AbstractArray = None ,
310- cmap : None | str | matplotlib .colors .Colormap = None ,
311- norm : None | str | matplotlib .colors .Normalize = None ,
312- vmin : None | na .ArrayLike = None ,
313- vmax : None | na .ArrayLike = None ,
314- cbar_fraction : float = 0.1 ,
315- ) -> IPython .display .HTML :
316- """
317- Create a Javascript animation ready to be displayed in a Jupyter notebook.
318-
319- Converts the output of :meth:`animate` to Javascript using
320- :meth:`matplotlib.animation.Animation.to_jshtml`,
321- and then wraps the html string in :class:`IPython.display.HTML`.
322-
323- Parameters
324- ----------
325- ax
326- The :class:`~matplotlib.axes.Axes` instance(s) to use.
327- If :obj:`None`, a new set of axes will be created.
328- cmap
329- The colormap used to map scalar data to colors.
330- norm
331- The normalization method used to scale data into the range [0, 1] before
332- mapping to colors.
333- vmin
334- The minimum value of the data range.
335- If `norm` is :obj:`None`, this parameter will be ignored.
336- vmax
337- The maximum value of the data range.
338- If `norm` is :obj:`None`, this parameter will be ignored.
339- cbar_fraction
340- The fraction of the space to use for the colorbar axes.
341- """
342- ani = self .animate (
343- ax = ax ,
344- cmap = cmap ,
345- norm = norm ,
346- vmin = vmin ,
347- vmax = vmax ,
348- cbar_fraction = cbar_fraction ,
349- )
350-
351- result = ani .to_jshtml ()
352- result = IPython .display .HTML (result )
353-
354- plt .close (ani ._fig )
355-
356- return result
0 commit comments