def parse_rgi_meta(version=None): """Read the meta information (region and sub-region names)""" global _RGI_METADATA if version is None: version = cfg.PARAMS['rgi_version'] if version in _RGI_METADATA: return _RGI_METADATA[version] # Parse RGI metadata reg_names = pd.read_csv(get_demo_file('rgi_regions.csv'), index_col=0) if version in ['4', '5']: # The files where different back then subreg_names = pd.read_csv(get_demo_file('rgi_subregions_V5.csv'), index_col=0) else: f = os.path.join(get_demo_file('rgi_subregions_' 'V{}.csv'.format(version))) subreg_names = pd.read_csv(f) subreg_names.index = ['{:02d}-{:02d}'.format(s1, s2) for s1, s2 in zip(subreg_names['O1'], subreg_names['O2'])] subreg_names = subreg_names[['Full_name']] # For idealized reg_names.loc[0] = ['None'] subreg_names.loc['00-00'] = ['None'] _RGI_METADATA[version] = (reg_names, subreg_names) return _RGI_METADATA[version]
def apply_test_ref_tstars(baseline='cru4'): """Copy the testing ref tstars to the current working directory. Used mostly for testing. """ if not os.path.exists(cfg.PATHS['working_dir']): raise RuntimeError('Need a valid working_dir') shutil.copyfile(get_demo_file(f'oggm_ref_tstars_rgi5_{baseline}.csv'), os.path.join(cfg.PATHS['working_dir'], 'ref_tstars.csv')) shutil.copyfile( get_demo_file(f'oggm_ref_tstars_rgi5_{baseline}_calib_' f'params.json'), os.path.join(cfg.PATHS['working_dir'], 'ref_tstars_params.json'))
def get_ref_length_data(gdir): """Get the glacier lenght data from P. Leclercq's data base. https://folk.uio.no/paulwl/data.php For some glaciers only! """ df = pd.read_csv('rgi_leclercq_links_2014_RGIV6.csv') df = df.loc[df.RGI_ID == gdir.rgi_id] if len(df) == 0: raise RuntimeError('No length data found for this glacier!') ide = df.LID.values[0] f = get_demo_file('Glacier_Lengths_Leclercq.nc') with xr.open_dataset(f) as dsg: # The database is not sorted by ID. Don't ask me... grp_id = np.argwhere(dsg['index'].values == ide)[0][0] + 1 with xr.open_dataset(f, group=str(grp_id)) as ds: df = ds.to_dataframe() df.name = ds.glacier_name return df