Skip to content

Add a Cryo-NIRSP Plotting Example#598

Merged
Cadair merged 14 commits intoDKISTDC:mainfrom
Cadair:cryo_example
Aug 5, 2025
Merged

Add a Cryo-NIRSP Plotting Example#598
Cadair merged 14 commits intoDKISTDC:mainfrom
Cadair:cryo_example

Conversation

@Cadair
Copy link
Member

@Cadair Cadair commented Jul 30, 2025

@Cadair Cadair force-pushed the cryo_example branch 2 times, most recently from 9ce9f71 to 89df5b8 Compare July 30, 2025 16:07
@Cadair
Copy link
Member Author

Cadair commented Jul 30, 2025

@tschad Would you mind having a look at this and giving us your thoughts? It's a very early draft, but any feedback would be appreciated. I was trying to keep it very simple for now, hopefully we can add more examples later.

@tschad
Copy link

tschad commented Jul 31, 2025

Thanks @Cadair for asking for feedback on this. The general concept of what to show looks good to me. I do have a number of comments though.

First for a movie of these datasets I'd recommend having a look here: https://share.nso.edu/shared/dkist/tschad/cn_daily_movies/cn_daily_movie_20250322.mp4

For me, the line sp_subtracted = sp - (sp_mean.data * sp_mean.unit)[..., None]
results in an error: TypeError: Dataset.init() got an unexpected keyword argument 'psf'

I could get around the above issue with:
with ProgressBar():
sp_subtracted = sp
sp_subtracted.data = (sp.data - (sp_mean.data)[..., None]).compute() ## into memory

The aspect ratio of the "mean subtracted line peak" and "Mean counts" plots is off, but I'm not sure how to fix it. The FOV of this raster is roughly 160 x 230 arcsec.

Just a note that in the future the units of the data will not be 'counts'. As I recall it may not have a unit, but perhaps the DC remembers. Currently the actual data units are in relative units compared to disk center flats.

Regarding the slit positions on the context imager...this plot is a bit misleading as the context imager FOV follows the slit-location. So for any moment in time, the slit location relative to the context image is fixed. The current plot makes it seem as if the slit scans across the context image, but this is not true.

Cheers!

@Cadair
Copy link
Member Author

Cadair commented Jul 31, 2025

Thanks!

@tschad
Copy link

tschad commented Jul 31, 2025

Also, I would recommend being somewhat specific as to when data is put in memory and when it is not. I very often use dask.diagnostics.ProgressBar() for when I call a compute calculation on the dataset.

If one doesn't do this, or are not aware of it, then some commands take a long time. For example, in the example, the
sp_sum_wave.plot() call is where the dask array grabs the data, leading to a long plot time.

Alternatively, putting it in memory first and then plotting makes the plotting go fast...
with ProgressBar():
sp_sum_wave = sp.rebin((-1,-1,1), function=np.sum).squeeze()
sp_sum_wave.data = sp_sum_wave.data.compute() ## puts the summed wavelength into memory

@Cadair
Copy link
Member Author

Cadair commented Aug 4, 2025

Thanks so much for your feedback @tschad. Here some responses:

For me, the line sp_subtracted = sp - (sp_mean.data * sp_mean.unit)[..., None]
results in an error: TypeError: Dataset.__init__() got an unexpected keyword argument 'psf'

This bug is fixed in this PR.

The aspect ratio of the "mean subtracted line peak" and "Mean counts" plots is off, but I'm not sure how to fix it. The FOV of this raster is roughly 160 x 230 arcsec.

Do you mean the axis labels or the aspect ratio of the pixels? If it's the tick labels then we need to fix the WCSes 🙈 (If it's the aspect ratio, we also might need to fix the WCS or I've messed up the calculation).

Also, I would recommend being somewhat specific as to when data is put in memory and when it is not.

I definitely think we should document this, but I am hesitant to put it in this example, as I'd rather not take the diversion into when and how to use dask.compute() in a tutorial on Cryo-NIRSP plotting.

Regarding the slit positions on the context imager...this plot is a bit misleading as the context imager FOV follows the slit-location

The limitation here is that we have only included the first FITS file in the sample data download so as to not bloat things too much. I've updated this whole section quite a lot, including probably a rather too complicated last plot.

@Cadair Cadair force-pushed the cryo_example branch 2 times, most recently from a6836b0 to 4cb9f21 Compare August 4, 2025 13:11
@Cadair Cadair marked this pull request as ready for review August 4, 2025 13:14
Copy link
Contributor

@SolarDrew SolarDrew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, not had a chance to properly look at the new plots but if this can't wait until I do, I'm happy merging it 👍

@Cadair
Copy link
Member Author

Cadair commented Aug 4, 2025

I'll probably not merge it until @tschad has had another look or just before we cut a release.

@tschad
Copy link

tschad commented Aug 4, 2025

Thanks @Cadair . Looks better, though here are a couple more comments:

  1. The aspect ratio issue looks related to how you calculate its value. The CryoNIRSP scan is not aligned with the WCS axes, so you need to calculate it along the stepping and slit axes, as follows:
dlon = np.abs(space_2[1,0].Tx - space_2[0,0].Tx)
dlat = np.abs(space_2[0,1].Ty - space_2[0,0].Ty)
aspect = dlon / dlat

I get dlon,dlat,aspect == (<Angle 0.44393963 arcsec>, <Angle 0.1126569 arcsec>, <Quantity 3.940634>)

With that change, you get a much better plot..

image
  1. ) Wrt the slit orientation on the CI image, unfortunately we do have a bug in the CI coordinates wherein we need to add a flip of the image axes to get something close to what is correct.

Here's an example starting with ci (i.e. the defined CI dataset from the example)

files = sorted(glob.glob(str(ci.files.basepath) + '/*fits'))
ci_map = sunpy.map.Map(files[0])
ci_map = sunpy.map.Map(ci_map.data[::-1,::],ci_map.meta).rotate()  ## FLIP DATA 

fig = plt.figure(layout="constrained")
ax = plt.subplot(projection = ci_map)
vmin, vmax = np.nanpercentile(ci_map.data, [40,99.5])
ci_map.plot(norm = PowerNorm(0.3,vmin = vmin,vmax = vmax),cmap = 'Reds_r')
slit_coords = sp[0,:,0].axis_world_coords()[0]
with SphericalScreen(slit_coords[0].observer):
    ax.plot_coord(slit_coords, color="green")
fig.tight_layout()
image

@Cadair
Copy link
Member Author

Cadair commented Aug 5, 2025

Thanks again @tschad, I've incorporate the aspect and data flip changes, although not the rotate with sunpy map.

On the WCS issue, is the actual problem that the CDELT for that axis has the wrong sign?

@tschad
Copy link

tschad commented Aug 5, 2025

Thanks @Cadair . Looks good to me.

The CI WCS issue could be remedied with a CDELT sign flip; though, we had originally decided to flip the data in processing so that the image renders in a non-WCS-aware image viewer with the expected on-sky perspective. We already flip the SP spectral axis in this way during processing to make the wavelengths increase to the right (on the camera, it is the opposite).

There are other WCS related issues with the CI that will need to be addressed in the near future...mostly correcting FOV offsets and camera ROI related offsets.

@Cadair Cadair merged commit 26c8ea5 into DKISTDC:main Aug 5, 2025
29 checks passed
@Cadair
Copy link
Member Author

Cadair commented Aug 5, 2025

Thanks a lot for all your feedback on this @tschad hopefully get those wcs bits fixed soon 😁

@Cadair Cadair deleted the cryo_example branch August 6, 2025 09:12
@Cadair Cadair mentioned this pull request Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants