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

fix qc handling #136

Merged
merged 4 commits into from
Jan 28, 2025
Merged

fix qc handling #136

merged 4 commits into from
Jan 28, 2025

Conversation

hgloeckner
Copy link
Contributor

  • fix the ancillary vars in l3
  • add the 'all' flag to the example config

@hgloeckner hgloeckner mentioned this pull request Jan 17, 2025
Copy link
Contributor

@tmieslinger tmieslinger left a comment

Choose a reason for hiding this comment

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

Could you help me understand the default behaviour of the function add_qc_to_interim_l3?

  1. If nothing is explicitly specified keepwould be keep=["sonde_qc"].
  2. you'd end up in the else-block (line1512) and something will happen to all var != "sonde_id" the ds[var].attrs
  3. and now, would you not end up again in the else-block line 1533 and get the warning? keep would be reset to keep=[]
  4. keep=[] would be appended again by ["sonde_qc"] before ds_qc is created

This seems strange and I am pretty sure I have a bug in my thinking somewhere. Could you go through the default behaviour once and point me to my bug? 😅

pydropsonde/helper/quality.py Show resolved Hide resolved
Comment on lines +1514 to +1525
if var != "sonde_id":
ds[var].attrs.pop("ancillary_variables", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot follow here: do you remove the key "ancillary_variables" from the dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. if not all qc variables from level2 to level3, then the entry in the attributes of the variables is deleted (otherwise it would be referring to qc variables that are no longer in the dataset).
The attribute is just a string, so I thought it would be easier to completely remove it first and then add it again later with the qc flags that actually made it into the dataset.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense :)

Comment on lines +1522 to +1541
for var in self.qc.qc_by_var.keys():
ds = hx.add_ancillary_var(ds, var, var + "_qc")
if (not np.isin("q", self.qc.qc_vars)) and np.isin(
"rh", self.qc.qc_vars
):
ds = hx.add_ancillary_var(ds, "q", "rh_qc")
if (not np.isin("theta", self.qc.qc_vars)) and np.isin(
"ta", self.qc.qc_vars
):
ds = hx.add_ancillary_var(ds, "theta", "ta_qc")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I can follow here. However, from the previous changes to add_variable_flags_to_ds I had thought that you'd be able to handle those explicitly stated cases with add_variable_flags_to_ds(add_to=...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

theoretically yes, but the if is necessary anyways right? And this is already the case where all the qc details are dropped, so it doesn't make a difference. (or am i missing something?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, maybe in other words: the change above is such that one can add all the qc flags from one variable to another. For example, rh_qc, rh_near_surface_count, rh_profile_fullness can be added with this one liner as ancillaries to q. It also calculates the aggregated qc flag for a variable, which is not necessary here since the aggregated flag already exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand now better the different QCs :) thanks!

@hgloeckner
Copy link
Contributor Author

Could you help me understand the default behaviour of the function add_qc_to_interim_l3?

1. If nothing is explicitly specified `keep`would be `keep=["sonde_qc"]`.

2. you'd end up in the `else`-block (line1512) and something will happen to all var != "sonde_id" the `ds[var].attrs`

3. and now, would you not end up again in the `else`-block line 1533 and get the warning? keep would be reset to `keep=[]`

4. `keep=[]` would be appended again by ["sonde_qc"] before ds_qc is created

This seems strange and I am pretty sure I have a bug in my thinking somewhere. Could you go through the default behaviour once and point me to my bug? 😅

You are completly right. the default should be None.

Copy link
Contributor

@tmieslinger tmieslinger left a comment

Choose a reason for hiding this comment

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

The changes seem fine to me :)
Working my way through the QC also reminded me of the advantage of adding more info on QC handling to the documentation "soonish", maybe when the QC related PRs are merged.

Comment on lines +1514 to +1525
if var != "sonde_id":
ds[var].attrs.pop("ancillary_variables", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense :)

Comment on lines +1522 to +1541
for var in self.qc.qc_by_var.keys():
ds = hx.add_ancillary_var(ds, var, var + "_qc")
if (not np.isin("q", self.qc.qc_vars)) and np.isin(
"rh", self.qc.qc_vars
):
ds = hx.add_ancillary_var(ds, "q", "rh_qc")
if (not np.isin("theta", self.qc.qc_vars)) and np.isin(
"ta", self.qc.qc_vars
):
ds = hx.add_ancillary_var(ds, "theta", "ta_qc")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand now better the different QCs :) thanks!

@hgloeckner hgloeckner force-pushed the fix_qc_handling branch 2 times, most recently from 58034ea to 23606ba Compare January 28, 2025 14:46
@hgloeckner hgloeckner merged commit e7fcd44 into atmdrops:main Jan 28, 2025
5 checks passed
@hgloeckner hgloeckner deleted the fix_qc_handling branch February 6, 2025 09:54
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.

2 participants