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

fix: mosaic nan #323

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

fix: mosaic nan #323

wants to merge 28 commits into from

Conversation

mmann1123
Copy link
Collaborator

What is this PR changing?

This resolves issues with nan's in arrays during mosaics.
Closes #322

Checklist

  • [ x] Remember to add a semantic tag to the commit name

Tag options:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing or correcting existing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation

Example:

fix: <branch name> PR number

@mmann1123 mmann1123 added the bug Something isn't working label Jul 18, 2024
@mmann1123 mmann1123 self-assigned this Jul 18, 2024
@@ -76,91 +76,91 @@ def _check_config_globals(
bounds_by (str)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only formatting changse

@@ -191,6 +191,11 @@ def mask_nodata(self) -> xr.DataArray:
``xarray.DataArray``
"""
nodata_value = self._obj.gw.nodataval

if np.isnan(nodata_value):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

skip replacing nodata with nan if already nodata is already nan

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could be dropped but might speed up things

added test.py by accident
srtm30m_bounding_boxes = str(p / "srtm30m_bounding_boxes.gpkg")
wrs2 = str(p / "wrs2.tar.gz")

l8_224077_20200518_B2_nan = str(p / "l8_224077_20200518_B2_nan.tif")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added version with nan for missing data values

),
)
)

def test_mosaic_max_nan(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added tests specific to union and nan

@mmann1123
Copy link
Collaborator Author

@jgrss I have resolved the problems with mosaicing - but I am getting a new error with h5netcdf tests, I tried pining h5netcdf versions 1.1 and 1.2 but that didn't resolve it. Just wondering if you have any thoughts here.

On reading and writing its thowing:

======================================================================
FAIL: test_to_netcdf (tests.test_write.TestWrite.test_to_netcdf)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/geowombat/geowombat/tests/test_write.py", line 29, in test_to_netcdf
    .gw.to_netcdf(filename=out_path, overwrite=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/geowombat/core/geoxarray.py", line 731, in to_netcdf
    to_netcdf(self._obj, filename, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/geowombat/core/io.py", line 663, in to_netcdf
    ds.to_netcdf(
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/xarray/core/dataset.py", line 2327, in to_netcdf
    return to_netcdf(  # type: ignore  # mypy cannot resolve the overloads:(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/xarray/backends/api.py", line 1337, in to_netcdf
    dump_to_store(
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/xarray/backends/api.py", line 1384, in dump_to_store
    store.store(variables, attrs, check_encoding, writer, unlimited_dims=unlimited_dims)
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/xarray/backends/common.py", line 366, in store
    self.set_dimensions(variables, unlimited_dims=unlimited_dims)
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/xarray/backends/common.py", line 443, in set_dimensions
    self.set_dimension(dim, length, is_unlimited)
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/xarray/backends/h5netcdf_.py", line 260, in set_dimension
    self.ds.dimensions[name] = length
    ~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/h5netcdf/dimensions.py", line 29, in __setitem__
    self._objects[name] = Dimension(self._group, name, size, create_h5ds=True)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/h5netcdf/dimensions.py", line 91, in __init__
    self._create_scale()
  File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/h5netcdf/dimensions.py", line 211, in _create_scale
    if not self._root._h5py.h5ds.is_scale(self._h5ds.id):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5ds.pyx", line 35, in h5py.h5ds.is_scale
  File "h5py/defs.pyx", line 4505, in h5py.defs.H5DSis_scale
RuntimeError: Unspecified error in H5DSis_scale (return value <0)

@@ -513,6 +513,18 @@ def __init__(
w = src.block_window(1, 0, 0)
kwargs["chunks"] = (band_chunks, w.height, w.width)

# kw = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would like to send a note to the user if they have config updates when using mosaic or stacking multiple images - since updates to res, etc don't get used since open_warp isn't called -

However when _check_config_globals is run its breaking all the tests and I am not sure why.

@mmann1123
Copy link
Collaborator Author

@jgrss This is ready to merge.

@mmann1123
Copy link
Collaborator Author

@jgrss I am happy to report I finally figured out how to update the ml scikit-learn to the newest version! Can you take a look through?

@jgrss
Copy link
Owner

jgrss commented Feb 5, 2025

@jgrss I am happy to report I finally figured out how to update the ml scikit-learn to the newest version! Can you take a look through?

I'll take a look (after a long delay).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mosaic Fails with nan nodata
2 participants