def run_tr55(census, model_input): """ A thin Celery wrapper around our TR55 implementation. """ et_max = 0.207 precip = _get_precip_value(model_input) if precip is None: raise Exception('No precipitation value defined') # TODO: These next two lines are just for # demonstration purposes. modifications = get_census_modifications(model_input) census['modifications'] = modifications def simulate_day(cell, cell_count): soil_type, land_use = cell.lower().split(':') et = et_max * lookup_ki(land_use) return simulate_cell_day((precip, et), cell, cell_count) model_output = simulate_modifications(census, fn=simulate_day) return { 'inputmod_hash': model_input['inputmod_hash'], 'census': census, 'runoff': model_output, 'quality': format_quality(model_output) }
def run_tr55(census, model_input): """ A thin Celery wrapper around our TR55 implementation. """ et_max = 0.207 precip = model_input['precip'] # TODO: These next two lines are just for # demonstration purposes. modifications = get_census_modifications(model_input) census['modifications'] = modifications print(census) def simulate_day(cell, cell_count): soil_type, land_use = cell.lower().split(':') et = et_max * lookup_ki(land_use) return simulate_cell_day((precip, et), cell, cell_count) model_output = simulate_modifications(census, fn=simulate_day) return { 'runoff': model_output, 'quality': format_quality(model_output) }
'desert' ] soil_types = ['a', 'b', 'c', 'd'] et_max = 0.207 pre_columbian = False # For each input value, compute the model outputs for a # single day and tile. for precip, land_use, soil_type in product(precips, land_uses, soil_types): cells = { 'cell_count': 1, 'distribution': { '%s:%s' % (soil_type, land_use): {'cell_count': 1} } } def fn(cell, cell_count): (soil_type, land_use) = cell.lower().split(':') et = et_max * lookup_ki(land_use) return simulate_cell_day((precip, et), cell, cell_count) model_out = (simulate_modifications(cells, fn=fn) ['unmodified']['distribution'].values()[0]) writer.writerow((precip, land_use, soil_type, model_out['et'], model_out['inf'], model_out['runoff']))