jgrss / geowombat

GeoWombat: Utilities for geospatial data
https://geowombat.readthedocs.io
MIT License
184 stars 10 forks source link

Mosaic Fails with nan nodata #322

Open mmann1123 opened 2 months ago

mmann1123 commented 2 months ago

Looks like nan values interfers with mosaicing images. Although I might be missing something.

# %%
import geowombat as gw
import rasterio
from geowombat.data import l8_224077_20200518_B2, l8_224078_20200518_B2
import matplotlib.pyplot as plt

fig, ax = plt.subplots(dpi=200)

with gw.open(
    [l8_224077_20200518_B2, l8_224078_20200518_B2],
    mosaic=True,
    bounds_by="union",
) as src:
    print(src)
src.where(src != 0).gw.imshow(robust=True, ax=ax)

# %%
fig, ax = plt.subplots(dpi=200)

with gw.open([l8_224077_20200518_B2], mosaic=True) as src:
    attrs = src.attrs
    src = src.where(src > 0)
    print(src)
    src.attrs = attrs
    src.gw.save(
        "l8_224077_20200518_B2.tif",
    )

src.gw.imshow(robust=True, ax=ax)
# %%
fig, ax = plt.subplots(dpi=200)

with gw.open(
    [l8_224078_20200518_B2],
    mosaic=True,
) as src:
    attrs = src.attrs
    src = src.where(src > 0)
    print(src)
    src.attrs = attrs
    src.gw.save(
        "l8_224078_20200518_B2.tif",
    )
src.gw.imshow(robust=True, ax=ax)

# %%
fig, ax = plt.subplots(dpi=200)
import numpy as np
with gw.open(
    ["l8_224077_20200518_B2.tif", "l8_224078_20200518_B2.tif"],
    mosaic=True,
    bounds_by="union",
    nodata=np.nan,
) as src:
    print(src)
src.gw.imshow(robust=True, ax=ax)

# %%

Screenshot from 2024-07-15 16-11-20

mmann1123 commented 2 months ago

Nearly fixed in branch fix_mosaic_nan @jgrss