Ejemplo n.º 1
0
 def testComma(self):
     sel = SimpleModule('v.db.select', flags='c', map=self.invect,
                        where="{col}='{val}'".format(col=self.col,
                                                     val=self.val),
                        separator=',')
     sel.run()
     self.assertLooksLike(reference=out_sep, actual=sel.outputs.stdout)
Ejemplo n.º 2
0
 def testWhere(self):
     """Testing v.db.select with where option"""
     sel = SimpleModule('v.db.select', flags='c', map=self.invect,
                        where="{col}='{val}'".format(col=self.col,
                                                     val=self.val))
     sel.run()
     self.assertLooksLike(reference=out_where, actual=sel.outputs.stdout)
Ejemplo n.º 3
0
 def test_flag_c(self):
     """Testing output with flag c"""
     string = """17|628137.4371495|63995.550883875||*
     18|782600.5631495|152698.890883875||*
     19|502813.9381495|235232.577883875||*
     20|705922.6251495|136589.359883875||*"""
     r_what = SimpleModule('r.what',
                           map=self.input,
                           coordinates=self.coordinates,
                           flags='c')
     r_what.outputs.stdout = string
     self.assertLooksLike(reference=string, actual=r_what.outputs.stdout)
Ejemplo n.º 4
0
 def test_flag_i(self):
     """Testing output with flag i"""
     string = """13|634688.2501495|100629.616883875||*
     14|287638.7811495|207582.624883875||*
     15|366218.5321495|222940.625883875||*
     16|385212.4371495|236593.109883875||*"""
     r_what = SimpleModule('r.what',
                           map=self.input,
                           coordinates=self.coordinates,
                           flags='i')
     r_what.outputs.stdout = string
     self.assertLooksLike(reference=string, actual=r_what.outputs.stdout)
Ejemplo n.º 5
0
 def test_flag_r(self):
     """Testing output with flag r"""
     string = """9|399187.0631495|220018.859883875||*
     10|685098.9371495|33282.089883875||*
     11|577750.8131495|257153.109883875||*
     12|794095.5621495|199742.671883875||*"""
     r_what = SimpleModule('r.what',
                           map=self.input,
                           coordinates=self.coordinates,
                           flags='r')
     r_what.outputs.stdout = string
     self.assertLooksLike(reference=string, actual=r_what.outputs.stdout)
Ejemplo n.º 6
0
 def test_flag_f(self):
     """Testing output with flag f"""
     string = """5|706338.2501495|54889.417883875||*
     6|758009.7501495|112019.898883875||*
     7|754002.7501495|200902.234883875||*
     8|704771.7501495|183364.484883875||*"""
     r_what = SimpleModule('r.what',
                           map=self.input,
                           coordinates=self.coordinates,
                           flags='f')
     r_what.outputs.stdout = string
     self.assertLooksLike(reference=string, actual=r_what.outputs.stdout)
Ejemplo n.º 7
0
 def test_raster_mode_one_direction(self):
     """Test mode with 1 point and one direction"""
     module = SimpleModule('r.horizon',
                           elevation='elevation',
                           output=self.horizon_output,
                           direction=50)
     self.assertModule(module)
     ref = {'min': 0, 'max': 0.70678365230560, 'stddev': 0.0360724286360789}
     self.assertRasterFitsUnivar(
         raster='test_horizon_output_from_elevation_050',
         reference=ref,
         precision=1e6)
Ejemplo n.º 8
0
 def test_profile_region(self):
     rprofile = SimpleModule(
         'r.profile',
         input='elevation',
         null_value='nodata',
         coordinates=[644914, 224579, 644986, 224627, 645091, 224549])
     self.assertModule(rprofile)
     self.assertMultiLineEqual(rprofile.outputs.stdout.strip(),
                               output3.strip())
     self.assertIn(
         "WARNING: Endpoint coordinates are outside of current region settings",
         rprofile.outputs.stderr)
Ejemplo n.º 9
0
 def test_simple(self):
     """Test simple t.rast.neighbors"""
     trast_list = SimpleModule("t.rast.neighbors",
                               quiet=True,
                               input="A",
                               output="B",
                               size="5",
                               basename='b',
                               overwrite=True)
     self.assertModule(trast_list)
     self.assertRasterMinMax('b_2001_01', 1, 10)
     self.assertRasterMinMax('b_2001_02', 1, 10)
