Closed DamienIrving closed 1 year ago
Thanks @DamienIrving for the well documented issue.
Can we generalize this to any index involving a difference ? This would be the following generic indices:
As a fix, we could convert to degC before doing the computation so that we would have the expected ECAD output unit (degC). However, with farennheit it means the output might be unexpected:
x = 10 degF # ~= -12 degC
y = 50 degF # == 10degC
y - x == "40 degF"
x_c = -12 degC
y_c = 10 degC
y_c - x_c = 32degC
not actual code
Otherwise we can choose to not follow the ECAD recommended unit for these indices and avoid unit conversion completely. edit: It means the output would have the same unit as one of the input.
A related CF issue: https://github.com/cf-convention/vocabularies/issues/125
Yes, this issue can be generalised to any index involving a difference.
That CF issue is interesting and captures the root of the problem - we're dealing with relative as opposed to absolute temperatures with these indices involving a difference.
I think I'd lean towards converting to degC before doing the calculation. I appreciate that creates a slight interpretation issue with respect to Fahrenheit temperatures, but I think it's the best option.
I also think that we should convert before the calculation, it is the safest option.
On Feb 15, 2023, at 12:35 AM, Damien Irving @.***> wrote:
Yes, this issue can be generalised to any index involving a difference.
That CF issue is interesting and captures the root of the problem - we're dealing with relative as opposed to absolute temperatures with these indices involving a difference.
I think I'd lean towards converting to degC before doing the calculation. I appreciate that creates a slight interpretation issue with respect to Fahrenheit temperatures, but I think it's the best option.
— Reply to this email directly, view it on GitHub https://github.com/cerfacs-globc/icclim/issues/255#issuecomment-1430531207, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXZ3ST7BMGZ6LNUK6M7AETWXQJDBANCNFSM6AAAAAAU22D3GE. You are receiving this because you are subscribed to this thread.
I finally have some time to work on a fix, I will try to publish the PR soon.
Description
It appears that for indices that involve calculating the difference between two temperatures (e.g. DTR, ETR, VDTR), unit conversion is performed after the difference is taken. This is problematic if the input units are Kelvin, because the difference between two temperatures in Kelvin is equivalent to the difference in Celsius and hence no unit conversion is required.
Minimal reproducible example
Example 2: Index ETR
Output received
The output (in
out_f
) is a data array (with units = C) whose values range from -270 to -182 because unit conversion (i.e. subtracting 273.15 to move from K to C) appears to have been performed after the difference in temperatures (in Kelvin) was calculated.