Skip to content

Corrections for Lo Maps - #3370

Open
vineetbansal wants to merge 18 commits into
IMAP-Science-Operations-Center:devfrom
vineetbansal:vb/lo_bootstrap
Open

Corrections for Lo Maps#3370
vineetbansal wants to merge 18 commits into
IMAP-Science-Operations-Center:devfrom
vineetbansal:vb/lo_bootstrap

Conversation

@vineetbansal

Copy link
Copy Markdown
Collaborator

Added sputter/bootstrap/CG correction, and ISN masking for Lo maps.

The combined maps after ISN-masking are likely incorrect, since I still don't know how that masking is supposed to get done for combined maps (currently a pixel of the combined map is masked if any of those pivots would have masked it.)

@tmplummer tmplummer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a huge diff to look at. I did my best. Mostly this code looks really good! My main gripe is that the algorithms that I implemented based off of Nathan's alg docs are no longer getting used for Lo. I will note that those algorithms were validated using Nathan's data so at some point it would be good to understand if he changed something or if they could be pulled in and used.

Comment on lines +1173 to +1174
corrected = counts - np.einsum("ts,esp->etp", sputter_matrix, source_counts)
variance = counts + np.einsum("ts,esp->etp", sputter_matrix**2, source_counts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

einsum is great to use, but can you try to describe what these are doing?

return speed**2 * energy_u


def _compton_getting_correct_intensity(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did Nathan totally change the CG correction. The common CG correction code that I wrote was based off of his document so I would have thought that it could be used on Lo data. The part that adjusts PSET data is here: https://github.com/IMAP-Science-Operations-Center/imap_processing/blob/dev/imap_processing/ena_maps/utils/corrections.py#L736
Then the interpolation to the helo-frame energies is here: https://github.com/IMAP-Science-Operations-Center/imap_processing/blob/dev/imap_processing/ena_maps/utils/corrections.py#L797

change = np.sqrt(np.nanmean((source / previous) ** 2)) - 1.0
if np.isfinite(change) and abs(change) < c.CG_CONVERGENCE_TOLERANCE:
logger.debug(f"Source spectrum converged after {iteration + 1} iterations")
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems very close to what the PowerLawFluxCorrector does. Is it not usable? I wrote it and validated it based on Nathan's algorithm document.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It seems to me like the algorithm document may have diverged since the code was first written. Specifically, I'm seeing:

  1. The current implementation of estimate_power_law_slope in PowerLawFluxCorrector uses central differences, while the algorithm document (and this implementation) uses forward differences. (eq A1)
  2. The top level uses backward difference in this implementation, while in the algorithm document (and this implementation) we copy the level below. (eq A2)

I suppose its possible to emulate the new behavior by adding optional flags to the function. Maybe we open an issue on this and get back to it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it has diverged, it might make sense to not force it into shared code. Originally, Hi and Lo had different algorithms for this stuff specified. The project leadership said they needed to use the same algorithm, so Hi adopted Nathan's algorithm but were not too happy about it. So, at this point, maybe letting Hi and Lo diverge makes sense and that way either team can modify at will without any side-effects.

Comment on lines +126 to +127
CG_MAX_ITERATIONS: int = 20
CG_CONVERGENCE_TOLERANCE: float = 0.005

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a really big PR, so I didn't track it down, but IIRC, the flux correction is totally separate from the CG correction. Doesn't the flux correction get applied to maps in either the s/c or helio-frame? I would expect these variables to be specifically named to flux correction rather than having to do with the CG correction.

# in the spacecraft frame purely from the spacecraft's own motion, i.e.
# 1/2 m_H U^2 at the nominal spacecraft speed of ~30 km/s. The kinematics
# of the correction are scaled by it.
CG_ENA_ENERGY_AT_SPACECRAFT_SPEED_EV: float = 4.661

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the CG correction that I implemented, this was computed exactly using SPICE. Probably is just in the noise.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes - spice is the correct way to go. Almost none of the steps in the dropbox use spice, and I didn't realize you'd already implemented this. I'll look at your implementation and use it instead.

@vineetbansal

vineetbansal commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for taking the time to review @tmplummer - I'll go through your suggestions and reduce code duplication where I can. Perhaps we can create issues on the ones I'm not able to tackle right away and I'll get to those asap.

The major change in Lo's approach seems to be that equations were written for a pre-binning stage (psets), but later on they moved to a map-making approach that creates bins first, and then modifies intensities for each bin through these corrections. It may be possible to leverage existing code to do so, but it will take some more investigating.

I'm out for a couple of days but will pick this up again next Monday.

@tmplummer tmplummer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine with these changes. As you noted, any places that use of shared code can be investigated are fine to capture in new issues.

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.

2 participants