Ejemplo n.º 10
0
 def test_time_suffix(self):
     """Test simple t.rast.neighbors"""
     trast_list = SimpleModule("t.rast.neighbors",
                               quiet=True,
                               input="A",
                               output="B",
                               size="5",
                               basename='b',
                               suffix="time",
                               overwrite=True)
     self.assertModule(trast_list)
     self.assertRasterExists('b_2001_01_01T00_00_00')
Ejemplo n.º 11
0
 def test_formats_landcover(self):
     recode = SimpleModule(
         "r.recode",
         input="landuse@PERMANENT",
         output="recoded",
         rules="-",
         overwrite=True,
     )
     recode.inputs.stdin = rules4
     self.assertModule(recode)
     info = "min=1\nmax=3\ndatatype=CELL"
     self.assertRasterFitsInfo(raster="recoded", reference=info)
Ejemplo n.º 12
0
    def test_rgb_maps(self):
        """Generates rgb maps from a raster map test"""
        module = SimpleModule("r.rgb",
                              input=self.mapName,
                              red=self.red,
                              green=self.green,
                              blue=self.blue)
        self.assertModule(module)

        self.assertRasterExists(self.red)
        self.assertRasterExists(self.green)
        self.assertRasterExists(self.blue)
Ejemplo n.º 13
0
    def test_line_d(self):
        output_str = """cat|name|a_median|a_number|a_range
1|first|192|3|1
2|second|181|41|6
"""
        self.assertModule("v.rast.stats", map="test_line", raster="map_a",
                          method=["median", "number", "range"], flags="dc",
                          column_prefix="a")
        v_db_select = SimpleModule("v.db.select", map="test_line")

        self.runModule(v_db_select)
        self.assertLooksLike(output_str, str(v_db_select.outputs.stdout))
Ejemplo n.º 14
0
    def test_aggregation_2months(self):
        """Aggregation two month"""
        self.assertModule("t.rast.aggregate",
                          input="A",
                          output="B",
                          basename="b",
                          granularity="2 months",
                          method="minimum",
                          sampling=["contains"],
                          nprocs=4,
                          offset=10)

        tinfo_string = """start_time=2001-01-01 00:00:00
                        end_time=2001-05-01 00:00:00
                        granularity=2 months
                        map_time=interval
                        aggregation_type=minimum
                        number_of_maps=2
                        min_min=100.0
                        min_max=500.0
                        max_min=100.0
                        max_max=500.0"""

        info = SimpleModule("t.info", flags="g", input="B")
        #info.run()
        #print info.outputs.stdout
        self.assertModuleKeyValue(module=info,
                                  reference=tinfo_string,
                                  precision=2,
                                  sep="=")

        # Check the map names are correct
        lister = SimpleModule("t.rast.list",
                              input="B",
                              columns="name",
                              flags="s")
        self.runModule(lister)
        #print lister.outputs.stdout
        maps = "b_11" + os.linesep + "b_12" + os.linesep
        self.assertEqual(maps, lister.outputs.stdout)
Ejemplo n.º 15
0
    def test_simple_where_2(self):
        self.assertModule("t.rast.gapfill",
                          input="A",
                          where="start_time <= '2001-05-01'",
                          basename="test",
                          nprocs=1,
                          verbose=True,
                          suffix="num%01")

        #self.assertModule("t.info",  type="strds", flags="g",  input="A")

        tinfo_string = """start_time='2001-01-01 00:00:00'
                                end_time='2002-01-01 00:00:00'
                                granularity='1 month'
                                map_time=interval
                                number_of_maps=5
                                min_min=100.0
                                min_max=1200.0
                                max_min=100.0
                                max_max=1200.0"""

        info = SimpleModule("t.info", flags="g", type="strds", input="A")
        self.assertModuleKeyValue(module=info,
                                  reference=tinfo_string,
                                  precision=2,
                                  sep="=")

        text = """name|start_time|end_time|min|max
a_1|2001-01-01 00:00:00|2001-02-01 00:00:00|100.0|100.0
test_4_1|2001-02-01 00:00:00|2001-03-01 00:00:00|200.0|200.0
test_4_2|2001-03-01 00:00:00|2001-04-01 00:00:00|300.0|300.0
a_2|2001-04-01 00:00:00|2001-05-01 00:00:00|400.0|400.0
a_3|2001-12-01 00:00:00|2002-01-01 00:00:00|1200.0|1200.0
"""
        rast_list = SimpleModule("t.rast.list",
                                 columns=("name", "start_time", "end_time",
                                          "min,max"),
                                 input="A")
        self.assertModule(rast_list)
        self.assertLooksLike(text, rast_list.outputs.stdout)
