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

fixes for pandas deprecated syntax #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions MBsandbox/massbalance_sandbox_oggm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,16 +1294,16 @@ def get_specific_winter_mb(self, heights, year=None, #begin_winter_mb=None, end_
pd_mb_overview_sel_gdir = pd_mb_overview.loc[pd_mb_overview.rgi_id == self.fl.rgi_id]
pd_mb_overview_sel_gdir_yr = pd_mb_overview_sel_gdir.loc[pd_mb_overview_sel_gdir.Year == year]
### starting period
m_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype(np.datetime64).iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype(np.datetime64).iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype(np.datetime64).iloc[0].days_in_month
m_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype('datetime64[ns]').iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype('datetime64[ns]').iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype('datetime64[ns]').iloc[0].days_in_month
# ratio of 1st month that we want to estimate?
# if d_start is 1 -> ratio should be 1 --> the entire month should be added to the winter MB
ratio_m_start = 1 - (d_start-1)/m_start_days_in_month
### end period
m_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].day
m_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].day
# ratio of last month that we want to estimate?
# if d_end == m_end_days_in_month, then the entire month should be used
ratio_m_end = d_end/m_end_days_in_month
Expand Down Expand Up @@ -1484,16 +1484,16 @@ def get_specific_summer_mb(self, heights, year=None, # begin_winter_mb=None, en
pd_mb_overview_sel_gdir = pd_mb_overview.loc[pd_mb_overview.rgi_id == self.fl.rgi_id]
pd_mb_overview_sel_gdir_yr = pd_mb_overview_sel_gdir.loc[pd_mb_overview_sel_gdir.Year == year]
### starting period
m_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].days_in_month
m_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].days_in_month
# ratio of 1st month that we want to estimate?
# if d_start is 1 -> ratio should be 1 --> the entire month should be added to the winter MB
ratio_m_start = 1 - (d_start - 1) / m_start_days_in_month
### end period
m_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype(np.datetime64).iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype(np.datetime64).iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype(np.datetime64).iloc[0].day
m_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype('datetime64[ns]').iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype('datetime64[ns]').iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype('datetime64[ns]').iloc[0].day
# ratio of last month that we want to estimate?
# if d_end == m_end_days_in_month, then the entire month should be used
ratio_m_end = d_end / m_end_days_in_month
Expand Down
28 changes: 14 additions & 14 deletions MBsandbox/mbmod_daily_oneflowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,16 +1770,16 @@ def get_specific_winter_mb(self, heights, year=None, #begin_winter_mb=None, end_
pd_mb_overview_sel_gdir = pd_mb_overview.loc[pd_mb_overview.rgi_id == self.fl.rgi_id]
pd_mb_overview_sel_gdir_yr = pd_mb_overview_sel_gdir.loc[pd_mb_overview_sel_gdir.Year == year]
### starting period
m_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype(np.datetime64).iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype(np.datetime64).iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype(np.datetime64).iloc[0].days_in_month
m_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype('datetime64[ns]').iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype('datetime64[ns]').iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['BEGIN_PERIOD'].astype('datetime64[ns]').iloc[0].days_in_month
# ratio of 1st month that we want to estimate?
# if d_start is 1 -> ratio should be 1 --> the entire month should be added to the winter MB
ratio_m_start = 1 - (d_start-1)/m_start_days_in_month
### end period
m_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].day
m_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].day
# ratio of last month that we want to estimate?
# if d_end == m_end_days_in_month, then the entire month should be used
ratio_m_end = d_end/m_end_days_in_month
Expand Down Expand Up @@ -1960,16 +1960,16 @@ def get_specific_summer_mb(self, heights, year=None, # begin_winter_mb=None, en
pd_mb_overview_sel_gdir = pd_mb_overview.loc[pd_mb_overview.rgi_id == self.fl.rgi_id]
pd_mb_overview_sel_gdir_yr = pd_mb_overview_sel_gdir.loc[pd_mb_overview_sel_gdir.Year == year]
### starting period
m_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype(np.datetime64).iloc[0].days_in_month
m_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].month
d_start = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].day
m_start_days_in_month = pd_mb_overview_sel_gdir_yr['END_WINTER'].astype('datetime64[ns]').iloc[0].days_in_month
# ratio of 1st month that we want to estimate?
# if d_start is 1 -> ratio should be 1 --> the entire month should be added to the winter MB
ratio_m_start = 1 - (d_start - 1) / m_start_days_in_month
### end period
m_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype(np.datetime64).iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype(np.datetime64).iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype(np.datetime64).iloc[0].day
m_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype('datetime64[ns]').iloc[0].month + 1
m_end_days_in_month = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype('datetime64[ns]').iloc[0].days_in_month
d_end = pd_mb_overview_sel_gdir_yr['END_PERIOD'].astype('datetime64[ns]').iloc[0].day
# ratio of last month that we want to estimate?
# if d_end == m_end_days_in_month, then the entire month should be used
ratio_m_end = d_end / m_end_days_in_month
Expand Down Expand Up @@ -3891,7 +3891,7 @@ def get_annual_mb(self, heights, year=None,
mb = self.interp_yr(heights)

pd_out = pd.DataFrame({'yr': year, 'heights': heights, 'mb': mb})
self._mb_debug_container = self._mb_debug_container.append(pd_out)
self._mb_debug_container = pd.concat([self._mb_debug_container, pd_out], ignore_index=True)

if add_climate:
t, tmelt, prcp, prcpsol = self.get_annual_climate(heights)
Expand Down Expand Up @@ -4576,5 +4576,5 @@ def get_annual_mb(self, heights, year=None, **kwargs):
else:
_mb_spec = _mb
pd_out = pd.DataFrame({'yr': year, 'ryr': ryr, 'heights': heights, 'mb': _mb_spec})
self._mb_debug_container = self._mb_debug_container.append(pd_out)
self._mb_debug_container = pd.concat([self._mb_debug_container, pd_out], ignore_index=True)
return _mb
6 changes: 3 additions & 3 deletions MBsandbox/tests/test_hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def test_hydro_daily_vs_annual_from_oggm_core(self, gdir, #inversion_params,
odf_mean_monthly_d_mb = odf_da.resample("M").sum()
#snow bucket is a sate variable so NO sum
odf_mean_monthly_d_mb["snow_bucket"] = odf_da["snow_bucket"].resample("M").mean()

odf_mean_monthly_d_mb.rename(columns={'calendar_day_2d': 'calendar_month_2d'}, inplace=True)
#assert mean monthly from daily mb and from monthly mb are similar
#np.testing.assert_array_equal(odf_mean_monthly_d_mb.columns[1:], odf_ma.columns[1:])
#mean monthly from daily and monthly mb are not the same for February because leap years are included in daily mb,
Expand All @@ -732,7 +732,7 @@ def test_hydro_daily_vs_annual_from_oggm_core(self, gdir, #inversion_params,
for c in odf_ma.columns[1:]:
rtol = 1e-5
if c == 'melt_off_glacier':
#rtol = 0.15
rtol = 1.0
# quite different, up tp 50%!
# but this is 'ok' as fabien said
# run_with_hydro with annual update is just very different there
Expand All @@ -744,7 +744,7 @@ def test_hydro_daily_vs_annual_from_oggm_core(self, gdir, #inversion_params,
rtol = 0.8 #0.5
if not tests_melt_off_glacier:
continue
if c in ['snow_bucket'] or c == 'residual_mb':
if c in ['calendar_month_2d', 'snow_bucket'] or c == 'residual_mb':
continue
print(c)
assert_allclose(odf_mean_monthly_d_mb[c][2:], odf_ma[c][2:], rtol=rtol)
Expand Down
16 changes: 8 additions & 8 deletions MBsandbox/tests/test_mb_modules_oneflowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,8 @@ def test_specific_winter_mb_no_sfc_type(self, gdir, gdir_aletsch, mb_type):
for e, y in enumerate(pd_mb_overview_sel_gdir_aletsch.Year):
# if the actual WGMS period is longer than the default Oct1st - Apr30 period, at least precipitation
# should be more!
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype(np.datetime64)[y].month < 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype(np.datetime64)[y].month > 4
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype('datetime64[ns]')[y].month < 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype('datetime64[ns]')[y].month > 4
if condi_m_e and condi_m_s:
### all those that are always above zero and are summed up should be larger:
# tfm (here it can also be equal)
Expand All @@ -978,8 +978,8 @@ def test_specific_winter_mb_no_sfc_type(self, gdir, gdir_aletsch, mb_type):

# if the actual WGMS period is short than the default Oct1st - Apr30 period, at least precipitation
# should be smaller!
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype(np.datetime64)[y].month >= 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype(np.datetime64)[y].month <= 4
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype('datetime64[ns]')[y].month >= 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype('datetime64[ns]')[y].month <= 4
if condi_m_e and condi_m_s:
### all those that are always above zero and are summed up should be larger:
# tfm (here it can also be equal)
Expand Down Expand Up @@ -1226,8 +1226,8 @@ def test_specific_winter_mb_sfc_type(self, gdir, gdir_aletsch, mb_type):
for e, y in enumerate(pd_mb_overview_sel_gdir_aletsch.Year):
# if the actual WGMS period is longer than the default Oct1st - Apr30 period, at least precipitation
# should be more!
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype(np.datetime64)[y].month < 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype(np.datetime64)[y].month > 4
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype('datetime64[ns]')[y].month < 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype('datetime64[ns]')[y].month > 4
if condi_m_e and condi_m_s:
### all those that are always above zero and are summed up should be larger:
# tfm (here it can also be equal)
Expand All @@ -1239,8 +1239,8 @@ def test_specific_winter_mb_sfc_type(self, gdir, gdir_aletsch, mb_type):

# if the actual WGMS period is short than the default Oct1st - Apr30 period, at least precipitation
# should be smaller!
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype(np.datetime64)[y].month >= 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype(np.datetime64)[y].month <= 4
condi_m_s = pd_mb_overview_sel_gdir_aletsch['BEGIN_PERIOD'].astype('datetime64[ns]')[y].month >= 10
condi_m_e = pd_mb_overview_sel_gdir_aletsch['END_WINTER'].astype('datetime64[ns]')[y].month <= 4
if condi_m_e and condi_m_s:
### all those that are always above zero and are summed up should be larger:
# tfm (here it can also be equal)
Expand Down