Skip to content

Commit

Permalink
Start from L1 in prepro gdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Nov 21, 2023
1 parent d3e951e commit fe3d6ea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
32 changes: 32 additions & 0 deletions oggm/cli/prepro_levels.py
Expand Up @@ -81,6 +81,7 @@ def run_prepro_levels(rgi_version=None, rgi_reg=None, border=None,
elev_bands=False, centerlines=False,
override_params=None,
mb_calibration_strategy='informed_threestep',
select_source_from_dir=None, keep_dem_folders=False,
add_consensus_thickness=False, add_itslive_velocity=False,
add_millan_thickness=False, add_millan_velocity=False,
add_hugonnet_dhdt=False,
Expand Down Expand Up @@ -133,6 +134,14 @@ def run_prepro_levels(rgi_version=None, rgi_reg=None, border=None,
- 'informed_threestep' (default)
- 'melt_temp'
- 'temp_melt'
select_source_from_dir : str
if starting from a level 1 "ALL" or "STANDARD" DEM sources directory,
select the chosen DEM source here. If you set it to "BY_RES" here,
COPDEM will be used and its resolution chosen based on the gdir's
map resolution (COPDEM30 for dx < 60 m, COPDEM90 elsewhere).
keep_dem_folders : bool
if `select_source_from_dir` is used, wether to keep the original
DEM folders in or not.
add_consensus_thickness : bool
adds (reprojects) the consensus estimates thickness to the glacier
directories. With elev_bands=True, the data will also be binned.
Expand Down Expand Up @@ -427,6 +436,16 @@ def _time_log():
'N elev bands type: {}.'
''.format(len(gdirs_cent), len(gdirs_band)))

# If we are coming from a multi-dem setup, let's select it from there
if select_source_from_dir is not None:
from oggm.shop.rgitopo import select_dem_from_dir
workflow.execute_entity_task(select_dem_from_dir, gdirs_band,
dem_source=select_source_from_dir,
keep_dem_folders=keep_dem_folders)
workflow.execute_entity_task(select_dem_from_dir, gdirs_cent,
dem_source=select_source_from_dir,
keep_dem_folders=keep_dem_folders)

# HH2015 method
workflow.execute_entity_task(tasks.simple_glacier_masks, gdirs_band)

Expand Down Expand Up @@ -814,6 +833,17 @@ def parse_args(args):
'compatible with level 1 folders, after which '
'the processing will stop. The default is to use '
'the default OGGM DEM.')
parser.add_argument('--select-source-from-dir', type=str,
default=None,
help='if starting from a level 1 "ALL" or "STANDARD" DEM '
'sources directory, select the chosen DEM source here. '
'If you set it to "BY_RES" here, COPDEM will be used and '
'its resolution chosen based on the gdirs map resolution '
'(COPDEM30 for dx < 60 m, COPDEM90 elsewhere).')
parser.add_argument('--keep-dem-folders', type=bool,
default=False,
help='if `select_source_from_dir` is used, wether to keep '
'the original DEM folders in or not.')
parser.add_argument('--add-consensus-thickness', nargs='?', const=True, default=False,
help='adds (reprojects) the consensus thickness '
'estimates to the glacier directories. '
Expand Down Expand Up @@ -919,6 +949,8 @@ def parse_args(args):
logging_level=args.logging_level,
elev_bands=args.elev_bands,
centerlines=args.centerlines,
select_source_from_dir=args.select_source_from_dir,
keep_dem_folders=args.keep_dem_folders,
add_consensus_thickness=args.add_consensus_thickness,
add_millan_thickness=args.add_millan_thickness,
add_itslive_velocity=args.add_itslive_velocity,
Expand Down
14 changes: 4 additions & 10 deletions oggm/shop/rgitopo.py
Expand Up @@ -91,23 +91,17 @@ def select_dem_from_dir(gdir, dem_source=None, keep_dem_folders=False):
the glacier directory
dem_source : str
the source to pick from. If 'RGI', we assume that there is a
`dem_source` attribute in the RGI file.
`dem_source` attribute in the RGI file. If 'BY_RES', we use
COPDEM30 for all gdirs with resolution smaller than 60m
keep_dem_folders : bool
the default is to delete the other DEM directories to save space.
Set this to True to prevent that (e.g. for sensitivity tests)
"""

# Start by deleting noise
for fn in os.listdir(gdir.dir):
if fn in ['glacier_mask.tif', 'glacier_grid.json',
'outlines.tar.gz', 'intersects.tar.gz']:
continue
fn = os.path.join(gdir.dir, fn)
if os.path.isfile(fn):
os.remove(fn)

if dem_source == 'RGI':
dem_source = gdir.rgi_dem_source
if dem_source == 'BY_RES':
dem_source = 'COPDEM30' if gdir.grid.dx < 60 else 'COPDEM90'

sources = [f.name for f in os.scandir(gdir.dir) if f.is_dir()
and not f.name.startswith('.')]
Expand Down
3 changes: 3 additions & 0 deletions oggm/tests/test_utils.py
Expand Up @@ -965,6 +965,7 @@ def test_parse_args(self):
'--map-border', '160',
'--output', 'local/out',
'--working-dir', 'local/work',
'--select-source-from-dir', 'BY_RES',
'--dem-source', 'ALL',
'--add-consensus-thickness',
'--add-millan-thickness',
Expand All @@ -984,6 +985,8 @@ def test_parse_args(self):
assert not kwargs['is_test']
assert not kwargs['elev_bands']
assert not kwargs['centerlines']
assert kwargs['select_source_from_dir'] == 'BY_RES'
assert kwargs['keep_dem_folders'] is False
assert kwargs['add_consensus_thickness']
assert kwargs['add_millan_thickness']
assert kwargs['add_millan_velocity']
Expand Down

0 comments on commit fe3d6ea

Please sign in to comment.