Ejemplo n.º 16
0
    def test_small_area_with_centroid(self):
        # Output of v.rast.stats
        univar_string = """cat|name|a_number|a_null_cells|a_minimum|a_maximum|a_range|a_average|a_stddev|a_variance|a_coeff_var|a_sum|a_first_quartile|a_median|a_third_quartile|a_percentile_90
1|first|1|0|90|90|0|90|0|0|0|90|90|90|90|90
2|second|1|0|88|88|0|88|0|0|0|88|88|88|88|88
"""

        self.assertModule("v.rast.stats", map='test_small_area', raster="row_map",
                          flags="c", column_prefix="a", type_=["area","centroid"])
        v_db_select = SimpleModule("v.db.select", map="test_small_area")

        self.runModule(v_db_select)
        self.assertLooksLike(univar_string, str(v_db_select.outputs.stdout))
Ejemplo n.º 17
0
 def test_flag_n(self):
     """Testing output with flag n"""
     string = """1|145096.8591495|154534.264883875||*
     2|616341.4371495|146049.750883875||*
     3|410595.7191495|174301.828883875||*
     4|734153.6871495|169168.437883875||*
     """
     r_what = SimpleModule('r.what',
                           map=self.input,
                           coordinates=self.coordinates,
                           flags='n')
     r_what.outputs.stdout = string
     self.assertLooksLike(reference=string, actual=r_what.outputs.stdout)
Ejemplo n.º 18
0
    def test_1t(self):

        t_rast_whatcsv = SimpleModule("t.rast.whatcsv",  strds="A",
                                      csv="test.csv", overwrite=True,
                                      skip=0, verbose=True)
        self.assertModule(t_rast_whatcsv)

        text="""1|115.0043586274|36.3593955783||100
2|79.6816763826|45.2391522853||200
3|97.4892579600|79.2347263950||300
4|115.0043586274|36.3593955783||400
"""
        self.assertLooksLike(text,  t_rast_whatcsv.outputs.stdout)
Ejemplo n.º 19
0
 def test_flag_v(self):
     """Testing output with flag v"""
     string = """21|620397.8131495|246847.640883875||*
     22|738465.3751495|237233.983883875||*
     23|708944.7501495|247632.296883875||*
     24|526666.6871495|249780.312883875||*"""
     r_what = SimpleModule('r.what',
                           map=self.input,
                           coordinates=self.coordinates,
                           flags='v',
                           points=self.points)
     r_what.outputs.stdout = string
     self.assertLooksLike(reference=string, actual=r_what.outputs.stdout)
Ejemplo n.º 20
0
    def test_flagd(self):
        """Testing flag d with map hospitals"""
        univar_string = """number of primitives: 160
number of non zero distances: 12561
number of zero distances: 0
minimum: 9.16773
maximum: 760776
range: 760767
sum: 2.69047e+09
mean: 214193
mean of absolute values: 214193
population standard deviation: 128505
population variance: 1.65136e+10
population coefficient of variation: 0.599953
sample standard deviation: 128511
sample variance: 1.6515e+10
kurtosis: 0.277564
skewness: 0.801646"""
        v_univar = SimpleModule('v.univar', map='hospitals', column='CITY', flags='d')
        v_univar.run()
        self.assertLooksLike(actual=v_univar.outputs.stdout.encode('utf8'),
                             reference=univar_string)
Ejemplo n.º 21
0
    def test_flagg(self):
        """Testing flag g with map lakes"""
        output_str = """n=15279
nmissing=0
nnull=0
min=1
max=15279
range=15278
sum=1.16732e+08
mean=7640
mean_abs=7640
population_stddev=4410.67
population_variance=1.9454e+07
population_coeff_variation=0.577312
sample_stddev=4410.81
sample_variance=1.94553e+07
kurtosis=-1.20024
skewness=-2.41826e-14"""
        v_univar = SimpleModule("v.univar", flags="g", map='lakes', column='cat')
        v_univar.run()
        self.assertLooksLike(actual=v_univar.outputs.stdout.encode('utf8'),
                             reference=output_str)
