Comments (6)
Thanks for the great issue @maawoo. I don't think you're doing anything wrong here; this is probably a bug. Which version are you using, btw? 1) I noticed #60 hasn't been released yet and 2) #35 from >= 0.2.0 is slightly related (though I highly doubt relevant here). Would it be possible for you to try with pip install git+https://github.com/gjoseph92/stackstac.git@main
to see if #60 fixes it?
One other thing to be aware of is that I believe rioxarray follows xarray conventions (rather than typical raster conventions) and expects coordinates to refer to pixel centers. So I'd think (but haven't tried) that xy_coords='center'
would actually give you (0, 0) offset in your output GeoTIFF, and xy_coords='topleft'
would give you (0.5, 0.5).
from stackstac.
Hi Gabe,
I was using 0.2.1 installed via pip install stackstac
. Forgot to check for any relevant changes that might not have been released yet. Thanks for the reminder to do that in the future!
Unfortunately the problem persists after installing from git and #60 doesn't fix it, which also means that xy_coords='center'
still results in an unexpected offset.
I did the following quick test regarding rioxarray with in.tif
being the same raster file as described above:
test = rioxarray.open_rasterio('./in.tif')
test.rio.to_raster('./out.tif')
The output is still perfectly aligned afterwards, so I assume rioxarray/rasterio somehow handle the conversion between raster and xarray conventions internally. I would've been very suprised if not tbh.
I think that the error lies somewhere here because there's no offset problem with xy_coords=False
, which skips the code block that I linked. Unfortunately I don't have much time to spare at the moment to look into this myself.
from stackstac.
Yup, something is definitely wrong with the xy_coords
logic. I'm really sorry about that; that's not the sort of thing you should have to question or debug as a user!
I also don't have a ton of time to look into this, but hopefully I can next week. If you could provide a full copy-pasteable reproducer, that would help a ton. What's your stac_obj
?
from stackstac.
No problem and as a user I'm always happy to contribute to projects that I have a personal interest in!
You can find a stripped-down example scene here:
https://upload.uni-jena.de/data/612dde1b411da9.40050697/xycoords.7z
I tested it with the following code, except that the asset href in the STAC Item needs to be changed to absolute to work with stackstac of course.
from pystac import Collection
import stackstac
import rioxarray
collection_path = '/path/to/collection.json'
stac_obj = Collection.from_file(collection_path)
scene_stack = stackstac.stack(items=stac_obj, chunksize=5120, xy_coords='center', dtype='float32', rescale=False)
vh = scene_stack.sel(band='vh')
vh.rio.to_raster('/.../out.tif')
Hope that helps!
from stackstac.
I think I'm observing something that is related: xy_coords='center'
mode of operation computes Y coordinates incorrectly when Y resolution is negative. What I'm observing is that as I switch from default to `'center`` both X and Y are shifted by half a pixel away from 0, but Y needs to move towards 0 as Y axis is inverted.
from stackstac.
@maawoo I'm pretty sure .rio
expects coordinates to be in center
mode. But see my comment about offset going wrong way for Y axis when using center. You can check for inconsistency by comparing output of .rio.transform()
with attribute reported by stackstac
.
This is what I'm observing:
xx.attrs['transform'], xx.rio.transform()
(Affine(10.0, 0.0, 499980.0,
0.0, -10.0, 9200020.0),
Affine(10.0, 0.0, 499980.0,
0.0, -10.0, 9200030.0))
which is consistent with your reports.
But if I apply a fix:
xx.y.data[:] = xx.y.data[:] - float(xx.resolution)
then I get consistent output from .rio.transform()
. If you can try applying that fix and check if you get data round-trip without an offset then?
- Load with
center
intoxx
xx.y.data[:] = xx.y.data[:] - float(xx.resolution)
- Save with
.rio
, load back compare.
from stackstac.
Related Issues (20)
- Multidimensional coordinnates is not supported HOT 2
- Black stripes on mosaicking HOT 3
- README example raises `DoesNotConformTo` HOT 3
- Only support pystac? HOT 1
- Slicing KeyError HOT 2
- High RAM use during stackstac.stack(items, epsg=item_crs) HOT 2
- Basic example SSLCertVerificationError HOT 12
- Accessing VZA and SZA bands? HOT 1
- Error for assests with multiple bands is not raised correctly
- Stack Contains NaT in Time Field HOT 6
- Dimension names from cube:dimensions HOT 1
- NetCDF Time Dimension HOT 1
- Create stac objects from stackstac xarray HOT 1
- Error using .sel on time index if timestamp not in np.datetime64
- Stackstac 0.5.0 produces bad pixel values for Sentinel-2 HOT 5
- 'bounds' is messing up the x, y coordinnates
- "errors_as_nodata" not working correctly HOT 1
- Could logging be disabled for skipping VRT
- Stacking local assets - slow performance
- Handle empty input better
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 stackstac.