Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/gis/renamed_options
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ r.sim.sediment|nwalk:nwalkers
r.sim.sediment|niterations:duration
r.sim.sediment|outiter:output_step
r.sim.sediment|outwalk:walkers_output
r.sim.sediment|random_seed:seed
r.sim.sediment|tauin:shear_stress
r.sim.sediment|tc:transport_capacity
r.sim.sediment|tranin:transport_coeff
Expand All @@ -353,6 +354,7 @@ r.sim.water|nwalk:nwalkers
r.sim.water|outiter:output_step
r.sim.water|outwalk:walkers_output
r.sim.water|rain_val:rain_value
r.sim.water|random_seed:seed
r.sim.water|traps:flow_control
# r.slope.aspect
r.slope.aspect|min_slp_allowed:min_slope
Expand Down
3 changes: 1 addition & 2 deletions raster/r.sim/r.sim.sediment/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ int main(int argc, char *argv[])
parm.diffc->guisection = _("Parameters");

parm.seed = G_define_standard_option(G_OPT_M_SEED);
parm.seed->key = "random_seed";

flag.generateSeed = G_define_flag();
flag.generateSeed->key = 's';
flag.generateSeed->label =
_("Generate random seed (result is non-deterministic) [deprecated]");
flag.generateSeed->description =
_("This flag is deprecated and will be removed in a future release. "
"Seeding is automatic or use parameter random_seed.");
"Seeding is automatic or use parameter seed.");

parm.threads = G_define_option();
parm.threads->key = "nprocs";
Expand Down
2 changes: 1 addition & 1 deletion raster/r.sim/r.sim.sediment/r.sim.sediment.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ <h3>Run summary</h3>
r.sim.sediment elevation=elevation water_depth=water_depth detachment_coeff=detachment \
transport_coeff=transport shear_stress=shear_stress man_value=1 \
sediment_flux=flux erosion_deposition=erdep transport_capacity=tc \
duration=1 random_seed=1 -p format=json
duration=1 seed=1 -p format=json
</pre></div>

<div class="code"><pre>
Expand Down
2 changes: 1 addition & 1 deletion raster/r.sim/r.sim.sediment/r.sim.sediment.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Summary of a run in JSON:
r.sim.sediment elevation=elevation water_depth=water_depth detachment_coeff=detachment \
transport_coeff=transport shear_stress=shear_stress man_value=1 \
sediment_flux=flux erosion_deposition=erdep transport_capacity=tc \
duration=1 random_seed=1 -p format=json
duration=1 seed=1 -p format=json
```

```json
Expand Down
18 changes: 9 additions & 9 deletions raster/r.sim/r.sim.sediment/tests/r_sim_sediment_random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ def simulate(session, walkers=None, env=None, **kwargs):

def test_same_seed_gives_same_flux(session):
"""Two runs with the same seed give the same sediment flux."""
first, _ = simulate(session, random_seed=1)
second, _ = simulate(session, random_seed=1)
first, _ = simulate(session, seed=1)
second, _ = simulate(session, seed=1)
assert np.array_equal(first, second)


def test_different_seeds_give_different_results(session):
"""Runs with different seeds give different fluxes and walker positions."""
first_flux, first_walkers = simulate(session, "walkers_seed_1", random_seed=1)
second_flux, second_walkers = simulate(session, "walkers_seed_2", random_seed=2)
first_flux, first_walkers = simulate(session, "walkers_seed_1", seed=1)
second_flux, second_walkers = simulate(session, "walkers_seed_2", seed=2)
assert not np.array_equal(first_flux, second_flux)
assert not np.array_equal(first_walkers, second_walkers)

Expand All @@ -83,7 +83,7 @@ def test_generated_seed_is_the_seed_option(session):
env = session.env.copy()
env["GRASS_RANDOM_SEED"] = "3"
generated, _ = simulate(session, env=env)
given, _ = simulate(session, random_seed=3)
given, _ = simulate(session, seed=3)
assert np.array_equal(generated, given)