Ejemplo n.º 22
0
    def test_zone_all(self):
        # Output of v.rast.stats
        univar_string = """cat|value|label|a_number|a_null_cells|a_minimum|a_maximum|a_range|a_average|a_stddev|a_variance|a_coeff_var|a_sum|a_first_quartile|a_median|a_third_quartile|a_percentile_90
1|1||1710|0|102|209|107|155.5|26.5502667908755|704.916666666667|17.0741265536177|265905|133|155.5|178|191
2|2||6390|0|121|280|159|200.5|33.0895250293302|1094.91666666667|16.5035037552769|1281195|177|200.5|224|245
"""

        self.assertModule("v.rast.stats", map="zone_map", raster="map_a",
                          flags="c", column_prefix="a")
        v_db_select = SimpleModule("v.db.select", map="zone_map")

        self.runModule(v_db_select)
        self.assertLooksLike(univar_string, str(v_db_select.outputs.stdout))
Ejemplo n.º 23
0
 def test_formats_random(self):
     recode = SimpleModule("r.recode",
                           input="random01",
                           output="recoded",
                           rules="-",
                           overwrite=True)
     recode.inputs.stdin = rules3
     self.assertModule(recode)
     category = read_command("r.category", map="recoded")
     n_cats = len(category.strip().split("\n"))
     if n_cats <= 2:
         self.fail(msg="Number of categories is <= 2 "
                   "which suggests input map values were read as integers.")
Ejemplo n.º 24
0
 def setUp(self):
     self.rsun = SimpleModule(
         "r.sun",
         elevation=self.elevation,
         slope=self.slope,
         aspect=self.aspect,
         day=172,
         time=18,
         beam_rad=self.beam_rad,
         glob_rad=self.glob_rad,
         incidout=self.incidout,
         overwrite=True,
     )
Ejemplo n.º 25
0
 def test_formats_random(self):
     recode = SimpleModule('r.recode',
                           input='random01',
                           output='recoded',
                           rules='-',
                           overwrite=True)
     recode.inputs.stdin = rules3
     self.assertModule(recode)
     category = read_command('r.category', map='recoded')
     n_cats = len(category.strip().split('\n'))
     if n_cats <= 2:
         self.fail(msg="Number of categories is <= 2 "
                   "which suggests input map values were read as integers.")
Ejemplo n.º 26
0
class TestRBlend(TestCase):
    """Test r.blend script"""

    map1 = 'elevation'
    map2 = 'aspect'
    temp1 = 'elev_shade_blend.r'
    temp2 = 'elev_shade_blend.g'
    temp3 = 'elev_shade_blend.b'
    mapsets_to_remove = []
    # mapset with a name is also a valid mathematical expression
    mapset_name = "1234-56-78"
    gisenv = SimpleModule('g.gisenv', get='MAPSET')
    TestCase.runModule(gisenv, expecting_stdout=True)
    old_mapset = gisenv.outputs.stdout.strip()

    @classmethod
    def setUpClass(cls):
        """Create maps in a small region."""
        # create a mapset with a name is also a valid mathematical expression
        cls.runModule("g.mapset", flags="c", mapset=cls.mapset_name)
        cls.mapsets_to_remove.append(cls.mapset_name)
        run_command('g.copy', raster=cls.map1 + '@PERMANENT,' + cls.map1)
        cls.runModule('g.region', raster=cls.map1, flags='p')

    @classmethod
    def tearDownClass(cls):
        """Remove temporary data"""
        gisenv = SimpleModule('g.gisenv', get='GISDBASE')
        cls.runModule(gisenv, expecting_stdout=True)
        gisdbase = gisenv.outputs.stdout.strip()
        gisenv = SimpleModule('g.gisenv', get='LOCATION_NAME')
        cls.runModule(gisenv, expecting_stdout=True)
        location = gisenv.outputs.stdout.strip()
        cls.runModule('g.remove',
                      flags='f',
                      type='raster',
                      name=(cls.temp1, cls.temp2, cls.temp3))
        cls.runModule("g.mapset", mapset=cls.old_mapset)
        for mapset_name in cls.mapsets_to_remove:
            mapset_path = os.path.join(gisdbase, location, mapset_name)
            silent_rmtree(mapset_path)

    def test_blend(self):
        """blends test with special mapset name"""

        # should not lead to syntax error, unexpected INTEGER, expecting VARNAME or NAME
        module = SimpleModule('r.blend',
                              first=self.map2,
                              second=self.map1 + '@' + self.mapset_name,
                              output='elev_shade_blend')
        self.assertModule(module)
