Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding xrt_teem #89

Merged
merged 50 commits into from
Feb 14, 2023
Merged

adding xrt_teem #89

merged 50 commits into from
Feb 14, 2023

Conversation

jslavin
Copy link
Contributor

@jslavin jslavin commented Nov 29, 2022

Adding xrt_teem.py only

jslavin and others added 12 commits September 20, 2022 16:36
Initial upload of xrt_teem.py, code to create temperature and emission measure maps from two images based on the filter ratio method. Code was originally written in IDL by N. Narukage and shows that IDL legacy to some extent.
Now flake8 compliant. Also chose simpler expression for binning data.
Several small changes were made to the code, mainly to improve readability. Seems easiest to delete and then upload newer version.
version of xrt_teem with unused imports removed, better naming of variables.
fixes in formatting (removing trailing whitespace, etc.) and one bug - spect1, spect2 used before being defined
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

@namurphy namurphy left a comment

Choose a reason for hiding this comment

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

Thank you again for doing this! I'm excited to have this added! I only took a quick look so far. I'll try to look at this again in the next day or two.

I noticed that the .fits files were giving pre-commit some indigestion, so I made two quick pull requests to tell some of the pre-commit hooks to ignore .fits files and update the pre-commit config. Assuming you have upstream set as the remote for the XRTpy repo, doing git pull upstream main and git push should get the changes merged into this branch.

With regards to documentation, a lot of what's in XRTpy is based off of PlasmaPy, so the PlasmaPy doc guide might be helpful here too.

xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/tests/test_xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
jslavin and others added 3 commits December 14, 2022 14:13
Accepting changes to docstring as suggested by Nick to use markdown formatting.

Co-authored-by: Nick Murphy <[email protected]>
Accept reformatting of docstring.

Co-authored-by: Nick Murphy <[email protected]>
Accept more reformatting of docstring.

Co-authored-by: Nick Murphy <[email protected]>
@joyvelasquez
Copy link
Contributor

pre-commit.ci autofix

@joyvelasquez
Copy link
Contributor

joyvelasquez commented Jan 25, 2023

@jslavin If possible, add documentation to the section of Getting Started - XRTpy Objects for users to get more information about xrt_teem before the squash and merge. However, this can be a later pull request of its own as well.

@wtbarnes
Copy link
Collaborator

I've not taken a close look at this, but one high level suggestion would be to make the two input XRT images sunpy map objects rather than accepting two data header pairs. This would vastly simplify the metadata handling as SunPy already includes code for handling XRT headers. For example, the parsing of the filter wheel combination is already done on the XRT map source in SunPy and can be accessed as a property.

I would also suggest that the return type of the emission and temperature also be SunPy maps. That way, a user can continue to take advantage of all the usual operations (e.g. cropping, visualization) on their derived temperature maps.

@wtbarnes
Copy link
Collaborator

wtbarnes commented Feb 4, 2023

Mark wants us to maintain fairly close correspondence of the XRTpy code with the IDL code.

Understood

By the way, I ran into some odd bugs at first when trying to make plots from the map outputs. For some reason, getting the date attribute to a map produced errors when I included the 'timesys' keyword in the metadata. In XRT data that has the value 'UTC (TBR)'. I found that there was no problem if I included the entire metadata from the image.

I suspect the issue is because, in the XRT map source, there is a fix for the non-standard TIMESYS entry "UTC (TBR)"
https://github.com/sunpy/sunpy/blob/a846ce09322cd6ded64da35ab0dc3ec90d970b44/sunpy/map/sources/hinode.py#L63-L67. When you include all of the metadata from the original image, Map recognizes this as an XRT map and thus handles the key appropriately. However, when you only use subset of the metadata, specifically when you don't set the INSTRUME key to "XRT", Map does not know how to handle this TIMESYS key since the fix is only applied for XRT maps. When you remove the TIMESYS key, map falls back to the default which is UTC https://github.com/sunpy/sunpy/blob/main/sunpy/map/mapbase.py#L815

I agree with you re: not including all the original metadata as it no longer applies to the resulting EM/temperature maps. My suggested fix would be to set the TIMESYS keyword to "UTC". Note also that if you use the header helper function (see my comment above), this will be handled for you.

I have now implemented returning Maps from xrt_teem. However I identified one behavior that's different between the IDL routine and the XRTpy routine. Using the superpixel method for a masked image, the summing is done treating the masked pixels as 0s. The mask itself is not summed, so the net effect is that any summed pixel will not be masked unless all the pixels that make it up are masked. The IDL routine on the other hand makes any binned pixel masked if it has any of its pixels masked. One could argue either way about the proper way to do that, though certainly you're not getting a properly summed pixel if some of the original pixels are masked. To change what is returned by superpixel would require modification of the code.

That's an interesting point. In sunpy, the logic of masked pixels in superpixel is handled by NumPy masked arrays which set masked pixels to zero when summing. Would you mind creating an issue about this on the sunpy repo? I would be interested to hear other's opinions on this behavior and whether there is room for flexibility.

Note that you could you could recreate the kind of mask you're talking about by passing the mask attached to your original Map to reshape_image_to_4d_superpixel (this is the function used by the superpixel method) and then summing over the appropriate dimensions.

Copy link
Contributor

@namurphy namurphy left a comment

Choose a reason for hiding this comment

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

Thank you again for doing this! I especially liked the writing style for the docstrings and example notebooks, since I found it quite understandable. A lot of my comments are related to reStructuredText formatting and thus should be fairly straightforward to implement.

My philosophy with code review is for the reviewer to offer thoughts and suggestions, and then usually have the code author decide whether or not to accept the suggestion since they're the expert on it. So, if there are suggestions that you disagree with or would prefer to address in a different way, please take the approach that you decide would be best.

Thank you again!

xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
xrtpy/response/xrt_teem.py Show resolved Hide resolved
xrtpy/response/xrt_teem.py Outdated Show resolved Hide resolved
jslavin and others added 4 commits February 9, 2023 14:23
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
@joyvelasquez
Copy link
Contributor

pre-commit.ci autofix

Comment on lines +1 to +8
:orphan:

`xrtpy.response.xrt_teem`
=========================

.. currentmodule:: xrtpy.response.xrt_teem

.. automodapi:: xrtpy.response.xrt_teem
Copy link
Contributor

Choose a reason for hiding this comment

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

When we add a new module, we often need to add a stub documentation file so that the docstrings from the module show up in the online documentation.

@@ -120,6 +120,7 @@ extend-ignore =
W605,
RST210,
RST213,
RST305,
Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot to add this error code as one of the linter checks to ignore. This one checks for undefined substitutions, but isn't smart enough to check for our globally defined substitutions.

@namurphy
Copy link
Contributor

@jslavin — I made a few edits directly to this pull request to try getting the docstring to show up in the documentation preview for xrt_teem, and to ignore a linter error regarding substitutions. It'll be necessary to do a git pull to get the updates.

There seems to be a problem with the reStructuredText references to other packages not forming links. This may be an issue with how intersphinx is set up, though I wasn't able to find any problems. I'll have to look into this a bit more to figure out what's happening here. I think there was also just a new release of Sphinx, which might(?) have something to do with it. In any case, that's outside the scope of this pull request, so it shouldn't hold this up.

@jslavin
Copy link
Contributor Author

jslavin commented Feb 14, 2023 via email

@jslavin jslavin merged commit 1dd7932 into HinodeXRT:main Feb 14, 2023
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.

4 participants