Skip to content

Commit 7e65ebf

Browse files
authored
Merge pull request #10 from ACCESS-NRI/add-defaults-to-LUC-script
Add defaults and checking for per_cell and per_tile
2 parents c7dd9c3 + 0d74613 commit 7e65ebf

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,22 @@ def prepare_mapping(nVeg, ConfigFile):
5555
with open(ConfigFile, 'r') as conf:
5656
MappingConf = yaml.safe_load(conf)
5757

58-
# At the moment, the only thing that requires defaults is the input to
59-
# output vegetation mapping. By default, it maps in a 1-to-1 manner, i.e.
58+
# By default, the vegetation maps in a 1-to-1 manner, i.e.
6059
# vegetation type 1 in the old vegetation map maps to vegetation type 1 in
6160
# the new vegetation map.
6261
VegetationMapping = {i: [i] for i in range(nVeg)}
6362

63+
# It may be that the user removes either per_tile or per_cell entries in
64+
# the config- apply default values (empty list) that are iterable in that
65+
# case. Also, ensure that it's a list instance
66+
MappingConf['per_cell'] = MappingConf.get('per_cell') or []
67+
if not isinstance(MappingConf['per_cell'], list):
68+
MappingConf['per_cell'] = [MappingConf['per_cell']]
69+
70+
MappingConf['per_tile'] = MappingConf.get('per_tile') or []
71+
if not isinstance(MappingConf['per_tile'], list):
72+
MappingConf['per_tile'] = [MappingConf['per_tile']]
73+
6474
# Apply the supplied mappings
6575
if 'vegetation_map' in MappingConf:
6676
for OutVegType, InVegTypes in MappingConf['vegetation_map'].items():

0 commit comments

Comments
 (0)