Ejemplo n.º 27
0
 def test_where(self):
     """Test simple t.rast.neighbors"""
     trast_list = SimpleModule("t.rast.neighbors",
                               quiet=True,
                               input="A",
                               output="B",
                               basename='b',
                               overwrite=True,
                               size="5",
                               where="start_time <= '2001-02-01 00:00:00'")
     self.assertModule(trast_list)
     self.assertRasterExists('b_2001_01')
     self.assertRasterMinMax('b_2001_02', 1, 10)
     self.assertRasterDoesNotExist('b_2001_03')
Ejemplo n.º 28
0
    def test_creates_raster_plane_map(self):
        """Create a tilted plane raster map test"""
        module = SimpleModule(
            "r.plane",
            output=self.mapOutput,
            dip=45,
            easting=527500.0,
            northing=165000.0,
            elevation=1000,
            type="FCELL",
        )
        self.assertModule(module)

        self.assertRasterExists(self.mapOutput)
Ejemplo n.º 29
0
    def test_values(self):
        self.assertModule("v.what.strds",
                          input="points",
                          strds="A",
                          output="what_strds",
                          overwrite=True)
        db_sel = SimpleModule("v.db.select", map="what_strds")
        self.assertModule(db_sel)
        output = """cat|A_2001_01_01|A_2001_04_01|A_2001_07_01|A_2001_10_01
1|100|200|300|400
2|100|200|300|400
3|100|200|300|400
"""
        self.assertMultiLineEqual(output, decode(db_sel.outputs.stdout))
Ejemplo n.º 30
0
    def test_stop(self):
        self.assertModule('t.rast.accdetect', input='A', occurrence='B',
                          indicator="C", start="2001-01-01", stop='2008-12-31',
                          cycle="12 months", basename='result', range=(1,8))
        tinfo_string="""semantic_type=mean
        start_time=2001-01-01 00:00:00
        end_time=2009-01-01 00:00:00
        granularity=1 month
        map_time=interval
        number_of_maps=96"""
        info = SimpleModule("t.info", flags="g", type="strds", input="B")
        self.assertModuleKeyValue(module=info, reference=tinfo_string,
                                  precision=2, sep="=")

        tinfo_string="""semantic_type=mean
        start_time=2001-01-01 00:00:00
        end_time=2009-01-01 00:00:00
        granularity=1 month
        map_time=interval
        number_of_maps=96"""
        info = SimpleModule("t.info", flags="g", type="strds", input="C")
        self.assertModuleKeyValue(module=info, reference=tinfo_string,
                                  precision=2, sep="=")
Ejemplo n.º 31
0
    def test_1(self):
        # Output of v.rast.stats
        univar_string = """cat|value|label|a_minimum|a_maximum|a_sum
1|1||102|209|265905
2|2||121|280|1281195
"""

        self.assertModule("v.rast.stats", map="zone_map", raster="map_a",
                          method=["minimum", "maximum", "sum"], flags="c",
                          column_prefix="a")
        v_db_select = SimpleModule("v.db.select", map="zone_map")

        self.runModule(v_db_select)
        self.assertLooksLike(univar_string, str(v_db_select.outputs.stdout))
Ejemplo n.º 32
0
 def test_num_suffix(self):
     """Test simple t.rast.neighbors"""
     trast_list = SimpleModule(
         "t.rast.neighbors",
         quiet=True,
         input="A",
         output="B",
         size="5",
         basename="b",
         suffix="num%03",
         overwrite=True,
     )
     self.assertModule(trast_list)
     self.assertRasterExists("b_001")
Ejemplo n.º 33
0
 def testGroup(self):
     """Testing v.db.select with group option"""
     sel = SimpleModule('v.db.select', flags='c', map=self.invect,
                        columns=self.col, group=self.col)
     sel.run()
     self.assertLooksLike(reference=out_group, actual=sel.outputs.stdout)