Comments (11)
Maybe this is just my lack of understanding. Is scale_factor
used to update the array only when used in functions like NDVI etc?
Is there a way to scale it directly?
from geowombat.data import l8_224078_20200518
with gw.config.update(scale_factor=0.0001):
with gw.open(l8_224078_20200518) as src:
print(src.values[0])
print(src.scales)
print(src.gw.scale_factor)
[[ 0 0 0 ... 0 0 0]
[ 0 0 0 ... 0 0 0]
[ 0 0 0 ... 0 0 0]
...
[7692 7518 7513 ... 7440 7432 7415]
[7586 7590 7610 ... 7440 7411 7425]
[7576 7743 7770 ... 7464 7443 7406]]
(1.0, 1.0, 1.0)
0.0001
from geowombat.
Thanks for highlighting this. Currently, scale_factor
is only passed to functions that use it. We don't, however, apply the 'scales' attribute upon opening. That attribute comes from rasterio/open_rasterio.
The way that scale_factor
is currently used is legacy. Do you think we should apply the 'scales' attribute upon opening?
Say for a 3-band raster, scales of 1 would not trigger any scaling.
with gw.open('image.tif) as src:
print(src.attrs['scales'])
(1.0, 1.0, 1.0)
# src would not have scaling applied
but if scales do not equal 1
with gw.open('image.tif) as src:
print(src.attrs['scales'])
(1e-4, 1e-4, 1e-4)
# Within open(), we would do something like
self._obj = self._obj * src.attrs['scales']
# src would have scaling applied
The config would be an attribute override, similar to how nodata
is used.
with gw.config.update(scale_factor=255.0):
with gw.open('image.tif) as src:
# Within open(), we would do something like
if config['scale_factor'] is not None:
# The 'scales' attribute would be ignored
self._obj = self._obj * config['scale_factor']
Then, any function/method level scaling would be applied again, if requested. E.g.
with gw.config.update(scale_factor=255.0):
with gw.open('image.tif) as src:
# src would have 255 x applied
# scale_factor here would be applied again, but defaulted to None
src.gw.ndvi(scale_factor=#)
from geowombat.
See also rasterio's approach and rioxarray's mask_and_scale approach i.e., leave it to the user.
from geowombat.
@mmann1123 experiment with branch jgrss/scales_216 and let me know if it does what you would expect.
from geowombat.
In particular, see new open() keywords for scaling and new tests for examples.
from geowombat.
@jgrss I like the use of scale_data
in open
with #jgrss/scales_216. Its passing tests on my end.
Good to see that attrs['scales']
is 1 if scaling is applied. But shouldn't attrs['scales']
be updated to 0.0001 if scale_data =False
?
>>> with gw.open(l8_224078_20200518, scale_data=False,scale_factor=0.0001) as src:
... print(src)
...
<xarray.DataArray (band: 3, y: 1860, x: 2041)>
dask.array<open_rasterio-5c7bef10720d35eff3f9baa732b582af<this-array>, shape=(3, 1860, 2041), dtype=uint16, chunksize=(3, 256, 256), chunktype=numpy.ndarray>
Coordinates:
* band (band) int64 1 2 3
* x (x) float64 7.174e+05 7.174e+05 7.174e+05 ... 7.785e+05 7.786e+05
* y (y) float64 -2.777e+06 -2.777e+06 ... -2.833e+06 -2.833e+06
Attributes:
transform: (30.0, 0.0, 717345.0, 0.0, -30.0, -2776995.0)
crs: 32621
res: (30.0, 30.0)
is_tiled: 1
nodatavals: (nan, nan, nan)
_FillValue: nan
scales: (1.0, 1.0, 1.0)
offsets: (0.0, 0.0, 0.0)
AREA_OR_POINT: Area
filename: /geowombat/src/geowombat/data/LC08_L1TP_224078_20200...
resampling: nearest
_data_are_separate: 0
_data_are_stacked: 0
from geowombat.
shouldn't attrs['scales'] be updated to 0.0001 if scale_data =False?
Ah, good call. I can add that.
from geowombat.
See #221
from geowombat.
from geowombat.
Do you mean a geowombat
version change? It was upgraded from v2.0.11
to v2.0.12
. Do you know what triggers conda
? Is it a release?
from geowombat.
from geowombat.
Related Issues (20)
- Failed to Install Geowombat on pip and conda HOT 12
- Requirement differences between package & conda-forge HOT 6
- Coordinating efforts on potential new geospatial Xarray accessor HOT 2
- Regression capability in geowombat HOT 3
- ARM Installation Issues HOT 9
- Apply interpolation HOT 4
- Stac import HOT 2
- series.apply big tiff / bad block
- EVI equation is wrong HOT 2
- Support for pyproj 3.4.1? HOT 8
- Slow extract HOT 2
- mosaic bounds HOT 4
- fit_predict
- Stack & Mosaic Advice? HOT 6
- writing with Bigtiff HOT 2
- [] in open trigger stacking
- polygon_to_array returns shorter y dimension than source rasters HOT 26
- band names HOT 1
- Unable to import geowombat HOT 1
- Mosaic Fails with nan nodata HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geowombat.