Skip to content

Commit

Permalink
from_prepro: also allow single strings (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Jan 11, 2019
1 parent 9e3d000 commit 6c1e9eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 17 additions & 6 deletions oggm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def setUp(self):
self.rgidf = gpd.read_file(rgi_file)
self.rgidf['RGIId'] = [rid.replace('RGI50', 'RGI60')
for rid in self.rgidf.RGIId]
cfg.PARAMS['use_multiprocessing'] = True
cfg.PARAMS['use_multiprocessing'] = False
cfg.PATHS['dem_file'] = utils.get_demo_file('srtm_oetztal.tif')
cfg.PATHS['working_dir'] = self.testdir
self.clean_dir()
Expand Down Expand Up @@ -405,7 +405,7 @@ def test_to_and_from_tar_string(self):
def test_start_from_level_1(self):

# Go - initialize working directories
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:4],
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:2],
from_prepro_level=1,
prepro_rgi_version='61',
prepro_border=160)
Expand All @@ -419,7 +419,7 @@ def test_start_from_level_1(self):
def test_start_from_level_1_str(self):

# Go - initialize working directories
entitites = self.rgidf.iloc[:4].RGIId
entitites = self.rgidf.iloc[:2].RGIId
cfg.PARAMS['border'] = 10
gdirs = workflow.init_glacier_regions(entitites,
from_prepro_level=1)
Expand All @@ -430,10 +430,21 @@ def test_start_from_level_1_str(self):
assert n_intersects > 0
workflow.execute_entity_task(tasks.glacier_masks, gdirs)

# One string
cfg.PARAMS['border'] = 10
gdirs = workflow.init_glacier_regions('RGI60-11.00897',
from_prepro_level=1)
n_intersects = 0
for gdir in gdirs:
assert gdir.has_file('dem')
n_intersects += gdir.has_file('intersects')
assert n_intersects > 0
workflow.execute_entity_task(tasks.glacier_masks, gdirs)

def test_start_from_level_2(self):

# Go - initialize working directories
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:4],
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:2],
from_prepro_level=2,
prepro_rgi_version='61',
prepro_border=160)
Expand All @@ -448,7 +459,7 @@ def test_start_from_level_2(self):
def test_start_from_level_3(self):

# Go - initialize working directories
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:4],
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:2],
from_prepro_level=3,
prepro_rgi_version='61',
prepro_border=160)
Expand All @@ -463,7 +474,7 @@ def test_start_from_level_3(self):
def test_start_from_level_4(self):

# Go - initialize working directories
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:4],
gdirs = workflow.init_glacier_regions(self.rgidf.iloc[:2],
from_prepro_level=4,
prepro_rgi_version='61',
prepro_border=160)
Expand Down
3 changes: 3 additions & 0 deletions oggm/utils/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def query_yes_no(question, default="yes"): # pragma: no cover
def tolist(arg, length=None):
"""Makes sure that arg is a list."""

if isinstance(arg, str):
return [arg]

try:
(e for e in arg)
except TypeError:
Expand Down

0 comments on commit 6c1e9eb

Please sign in to comment.