Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t.register: support mapset name in input file #2863

Merged
merged 21 commits into from
Mar 23, 2023

Conversation

ninsbl
Copy link
Member

@ninsbl ninsbl commented Feb 27, 2023

Before this PR, input files for registering maps with fully classified map names like here:

prec_1@$MAPSET|2001-01-01|2001-04-01|semantic_label
prec_2@$MAPSET|2001-04-01|2001-07-01|semantic_label
prec_3@$MAPSET|2001-07-01|2001-10-01|semantic_label
prec_4@$MAPSET|2001-10-01|2002-01-01|semantic_label
prec_5@$MAPSET|2002-01-01|2002-04-01|semantic_label
prec_6@$MAPSET|2002-04-01|2002-07-01|semantic_label

threw an error. Now, maps in the register file can be specified with a fully qualified map name (including the mapset name), which should be even faster than using unqualified map names, as existence check is skipped.

@ninsbl ninsbl added bug Something isn't working temporal Related to temporal data processing Python Related code is in Python labels Feb 27, 2023
@ninsbl ninsbl added this to the 8.3.0 milestone Feb 27, 2023
@ninsbl ninsbl requested a review from metzm February 27, 2023 21:58
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the test. Can you please enable the test by moving the file to testsuite directory? (I did that recently in b59a047 for r3.out.vtk.) There it would run in CI and fail it if the test fails. A different question is what the test actually tests automatically, but just testing that the modules don't fail is not bad for starters.

python/grass/temporal/register.py Outdated Show resolved Hide resolved
python/grass/temporal/register.py Outdated Show resolved Hide resolved
python/grass/temporal/register.py Outdated Show resolved Hide resolved
@ninsbl
Copy link
Member Author

ninsbl commented Feb 28, 2023

Thanks for updating the test. Can you please enable the test by moving the file to testsuite directory? (I did that recently in b59a047 for r3.out.vtk.) There it would run in CI and fail it if the test fails. A different question is what the test actually tests automatically, but just testing that the modules don't fail is not bad for starters.

Sure. There are more test files though. And I am not sure if all tests are currently successful. I will have a look at them and evtl. port them to Python...

@wenzeslaus
Copy link
Member

Seems totally unrelated, but v.to.lines test failed for macOS, have we seen this before?

 Running ./scripts/v.to.lines/testsuite/test_v_to_lines.py...
========================================================================
.========================================================================
FAILED ./scripts/v.to.lines/testsuite/test_v_to_lines.py - Timeout >300.0s

@nilason
Copy link
Contributor

nilason commented Mar 1, 2023

Seems totally unrelated, but v.to.lines test failed for macOS, have we seen this before?

 Running ./scripts/v.to.lines/testsuite/test_v_to_lines.py...
========================================================================
.========================================================================
FAILED ./scripts/v.to.lines/testsuite/test_v_to_lines.py - Timeout >300.0s

Mac timeout caused fails do occur, but rarely enough for me to not see any pattern.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that the similar code is replaced by a function, but I have doubts about when the function actually does and what is considered an error.

Comment on lines 122 to 129
element = {
"rast": "cell",
"raster": "cell",
"rast3d": "grid3",
"raster3d": "grid3",
"raster_3d": "grid3",
"vector": "vector",
}[type]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How comes it worked before without this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked because

a) the find_file function replaces "raster" with "cell" (and then gives a message if in verbose mode that the user may not be able to understand, see:

if element == "raster" or element == "rast":
verbose(_('Element type should be "cell" and not "%s"') % element)
element = "cell"
) and
b) if a 3d map was not found (which I guess never was the case) the function simply assumed it is in the current mapset, which may be true for the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but perhaps best hidden in a library function which actually understands the user-facing types and does not complain about them, but that's for a different PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in find_file

python/grass/temporal/register.py Outdated Show resolved Hide resolved
python/grass/temporal/register.py Outdated Show resolved Hide resolved
python/grass/temporal/register.py Show resolved Hide resolved
python/grass/temporal/register.py Outdated Show resolved Hide resolved
@ninsbl
Copy link
Member Author

