Skip to content

Commit

Permalink
Update demo plot to use maps
Browse files Browse the repository at this point in the history
  • Loading branch information
samaloney committed Sep 2, 2024
1 parent 377dae4 commit 40a2a65
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 31 deletions.
1 change: 1 addition & 0 deletions changelog/100.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update livetime correction parameter `eta`, `tau` and add code to calculate pileup 'beta' :func:`stixpy.calibration.livetime.pileup_correction_factor`.
1 change: 1 addition & 0 deletions changelog/106.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ELUT correction when the requested data has less then than 32 energy channels.
1 change: 1 addition & 0 deletions changelog/106.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add background subtraction step to imaging demo, update `EnergyEdgeMasks`.
1 change: 1 addition & 0 deletions changelog/107.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update `~stixpy.calibration.energy.get_elut` to use correct science energy channels for given date.
1 change: 1 addition & 0 deletions changelog/107.feature.rst
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions changelog/111.feature.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions changelog/112.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct calculation of the HPC coordinate of the center of the STIX pointing in the imaging demo.
1 change: 1 addition & 0 deletions changelog/115.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update imaging demo for latest changes in `xrayvision <https://github.com/TCDSolar/xrayvision>`_.
1 change: 1 addition & 0 deletions changelog/116.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Format code with ruff and turn on ruff format in pre-commit.
1 change: 1 addition & 0 deletions changelog/118.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions changelog/123.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the imaging demo compatible with :class:`~xrayvision.visibility.Visibilities`
1 change: 1 addition & 0 deletions changelog/124.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update code and examples to use new :class:`~xrayvision.visibility.Visibilities`, tidy API of `~stixpy.imaging.em.em`.
1 change: 1 addition & 0 deletions changelog/125.feature.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions changelog/128.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions changelog/132.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix typo in `~stixpy.product.sources.science.ScienceData` 'durtaion' -> 'duration'.
1 change: 1 addition & 0 deletions changelog/134.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions changelog/137.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions changelog/141.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert reconstructions to proper sunpy maps in `imaging_demo`.
1 change: 1 addition & 0 deletions changelog/89.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update README, fix graphviz RTD configuration, configure theme logo text.
2 changes: 2 additions & 0 deletions changelog/90.feature.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions changelog/98.feature.rst
Original file line number Diff line number Diff line change
@@ -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`.
71 changes: 40 additions & 31 deletions examples/imaging_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
=================
Imaging example
=================
__ imaging_demo:
============
Imaging Demo
============
How to create visibility from pixel data and make images.
Expand Down Expand Up @@ -51,12 +52,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
Expand Down Expand Up @@ -136,14 +137,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()

Expand All @@ -155,8 +158,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
Expand Down Expand Up @@ -231,10 +235,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`

Expand All @@ -255,23 +255,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()

0 comments on commit 40a2a65

Please sign in to comment.