-
Notifications
You must be signed in to change notification settings - Fork 57
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
Support for temperature differences in CF attributes #1836
base: main
Are you sure you want to change the base?
Changes from 2 commits
66ce334
a403c22
b93ba8a
6227609
2d59a8d
4fae706
f891332
5539c79
9083982
695b8c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -701,6 +701,7 @@ def temperature_sum( | |
|
||
out = (data - threshold).where(cond).resample(time=freq).sum() | ||
out = direction * out | ||
out.attrs["units_metadata"] = "temperature: difference" | ||
return to_agg_units(out, data, "integral") | ||
Comment on lines
+920
to
921
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. For degC input, this outputs:
because #1804 decided that we should avoid delta temperatures and put absolute ones instead. Should we revert this ? In any case, I think 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. You mean revert going through absolute temperature ? I think this is not necessary with this PR. Not sure about 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. Well, going to absolute temperatures and this PR both try to solve the same problem. I guess they are compatible, but I feel both aren't needed at the same time. We could revert to make it cleaner. My point about 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 didn't want to sabotage the work you had done and it seemed prudent to keep the changes as small as possible. So no strong opinion on this one. My thinking was that 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. Well it now does/could with your additions, no ? But in any case, isn't the logic the same ? All operations that transform an |
||
|
||
|
||
|
@@ -718,7 +719,6 @@ def interday_diurnal_temperature_range( | |
freq : str | ||
Resampling frequency defining the periods as defined in :ref:`timeseries.resampling`. | ||
|
||
|
||
Returns | ||
------- | ||
xr.DataArray | ||
|
@@ -728,8 +728,8 @@ def interday_diurnal_temperature_range( | |
vdtr = abs((high_data - low_data).diff(dim="time")) | ||
out = vdtr.resample(time=freq).mean(dim="time") | ||
|
||
u = str2pint(low_data.units) | ||
out.attrs["units"] = pint2cfunits(u - u) | ||
out.attrs["units"] = low_data.attrs["units"] | ||
out.attrs["units_metadata"] = "temperature: difference" | ||
return out | ||
|
||
|
||
|
@@ -755,8 +755,8 @@ def extreme_temperature_range( | |
|
||
out = high_data.resample(time=freq).max() - low_data.resample(time=freq).min() | ||
|
||
u = str2pint(low_data.units) | ||
out.attrs["units"] = pint2cfunits(u - u) | ||
out.attrs["units"] = low_data.attrs["units"] | ||
out.attrs["units_metadata"] = "temperature: difference" | ||
return out | ||
|
||
|
||
|
@@ -892,6 +892,8 @@ def cumulative_difference( | |
if freq is not None: | ||
diff = diff.resample(time=freq).sum(dim="time") | ||
|
||
diff.attrs["units_metadata"] = "temperature: difference" | ||
|
||
return to_agg_units(diff, data, op="integral") | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -583,7 +583,8 @@ def _annual_cycle( | |
# TODO: In April 2024, use a match-case. | ||
if stat == "absamp": | ||
out = ac.max("dayofyear") - ac.min("dayofyear") | ||
out.attrs["units"] = xc.core.units.ensure_delta(units) | ||
out.attrs["units"] = units | ||
out.attrs["units_metadata"] = "temperature: difference" | ||
huard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif stat == "relamp": | ||
out = (ac.max("dayofyear") - ac.min("dayofyear")) * 100 / ac.mean("dayofyear") | ||
out.attrs["units"] = "%" | ||
|
@@ -699,7 +700,8 @@ def _annual_statistic( | |
|
||
if stat == "absamp": | ||
out = yrs.max() - yrs.min() | ||
out.attrs["units"] = xc.core.units.ensure_delta(units) | ||
out.attrs["units"] = units | ||
out.attrs["units_metadata"] = "temperature: difference" | ||
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. un ptit dernier! 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. Merci ! Ça me fait penser que 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. Je ne trouve pas 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. En théorie il n'y a pas d'autres unités ayant le problème "difference" vs "on_scale". En tout cas, rien dans pint, rien dans CF. 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. mais le problème de division par zero dans "relamp" ne dépend pas de "difference" vs "on_scale". 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. En effet, les unités de relamp ne dépendent pas de rien d'autre. Et je suis d'accord que la division par zéro est un autre problème. Même que de changer les unités de degC a K pour calculer un % n'est peut-être pas quelque chose qu'on devrait faire silencieusement ? Je propose de pelleter le problème chez l'usager. Et donc de ne rien faire. |
||
elif stat == "relamp": | ||
out = (yrs.max() - yrs.min()) * 100 / yrs.mean() | ||
out.attrs["units"] = "%" | ||
|
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.
PVI, "pluvieux" avait été remplacé par "avec précipitation" à beaucoup d'endroits dans #1123.
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.
Ok, bon à savoir. Je vais faire un autre PR pour harmoniser.