-
Notifications
You must be signed in to change notification settings - Fork 12
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
Ultra l1b extended events #686
base: dev
Are you sure you want to change the base?
Ultra l1b extended events #686
Conversation
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.
Great to see some algorithm code being implemented.
This is a very large PR. I was unable to to a thorough review but provided what feedback I could.
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 is too much for me to review in one sitting, but I left some general comments now.
I'd really like to see this broken up into roughly each individual function as a PR, which means this one PR turns into ~15-20. I think this would go much faster and easier for getting feedback on as well.
# I suspect that the lookup table is different. | ||
test_xc = df_filt["Xc"].iloc[index].astype("float") | ||
etof, xc = get_coincidence_positions(de_dataset, tof, "ultra45") | ||
assert xc == pytest.approx(test_xc.values, rel=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.
Here and elsewhere in the tests it would be helpful to use the numpy testing utilities for array comparisons.
https://numpy.org/doc/stable/reference/generated/numpy.testing.assert_allclose.html
np.testing.assert_allclose(xc, test_xc.values, rtol=...)
# TODO: the first value doesn't match. Look into this. | ||
assert np.array_equal(test_energy[1::], energy[1::].astype(float)) |
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 seems like it should have an xfail/skip associated with it. A TODO in the tests doesn't seem ideal as I'm not sure we'll get back to it, so it could get lost in time.
# TODO: the first value doesn't match. Look into this. | |
assert np.array_equal(test_energy[1::], energy[1::].astype(float)) | |
# TODO: the first value doesn't match. Look into this. | |
np.testing.assert_array_equal(test_energy[1::], energy[1::].astype(float)) |
|
||
# Pulse height | ||
ph_indices = np.where( | ||
(de_dataset["STOP_TYPE"] == 1) | (de_dataset["STOP_TYPE"] == 2) |
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.
Should STOP_TYPE be an Enum? What do 1 and 2 mean here?
# Pulse height | ||
ph_indices = np.where( | ||
(de_dataset["STOP_TYPE"] == 1) | (de_dataset["STOP_TYPE"] == 2) | ||
)[0] |
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.
You only want the first occurrence, or do you want all sets of indices matching this condition?
Numpy also suggests using nonzero()
instead to get the indices. https://numpy.org/doc/stable/reference/generated/numpy.where.html
ph_indices = np.nonzero(de_dataset["STOP_TYPE"] == 1) | (de_dataset["STOP_TYPE"] == 2)
ph_etof, ph_xc = get_coincidence_positions(de_dataset, ph_tof, "ultra45") | ||
|
||
# SSD | ||
ssd_indices = np.where(de_dataset["STOP_TYPE"] >= 8)[0] |
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.
Suggest changing all "where" to nonzero and making sure you only want the first occurrence or if you want all of the indices. (indices to me means there could be multiples whereas you're only grabbing the first ssd_index currently)
ssd_indices = np.where(de_dataset["STOP_TYPE"] >= 8)[0] | |
ssd_indices = np.nonzero(de_dataset["STOP_TYPE"] >= 8) |
imap_processing/ultra/lookup_tables/FM45_Startup1_ULTRA_IMGPARAMS_20240719.csv
Show resolved
Hide resolved
@@ -5,7 +5,7 @@ build-backend = "poetry_dynamic_versioning.backend" | |||
[tool.poetry] | |||
name = "imap-processing" | |||
# Gets updated dynamically by the poetry-dynamic-versioning plugin | |||
version = "0.0.0" | |||
version = "0.3.0.post24.dev0+517786f" |
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 should be left as "0.0.0" and not updated, see the comment above. There is something going wrong with your install if this is getting committed I think.
t2 = np.zeros(len(de_dataset["STOP_TYPE"])) | ||
tof = np.zeros(len(de_dataset["STOP_TYPE"])) | ||
|
||
# Stop Type: 1=Top, 2=Bottom |
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.
Would suggest an Enum for this. STOP_TYPE.Top, STOP_TYPE.Bottom
or similar
# For the stop anode, there are mismatches between the coincidence TDCs, | ||
# i.e., CoinN and CoinS. They must be normalized via lookup tables. | ||
|
||
# TpCoinNNorm Top |
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 think there is a lot of duplicated code for the two cases here, so would it make sense to try and factor some of this out? I think you could also subset your dataset instead of keeping track of the indices and using those all the itme.
https://docs.xarray.dev/en/v2024.06.0/generated/xarray.Dataset.where.html
top_ds = de_dataset.where(de_dataset["COIN_TYPE"] == 1)
Ok. I'll create separate branches to break it up. |
Change Summary
Overview
All of l1b de except any SPICE utilization. Note that I still don't have recent lookup tables so I will update this code once I have them.
New Files
lookup_utils.py
ultra_l1b_extended.py
/lookup_tables (5 files)
imap_processing/tests/ultra/test_data/l0/FM45_40P_Phi28p5_BeamCal_LinearScan_phi28.50_theta-0.00_Ultra_Image_Raw_Event_20240207T102746_withFSWcalcs.csv
Updated Files
imap_ultra_l1b_variable_attrs.yaml
conftest.py
de.py
Testing
test_lookup_utils.py
test_ultra_l1b_extended.py
test_ultra_l1b.py
Environment
poetry.lock
pyproject.toml