def test_layers_compact_evenly(grid): for layer in range(1): grid.event_layers.add(100.0, porosity=0.7) compact = Compact(grid, porosity_min=0.1, porosity_max=0.7) compact.run_one_step() assert grid.event_layers["porosity"].ptp(axis=1) == approx(0.0)
def test_property_getter_setter(grid, property, value): compact = Compact(grid, **{property: value}) assert getattr(compact, property) == approx(value) assert dict(compact.params)[property] == approx(value) compact = Compact(grid) setattr(compact, property, value) assert getattr(compact, property) == approx(value) assert dict(compact.params)[property] == approx(value)
def test_init_with_layers_added(grid): for layer in range(5): grid.event_layers.add(100.0, porosity=0.7) compact = Compact(grid, porosity_min=0.1, porosity_max=0.7) compact.run_one_step() assert np.all(grid.event_layers["porosity"][:-1] < 0.7) assert grid.event_layers["porosity"][-1] == approx(0.7) assert np.all(grid.event_layers.dz[-1] == approx(100.0)) assert np.all(grid.event_layers.dz[:-1] < 100.0)
def test_matches_module(grid): dz = np.full((100, 3), 1.0) phi = np.full((100, 3), 0.5) phi_expected = compaction.compact(dz, phi, porosity_max=0.5) for layer in range(100): grid.event_layers.add(1.0, porosity=0.5) compact = Compact(grid, porosity_min=0.0, porosity_max=0.5) compact.calculate() assert_array_almost_equal(grid.event_layers["porosity"][-1::-1, :], phi_expected)
def test_grid_size(benchmark, size): grid = RasterModelGrid((3, 101)) for layer in range(size): grid.event_layers.add(1.0, porosity=0.5) compact = Compact(grid, porosity_min=0.0, porosity_max=0.5) benchmark(compact.calculate) assert np.all(grid.event_layers["porosity"][:-1] < 0.5) assert grid.event_layers["porosity"][-1] == approx(0.5) assert np.all(grid.event_layers.dz[-1] == approx(1.0)) assert np.all(grid.event_layers.dz[:-1] < 1.0)
def __init__( self, grid=None, clock=None, output=None, submarine_diffusion=None, sea_level=None, subsidence=None, flexure=None, sediments=None, bathymetry=None, compaction=None, ): config = { "grid": grid, "clock": clock, "output": output, "submarine_diffusion": submarine_diffusion, "sea_level": sea_level, "subsidence": subsidence, "flexure": flexure, "sediments": sediments, "bathymetry": bathymetry, "compaction": compaction, } missing_kwds = [kwd for kwd, value in config.items() if value is None] if missing_kwds: raise ValueError( "missing required config parameters for SequenceModel ({0})". format(", ".join(missing_kwds))) self._clock = TimeStepper(**clock) self._grid = RasterModelGrid.from_dict(grid) self._components = OrderedDict() if output: self._output = OutputWriter(self._grid, **output) self._components["output"] = self._output BathymetryReader(self.grid, **bathymetry).run_one_step() z = self.grid.at_node["topographic__elevation"] z0 = self.grid.add_empty("bedrock_surface__elevation", at="node") z0[:] = z - 100.0 self.grid.at_grid["x_of_shore"] = np.nan self.grid.at_grid["x_of_shelf_edge"] = np.nan self.grid.event_layers.add( 100.0, age=self.clock.start, water_depth=-z0[self.grid.core_nodes], t0=10.0, percent_sand=0.5, porosity=0.5, ) if "filepath" in sea_level: self._sea_level = SeaLevelTimeSeries(self.grid, sea_level.pop("filepath"), start=clock["start"], **sea_level) else: self._sea_level = SinusoidalSeaLevel(self.grid, start=clock["start"], **sea_level) self._subsidence = SubsidenceTimeSeries(self.grid, **subsidence) self._submarine_diffusion = SubmarineDiffuser(self.grid, **submarine_diffusion) self._fluvial = Fluvial( self.grid, 0.5, start=0, sediment_load=submarine_diffusion["sediment_load"], plain_slope=submarine_diffusion["plain_slope"], hemipelagic=sediments["hemipelagic"], ) self._flexure = SedimentFlexure(self.grid, **flexure) self._shoreline = ShorelineFinder(self.grid, alpha=submarine_diffusion["alpha"]) self._compaction = Compact(self.grid, **compaction) self._components.update( sea_level=self._sea_level, subsidence=self._subsidence, compaction=self._compaction, submarine_diffusion=self._submarine_diffusion, fluvial=self._fluvial, flexure=self._flexure, shoreline=self._shoreline, )
def test_init_with_bad_param(grid, param, value): params = {param: value} with raises(ValueError): Compact(grid, **params)
def test_init_without_layers_added(grid): compact = Compact(grid) compact.run_one_step() assert grid.event_layers.number_of_layers == 0