-
Notifications
You must be signed in to change notification settings - Fork 10
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
Updating attributes with band math #24
Comments
Maybe I should show the exact issue I am seeing, maybe not related to attributes.
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... |
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 |
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') |
The band math attributes below will now be updated.
I also added a 'vi' attribute. When I merge your examples I will push these changes with version |
I am closing this for now, but we can reopen if there are additional attributes that we want to add. |
Maybe a minor tweek to improve band math.
returns
Shouldn't attributes be updated to reflect a single band after running band math? For instance nodatavals: (0.0), scales: (1.0) etc? This can be problematic I think when going to write out NDVI and needing to reset attributes.
The text was updated successfully, but these errors were encountered: