Skip to content

Commit

Permalink
Merge 504f3b5 into ba6ffed
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Oct 26, 2022
2 parents ba6ffed + 504f3b5 commit bf80dfc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
12 changes: 9 additions & 3 deletions oggm/shop/millan22.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def _filter_and_reproj(gdir, var, gdf, allow_neg=True):

# Subset to avoid mega files
dsb = salem.GeoTiff(input_file)
x0, x1, y0, y1 = gdir.grid.extent
dsb.set_subset(corners=((x0, y0), (x1, y1)), crs=gdir.grid.proj, margin=5)
x0, x1, y0, y1 = gdir.grid.extent_in_crs(dsb.grid.proj)
dsb.set_subset(corners=((x0, y0), (x1, y1)),
crs=dsb.grid.proj,
margin=5)

data = _filter(dsb)
if not allow_neg:
Expand Down Expand Up @@ -185,7 +187,11 @@ def velocity_to_gdir(gdir, add_error=False):
f'glacier: {gdir.rgi_id}')

vel, files, grids = _filter_and_reproj(gdir, 'v', sel, allow_neg=False)
assert len(grids) == 1, 'Multiple velocity grids - dont know what to do.'
if len(grids) == 0:
raise RuntimeError('There is no velocity data for this glacier')
if len(grids) > 1:
raise RuntimeError('Multiple velocity grids - dont know what to do.')

sel = sel.loc[sel.file_id == files[0]]
vx, _, gridsx = _filter_and_reproj(gdir, 'vx', sel)
vy, _, gridsy = _filter_and_reproj(gdir, 'vy', sel)
Expand Down
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 = '8a3c41a36d190c6c78029b5032648ce94ee2026c'
SAMPLE_DATA_COMMIT = 'dbd57434df8fade8d8df9206839b9bf26a1ef8e6'

CHECKSUM_URL = 'https://cluster.klima.uni-bremen.de/data/downloads.sha256.hdf'
CHECKSUM_VALIDATION_URL = CHECKSUM_URL + '.sha256'
Expand Down
27 changes: 21 additions & 6 deletions oggm/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,34 @@ def gdir_from_tar(entity, from_tar):
return oggm.GlacierDirectory(entity, from_tar=from_tar)


def _check_rgi_input(rgidf=None):
def _check_rgi_input(rgidf=None, err_on_lvl2=False):
"""Complain if the input has duplicates."""

if rgidf is None:
return

msg = ('You have glaciers with connectivity level 2 in your list. '
'OGGM does not provide pre-processed directories for these.')

# Check if dataframe or list of strs
try:
rgi_ids = rgidf.RGIId
# if dataframe we can also check for connectivity
if 'Connect' in rgidf and np.any(rgidf['Connect'] == 2):
log.workflow('WARNING! You have glaciers with connectivity level '
'2 in your list. OGGM does not provide pre-processed '
'directories for these.')
if err_on_lvl2:
raise RuntimeError(msg)
except AttributeError:
rgi_ids = utils.tolist(rgidf)
# Check for Connectivity level 2 here as well
not_good_ids = pd.read_csv(utils.get_demo_file('rgi6_ids_conn_lvl2.csv'),
index_col=0)
try:
if err_on_lvl2 and len(not_good_ids.loc[rgi_ids]) > 0:
raise RuntimeError(msg)
except KeyError:
# Were good
pass

u, c = np.unique(rgi_ids, return_counts=True)
if len(u) < len(rgi_ids):
raise InvalidWorkflowError('Found duplicates in the list of '
Expand Down Expand Up @@ -342,7 +355,7 @@ def init_glacier_directories(rgidf=None, *, reset=False, force=False,
the initialised glacier directories
"""

_check_rgi_input(rgidf)
_check_rgi_input(rgidf, err_on_lvl2=from_prepro_level)

if reset and not force:
reset = utils.query_yes_no('Delete all glacier directories?')
Expand All @@ -355,7 +368,9 @@ def init_glacier_directories(rgidf=None, *, reset=False, force=False,
if cfg.PARAMS['has_internet'] and not utils.url_exists(url):
raise InvalidParamsError("base url seems unreachable with these "
"parameters: {}".format(url))
if 'oggm_v1.4' in url and from_prepro_level >=3 and not cfg.PARAMS['prcp_scaling_factor']:
if ('oggm_v1.4' in url and
from_prepro_level >= 3 and
not cfg.PARAMS['prcp_scaling_factor']):
log.warning('You seem to be using v1.4 directories with a more '
'recent version of OGGM. While this is possible, be '
'aware that some defaults parameters have changed. '
Expand Down

0 comments on commit bf80dfc

Please sign in to comment.