OGGM / massbalance-sandbox

New generation of OGGM mass-balance models
BSD 3-Clause "New" or "Revised" License
6 stars 11 forks source link

Pytest issues & code upgrade: re-name climate variables to the latest version #49

Open bearecinos opened 6 months ago

bearecinos commented 6 months ago

Two pytests fail due to the same problem: different mass balance keys for time between old and new oggm version.

image

pytests fails

In test_hydro.py

These two dataframes end up with different column names (the one produced with the sandbox code has only calendar .. the other one hydro):

odf_mean_monthly_d_mb.columns
Index(['calendar_day_2d', 'melt_off_glacier', 'melt_on_glacier',
       'liq_prcp_off_glacier', 'liq_prcp_on_glacier', 'snowfall_off_glacier',
       'snowfall_on_glacier', 'snow_bucket', 'residual_mb', 'tot_prcp',
       'runoff'],
      dtype='object')
odf_ma.columns
Index(['hydro_month_2d', 'calendar_month_2d', 'melt_off_glacier',
       'melt_on_glacier', 'liq_prcp_off_glacier', 'liq_prcp_on_glacier',
       'snowfall_off_glacier', 'snowfall_on_glacier', 'snow_bucket',
       'residual_mb'],
      dtype='object')

So First I thought its possible that the change from hydro to calendar in the flowline.pyv1.6 is messing this test, but if @lilianschuster is re-sampling the daily output to monthly, in order to compare it with the default OGGM monthly output you should change the variable name to calendar_month_2d instead of daily?

I then did a varname to varname comparison outside of the for loop, to bypass the 'hydro_month_2d', 'calendar_month_2d' & 'calendar_day_2d' names issue.

assert_allclose(odf_mean_monthly_d_mb['melt_off_glacier'][2:], odf_ma['melt_off_glacier'][2:], rtol=1.0) #(only passes with tol = 1.0) ✔️ assert_allclose(odf_mean_monthly_d_mb['melt_on_glacier'][2:], odf_ma['melt_on_glacier'][2:], rtol=1e-5) ✔️ assert_allclose(odf_mean_monthly_d_mb['liq_prcp_off_glacier'][2:], odf_ma['liq_prcp_off_glacier'][2:], rtol=1e-5) ✔️ assert_allclose(odf_mean_monthly_d_mb['snowfall_off_glacier'][2:], odf_ma['snowfall_off_glacier'][2:], rtol=1e-5) ✔️
assert_allclose(odf_mean_monthly_d_mb['snowfall_on_glacier'][2:], odf_ma['snowfall_on_glacier'][2:], rtol=1e-5) ✔️

assert_allclose(odf_mean_monthly_d_mb['snow_bucket'][2:], odf_ma['snow_bucket'][2:], rtol=1e-5) ❌ This one and residual_mb are very different! But I guess you don't expect them to be the same..

I think the solution to this is quite simple but for me to identify where exactly the hydro to calendar changes will go in the sandbox is a bit tricky... But if you tell me more or less if I am in the right direction I'm sure we can figure it out 😃