Expand All @@ -94,9 +94,9 @@ def test_results_do_not_depend_on_nprocs(session, nprocs):
The water depth is an input here, so nothing a walker reacts to is
changed by the other walkers of the same step.
"""
serial_flux, serial = simulate(session, f"walkers_{nprocs}_serial", random_seed=5)
serial_flux, serial = simulate(session, f"walkers_{nprocs}_serial", seed=5)
parallel_flux, parallel = simulate(
session, f"walkers_{nprocs}_parallel", random_seed=5, nprocs=nprocs
session, f"walkers_{nprocs}_parallel", seed=5, nprocs=nprocs
)
assert serial.size
assert np.array_equal(parallel, serial)
Expand All @@ -107,11 +107,11 @@ def test_results_do_not_depend_on_nprocs(session, nprocs):
def test_seed_outside_range_is_an_error(session, seed):
"""A seed the generator cannot use is refused, not silently wrapped."""
with pytest.raises(CalledModuleError, match="outside the range"):
simulate(session, random_seed=seed)
simulate(session, seed=seed)


@pytest.mark.parametrize("seed", ["12abc", "1.5", "-", "99999999999999999999"])
def test_seed_which_is_not_an_integer_is_an_error(session, seed):
"""A seed which the parser lets through but which is not an integer is refused."""
with pytest.raises(CalledModuleError, match="Invalid random seed"):
simulate(session, random_seed=seed)
simulate(session, seed=seed)
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def sediment_inputs(session_tools):
"shear_stress": "shear_stress",
"man_value": 1,
"diffusion_coeff": 0.05,
"random_seed": 1,
"seed": 1,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_default(self):
shear_stress=self.tauin,
sediment_flux=self.sedflux,
erosion_deposition=self.erdep,
random_seed=1,
seed=1,
)

# Assert that the output rasters exist
Expand Down
3 changes: 1 addition & 2 deletions raster/r.sim/r.sim.water/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,14 @@ int main(int argc, char *argv[])
flag.tserie->guisection = _("Output");

parm.seed = G_define_standard_option(G_OPT_M_SEED);
parm.seed->key = "random_seed";

flag.generateSeed = G_define_flag();
flag.generateSeed->key = 's';
flag.generateSeed->label =
_("Generate random seed (result is non-deterministic) [deprecated]");
flag.generateSeed->description =
_("This flag is deprecated and will be removed in a future release. "
"Seeding is automatic or use parameter random_seed.");
"Seeding is automatic or use parameter seed.");

parm.threads = G_define_option();
parm.threads->key = "nprocs";
Expand Down
14 changes: 7 additions & 7 deletions raster/r.sim/r.sim.water/r.sim.water.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ <h3>Run summary</h3>

<div class="code"><pre>
r.sim.water elevation=elevation depth=depth discharge=discharge rain_value=50 \
man_value=0.05 nwalkers=100000 duration=20 output_step=10 random_seed=3 \
man_value=0.05 nwalkers=100000 duration=20 output_step=10 seed=3 \
-t -p format=json
</pre></div>

Expand All @@ -251,7 +251,7 @@ <h3>Run summary</h3>
nwalkers=100000,
duration=20,
output_step=10,
random_seed=3,
seed=3,
flags="tp",
format="json",
)
Expand All @@ -273,7 +273,7 @@ <h3>Run summary</h3>
nwalkers=100000,
duration=20,
output_step=10,
random_seed=3,
seed=3,
flags="tp",
format="json",
)
Expand Down Expand Up @@ -325,7 +325,7 @@ <h3>Run summary</h3>
<h3>Random numbers and parallel processing</h3>

The walkers are placed and moved using pseudo-random numbers. The seed
is given by <b>random_seed</b>; without it, a seed is generated and
is given by <b>seed</b>; without it, a seed is generated and
recorded in the history of the output maps and in the run summary as
<code>seed</code>, so that the run can be repeated. With more than one thread, the
results differ slightly between thread counts and between repeated runs,
Expand Down Expand Up @@ -421,7 +421,7 @@ <h2>EXAMPLE</h2>

<div class="code"><pre>
r.sim.water elevation=elevation man=mannings rain_value=20 depth=depth \
duration=30 random_seed=1
duration=30 seed=1
</pre></div>

In Python with grass.script:
Expand All @@ -434,7 +434,7 @@ <h2>EXAMPLE</h2>
rain_value=20,
depth="depth",
duration=30,
random_seed=1,
seed=1,
)
</pre></div>

Expand All @@ -447,7 +447,7 @@ <h2>EXAMPLE</h2>
rain_value=20,
depth="depth",
duration=30,
random_seed=1,
seed=1,
)
</pre></div>

Expand Down
2 changes: 1 addition & 1 deletion raster/r.sim/r.sim.water/r.sim.water.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
" depth=\"depth\",\n",
" output_step=5,\n",
" duration=30,\n",
" random_seed=1,\n",
" seed=1,\n",
" nprocs=1,\n",
")"
]
Expand Down
14 changes: 7 additions & 7 deletions raster/r.sim/r.sim.water/r.sim.water.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Summary of a time series run with two output steps in JSON:

```sh
r.sim.water elevation=elevation depth=depth discharge=discharge rain_value=50 \
man_value=0.05 nwalkers=100000 duration=20 output_step=10 random_seed=3 \
man_value=0.05 nwalkers=100000 duration=20 output_step=10 seed=3 \
-t -p format=json
```

Expand All @@ -241,7 +241,7 @@ Summary of a time series run with two output steps in JSON:
nwalkers=100000,
duration=20,
output_step=10,
random_seed=3,
seed=3,
flags="tp",
format="json",
)
Expand All @@ -263,7 +263,7 @@ Summary of a time series run with two output steps in JSON:
nwalkers=100000,
duration=20,
output_step=10,
random_seed=3,
seed=3,
flags="tp",
format="json",
)
Expand Down Expand Up @@ -316,7 +316,7 @@ The printed summary:
### Random numbers and parallel processing

The walkers are placed and moved using pseudo-random numbers. The seed
is given by **random_seed**; without it, a seed is generated and
is given by **seed**; without it, a seed is generated and
recorded in the history of the output maps and in the run summary as
`seed`, so that the run can be repeated. With more than one thread, the
results differ slightly between thread counts and between repeated runs,
Expand Down Expand Up @@ -412,7 +412,7 @@ Simulate 30 minutes of overland flow with a uniform rainfall excess of

```sh
r.sim.water elevation=elevation man=mannings rain_value=20 depth=depth \
duration=30 random_seed=1
duration=30 seed=1
```

=== "Python (grass.script)"
Expand All @@ -425,7 +425,7 @@ Simulate 30 minutes of overland flow with a uniform rainfall excess of
rain_value=20,
depth="depth",
duration=30,
random_seed=1,
seed=1,
)
```

Expand All @@ -438,7 +438,7 @@ Simulate 30 minutes of overland flow with a uniform rainfall excess of
rain_value=20,
depth="depth",
duration=30,
random_seed=1,
seed=1,
)
```
<!-- markdownlint-enable MD046 -->
Expand Down
4 changes: 2 additions & 2 deletions raster/r.sim/r.sim.water/tests/r_sim_water_landforms_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def surface(row_values, column_values):
SPUR = surface(DOWNSLOPE, [-1.8, -0.8, -0.2, 0.0, -0.2, -0.8, -1.8])


def landform_depth(project, elevation, *, random_seed=SEED, **kwargs):
def landform_depth(project, elevation, *, seed=SEED, **kwargs):
"""Simulate r.sim.water on an elevation array in a new project; return depth.

The region is one cell per array element at unit resolution. Only the
Expand All @@ -110,7 +110,7 @@ def landform_depth(project, elevation, *, random_seed=SEED, **kwargs):
return tools.r_sim_water(
elevation=elevation,
depth=np.array,
random_seed=random_seed,
seed=seed,
rain_value=RAIN,
infil_value=0,
man_value=0.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def simulate(session, elevation, man, **kwargs):
rain_value=50,
nwalkers=2000,
duration=2,
random_seed=1,
seed=1,
nprocs=1,
flags="p",
format="json",
Expand Down
2 changes: 1 addition & 1 deletion raster/r.sim/r.sim.water/tests/r_sim_water_nprocs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def depth(session, nprocs, rain=RAIN, **kwargs):
man_value=0.05,
nwalkers=400,
duration=2,
random_seed=1,
seed=1,
nprocs=nprocs,
**kwargs,
)
Expand Down
Loading
Loading