ninsbl commented Mar 5, 2023

In order to disentangle the issues a bit here, I created two different feature branches in my fork from which I can create PRs if the direction to solve this is right.

  1. Regarding find_file, I replaced the current translation of raster and rast to cell with a more comprehensive replacement for such element types that are used in the code. Here, the logic does not change but message level is decreased from verbose to debug, as it is more relevant for development any way. See: main...ninsbl:grass:find_file_elements for proposed changes.
  2. Regarding the build_id function in abstract_map_dataset: Here, I would suggest to add a keyword argument check_mapset_element, which searches for a given element with the given name on the current search path, but only if an element type and no mapset is given. So the behavior remains the same. The costs for that function increase by one if-check, though. See here for how I would propose to implement it: main...ninsbl:grass:bstract_map_dataset_build_id

With those two changes in place, the function added in this PR would be obsolet and we could do:

# Vector maps
# With checks executed
AbstractMapDataset.build_id("streams:1", None, None, check_mapset_element="vector")
# Without existence checks
AbstractMapDataset.build_id("streams:1", "PERMANENT", None, check_mapset_element="vector")
AbstractMapDataset.build_id("streams", "PERMANENT", 1, check_mapset_element="vector")
AbstractMapDataset.build_id("streams:1@PERMANENT", None, None, check_mapset_element="vector")
AbstractMapDataset.build_id("streams:1@PERMANENT")
# Note that the existence of a layer is not checked for vector maps

# Raster maps
# With checks executed
AbstractMapDataset.build_id("elevation", None, None, check_mapset_element="raster")
AbstractMapDataset.build_id("elevation", None, None, check_mapset_element="cell")
# Without existence checks
AbstractMapDataset.build_id("elevation", "PERMANENT", None, check_mapset_element="raster")
AbstractMapDataset.build_id("elevation", "PERMANENT")
AbstractMapDataset.build_id("elevation@PERMANENT")
AbstractMapDataset.build_id("elevation@PERMANENT", "mapset_that_does_not_exist", None)

All would basically return the same id.

That would appear to me as the clearest implementation with least duplication / repetition of functionality and without changing current behavior.

Any thoughts, should I open PRs for the suggested changes to the two functions in question?

@ninsbl
Copy link
Member Author

ninsbl commented Mar 17, 2023

a7c0030 illustrates how this would be solved if #2882 was merged... (because of missing kwarg that comes with #2882, the tests should currently fail. Would need a rebase in case)...

@ninsbl ninsbl force-pushed the t_register_mapset branch 2 times, most recently from de6ba10 to a7c0030 Compare March 20, 2023 21:21
@ninsbl ninsbl requested a review from wenzeslaus March 23, 2023 10:03
@ninsbl
Copy link
Member Author

ninsbl commented Mar 23, 2023

Should be ready to merge as requested changes are addressed...

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. Addressing the other issues in separate PRs helped quite a bit here. Impressive amount of enabled tests and a test for the new and old functionality.

@wenzeslaus wenzeslaus removed the request for review from metzm March 23, 2023 13:56
@ninsbl
Copy link
Member Author

ninsbl commented Mar 23, 2023

Thanks @wenzeslaus
There remain some shell script tests that have not been ported to Python, but that would be another PR.

@ninsbl ninsbl merged commit 6686aa7 into OSGeo:main Mar 23, 2023
@wenzeslaus
Copy link
Member

...There remain some shell script tests that have not been ported to Python...

Simple git mv will take care of enabling them. Shell scripts are supported (at least on unix-like systems) so that these legacy scripts can at least run with minimal or no changes (another reason was to have a shell-user friendly way of creating tests, but that really did not help with contributions).

neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
* support mapset in file

* move some tests to Python

* use new build_id_from_search_path

* add documentation in the manual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Related code is in Python temporal Related to temporal data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants