Git Product home page Git Product logo

Comments (5)

jgrss avatar jgrss commented on May 23, 2024 1

The band math attributes below will now be updated.

new_attrs['nodatavals'] = (nodata)
new_attrs['scales'] = (1.0)
new_attrs['offsets'] = (0.0)

I also added a 'vi' attribute. When I merge your examples I will push these changes with version 1.2.5.

from geowombat.

mmann1123 avatar mmann1123 commented on May 23, 2024

Maybe I should show the exact issue I am seeing, maybe not related to attributes.

with gw.config.update(sensor='rgbn', scale_factor=0.0001):
    with gw.open([rgbn_suba, rgbn_subb],
          band_names=['blue', 'green', 'red', 'nir'],
          mosaic=True,
          bounds_by='union') as ds_mos:
                
                ndvi = ds_mos.gw.ndvi()

                # Xarray drops attributes
                attrs = ndvi.attrs.copy()
                ndvi.attrs['nodatavals'] = (0.0)
                ndvi.attrs['scales'] = (1.0)
                ndvi.attrs['offsets'] = (0.0)
 
                ndvi.attrs = attrs
                print(attrs)
                # Write the data to a GeoTiff
                ndvi.gw.to_raster( '/home/mmann1123/Desktop/output2.tif',
                                    verbose=1,
                                    n_workers=4,    # number of process workers sent to ``concurrent.futures``
                                    n_threads=2,    # number of thread workers sent to ``dask.compute``
                                    n_chunks=200)   # number of window chunks

throws:

ValueError: Source shape (1, 64) is inconsistent with given indexes 1

I am assuming it has to do with the use of the config, but not sure there is a config for single band...

from geowombat.

jgrss avatar jgrss commented on May 23, 2024

I agree, the attributes should be updated for band math.

I will see if I can figure out the shape issue. One quick note--if you specify the sensor in the configuration then you don't have to specify the band names in gw.open(). But, I see that I named the files incorrectly. They are stored as blue, green, red, NIR, not red, gree, blue, NIR.

from geowombat.

jgrss avatar jgrss commented on May 23, 2024

Ok, the attributes were not the issue when writing the results to file. The problem seems to be the chunk size. The image block size is 64x64, which led to a single row/column at the image edge. Using a larger chunk size fixed it.

>>> with gw.config.update(sensor='bgrn', scale_factor=0.0001):
>>>     
>>>     with gw.open([rgbn_suba, rgbn_subb],
>>>                  mosaic=True,
>>>                  bounds_by='union',
>>>                  chunks=256) as ds_mos:
>>> 
>>>         attrs = ds_mos.attrs.copy()
>>>         
>>>         # Calculate the NDVI
>>>         ndvi = ds_mos.gw.ndvi()
>>>         
>>>         # Mask the NDVI
>>>         masker = ndvi >= -0.25
>>>         ndvi = ndvi * masker
>>>         
>>>         # The 'no data' values are set as None from `ds_mos.gw.ndvi()`
>>>         # After masking, set the 'no data' values as 0.
>>>         ndvi.attrs = attrs
>>>         ndvi.attrs['nodatavals'] = (0)
>>>         
>>>         # Write the data to a GeoTiff
>>>         ndvi.gw.to_raster('ndvi.tif',
>>>                           overwrite=True,
>>>                           n_workers=4,    # number of process workers sent to ``concurrent.futures``
>>>                           n_threads=2,    # number of thread workers sent to ``dask.compute``
>>>                           n_chunks=200,   # number of window chunks
>>>                           compress='lzw')

from geowombat.

jgrss avatar jgrss commented on May 23, 2024

I am closing this for now, but we can reopen if there are additional attributes that we want to add.

from geowombat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.