From 12adba2bdb2e491e634254b2cf3ad0b2f6d3df22 Mon Sep 17 00:00:00 2001 From: Lachlan Whyborn Date: Thu, 2 Jul 2026 12:05:18 +1000 Subject: [PATCH 1/2] Add defaults and checking for per_cell and per_tile --- .../adjust_restart_for_new_land_cover.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py b/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py index 9059d80..e4bc423 100644 --- a/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py +++ b/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py @@ -55,12 +55,22 @@ def prepare_mapping(nVeg, ConfigFile): with open(ConfigFile, 'r') as conf: MappingConf = yaml.safe_load(conf) - # At the moment, the only thing that requires defaults is the input to - # output vegetation mapping. By default, it maps in a 1-to-1 manner, i.e. + # By default, the vegetation maps in a 1-to-1 manner, i.e. # vegetation type 1 in the old vegetation map maps to vegetation type 1 in # the new vegetation map. VegetationMapping = {i: [i] for i in range(nVeg)} + # It may be that the user removes either per_tile or per_cell entries in + # the config- apply default values (empty list) that are iterable in that + # case. Also, ensure that it's a list instance + MappingConf['per_cell'] = MappingConf.get('per_cell', []) + if not isinstance(MappingConf['per_cell'], list): + MappingConf['per_cell'] = [MappingConf['per_cell']] + + MappingConf['per_tile'] = MappingConf.get('per_tile', []) + if not isinstance(MappingConf['per_tile'], list): + MappingConf['per_tile'] = [MappingConf['per_tile']] + # Apply the supplied mappings if 'vegetation_map' in MappingConf: for OutVegType, InVegTypes in MappingConf['vegetation_map'].items(): From 0d7461391619f51c864379e72e7cadb7e34afe20 Mon Sep 17 00:00:00 2001 From: Alexander Norton Date: Thu, 2 Jul 2026 16:29:23 +1000 Subject: [PATCH 2/2] Change MappingConf retrieval for per_cell and per_tile This change ensures that the per_cell and per_tile fields in MappingConf do not end up with `None` values if the config file has no listed items under per_cell or per_tile. --- .../adjust_restart_for_new_land_cover.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py b/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py index e4bc423..8605ed1 100644 --- a/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py +++ b/adjust_restart_for_new_land_cover/adjust_restart_for_new_land_cover.py @@ -63,11 +63,11 @@ def prepare_mapping(nVeg, ConfigFile): # It may be that the user removes either per_tile or per_cell entries in # the config- apply default values (empty list) that are iterable in that # case. Also, ensure that it's a list instance - MappingConf['per_cell'] = MappingConf.get('per_cell', []) + MappingConf['per_cell'] = MappingConf.get('per_cell') or [] if not isinstance(MappingConf['per_cell'], list): MappingConf['per_cell'] = [MappingConf['per_cell']] - MappingConf['per_tile'] = MappingConf.get('per_tile', []) + MappingConf['per_tile'] = MappingConf.get('per_tile') or [] if not isinstance(MappingConf['per_tile'], list): MappingConf['per_tile'] = [MappingConf['per_tile']]