def elevation_1_test(self): "Model 'elevation', test 1" model = PISM.SurfaceElevation(self.grid, PISM.AtmosphereUniform(self.grid)) model.init(self.geometry) model.update(self.geometry, 0, 1) T = 268.15 omega = 0.0 SMB = -8.651032746943449e-05 accumulation = 0.0 melt = -SMB runoff = melt check_model(model, T, omega, SMB, accumulation=accumulation, melt=melt, runoff=runoff) probe_interface(model)
def test_atmosphere_elevation_change_scale(self): "Modifier 'elevation_change': scaling" config.set_string("atmosphere.elevation_change.precipitation.method", "scale") model = PISM.AtmosphereUniform(self.grid) modifier = PISM.AtmosphereElevationChange(self.grid, model) modifier.init(self.geometry) # change surface elevation self.geometry.ice_surface_elevation.shift(self.dz) # check that the temperature and precipitation changed accordingly modifier.update(self.geometry, 0, 1) C = config.get_number( "atmosphere.precip_exponential_factor_for_temperature") dT = -self.precip_dTdz * self.dz / 1000.0 P = sample(model.mean_precipitation()) dP = np.exp(C * dT) * P - P check_modifier(model, modifier, T=self.dT, P=dP, ts=[0.5], Ts=[self.dT], Ps=[dP])
def run_model(grid, orography): "Run the PISM implementation of the model to compare to the Python version." model = PISM.AtmosphereOrographicPrecipitation( grid, PISM.AtmosphereUniform(grid)) geometry = PISM.Geometry(grid) with PISM.vec.Access(nocomm=geometry.ice_thickness): for i, j in grid.points(): geometry.ice_thickness[i, j] = orography[j, i] geometry.bed_elevation.set(0.0) geometry.sea_level_elevation.set(0.0) geometry.ice_area_specific_volume.set(0.0) # compute surface elevation from ice thickness and bed elevation geometry.ensure_consistency(0) model.init(geometry) model.update(geometry, 0, 1) config = PISM.Context().config water_density = config.get_number("constants.fresh_water.density") # convert from kg / (m^2 s) to mm/s return model.mean_precipitation().numpy() / (1e-3 * water_density)
def setUp(self): self.filename = tmp_name("atmosphere_anomaly_input") self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.geometry.ice_thickness.set(1000.0) self.model = PISM.AtmosphereUniform(self.grid) self.dT = -5.0 self.dP = 20.0 dT = PISM.IceModelVec2S(self.grid, "air_temp_anomaly", PISM.WITHOUT_GHOSTS) dT.set_attrs("climate", "air temperature anomaly", "Kelvin", "Kelvin", "", 0) dT.set(self.dT) dP = PISM.IceModelVec2S(self.grid, "precipitation_anomaly", PISM.WITHOUT_GHOSTS) dP.set_attrs("climate", "precipitation anomaly", "kg m-2 s-1", "kg m-2 s-1", "", 0) dP.set(self.dP) output = PISM.util.prepare_output(self.filename) dT.write(output) dP.write(output) config.set_string("atmosphere.anomaly.file", self.filename)
def test_atmosphere_uniform(self): "Model 'uniform'" model = PISM.AtmosphereUniform(self.grid) model.init(self.geometry) model.update(self.geometry, 0, 1) P = PISM.util.convert(self.P, "kg m-2 year-1", "kg m-2 s-1") check_model(model, T=self.T, P=P, ts=[0.5], Ts=[self.T], Ps=[P])
def setUp(self): self.filename = "atmosphere_delta_T_input.nc" self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.geometry.ice_thickness.set(1000.0) self.model = PISM.AtmosphereUniform(self.grid) self.dT = -5.0 create_scalar_forcing(self.filename, "delta_T", "Kelvin", [self.dT], [0])
def setUp(self): self.filename = "atmosphere_frac_P_input.nc" self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.geometry.ice_thickness.set(1000.0) self.model = PISM.AtmosphereUniform(self.grid) self.P_ratio = 5.0 create_scalar_forcing(self.filename, "frac_P", "1", [self.P_ratio], [0]) config.set_string("atmosphere.frac_P.file", self.filename)
def setUp(self): self.filename = "atmosphere_precip_scaling_input.nc" self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.geometry.ice_thickness.set(1000.0) self.model = PISM.AtmosphereUniform(self.grid) self.dT = 5.0 create_scalar_forcing(self.filename, "delta_T", "Kelvin", [self.dT], [0]) config.set_string("atmosphere.precip_scaling.file", self.filename)
def surface_pik_test(self): "Model 'pik'" model = PISM.SurfacePIK(self.grid, PISM.AtmosphereUniform(self.grid)) model.init(self.geometry) model.update(self.geometry, 0, 1) check_model(model, self.T, 0.0, self.M, accumulation=self.M) write_state(model, self.output_filename) probe_interface(model)
def ismip6_test(self): "Surface model ISMIP6" atmosphere = PISM.AtmosphereUniform(self.grid) model = PISM.SurfaceISMIP6(self.grid, atmosphere) model.init(self.geometry) t = self.ctx.time.current() dt = model.max_timestep(t).value() model.update(self.geometry, t, dt)
def setUp(self): self.filename = tmp_name("atmosphere_delta_P_input") self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.geometry.ice_thickness.set(1000.0) self.model = PISM.AtmosphereUniform(self.grid) self.dP = 5.0 create_scalar_forcing(self.filename, "delta_P", "kg m-2 s-1", [self.dP], [0], time_bounds=[0, 1]) config.set_string("atmosphere.delta_P.file", self.filename)
def test_surface_given(self): "Model 'given'" atmosphere = PISM.AtmosphereUniform(self.grid) config.set_string("surface.given.file", self.filename) model = PISM.SurfaceGiven(self.grid, atmosphere) model.init(self.geometry) model.update(self.geometry, 0, 1) check_model(model, self.T, 0.0, self.M, accumulation=self.M) write_state(model, self.output_filename) probe_interface(model)
def test_surface_pdd(self): "Model 'pdd'" model = PISM.SurfaceTemperatureIndex(self.grid, PISM.AtmosphereUniform(self.grid)) model.init(self.geometry) model.update(self.geometry, 0, self.dt) check_model(model, T=self.T, SMB=self.SMB, omega=0.0, mass=0.0, thickness=0.0, melt=40, runoff=16)
def synthetic_geometry(grid, orography): config = PISM.Context().config # set wind speed and direction config.set_number("atmosphere.orographic_precipitation.wind_speed", 15.0) config.set_number("atmosphere.orographic_precipitation.wind_direction", 270) config.set_number("atmosphere.orographic_precipitation.conversion_time", 1000.0) config.set_number("atmosphere.orographic_precipitation.fallout_time", 1000.0) config.set_number( "atmosphere.orographic_precipitation.water_vapor_scale_height", 2500.0) config.set_number( "atmosphere.orographic_precipitation.moist_stability_frequency", 0.005) config.set_number("atmosphere.orographic_precipitation.reference_density", 7.4e-3) # eliminate the effect of the Coriolis force config.set_number("atmosphere.orographic_precipitation.coriolis_latitude", 0.0) model = PISM.AtmosphereOrographicPrecipitation( grid, PISM.AtmosphereUniform(grid)) geometry = PISM.Geometry(grid) with PISM.vec.Access(nocomm=geometry.ice_thickness): for i, j in grid.points(): geometry.ice_thickness[i, j] = orography[j, i] geometry.bed_elevation.set(0.0) geometry.sea_level_elevation.set(0.0) geometry.ice_area_specific_volume.set(0.0) # compute surface elevation from ice thickness and bed elevation geometry.ensure_consistency(0) model.init(geometry) model.update(geometry, 0, 1) # convert from mm/s to mm/hour return model.mean_precipitation().numpy() * 3600
def input_file(filename): ctx = PISM.Context() grid = PISM.IceGrid.FromFile(ctx.ctx, filename, ["topg"], PISM.CELL_CENTER) geometry = PISM.Geometry(grid) geometry.bed_elevation.regrid(filename) geometry.ice_thickness.set(0.0) geometry.sea_level_elevation.set(0.0) geometry.ensure_consistency(0.0) model = PISM.AtmosphereOrographicPrecipitation( grid, PISM.AtmosphereUniform(grid)) model.init(geometry) model.update(geometry, 0, 1) model.mean_precipitation().dump(config.get_string("output.file_name"))
def setUp(self): self.filename = tmp_name("atmosphere_frac_P_input") self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.geometry.ice_thickness.set(1000.0) self.model = PISM.AtmosphereUniform(self.grid) self.P_ratio = 5.0 frac_P = PISM.IceModelVec2S(self.grid, "frac_P", PISM.WITHOUT_GHOSTS) frac_P.set_attrs("climate", "precipitation scaling", "1", "1", "", 0) frac_P.set(self.P_ratio) try: output = PISM.util.prepare_output(self.filename) frac_P.write(output) finally: output.close() config.set_string("atmosphere.frac_P.file", self.filename)
def factory_test(self): "Surface model factory" atmosphere = PISM.AtmosphereUniform(self.grid) factory = PISM.SurfaceFactory(self.grid, atmosphere) simple = factory.create("simple") model = factory.create("simple,cache") try: factory.create("invalid_model") return False except RuntimeError: pass try: factory.create("simple,invalid_modifier") return False except RuntimeError: pass
def elevation_2_test(self): "Model 'elevation', test 2" T_min = -5.0 T_max = 0.0 z_min = 1000.0 z_ela = 1100.0 z_max = 1500.0 M_min = -1.0 M_max = 5.0 self.geometry.ice_thickness.set(0.5 * (z_min + z_max)) self.geometry.ensure_consistency(0.0) options.setValue("-ice_surface_temp", "{},{},{},{}".format(T_min, T_max, z_min, z_max)) options.setValue( "-climatic_mass_balance", "{},{},{},{},{}".format(M_min, M_max, z_min, z_ela, z_max)) T = PISM.util.convert(0.5 * (T_min + T_max), "Celsius", "Kelvin") SMB = PISM.util.convert( 1.87504, "m/year", "m/s") * config.get_number("constants.ice.density") model = PISM.SurfaceElevation(self.grid, PISM.AtmosphereUniform(self.grid)) model.init(self.geometry) model.update(self.geometry, 0, 1) check_model(model, T=T, SMB=SMB, omega=0, mass=0, thickness=0, accumulation=SMB)
def test_atmosphere_elevation_change_shift(self): "Modifier 'elevation_change': lapse rate" config.set_string("atmosphere.elevation_change.precipitation.method", "shift") model = PISM.AtmosphereUniform(self.grid) modifier = PISM.AtmosphereElevationChange(self.grid, model) modifier.init(self.geometry) # change surface elevation self.geometry.ice_surface_elevation.shift(self.dz) # check that the temperature changed accordingly modifier.update(self.geometry, 0, 1) check_modifier(model, modifier, T=self.dT, P=self.dP, ts=[0.5], Ts=[self.dT], Ps=[self.dP])
def surface_simple(grid): return PISM.SurfaceSimple(grid, PISM.AtmosphereUniform(grid))
def setUp(self): self.grid = shallow_grid() self.geometry = PISM.Geometry(self.grid) self.atmosphere = PISM.AtmosphereUniform(self.grid) self.output_filename = filename("surface_pdd_output_")
def setUp(self): self.grid = shallow_grid() self.output_filename = "surface_simple_output.nc" self.atmosphere = PISM.AtmosphereUniform(self.grid) self.geometry = PISM.Geometry(self.grid)