Skip to content

[Bug] t.rast.extract: expression fails with fully qualified STRDS name if STRDS and mapset name are identical #6254

@ninsbl

Description

@ninsbl

Describe the bug

When running t.rast.extract with an STRDS as input where both STRDS-name and mapset name are identical, the expression will become invalid:

To reproduce

import grass.script as gs
gs.create_project(tmp_path)

with gs.setup.init("/tmp", location="test") as session:
    gs.use_temp_region()
    gs.run_command("g.mapset", mapset="perc", flags="c")
    gs.run_command("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")
    gs.run_command("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)
    for i in range(1,7):
        gs.run_command("r.mapcalc", expression=f"prec_{i} = {i}00", overwrite=True)
        gs.run_command("r.semantic.label", map=f"prec_{i}",semantic_label=f"S2_{i}", overwrite=True)

    gs.run_command(
        "t.create",
        type="strds",
        temporaltype="absolute",
        output="prec",
        title="A test",
        description="A test",
        overwrite=True,
    )
    gs.run_command(
        "t.register",
        flags="i",
        type="raster",
        input="prec",
        maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6",
        start="2001-01-01",
        increment="3 months",
        overwrite=True,
    )
    gs.run_command("g.mapset", mapset="another_mapset", flags="c")
    gs.run_command(
        "t.rast.extract",
        input="prec",
        output="prec_2",
        where="start_time > '2001-06-01'",
        expression=" if(prec@perc>400,prec@perc,null())",
        basename="prec_2",
        nprocs=2,
        verbose=True,
        overwrite=True,
    )

Expected behavior

The expression should work with fully qualified STRDS name, even if STRDS and mapset name are identical.

Additional context

The issue is probably here:

expr = expr.replace(sp.base.get_map_id(), row["id"])
expr = expr.replace(sp.base.get_name(), row["id"])

The replacement should probably include an @

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions