-
Notifications
You must be signed in to change notification settings - Fork 40
CoDICE l2 sw species metadata update #3378
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
Open
lacoak21
wants to merge
4
commits into
IMAP-Science-Operations-Center:dev
Choose a base branch
from
lacoak21:codice_l2_fix_metdata
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # <=== Useful Variables ===> | ||
| real_fillval: &real_fillval -1.0E+31 | ||
|
|
||
| # <=== Coordinates ===> | ||
| energy_per_charge: | ||
| CATDESC: Energy per charge | ||
| DEPEND_1: esa_step | ||
| FIELDNAM: Energy per charge | ||
| FILLVAL: *real_fillval | ||
| FORMAT: F12.6 | ||
| LABLAXIS: E/q | ||
| SCALETYP: log | ||
| UNITS: keV/e | ||
| VALIDMAX: 81.216 | ||
| VALIDMIN: 0.00288 | ||
| VAR_TYPE: support_data | ||
|
|
||
| # <=== LABL_PTR_i Attributes ===> | ||
| energy_per_charge_label: | ||
| CATDESC: Energy per charge | ||
| DEPEND_1: esa_step | ||
| FIELDNAM: Energy per charge | ||
| FORMAT: A10 | ||
| VAR_TYPE: metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,11 @@ | |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def convert_to_rates(dataset: xr.Dataset, descriptor: str) -> np.ndarray: | ||
| def convert_to_rates( | ||
| dataset: xr.Dataset, | ||
| descriptor: str, | ||
| cdf_attrs: ImapCdfAttributes | None = None, | ||
| ) -> np.ndarray: | ||
| """ | ||
| Apply a conversion from counts to rates. | ||
|
|
||
|
|
@@ -35,6 +39,10 @@ def convert_to_rates(dataset: xr.Dataset, descriptor: str) -> np.ndarray: | |
| The L1b dataset containing the data to convert. | ||
| descriptor : str | ||
| The descriptor of the data product of interest. | ||
| cdf_attrs : ImapCdfAttributes | ||
| The CDF attributes manager, with L1b variable attributes loaded. | ||
| Callers that only need the intermediate values (e.g. I-ALiRT, which | ||
| discards them after computing ratios) can omit this. | ||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -49,19 +57,31 @@ def convert_to_rates(dataset: xr.Dataset, descriptor: str) -> np.ndarray: | |
| ) | ||
| if descriptor.startswith("lo-"): | ||
| # Calculate energy_per_charge using voltage_table and k_factor | ||
| energy_attrs = dataset["voltage_table"].attrs | { | ||
| "UNITS": "keV/e", | ||
| "LABLAXIS": "E/q", | ||
| "CATDESC": "Energy per charge", | ||
| "FIELDNAM": "Energy per charge", | ||
| } | ||
| # 1e3 is to convert eV to keV | ||
| energy_per_charge = ( | ||
| dataset["voltage_table"].values * dataset["k_factor"].values * 1e-3 | ||
| ) | ||
| dataset["energy_per_charge"] = xr.DataArray( | ||
| dataset["voltage_table"].values * dataset["k_factor"].values * 1e-3, | ||
| energy_per_charge, | ||
| dims=[ | ||
| "esa_step", | ||
| ], | ||
| attrs=energy_attrs, | ||
| attrs=cdf_attrs.get_variable_attributes( | ||
| "energy_per_charge", check_schema=False | ||
| ) | ||
| if cdf_attrs is not None | ||
| else {}, | ||
| ) | ||
| dataset["energy_per_charge_label"] = xr.DataArray( | ||
| np.array([f"{value:.3f}" for value in energy_per_charge]), | ||
| dims=[ | ||
| "esa_step", | ||
| ], | ||
| attrs=cdf_attrs.get_variable_attributes( | ||
| "energy_per_charge_label", check_schema=False | ||
| ) | ||
| if cdf_attrs is not None | ||
| else {}, | ||
| ) | ||
|
lacoak21 marked this conversation as resolved.
|
||
|
|
||
| if descriptor in [ | ||
|
|
@@ -180,6 +200,7 @@ def process_codice_l1b(file_path: Path) -> xr.Dataset: | |
| # Get the L1b CDF attributes | ||
| cdf_attrs = ImapCdfAttributes() | ||
| cdf_attrs.add_instrument_global_attrs("codice") | ||
| cdf_attrs.add_instrument_variable_attrs("codice", "l1b") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I didn't realize we are not using l1b attrs. Nice addition! |
||
|
|
||
| # Use the L1a data product as a starting point for L1b | ||
| l1b_dataset = l1a_dataset.copy(deep=True) | ||
|
|
@@ -190,4 +211,5 @@ def process_codice_l1b(file_path: Path) -> xr.Dataset: | |
| return convert_to_rates( | ||
| l1b_dataset, | ||
| descriptor, | ||
| cdf_attrs, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so this is handler for I-ALiRT use case? If so, can you add note about that? I am afraid that we will loose this context in the future.
Same comment for below if check.