.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/align_iris_aia_rolled.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_gallery_align_iris_aia_rolled.py: ===================================== Aligning IRIS SJI (rolled) to SDO/AIA ===================================== In this example we will show how to align a rolled IRIS dataset to SDO/AIA. You can get IRIS data with co-aligned SDO data (and more) from https://iris.lmsal.com/search/ .. GENERATED FROM PYTHON SOURCE LINES 10-26 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np import pooch import sunpy.map from aiapy.calibrate import update_pointing from astropy.coordinates import SkyCoord from astropy.time import Time, TimeDelta from astropy.wcs.utils import wcs_to_celestial_frame from sunpy.net import Fido from sunpy.net import attrs as a from irispy.io import read_files from irispy.obsid import ObsID .. GENERATED FROM PYTHON SOURCE LINES 27-32 We start with getting the data. This is done by downloading the data from the IRIS archive. In this case, we will use ``pooch`` as to keep this example self contained but using your browser will also work. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python sji_filename = pooch.retrieve( "http://www.lmsal.com/solarsoft/irisa/data/level2_compressed/2014/09/19/20140919_051712_3860608353/iris_l2_20140919_051712_3860608353_SJI_2832_t000.fits.gz", known_hash="02a1cdbe2014e24b04ff782dcfdbaf553c5a03404813888ddea8c50a9d6b2630", ) .. GENERATED FROM PYTHON SOURCE LINES 39-40 We will now open the slit-jaw imager (SJI) file we just downloaded. .. GENERATED FROM PYTHON SOURCE LINES 40-47 .. code-block:: Python sji_2832 = read_files(sji_filename) # Printing will give us an overview of the file. print(sji_2832) # ``.meta`` contains the entire FITS header from the primary HDU. # Since it is very long, we won't actually print it here. .. rst-class:: sphx-glr-script-out .. code-block:: none SJICube ------- Observatory: IRIS Instrument: SJI Bandpass: 2832.0 Obs. Start: 2014-09-19T05:17:12.610 Obs. End: 2014-09-19T07:14:54.895 Instance Start: 2014-09-19T05:17:31.110 Instance End: 2014-09-19T07:13:24.610 Total Frames in Obs.: None IRIS Obs. id: 3860608353 IRIS Obs. Description: Large sit-and-stare 0.3x120 1s C II Mg II h/k Mg II w s Deep x Axis Types: [('custom:pos.helioprojective.lon', 'custom:pos.helioprojective.lat', 'time', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM', 'custom:CUSTOM'), ('custom:pos.helioprojective.lon', 'custom:pos.helioprojective.lat'), ('custom:pos.helioprojective.lon', 'custom:pos.helioprojective.lat')] Roll: 45.0001 Cube dimensions: [ 65. 387. 364.] pix .. GENERATED FROM PYTHON SOURCE LINES 48-50 Can't remember what is OBSID 3860608353? **irispy-lmsal** has an utility function that will provide more information. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python print(ObsID(sji_2832.meta["OBSID"])) .. rst-class:: sphx-glr-script-out .. code-block:: none IRIS OBS ID 3860608353 ---------------------- Description: Large sit-and-stare 0.3x120 1s SJI filters: C II Mg II h/k Mg II w s SJI field of view: 120x120 Exposure time: 8.0 s Binning: Spatial x 2, Spectral x 2 FUV binning: FUV spectrally rebinned x 4 SJI cadence: SJI cadence default Compression: Default compression Linelist: Flare linelist 1 .. GENERATED FROM PYTHON SOURCE LINES 54-56 Now, we will plot the SJI. By default, **irispy-lmsal** will color the spatial axes. .. GENERATED FROM PYTHON SOURCE LINES 56-60 .. code-block:: Python sji_2832.plot() plt.show() .. image-sg:: /generated/gallery/images/sphx_glr_align_iris_aia_rolled_001.png :alt: align iris aia rolled :srcset: /generated/gallery/images/sphx_glr_align_iris_aia_rolled_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 61-62 We also have the option of going directly to an individual scan. .. GENERATED FROM PYTHON SOURCE LINES 62-66 .. code-block:: Python sji_cut = sji_2832[45] print(sji_cut) .. rst-class:: sphx-glr-script-out .. code-block:: none SJICube ------- Observatory: IRIS Instrument: SJI Bandpass: 2832.0 Obs. Start: 2014-09-19T05:17:12.610 Obs. End: 2014-09-19T07:14:54.895 Instance Start: 2014-09-19T06:39:00.270 Instance End: None Total Frames in Obs.: None IRIS Obs. id: 3860608353 IRIS Obs. Description: Large sit-and-stare 0.3x120 1s C II Mg II h/k Mg II w s Deep x Axis Types: [('custom:pos.helioprojective.lon', 'custom:pos.helioprojective.lat'), ('custom:pos.helioprojective.lon', 'custom:pos.helioprojective.lat')] Roll: 45.0001 Cube dimensions: [387. 364.] pix .. GENERATED FROM PYTHON SOURCE LINES 67-70 We need to get the coordinate frame for the IRIS data. While this is stored in the WCS, getting a coordinate frame is a little more involved. We will use this to do a cutout later on but for now we will plot it. .. GENERATED FROM PYTHON SOURCE LINES 70-79 .. code-block:: Python sji_frame = wcs_to_celestial_frame(sji_cut.basic_wcs) bbox = [ SkyCoord(-750 * u.arcsec, 90 * u.arcsec, frame=sji_frame), SkyCoord(-750 * u.arcsec, 95 * u.arcsec, frame=sji_frame), SkyCoord(-700 * u.arcsec, 90 * u.arcsec, frame=sji_frame), SkyCoord(-700 * u.arcsec, 95 * u.arcsec, frame=sji_frame), ] .. GENERATED FROM PYTHON SOURCE LINES 80-86 This dataset has a peculiarity: the observation has a 45 degree roll. The image does not have a 45 degree rotation because plotting shows the data in the way they are written in the file. We will a coordinate grid to make this clear. You can also change the axis labels and ticks if you so desire. `WCSAxes provides us an API we can use. `__ .. GENERATED FROM PYTHON SOURCE LINES 86-109 .. code-block:: Python plt.figure() ax = sji_cut.plot() plt.xlabel("Helioprojective Longitude (Solar-X) [arcsec]") plt.ylabel("Helioprojective Latitude (Solar-Y) [arcsec]") plt.title(f"IRIS SJI {sji_2832.meta['TWAVE1']}", pad=20) ax.coords.grid(color="orange", linestyle="solid") lon = ax.coords[0] lat = ax.coords[1] lon.set_ticklabel_position("all") lat.set_ticklabel_position("all") lon.set_axislabel(ax.get_xlabel(), color="black") lon.set_ticklabel("black") lat.set_axislabel(ax.get_ylabel(), color="red") lat.set_ticklabel("red") # Plot each corner of the box [ax.plot_coord(coord, "o") for coord in bbox] plt.show() .. image-sg:: /generated/gallery/images/sphx_glr_align_iris_aia_rolled_002.png :alt: IRIS SJI 2832.0 :srcset: /generated/gallery/images/sphx_glr_align_iris_aia_rolled_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 110-118 For example, let us cut out the top sunspot. We need to specify the corners for the cut (note the coordinate order is the same as the plotted image). Be aware that crop works in the default N/S frame, so it will crop along those axes where as the data is rotated. You will also need to create a proper bounding box, with 4 corners. ``crop`` will return you the smallest bounding box which contains those 4 points which we can see when we overlay the points we give it. .. GENERATED FROM PYTHON SOURCE LINES 118-126 .. code-block:: Python sji_crop = sji_cut.crop(*bbox) sji_crop.plot(vmin=0, vmax=5000) plt.xlabel("Solar X") plt.ylabel("Solar Y") plt.show() .. image-sg:: /generated/gallery/images/sphx_glr_align_iris_aia_rolled_003.png :alt: align iris aia rolled :srcset: /generated/gallery/images/sphx_glr_align_iris_aia_rolled_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 127-131 We will want to align the data to the AIA. First we will want to pick a timestamp during the observation. Lets us now find the SJI observation where the time is closest to 06:00 on 2014-09-19. .. GENERATED FROM PYTHON SOURCE LINES 131-138 .. code-block:: Python (time_sji,) = sji_2832.axis_world_coords("time") time_target = Time("2014-09-19T06:00:00.0") time_index = np.abs(time_sji - time_target).argmin() time_stamp = time_sji[time_index].isot print(time_index, time_stamp) .. rst-class:: sphx-glr-script-out .. code-block:: none 23 2014-09-19T05:59:10.020 .. GENERATED FROM PYTHON SOURCE LINES 139-143 The fact that it is rolled 45 degrees makes manual alignment tricky and will illustrate the usefulness of working with WCS. We will download an AIA 170 nm image from the VSO. Once we have acquired it, we will need to use **aiapy** to prep this image. .. GENERATED FROM PYTHON SOURCE LINES 143-158 .. code-block:: Python search_results = Fido.search( a.Time(time_stamp, Time(time_stamp) + TimeDelta(1 * u.minute), near=time_stamp), a.Instrument.aia, a.Wavelength(1700 * u.AA), ) files = Fido.fetch(search_results) aia_map = sunpy.map.Map(files[0]) aia_map = update_pointing(aia_map) # You don't need to register AIA images unless you need them aligned to other AIA images. # otherwise you are degrading the data as the affine transform is not perfect. # But it is the last step to get a level 1.5 image. # .. rst-class:: sphx-glr-script-out .. code-block:: none Files Downloaded: 0%| | 0/1 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: align_iris_aia_rolled.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_