def read_climate_statistics(gdir): """Reads the annual cycle of climate for [1985-2015] at the glacier terminus elevation. Parameters ---------- gdir : the glacier directory Returns ------- a pandas Dataframe with monthly average temp and precip """ with xr.open_dataset(gdir.get_filepath('climate_monthly')) as ds: ds = ds.load() ds = ds.sel(time=slice('1985', '2015')) dsm = ds.groupby('time.month').mean(dim='time') odf = pd.DataFrame() odf['temp_celcius'] = dsm.temp.to_series() odf['prcp_mm_mth'] = dsm.prcp.to_series() # We correct for altitude difference d = utils.glacier_statistics(gdir) odf['temp_celcius'] += (ds.ref_hgt - d['flowline_min_elev']) * 0.0065 return odf
def compute_climate_statistics(gdir, tmin='1985', tmax='2015', lapse_rate=0.0065): """Computes monthly average temperature and precipitation during the climate period defined by tmin and tmax. Temperatures are reduced to the terminus elevation assuming a constant lapse rate. Parameters ---------- gdir : oggm.GlacierDirectory the glacier directory defined by oggm tmin : int the beginning of the period of interest tmax : int the end of the period of interest Returns ------- odf : pd.DataFrame dataframe containing monthly average temperature and precipitation during tmin-tmax """ try: with xr.open_dataset(gdir.get_filepath('climate_monthly')) as ds: ds = ds.load() except FileNotFoundError: with xr.open_dataset(gdir.get_filepath('climate_historical')) as ds: ds = ds.load() ds = ds.sel(time=slice(str(tmin), str(tmax))) dsm = ds.groupby('time.month').mean(dim='time') odf = pd.DataFrame() odf['temp_celcius'] = dsm.temp.to_series() odf['prcp_mm_mth'] = dsm.prcp.to_series() # We correct for altitude difference d = utils.glacier_statistics(gdir) odf['temp_celcius'] += (ds.ref_hgt - d['flowline_min_elev']) * lapse_rate return odf