Skip to content

Commit

Permalink
Merge branch 'OSGeo:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
a0x8o authored Apr 1, 2024
2 parents ad79398 + 23d28c0 commit 43794ba
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/actions/create-upload-suggestions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ runs:
steps.upload-changes.outputs.artifact-url }})
- name: Fail action if some files were changed
if: >-
${{ (steps.files_changed.outputs.files_changed == 'true') &&
${{ (steps.files_changed.outputs.files_changed == 'true') &&
(steps.inputs.outputs.fail-if-changed == 'true') }}
shell: bash
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Coverity Scan
on:
workflow_dispatch: # run whenever a contributor calls it
schedule:
schedule:
- cron: '48 5 * * *' # Run at 05:48
# Coverity will let GRASS do a scan a maximum of twice per day, so this schedule will help GRASS fit within that limit with some additional space for manual runs

jobs:
build:
runs-on: [ ubuntu-latest ]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:

- name: Add extra exclusions to a gunittest config file
run: |
sed 's:exclude =:exclude = ${{
sed 's:exclude =:exclude = ${{
steps.get-exclude.outputs.extra-exclude
}}:g' .gunittest.cfg > .gunittest.extra.cfg
cat .gunittest.extra.cfg
Expand Down
5 changes: 0 additions & 5 deletions raster/r.surf.gauss/gaussurf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ int gaussurf(char *out, /* Name of raster maps to be opened. */

int row_count, col_count;

/****** INITIALISE RANDOM NUMBER GENERATOR ******/

/* You can set GRASS_RANDOM_SEED for repeatability */
G_math_srand_auto();

/****** OPEN CELL FILES AND GET CELL DETAILS ******/

fd_out = Rast_open_new(out, DCELL_TYPE);
Expand Down
24 changes: 24 additions & 0 deletions raster/r.surf.gauss/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ int main(int argc, char *argv[])

/****** INITIALISE ******/
double gauss_mean, gauss_sigma;
long seed_value;

struct GModule *module;
struct Option *out;
struct Option *mean;
struct Option *sigma;
struct Option *seed;

G_gisinit(argv[0]);

Expand All @@ -55,9 +57,31 @@ int main(int argc, char *argv[])
sigma->type = TYPE_DOUBLE;
sigma->answer = "1.0";

seed = G_define_option();
seed->key = "seed";
seed->type = TYPE_INTEGER;
seed->required = NO;
seed->label = _("Seed for random number generator");
seed->description = _("The same seed can be used to obtain same results"
" or random seed can be generated by other means.");

if (G_parser(argc, argv))
exit(EXIT_FAILURE);

/****** INITIALISE RANDOM NUMBER GENERATOR ******/
if (seed->answer) {
seed_value = atol(seed->answer);
G_srand48(seed_value);
G_verbose_message(_("Read random seed from %s option: %ld"), seed->key,
seed_value);
}
else {
/* default as it used to be */
seed_value = G_math_srand_auto();
G_verbose_message(_("Autogenerated random seed set to: %ld"),
seed_value);
}

sscanf(mean->answer, "%lf", &gauss_mean);
sscanf(sigma->answer, "%lf", &gauss_sigma);

Expand Down
91 changes: 91 additions & 0 deletions raster/r.surf.gauss/testsuite/test_r_surf_gauss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python3

"""
MODULE: Test of r.surf.gauss
AUTHOR(S): Corey White <ctwhite48 gmail com>
PURPOSE: Tests random gauss surface generation
COPYRIGHT: (C) 2023 - 2024 by Corey White and the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.
"""

import os
from grass.gunittest.case import TestCase
from grass.gunittest.main import test


class MeanSigmaTestCase(TestCase):
"""Test r.surf.gauss module"""

# Raster map name be used as output
output = "random_result"

@classmethod
def setUpClass(cls):
"""Ensures expected computational region"""
os.environ["GRASS_RANDOM_SEED"] = "42"
# modifying region just for this script
cls.use_temp_region()
cls.runModule("g.region", rows=10, cols=10)

@classmethod
def tearDownClass(cls):
"""Remove the temporary region"""
cls.del_temp_region()

def tearDown(self):
"""Remove the output created from the module"""
self.runModule("g.remove", flags="f", type="raster", name=[self.output])

def test_defaut_settings(self):
"""Check to see if univariate statistics match for default"""
self.assertModule("r.surf.gauss", output=self.output)
self.assertRasterFitsUnivar(
self.output,
reference=dict(mean=-0.044860, stddev=1.019485),
precision=1e-6,
)

def test_mean_sigma_params(self):
"""Check if mean and sigma params are accepted"""
mean_value = 3.0
sigma_value = 5.8
self.assertModule(
"r.surf.gauss",
mean=mean_value,
sigma=sigma_value,
output=self.output,
)
self.assertRasterExists(self.output, msg="Output was not created")
self.assertRasterFitsUnivar(
self.output,
reference=dict(mean=2.739812, stddev=5.913014),
precision=1e-6,
)

def test_random_seed_option(self):
"""Checks if random seed option sets random number"""
mean_value = 3.0
sigma_value = 5.8
self.assertModule(
"r.surf.gauss",
mean=mean_value,
sigma=sigma_value,
output=self.output,
seed=22,
)
self.assertRasterExists(self.output, msg="Output was not created")
self.assertRasterFitsUnivar(
self.output,
reference=dict(mean=3.183532, stddev=6.050756),
precision=1e-6,
)


if __name__ == "__main__":
test()
Loading

0 comments on commit 43794ba

Please sign in to comment.