Exemplo n.º 1
0
def main():
    # lazy imports
    import grass.temporal as tgis

    expression = options['expression']
    basename = options['basename']
    nprocs = options["nprocs"]
    spatial = flags["s"]
    register_null = flags["n"]
    granularity = flags["g"]

    # Check for PLY istallation
    try:
        # Intentionally unused imports
        import ply.lex as lex  # noqa: F401
        import ply.yacc as yacc  # noqa: F401
    except ImportError:
        grass.script.fatal(_("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules. "
                             "You can use t.rast3d.mapcalc that provides a limited but useful alternative to "
                             "t.rast3d.mapcalc2 without PLY requirement."))

    tgis.init(True)
    p = tgis.TemporalRaster3DAlgebraParser(run = True, debug=False, spatial = spatial, nprocs = nprocs, register_null = register_null)

    if granularity:
        if not p.setup_common_granularity(expression=expression, stdstype = 'str3ds', lexer = tgis.TemporalRasterAlgebraLexer()):
            grass.script.fatal(_("Unable to process the expression in granularity algebra mode"))

    p.parse(expression, basename, grass.script.overwrite())
Exemplo n.º 2
0
    def test_temporal_neighbors_1(self):
        """Simple temporal neighborhood computation test"""
        tra = tgis.TemporalRaster3DAlgebraParser(run=True, debug=True)
        tra.parse(expression='D = A[-1] + A[1]', basename="d", overwrite=True)

        D = tgis.open_old_stds("D", type="str3ds")
        D.select()
        self.assertEqual(D.metadata.get_number_of_maps(), 2)
        self.assertEqual(D.metadata.get_min_min(), 4)  # 1 + 3
        self.assertEqual(D.metadata.get_max_max(), 6)  # 2 + 4
        start, end = D.get_absolute_time()
        self.assertEqual(start, datetime.datetime(2001, 1, 2))
        self.assertEqual(end, datetime.datetime(2001, 1, 4))
Exemplo n.º 3
0
def main():
    expression = options['expression']
    basename = options['basename']
    nprocs = options["nprocs"]
    spatial = flags["s"]
    register_null = flags["n"]

    # Check for PLY istallation
    try:
        import ply.lex as lex
        import ply.yacc as yacc
    except:
        grass.script.fatal(
            _("Please install PLY (Lex and Yacc Python implementation) to use the temporal algebra modules. "
              "You can use t.rast3d.mapcalc that provides a limited but useful alternative to "
              "t.rast3d.mapcalc2 without PLY requirement."))

    tgis.init(True)
    p = tgis.TemporalRaster3DAlgebraParser(run=True,
                                           debug=False,
                                           spatial=spatial,
                                           nprocs=nprocs,
                                           register_null=register_null)
    p.parse(expression, basename, grass.script.overwrite())