From d96bdbd2c3afd9509f0abc76b3d4511149308af2 Mon Sep 17 00:00:00 2001 From: Shane Maloney Date: Thu, 29 Aug 2024 14:38:49 +0100 Subject: [PATCH] Update demo plot to use maps --- changelog/100.feature.rst | 1 + changelog/106.bugfix.rst | 1 + changelog/106.feature.rst | 1 + changelog/107.bugfix.rst | 1 + changelog/107.feature.rst | 1 + changelog/111.feature.rst | 1 + changelog/112.doc.rst | 1 + changelog/115.doc.rst | 1 + changelog/116.trivial.rst | 1 + changelog/118.bugfix.rst | 1 + changelog/123.feature.rst | 1 + changelog/124.feature.rst | 1 + changelog/125.feature.rst | 1 + changelog/128.bugfix.rst | 1 + changelog/132.bugfix.rst | 1 + changelog/134.bugfix.rst | 1 + changelog/137.bugfix.rst | 1 + changelog/141.doc.rst | 1 + changelog/89.doc.rst | 1 + changelog/90.feature.rst | 2 ++ changelog/98.feature.rst | 1 + examples/imaging_demo.py | 70 ++++++++++++++++++++++----------------- 22 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 changelog/100.feature.rst create mode 100644 changelog/106.bugfix.rst create mode 100644 changelog/106.feature.rst create mode 100644 changelog/107.bugfix.rst create mode 100644 changelog/107.feature.rst create mode 100644 changelog/111.feature.rst create mode 100644 changelog/112.doc.rst create mode 100644 changelog/115.doc.rst create mode 100644 changelog/116.trivial.rst create mode 100644 changelog/118.bugfix.rst create mode 100644 changelog/123.feature.rst create mode 100644 changelog/124.feature.rst create mode 100644 changelog/125.feature.rst create mode 100644 changelog/128.bugfix.rst create mode 100644 changelog/132.bugfix.rst create mode 100644 changelog/134.bugfix.rst create mode 100644 changelog/137.bugfix.rst create mode 100644 changelog/141.doc.rst create mode 100644 changelog/89.doc.rst create mode 100644 changelog/90.feature.rst create mode 100644 changelog/98.feature.rst diff --git a/changelog/100.feature.rst b/changelog/100.feature.rst new file mode 100644 index 0000000..6e52d80 --- /dev/null +++ b/changelog/100.feature.rst @@ -0,0 +1 @@ +Update livetime correction parameter `eta`, `tau` and add code to calculate pileup 'beta' :func:`stixpy.calibration.livetime.pileup_correction_factor`. diff --git a/changelog/106.bugfix.rst b/changelog/106.bugfix.rst new file mode 100644 index 0000000..0511860 --- /dev/null +++ b/changelog/106.bugfix.rst @@ -0,0 +1 @@ +Fix ELUT correction when the requested data has less then than 32 energy channels. diff --git a/changelog/106.feature.rst b/changelog/106.feature.rst new file mode 100644 index 0000000..839c716 --- /dev/null +++ b/changelog/106.feature.rst @@ -0,0 +1 @@ +Add background subtraction step to imaging demo, update `EnergyEdgeMasks`. diff --git a/changelog/107.bugfix.rst b/changelog/107.bugfix.rst new file mode 100644 index 0000000..66dde93 --- /dev/null +++ b/changelog/107.bugfix.rst @@ -0,0 +1 @@ +Update `~stixpy.calibration.energy.get_elut` to use correct science energy channels for given date. diff --git a/changelog/107.feature.rst b/changelog/107.feature.rst new file mode 100644 index 0000000..71132ba --- /dev/null +++ b/changelog/107.feature.rst @@ -0,0 +1 @@ +Update imaging demo to use images and construct `~sunpy.map.Map` using `~stixpy.coordinates.frames.STIXImaging` and `~sunpy.map.header_helper.make_fitswcs_header`. diff --git a/changelog/111.feature.rst b/changelog/111.feature.rst new file mode 100644 index 0000000..40c4591 --- /dev/null +++ b/changelog/111.feature.rst @@ -0,0 +1 @@ +Update :func:`~stixpy.coordinates.transforms.get_hpc_info` to use mean or interpolate pointing and location data based on number of data points in given timerange. Add function cache for aux data frequenly needed during coordinate transforms. diff --git a/changelog/112.doc.rst b/changelog/112.doc.rst new file mode 100644 index 0000000..de914cc --- /dev/null +++ b/changelog/112.doc.rst @@ -0,0 +1 @@ +Correct calculation of the HPC coordinate of the center of the STIX pointing in the imaging demo. diff --git a/changelog/115.doc.rst b/changelog/115.doc.rst new file mode 100644 index 0000000..b152e1c --- /dev/null +++ b/changelog/115.doc.rst @@ -0,0 +1 @@ +Update imaging demo for latest changes in `xrayvision `_. diff --git a/changelog/116.trivial.rst b/changelog/116.trivial.rst new file mode 100644 index 0000000..91e52a8 --- /dev/null +++ b/changelog/116.trivial.rst @@ -0,0 +1 @@ +Format code with ruff and turn on ruff format in pre-commit. diff --git a/changelog/118.bugfix.rst b/changelog/118.bugfix.rst new file mode 100644 index 0000000..fd2f311 --- /dev/null +++ b/changelog/118.bugfix.rst @@ -0,0 +1 @@ +Fix a bug where the incorrect unit was set on :class:`~stixpy.timeseries.quicklook.QLLightCurve`, :class:`~stixpy.timeseries.quicklook.QLBackground` and :class:`~stixpy.timeseries.quicklook.QLVariance`. diff --git a/changelog/123.feature.rst b/changelog/123.feature.rst new file mode 100644 index 0000000..3d0b4ec --- /dev/null +++ b/changelog/123.feature.rst @@ -0,0 +1 @@ +Make the imaging demo compatible with :class:`~xrayvision.visibility.Visibilities` diff --git a/changelog/124.feature.rst b/changelog/124.feature.rst new file mode 100644 index 0000000..ebf6e2d --- /dev/null +++ b/changelog/124.feature.rst @@ -0,0 +1 @@ +Update code and examples to use new :class:`~xrayvision.visibility.Visibilities`, tidy API of `~stixpy.imaging.em.em`. diff --git a/changelog/125.feature.rst b/changelog/125.feature.rst new file mode 100644 index 0000000..78997da --- /dev/null +++ b/changelog/125.feature.rst @@ -0,0 +1 @@ +Add missing QL products `~stixpy.product.sources.quicklook.QLVariance`, `~stixpy.product.sources.quicklook.QLFlareFlag`, and `~stixpy.product.sources.quicklook.QLTMStatusFlareList` to Product. Also added some useful properties to the for status words. diff --git a/changelog/128.bugfix.rst b/changelog/128.bugfix.rst new file mode 100644 index 0000000..ed5ef5f --- /dev/null +++ b/changelog/128.bugfix.rst @@ -0,0 +1 @@ +Fix bug where coordinate transforms did not support arrays of coordinates or times. To so support both integrated (e.g. images) and instantaneous (e.g. coarse flare flag) a new property `obstime_end` was added to `~stixpy.coordinates.frames.STIXImaging` when set if possible mean pointing and position information are use for transformations other wise they are interpolated between the two nearest data points. diff --git a/changelog/132.bugfix.rst b/changelog/132.bugfix.rst new file mode 100644 index 0000000..494d19c --- /dev/null +++ b/changelog/132.bugfix.rst @@ -0,0 +1 @@ +Fix typo in `~stixpy.product.sources.science.ScienceData` 'durtaion' -> 'duration'. diff --git a/changelog/134.bugfix.rst b/changelog/134.bugfix.rst new file mode 100644 index 0000000..39c3e88 --- /dev/null +++ b/changelog/134.bugfix.rst @@ -0,0 +1 @@ +Fix some inconsistencies on the data units in plots, also return handle to the image from `~stixpy.product.sources.science.SpectrogramPlotMixin.plot_spectrogram`. diff --git a/changelog/137.bugfix.rst b/changelog/137.bugfix.rst new file mode 100644 index 0000000..4fc7177 --- /dev/null +++ b/changelog/137.bugfix.rst @@ -0,0 +1 @@ +Fix bug reintroduce by last fix in `~stixpy.imaging.em.em`, update code in `~stixpy.calibration.visibility.calibrate_visibility` and imaging demo to use Tx, Ty rather than Ty, Tx as before. diff --git a/changelog/141.doc.rst b/changelog/141.doc.rst new file mode 100644 index 0000000..8972154 --- /dev/null +++ b/changelog/141.doc.rst @@ -0,0 +1 @@ +Convert reconstructions to proper sunpy maps in ref`:ref:`sphx_glr_generated_gallery_imaging_demo.py`. diff --git a/changelog/89.doc.rst b/changelog/89.doc.rst new file mode 100644 index 0000000..7d6151c --- /dev/null +++ b/changelog/89.doc.rst @@ -0,0 +1 @@ +Update README, fix graphviz RTD configuration, configure theme logo text. diff --git a/changelog/90.feature.rst b/changelog/90.feature.rst new file mode 100644 index 0000000..a9cbb95 --- /dev/null +++ b/changelog/90.feature.rst @@ -0,0 +1,2 @@ +Add a custom coordinate frame :class:`stixpy.coordinate.frames.STIXImaging` and the associated transformations (`~stixpy.coordinates.transforms.stixim_to_hpc`, `~stixpy.coordinates.transforms.hpc_to_stixim`) to and from `~sunpy.coordinates.frames.Helioprojective`. +Also add a `stixpy.map.stix.STIXMap` for `~sunpy.map.Map` source which properly displays the :class:`stixpy.coordinate.frames.STIXImaging` coordinate frame. diff --git a/changelog/98.feature.rst b/changelog/98.feature.rst new file mode 100644 index 0000000..b89eb23 --- /dev/null +++ b/changelog/98.feature.rst @@ -0,0 +1 @@ +Merged `stixpy.calibration.get_visibility_info_giordano` and `stixpy.calibration.get_visibility_info` into `stixpy.calibration.get_uv_points_data` and removed `stixpy.calibration.correct_phase_projection`. diff --git a/examples/imaging_demo.py b/examples/imaging_demo.py index 30c481b..cc73b2a 100644 --- a/examples/imaging_demo.py +++ b/examples/imaging_demo.py @@ -1,7 +1,7 @@ """ -================= -Imaging example -================= +============ +Imaging Demo +============ How to create visibility from pixel data and make images. @@ -51,12 +51,12 @@ ############################################################################### # Set time and energy ranges which will be considered for the science and the background file -time_range_sci = ["2021-09-23T15:21:00", "2021-09-23T15:24:00"] +time_range_sci = ["2021-09-23T15:20:00", "2021-09-23T15:23:00"] time_range_bkg = [ "2021-09-23T09:00:00", "2021-09-23T12:00:00", ] # Set this range larger than the actual observation time -energy_range = [28, 40] * u.keV +energy_range = [25, 28] * u.keV ############################################################################### # Create the meta pixel, A, B, C, D for the science and the background data @@ -136,14 +136,16 @@ ############################################################################### # Plot the both maps -fig = plt.figure(figsize=(12, 8)) -ax0 = fig.add_subplot(1, 2, 1, projection=fd_bp_map) -ax1 = fig.add_subplot(1, 2, 2, projection=hp_map_rotated) -fd_bp_map.plot(axes=ax0) + +fig = plt.figure(layout="constrained", figsize=(3, 6)) +ax = fig.subplot_mosaic( + [["stix"], ["hpc"]], per_subplot_kw={"stix": {"projection": fd_bp_map}, "hpc": {"projection": hp_map_rotated}} +) +fd_bp_map.plot(axes=ax["stix"]) fd_bp_map.draw_limb() fd_bp_map.draw_grid() -hp_map_rotated.plot(axes=ax1) +hp_map_rotated.plot(axes=ax["hpc"]) hp_map_rotated.draw_limb() hp_map_rotated.draw_grid() @@ -155,8 +157,9 @@ # because WCS axes and array are reversed max_stix = fd_bp_map.pixel_to_world(max_pixel[1], max_pixel[0]) -ax0.plot_coord(max_stix, marker=".", markersize=50, fillstyle="none", color="r", markeredgewidth=2) -ax1.plot_coord(max_stix, marker=".", markersize=50, fillstyle="none", color="r", markeredgewidth=2) +ax["stix"].plot_coord(max_stix, marker=".", markersize=50, fillstyle="none", color="r", markeredgewidth=2) +ax["hpc"].plot_coord(max_stix, marker=".", markersize=50, fillstyle="none", color="r", markeredgewidth=2) +fig.tight_layout() ################################################################################ # Use estimated flare location to create more accurate visibilities @@ -231,10 +234,6 @@ rotation_angle=90 * u.deg + roll, ) -clean_map = Map((clean_map.data, header)) -plt.figure() -clean_map.rotate().plot() - ############################################################################### # Crete a map using the MEM GE algorithm `mem` @@ -255,23 +254,32 @@ idx=idx, ) -vmax = max([clean_map.data.max(), mem_map.data.max(), em_map.value.max()]) + +clean_map = Map((clean_map.data, header)).rotate() +bp_map = Map((bp_nat, header)).rotate() +mem_map = Map((mem_map.data, header)).rotate() +em_map = Map((em_map, header)).rotate() + +vmax = max([clean_map.data.max(), mem_map.data.max(), em_map.data.max()]) ############################################################################### # Finally compare the images from each algorithm -fig, axes = plt.subplots(2, 2) -a = axes[0, 0].imshow(bp_nat.value) -axes[0, 0].set_title("Back Projection") -fig.colorbar(a) -b = axes[1, 0].imshow(clean_map.data, vmin=0, vmax=vmax) -axes[1, 0].set_title("Clean") -fig.colorbar(b) -c = axes[0, 1].imshow(mem_map.data, vmin=0, vmax=vmax) -axes[0, 1].set_title("MEM GE") -fig.colorbar(c) -d = axes[1, 1].imshow(em_map.value, vmin=0, vmax=vmax) -axes[1, 1].set_title("EM") -fig.colorbar(d) -fig.tight_layout() +fig = plt.figure(figsize=(12, 12)) +ax = fig.subplot_mosaic( + [ + ["bp", "clean"], + ["mem", "em"], + ], + subplot_kw={"projection": clean_map}, +) +a = bp_map.plot(axes=ax["bp"]) +ax["bp"].set_title("Back Projection") +b = clean_map.plot(axes=ax["clean"]) +ax["clean"].set_title("Clean") +c = mem_map.plot(axes=ax["mem"]) +ax["mem"].set_title("MEM GE") +d = em_map.plot(axes=ax["em"]) +ax["em"].set_title("EM") +fig.colorbar(a, ax=ax.values()) plt.show()