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

Move GDAL constraint into constraints file and update to GDAL 3.8 #1546

Merged
merged 13 commits into from
Apr 3, 2024

Conversation

emlys
Copy link
Member

@emlys emlys commented Mar 28, 2024

Description

Fixes #916
Create a new file constraints_tests.txt that stores dependency constraints needed to run our tests, but not necessarily to use invest in general.

Exclude gdal versions 3.6.* and 3.7.* which had the bug.

Fortunately, conda seems to have no problem with multiple requirements for the same package in one environment yaml file. This makes it easy to include the constraints file in our workflow - we can pass it in to the convert-requirements-to-conda-yml.py script just like another requirements file. The resulting yml will contain this:

  - GDAL>=3.4.2
  - GDAL!=3.6.*,!=3.7.*

Also includes updates needed for the latest versions of GDAL:

  • A validation test was broken with python 3.8 and gdal>=3.6.0. This was due to an error in the test.
  • An HRA test broke with gdal>=3.6.4 (due to the underlying GEOS update). This appeared to be an error in HRA that probably didn't affect results most of the time.
  • Some NDR tests broke with gdal >=3.7.0, probably related to the new GDT_Int8 type and deprecation of the PIXELTYPE=SIGNEDBYTE flag (hooray!)

Checklist

  • Updated HISTORY.rst and link to any relevant issue (if these changes are user-facing)
  • Updated the user's guide (if needed)
  • Tested the Workbench UI (if relevant)

@emlys emlys changed the title move gdal constraint into constraints file Move GDAL constraint into constraints file and update to GDAL 3.8 Apr 1, 2024
@@ -680,6 +676,10 @@ def execute(args):
dependent_task_list=[reprojected_vector_task]
))

# Habitats and stressors are rasterized with ALL_TOUCHED=TRUE
if name in habitats_info or name in stressors_info:
habitat_stressor_vectors.add(target_simplified_vector)
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 appears that the intent was to apply ALL_TOUCHED=TRUE when rasterizing habitats and stressors, but that was not happening because target_simplified_vector, not source_filepath, is used.

@@ -415,9 +415,9 @@ def ndr_eff_calculation(

# create direction raster in bytes
def _mfd_to_flow_dir_op(mfd_array):
result = numpy.zeros(mfd_array.shape, dtype=numpy.int8)
result = numpy.zeros(mfd_array.shape, dtype=numpy.uint8)
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this always should've been uint8. I think result is supposed to be an 8-digit binary number indicating which of the 8 directions around a pixel have flow. (i.e. 10000001 means there is flow to neighbors 0 and 7). The max value 11111111 = 255, so uint8 is needed.

I'm not sure exactly why it worked before, but it probably broke because of changes in GDAL's handling of signed 8-bit integers in 3.7.0.

@@ -2002,6 +2002,7 @@ def test_spatial_overlap_error(self):
layer = vector.CreateLayer('layer', vector_srs, ogr.wkbPoint)
new_feature = ogr.Feature(layer.GetLayerDefn())
new_feature.SetGeometry(ogr.CreateGeometryFromWkt('POINT (1 1)'))
layer.CreateFeature(new_feature)
Copy link
Member Author

Choose a reason for hiding this comment

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

The feature wasn't being added to the layer, so the layer was actually empty. I'm not sure what determines the extent of an empty layer, but I'm guessing it's undefined behavior. Some change in GDAL (or GEOS or PROJ?) caused the extent to include a nan.

By adding a feature to the layer, we get the expected behavior.

@emlys emlys requested a review from phargogh April 1, 2024 23:21
@emlys emlys self-assigned this Apr 1, 2024
@emlys emlys marked this pull request as ready for review April 1, 2024 23:21
Copy link
Member

@phargogh phargogh left a comment

Choose a reason for hiding this comment

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

I just had one comment about helping future us remember what belongs in the constraints file since we are regularly using it for conda/mamba applications. I'd be happy with a comment in the constraints file, but it could also be interesting to update the conda/mamba conversion script to handle environment markers if you thought that might be a better solution. Totally up to you :)

Aside from that, it looks great to me, thanks @emlys!

@@ -0,0 +1,5 @@
# This file contains package constraints needed to run the invest test suite
Copy link
Member

Choose a reason for hiding this comment

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

Since the concept of a constraints file is pip-specific (I think?) but we're using conda/mamba to manage our environments, would it be worth adding a note here about the syntax that is allowed in this file?

I'm guessing environment markers might be a big one that wouldn't be supported without further work on our requirements conversion script, for example!

@emlys
Copy link
Member Author

emlys commented Apr 3, 2024

Thanks @phargogh, I added a note about the constraints format!

@emlys emlys requested a review from phargogh April 3, 2024 17:49
Copy link
Member

@phargogh phargogh left a comment

Choose a reason for hiding this comment

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

The test failures appear to be specific to the recmodel's connection to the server, so I'm happy approving and merging this.

@phargogh phargogh merged commit 59145ca into natcap:main Apr 3, 2024
17 of 25 checks passed
phargogh added a commit to regro-cf-autotick-bot/natcap.invest-feedstock that referenced this pull request Apr 8, 2024
The version cap was added to avoid problems with our test suite.
For details, see how we resolved the issue in natcap/invest#1546
@emlys emlys mentioned this pull request Apr 24, 2024
@emlys emlys deleted the task/916 branch October 3, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Proposal, RFC] Separate requirements from constraints
2 participants