-
-
Notifications
You must be signed in to change notification settings - Fork 25
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 tests for iris tools #4
Conversation
ping @DanRyanIrish |
Thanks so much @abit2 for this PR and contributing to irispy. I'm going through it now. |
irispy/iris_tools.py
Outdated
DETECTOR_GAIN = {"NUV": 18., "FUV": 6., "SJI": 18.} | ||
DETECTOR_YIELD = {"NUV": 1., "FUV": 1.5, "SJI": 1.} | ||
DETECTOR_GAIN = {"NUV": 18., "FUV1": 6., "FUV2": 6., "SJI": 18.} | ||
DETECTOR_YIELD = {"NUV": 1., "FUV1": 1.5, "FUV2": 1.5, "SJI": 1.} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason there is only one an FUV key in this dictionary, rather than an FUV1 and FUV2 is that it reflects the metadata supplied by the IRIS instrument team and other aspects of the metadata may only be labelled FUV. Not everything is labelled FUV 1 or FUV2. So I think this should stay FUV for the time being. When determining what detector type to use, when can do something like if "FUV" in detector_type
. This will give us the right mapping whether detector_type is "FUV", "FUV1" or "FUV2".
irispy/iris_tools.py
Outdated
|
||
Returns | ||
------- | ||
data_photons: array-like | ||
IRIS data in units of photon counts. | ||
|
||
""" | ||
# if(data.isnan): | ||
# print("HELLO") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete these lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @abit2. Here are my comments on your changes to iris_tools.py and spectrograph.py. I'll look at test_iris_tools.py next.
irispy/iris_tools.py
Outdated
READOUT_NOISE = {"NUV": {"value": 1.2, "unit": "DN"}, "FUV": {"value": 3.1, "unit": "DN"}, | ||
"SJI": {"value": 1.2, "unit": "DN"}} | ||
|
||
|
||
def convert_DN_to_photons(data, detector_type): | ||
def convert_DN_to_photons(data, detector_type='NUV'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely don't think there should be a default setting for detector type here. The user should have to explicitly give the detector type. There is no reason why NUV is more likely to be wanted by the user than FUV or SJI and could cause the user to get incorrect answers without realising.
irispy/iris_tools.py
Outdated
@@ -35,17 +34,20 @@ def convert_DN_to_photons(data, detector_type): | |||
detector_type: `str` | |||
Detector/CCD upon which data was recorded. | |||
Can take values 'NUV', 'FUV' or 'SJI'. | |||
default_detector_type : `NUV` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For same reason as above, delete this line.
irispy/iris_tools.py
Outdated
return DETECTOR_GAIN[detector_type]/DETECTOR_YIELD[detector_type]*data | ||
|
||
|
||
def convert_photons_to_DN(data, detector_type): | ||
def convert_photons_to_DN(data, detector_type='NUV'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove default value for detector_type for same reason discussed above.
irispy/spectrograph.py
Outdated
@@ -247,19 +247,19 @@ def convert_DN_to_photons(self, spectral_window): | |||
# Check that DataArray is in units of DN. | |||
if "DN" not in self.data[spectral_window].attrs["units"]["intensity"]: | |||
raise ValueError("Intensity units of DataArray are not DN.") | |||
self.data[spectral_window].data = iris_tools.convert_DN_to_photons(spectral_window) | |||
self.data[spectral_window].data = iris_tools.convert_DN_to_photons(self.data[spectral_window], self.spectral_windows['name'== spectral_window]['detector type']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot. The calling of this function is indeed wrong. However, the way you've derived the detector_type however raises a VisibleDeprecationWarning
because astropy tables in the future will have to be index with integers rather than booleans. I've added an index to this table so you can replace self.spectral_windows['name'== spectral_window]['detector type']
with self.spectral_windows.loc[spectral_window]['detector type']
.
Also, replace self.data[spectral_window]
with self.data[spectral_window].data
in the function call.
irispy/spectrograph.py
Outdated
|
||
|
||
def convert_photons_to_DN(self, spectral_window): | ||
"""Converts DataArray from DN to photon counts.""" | ||
# Check that DataArray is in units of DN. | ||
if "photons" not in self.data[spectral_window].attrs["units"]["intensity"]: | ||
raise ValueError("Intensity units of DataArray are not DN.") | ||
self.data[spectral_window].data = iris_tools.convert_photons_to_DN(spectral_window) | ||
self.data[spectral_window].data = iris_tools.convert_photons_to_DN(self.data[spectral_window], self.spectral_windows['name'== spectral_window]['detector type']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, replace self.data[spectral_window]
with self.data[spectral_window].data
and self.spectral_windows['name'== spectral_window]['detector type']
with self.spectral_windows.loc[spectral_window]['detector type']
in function call.
irispy/tests/test_iris_tools.py
Outdated
# """Tests for functions in iris_tools.py""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete # from start of this line. That was my fault for putting it in the first place.
irispy/tests/test_iris_tools.py
Outdated
""" | ||
""" | ||
# source_DN = [[ 0.563004, 1.132289, -1.343129], [-0.719726, 1.441411, 1.566724]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the commented out line? Can it be deleted? The same question for the other commented out source_xxx = []
lines.
irispy/iris_tools.py
Outdated
@@ -55,6 +57,7 @@ def convert_photons_to_DN(data, detector_type): | |||
detector_type: `str` | |||
Detector/CCD upon which data was recorded. | |||
Can take values 'NUV', 'FUV' or 'SJI'. | |||
default_detector_type : `NUV` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For same reason as above, delete this line.
irispy/iris_tools.py
Outdated
@@ -77,6 +80,7 @@ def calculate_intensity_fractional_uncertainty(data, data_unit, detector_type): | |||
detector_type: `str` | |||
Detector/CCD upon which data was recorded. | |||
Can take values 'NUV', 'FUV' or 'SJI'. | |||
default_detector_type : `NUV` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For same reason as above, delete this line.
Thanks @abit2. I had a quick look at your PR it looks good. I'll let you know when I get a chance to make some more comments. |
irispy/iris_tools.py
Outdated
@@ -85,13 +90,17 @@ def calculate_intensity_fractional_uncertainty(data, data_unit, detector_type): | |||
Same shape as data. | |||
|
|||
""" | |||
if 'FUV' in detector_type: | |||
detector_type = 'FUV' | |||
|
|||
photons_per_dn = DETECTOR_GAIN[detector_type]/DETECTOR_YIELD[detector_type] | |||
if data_unit == "DN": | |||
intensity_ph = photons_per_dn*convert_DN_to_photons(data, detector_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanRyanIrish is this line correct should it be multiplied by photons_per_dn after the data has been converted to photons since in data_unit == 'photons' intensity_ph=data, can you please take a look?
Hi @abit2. This looks good! Could you add one more function to test_iris_tools.py to test that
|
irispy/iris_tools.py
Outdated
@@ -246,7 +246,7 @@ def get_iris_response(pre_launch=False, response_file=None, response_version=Non | |||
|
|||
|
|||
@custom_model | |||
def _gaussian1d_on_linear_bg(x, amplitude=None, mean=None, standard_deviation=None, | |||
def _gaussian1d_on_linear_bg(x=None, amplitude=None, mean=None, standard_deviation=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe for @custom_model, x
should be a positional argument, not a kwarg. So the original version is actually correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanRyanIrish this happened when I tried this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should not be called directly. It's only used as part of the fitting routine in _calculate_orbital_wavelength_variation()
. So you don't need to test this line, if that's what you're trying to do.
Great stuff. If this passes the Travis test, we should be ready to merge it! |
@DanRyanIrish any suggestions on what I should work next |
adding tests for iris tools and corrected the convert_photons_to_DN and DN_to_photons function in IRISRaster class