Skip to content

Commit

Permalink
Added test for the new RGI7 compatibility of the init_glacier_directo…
Browse files Browse the repository at this point in the history
…ries workflow (#1522)
  • Loading branch information
afisc committed Feb 11, 2023
1 parent 7e99b9e commit 197b2f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
6 changes: 5 additions & 1 deletion oggm/cli/prepro_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ def _time_log():

if is_test:
if test_ids is not None:
rgidf = rgidf.loc[rgidf.RGIId.isin(test_ids)]
try:
rgidf = rgidf.loc[rgidf.RGIId.isin(test_ids)]
except AttributeError:
#RGI7
rgidf = rgidf.loc[rgidf.rgi_id.isin(test_ids)]
else:
rgidf = rgidf.sample(4)

Expand Down
2 changes: 2 additions & 0 deletions oggm/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def secure_url_retrieve(url, *args, **kwargs):
'cluster.klima.uni-bremen.de/~oggm/test_files/' in url or
'klima.uni-bremen.de/~oggm/climate/cru/cru_cl2.nc.zip' in url or
'klima.uni-bremen.de/~oggm/geodetic_ref_mb' in url or
# this URL might be removed again after the final integration of RGI7 OGGM
'https://cluster.klima.uni-bremen.de/~fmaussion/misc/rgi7_data/00_rgi70_regions/' in url or
base_extra_L4 in url or
base_extra_L3 in url
)
Expand Down
18 changes: 18 additions & 0 deletions oggm/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,21 @@ def test_plot_region_model():

fig.tight_layout()
return fig


def test_rgi7_glacier_dirs():
# create test dir
if not os.path.exists(_TEST_DIR):
os.makedirs(_TEST_DIR)
# initialize
cfg.initialize()
# no intersects for RGI7 available
cfg.PARAMS['use_intersects'] = False
cfg.PATHS['working_dir'] = _TEST_DIR
# load and read test data
hef_rgi7_df = gpd.read_file(get_demo_file('Hintereisferner_RGI7.shp'))
# create GDIR
gdir = workflow.init_glacier_directories(hef_rgi7_df)[0]
assert gdir
assert gdir.rgi_region == '11'
assert gdir.rgi_area_km2 > 8
2 changes: 1 addition & 1 deletion oggm/utils/_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# The given commit will be downloaded from github and used as source for
# all sample data
SAMPLE_DATA_GH_REPO = 'OGGM/oggm-sample-data'
SAMPLE_DATA_COMMIT = '1a9caabc81a85c206fbb3bcc2dbea9a07c586bc6'
SAMPLE_DATA_COMMIT = 'a7cca19707bbb7f38c911cc94659ff34334a1d63'

CHECKSUM_URL = 'https://cluster.klima.uni-bremen.de/data/downloads.sha256.hdf'
CHECKSUM_VALIDATION_URL = CHECKSUM_URL + '.sha256'
Expand Down
5 changes: 3 additions & 2 deletions oggm/utils/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def parse_rgi_meta(version=None):

# Parse RGI metadata
if version == '7':
reg_names = gpd.read_file(file_downloader('https://cluster.klima.uni-bremen.de/~fmaussion/misc/rgi7_data/00_rgi70_regions/00_rgi70_O1Regions/00_rgi70_O1Regions.dbf'))
rgi7url = 'https://cluster.klima.uni-bremen.de/~fmaussion/misc/rgi7_data/00_rgi70_regions/'
reg_names = gpd.read_file(file_downloader(rgi7url + '00_rgi70_O1Regions/00_rgi70_O1Regions.dbf'))
reg_names.index = reg_names['o1region'].astype(int)
reg_names = reg_names['full_name']
subreg_names = gpd.read_file(file_downloader('https://cluster.klima.uni-bremen.de/~fmaussion/misc/rgi7_data/00_rgi70_regions/00_rgi70_O2Regions/00_rgi70_O2Regions.dbf'))
subreg_names = gpd.read_file(file_downloader(rgi7url + '00_rgi70_O2Regions/00_rgi70_O2Regions.dbf'))
subreg_names.index = subreg_names['o2region']
subreg_names = subreg_names['full_name']

Expand Down

0 comments on commit 197b2f2

Please sign in to comment.