Enable time-dependent effective areas determination in iris_tools#108
Conversation
|
Hi @kakirastern. Thanks for setting up this PR! I've left some comments outlining some simple initial changes. I think there are a few things we could do to help us understand what we need to do. I've laid those out in the description of the PR above for easy reference. Let me know here what you think. |
|
You are welcome @DanRyanIrish! I really like the look of the PR and think the plan appears very sound... Looking forward to contributing more to it soon. I have made some preliminary changes as per the comments in PR #102. |
|
They look good! Let me know whenever you're ready to report on whether you were able to get |
|
Yup, sure. Will take a while so will get back to you at least a couple days later. |
|
Hi @DanRyanIrish! So I have managed to use |
I'll figure out what the meaningful input should be and run the SSW version to get the expected output. |
|
Hi @kakirastern. I've added a section to the description of this issue above for benchmarking cases listing the result from the SSWIDL software. You should be able to compare the output of the Python version with this to start with. But first see the comment I left about the indentations as nothing will work properly until that is resolved. |
|
Thanks @DanRyanIrish for the suggestions and info! I did run into some bugs regarding the shape of a few variables defined as numpy arrays... which will need some work to fix. From what I understand of the situation this |
|
I will focus my time and effort to completing sunpy/ndcube#151 first for the time being and get back to this soon after that. Hope this arrangement is okay with you. |
|
Sounds like a good plan @kakirastern |
|
So I finally was able to get the new function If instead I perform fits for NUV ranges, I'd get the values I am not sure why the last fit carried out with the Python code yields a result that is different from the IDL fit. @DanRyanIrish, do you reckon this would imply some significant differences (in the long run)? |
|
@DanRyanIrish Any suggestions as to what I should do next? |
|
That's excellent news @kakirastern! Well done! A difference of The next thing to do is formalize this into a test, and to do it using the We're moving onto phase two of the roadmap already! (By the way, next time you compare values like this can you put the IDL and Python values side-by-side so I can easily see what the differences are? Thanks!) |
|
Yup, sure @DanRyanIrish. I will do better data presentation next time. (Should have made a table for it.) And, onto testing now... |
|
And, I will set the only error of |
|
|
Used the default 6 decimal places as the tolerance for the Now I see the following failure thrown: |
|
So I found out there are 3 lines in the file "test_spectrograph.py" which were causing problems before I commented them out. Not sure why they were there in the first place. Could have been used for debugging earlier. They actually appeared out of place before: https://github.com/sunpy/irispy/pull/108/files#diff-7c42eb0d015fb3346007f43ca206dd1aR140 |
|
Well done on getting the tests to pass! Looks great. The next step is to make the code in |
|
That would be great! |
DanRyanIrish
left a comment
There was a problem hiding this comment.
Here are some changes to get started on. Do the time-related ones last as they are likely to cause the most trouble. Also, where possible, do each change one at a time and then check that the output hasn't changed by running the test.
|
Thanks @DanRyanIrish for the suggestions! Will definitely work on them over the next few days. |
|
Hi @DanRyanIrish, I have incorporated all of the suggested changes to render the |
|
So if I do the following: I would get the following Question: Should I change the tolerance for the comparisons so that the tests will pass, or should I re-examine the code to try and debug, if it is a bug at all? |
DanRyanIrish
left a comment
There was a problem hiding this comment.
Here are some more comments. After these are addressed we can take another look.
|
Weird, I still got the same data... |
|
Both |
|
I believe the next stage is this:
But I will need guidance to do that. |
|
@DanRyanIrish and @hayesla I have resolved all the issues brought up in the reviews and have resolved them one-by-one. Hopefully this PR can be merged soon so new PR's can be open to make it complete. |
|
Hi @kakirastern. With @hayesla's help I figured out the confusion we were having earlier that prevented us from merging this PR today. I didn't realise that So I suggest that one last change be made: undo the changes in commit |
|
@DanRyanIrish No worries. Also, will I need to add |
d63892a to
c561d8f
Compare
|
Rebased PR and dropped commit c3abaf7. Then added another commit to change |
|
Hi @kakirastern. I see that you've made those changes. Once the CI passes I'm happy to merge this. You've done a great job on a very tricky assignment! How about you @hayesla? Are you happy to approve this? |
|
Good with me! |
Polish up work on #108 on the irispy/time_dependent_response branch
Picks up from PR #102 and addresses issue #27.
Goal
To allow the time-dependent effective areas to be derived using get_iris_response() in iris_tools in the same way that it is done in SSW.
Expected Outcomes
Project Description
The Interface Region Imaging Spectrograph (IRIS) is a NASA Small Explorer satellite designed to make spectroscopic and imaging observations of the solar chromosphere and transition region. An important tool in interpreting these observations is the instrument response function which expresses the relationship between the physical intensity of light entering the instrument and the data number (DN) recorded by the CCD detectors. The response function was carefully measured by the IRIS team before launch and this is currently available to IRISpy users for their analysis.
However, due to time-dependent factors like degradation, it is known that the response function evolves with time in orbit. For this reason the IRIS team has developed a fitting algorithm based on calibration flights that predicts the response function as a function of time. A direct translation of this algorithm from its original language, IDL (Interactive Data Langauage), into Python has already been performed but requires more work before it can be merged into IRISpy.
The
.genyfiles needed can be accessed at https://sohowww.nascom.nasa.gov/solarsoft/iris/response/.References:
iris_get_response.pro
fit_iris_xput.pro
Roadmap - fit_iris_xput
Triaging
fit_iris_xputexplaining what the inputs and outputs.Benchmarking
Bug-fixing
Make code fixes to get the Python version giving the same or effectively the same answers as the IDL version.
Improving Code Pythonically
Once we have a function that returns the same or similar values as the IDL version, the code will have to be made more Pythonic as well as updated to reflect more recent changes in SunPy practices. Benchmarking/testing must be repeated and updated at each stage to ensure we are not changing the values of the output.
download_fileinstead of Requests'getto download the.genyfiles. This adds thecacheandtimeoutfunctionalities to the download process.time_obsandtime_cal_coeffsintoastropy.time.timeobjects before subtracting to obtain a time difference calledt_diff(to be converted into years), which is used to compute the final fit.Incorporating Time-dependent Fitted Response into get_iris_response
get_iris_responsefunction in iris_tools.py to incorporate consideration of time-dependency.fit_iris_xputand add a time input._get_interpolated_effective_areafunction.Benchmarking Cases from SSW
The .geny files can be read in Python using scipy's read save function. See here for an example. Also note that the out is converted to a
dictfor easier handling the line after. The same attribute names should be maintained between the the IDL and Python structures.1: Result for a start time of period of constant coef/cal_coef
Lines starting with
IDL>are input;is the IDL comment symbolLines without
IDL>at the start are output.IDL> ; Perform fits for NUV ranges. Note the changes in p0.c_n_time and p0.coeffs_nuv variable names.
IDL> fit0_nuv = fit_iris_xput(tt, p0.c_n_time, p0.coeffs_nuv[*, , 0])
IDL> fit1_nuv = fit_iris_xput(tt, p0.c_n_time, p0.coeffs_nuv[, , 1])
IDL> fit2_nuv = fit_iris_xput(tt, p0.c_n_time, p0.coeffs_nuv[, *, 2])
IDL> print, fit0_nuv, fit1_nuv, fit2_nuv
0.23529011
0.25203046
0.25265095
Incorporating Time-dependent Fitted Response into Wider IRISpy Code-base
_get_interpolated_effective_area. This chain includesiris_tools.calculate_photons_per_sec_to_radiance_factor,iris_tools.convert_or_undo_photons_per_sec_to_radiance, andIRISSpectrogramCube.convert_to. Must confirm if there are more cases where this chain leads.Final Pythonic Tidy Up
Go through code produced above and make any cumbersome bits of code more Pythonic. This may also involve tidying up or writing a few new tests.