def read_ids(dbf_file_name, col_name): """Retruns all ids riversegments as strings. """ ids = read_dbf_cols(dbf_file_name, [col_name])[col_name] if all(isinstance(id_, int) for id_ in ids): ids = [str(id_)for id_ in ids] return ids
def __init__(self, config_file, Compartments, Links): config = read_config(config_file) print('initial conditions for compartments...', end='') self.compartments = Compartments.compartments self.comp_length = Compartments.comp_length self.compartment_links = Links.compartment_links self.riversegments_dbf = config['routing_model']['riversegments_path'] self.riversegments = read_dbf_cols(self.riversegments_dbf, ['WSO1_ID', 'STRAHLER', 'MQ', 'X', 'ELEV']) print('Done')
def __init__(self, config_file, Compartments): config = read_config(config_file) print('parameterize compartments...', end='') pandas.options.mode.chained_assignment = None self.compartments = Compartments.compartments self.comp_length = Compartments.comp_length self.riversegments_dbf = config['routing_model']['riversegments_path'] self.riversegments = read_dbf_cols(self.riversegments_dbf, ['WSO1_ID', 'X', 'ELEV', 'WIDTH', 'Kst']) print('Done')
def get_value_by_id(self, col_name, converter=1, ids=None): """Returns a dict catchment-id: value converter for units with default value 1 ids to filter (e.g. only Strahler) """ data = read_dbf_cols(self.riversegments_dbf, ['WSO1_ID', col_name]) res = {id_: value * converter for id_, value in zip(data['WSO1_ID'], data[col_name])} if ids: res = {id_: value for id_, value in res.items() if id_ in ids} return res