def load_soils(): def is_soil_file(x): return os.path.splitext(x)[1].lower() == '.json' soil_files = listdir_fullpath(soils_path, recursive=True, onlyFiles=True, filter=is_soil_file) for f in soil_files: key = filename_without_ext(f) if key in soils_dict: logging.warning('Duplicated soil name "%s". Found at two different paths: "%s" and "%s".' % (key, soils_dict[key], f)) continue soils_dict[key] = f
def init_from_yaml(self, yaml): if 'name' not in yaml: yaml['name'] = filename_without_ext(yaml['file_name']) if 'forecast_date' not in yaml: # If there's no forecast date defined, we explicitly define it as None. yaml['forecast_date'] = None if 'results' not in yaml: raise RuntimeError( 'Missing results property in forecast file %s.' % yaml['file_name']) # yaml['results'] = DotDict({'cycle': ['HWAM'], 'daily': []}) if 'daily' not in yaml['results']: yaml['results']['daily'] = [] if 'cycle' not in yaml['results']: yaml['results']['cycle'] = [] if len(yaml['results']['cycle']) == 0 and len( yaml['results']['daily']) == 0: raise RuntimeError( 'No expected results variables were provided in forecast file %s.' % yaml['file_name']) # Keys that belong to simulation objects and must be deleted from a Forecast object. simulation_keys = [ 'initial_conditions', 'agronomic_management', 'site_characteristics' ] for key in simulation_keys: if key in yaml: del yaml[key] self.__dict__.update(DotDict(yaml))