Skip to content

Commit

Permalink
Start to work towards reading the DEMs in OGGM (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Jan 11, 2020
1 parent 7d250db commit 7d66bd9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
5 changes: 3 additions & 2 deletions docs/index.rst
Expand Up @@ -101,11 +101,12 @@ Get in touch
- View the source code `on GitHub`_.
- Report bugs or share your ideas on the `issue tracker`_, and improve
the model by submitting a `pull request`_.

- Chat with us on `Slack`_! (just send us an email so we can add you)
- Follow us on `Twitter`_.
- Or you can always send us an `e-mail`_ the good old way.

.. _e-mail: https://mailman.zfn.uni-bremen.de/cgi-bin/mailman/listinfo/oggm-users
.. _e-mail: info@oggm.org
.. _Slack: https://slack.com
.. _on GitHub: https://github.com/OGGM/oggm
.. _issue tracker: https://github.com/OGGM/oggm/issues
.. _pull request: https://github.com/OGGM/oggm/pulls
Expand Down
2 changes: 1 addition & 1 deletion oggm/tests/test_utils.py
Expand Up @@ -648,7 +648,7 @@ def test_corrupted_file(self):
prepro_border=10)

cfile = utils.get_prepro_gdir('61', 'RGI60-11.00787', 10, 4,
demo_url=True)
base_url=utils.DEMO_GDIR_URL)
assert 'cluster.klima.uni-bremen.de/~fmaussion/' in cfile

# Replace with a dummy file
Expand Down
13 changes: 9 additions & 4 deletions oggm/utils/_downloads.py
Expand Up @@ -77,6 +77,7 @@

GDIR_URL = 'https://cluster.klima.uni-bremen.de/~fmaussion/gdirs/oggm_v1.1/'
DEMO_GDIR_URL = 'https://cluster.klima.uni-bremen.de/~fmaussion/demo_gdirs/'
DEMS_GDIR_URL = 'https://cluster.klima.uni-bremen.de/data/gdirs/dems_v0/'

CMIP5_URL = 'https://cluster.klima.uni-bremen.de/~nicolas/cmip5-ng/'

Expand Down Expand Up @@ -987,16 +988,20 @@ def _get_centerline_lonlat(gdir):
return olist


def get_prepro_gdir(rgi_version, rgi_id, border, prepro_level, demo_url=False):
def get_prepro_gdir(rgi_version, rgi_id, border, prepro_level, base_url=None):
with _get_download_lock():
return _get_prepro_gdir_unlocked(rgi_version, rgi_id, border,
prepro_level, demo_url)
prepro_level, base_url=base_url)


def _get_prepro_gdir_unlocked(rgi_version, rgi_id, border, prepro_level,
demo_url=False):
base_url=None):
# Prepro URL
url = DEMO_GDIR_URL if demo_url else GDIR_URL
if base_url is None:
base_url = GDIR_URL
if not base_url.endswith('/'):
base_url += '/'
url = base_url
url += 'RGI{}/'.format(rgi_version)
url += 'b_{:03d}/'.format(border)
url += 'L{:d}/'.format(prepro_level)
Expand Down
20 changes: 12 additions & 8 deletions oggm/workflow.py
Expand Up @@ -192,7 +192,7 @@ def execute_parallel_tasks(gdir, tasks):

def gdir_from_prepro(entity, from_prepro_level=None,
prepro_border=None, prepro_rgi_version=None,
check_demo_glacier=False):
check_demo_glacier=False, base_url=None):

if prepro_border is None:
prepro_border = int(cfg.PARAMS['border'])
Expand All @@ -203,23 +203,22 @@ def gdir_from_prepro(entity, from_prepro_level=None,
except AttributeError:
rid = entity

demo_url = False
if check_demo_glacier:
if check_demo_glacier and base_url is None:
demo_id = utils.demo_glacier_id(rid)
if demo_id is not None:
rid = demo_id
entity = demo_id
demo_url = True
base_url = utils.DEMO_GDIR_URL

tar_base = utils.get_prepro_gdir(prepro_rgi_version, rid, prepro_border,
from_prepro_level, demo_url=demo_url)
from_prepro_level, base_url=base_url)
from_tar = os.path.join(tar_base.replace('.tar', ''), rid + '.tar.gz')
return oggm.GlacierDirectory(entity, from_tar=from_tar)


def init_glacier_regions(rgidf=None, *, reset=False, force=False,
from_prepro_level=None, prepro_border=None,
prepro_rgi_version=None,
prepro_rgi_version=None, prepro_base_url=None,
from_tar=False, delete_tar=False,
use_demo_glaciers=None):
"""Initializes the list of Glacier Directories for this run.
Expand Down Expand Up @@ -247,10 +246,14 @@ def init_glacier_regions(rgidf=None, *, reset=False, force=False,
prepro_rgi_version : str
for `from_prepro_level` only: if you want to override the default
behavior which is to use `cfg.PARAMS['rgi_version']`
prepro_base_url : str
for `from_prepro_level` only: if you want to override the default
URL from which to download the gdirs. Default currently is
https://cluster.klima.uni-bremen.de/~fmaussion/gdirs/oggm_v1.1/
use_demo_glaciers : bool
whether to check the demo glaciers for download (faster than the
standard prepro downloads). The default is to decide whether or
not to check based on simple crietria such as glacier list size.
not to check based on simple criteria such as glacier list size.
from_tar : bool, default=False
extract the gdir data from a tar file. If set to `True`,
will check for a tar file at the expected location in `base_dir`.
Expand Down Expand Up @@ -316,7 +319,8 @@ def init_glacier_regions(rgidf=None, *, reset=False, force=False,
from_prepro_level=from_prepro_level,
prepro_border=prepro_border,
prepro_rgi_version=prepro_rgi_version,
check_demo_glacier=use_demo_glaciers)
check_demo_glacier=use_demo_glaciers,
base_url=prepro_base_url)
else:
# TODO: if necessary this could use multiprocessing as well
for entity in entities:
Expand Down

0 comments on commit 7d66bd9

Please sign in to comment.