-
Notifications
You must be signed in to change notification settings - Fork 83
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
rioxarray.write_transform() not changing transform #698
Comments
It appears that the dimensions |
Side note: |
This is how rioxarray adds coordinates based on the transform: Lines 1203 to 1206 in c15b860
|
Thanks for the suggestion. For the zip file previously attached, the case seems to be that the defined coordinate grid from So apart from that I included some additional data here where the coordinate issue is not of concern, which might help to get more closely to understanding the actual transform error As background information, for the torchgeo dataset implementation we are trying to achieve the following:
import xarray as xr
from rioxarray.merge import merge_arrays
query = {
"minx": 0,
"miny": 0,
"maxx": 50,
"maxy": 50
}
_crs = "EPSG:4326"
spatial_x_name = "longitude"
spatial_y_name = "latitude"
data_variables = ["sst", "sla"]
alt_ds= xr.open_dataset("/eo/dt_global_twosat_phy_l4_199311_vDT2021-M01.nc")
alt_ds = alt_ds.assign_coords(longitude=(alt_ds.longitude % 360 - 180)).roll(
longitude=(alt_ds.dims["longitude"] // 2)
)
sst_ds = xr.open_dataset("/eo/HadISST1_SST_update.nc")
sst_ds = sst_ds.sortby("latitude", ascending=True)
data_arrays = []
for ds in [sst_ds, alt_ds]:
ds.rio.set_spatial_dims(spatial_x_name, spatial_y_name, inplace=True)
for variable in data_variables:
if hasattr(ds, variable):
da = ds[variable]
if not da.rio.crs:
da.rio.write_crs(_crs, inplace=True)
elif da.rio.crs != _crs:
da = da.rio.reproject(_crs)
# clip box ignores time dimension
clipped = da.rio.clip_box(
minx=query["minx"], miny=query["miny"], maxx=query["maxx"], maxy=query["maxy"]
)
# rioxarray expects this order
clipped = clipped.transpose("time", spatial_y_name, spatial_x_name, ...)
data_arrays.append(clipped.squeeze())
merged_data = merge_arrays(
data_arrays, bounds=(query["minx"], query["miny"], query["maxx"], query["maxy"])
).data Running that snippet I get:
So I think there is a mismatch between how the bounds and transforms are defined vs how they are expected in rioxarray and I am not sure where exactly this difference is. |
#209 may be helpful. |
@snowman2 thanks for the hint! We'll see if that addresses the coordinate issue in the first paragraph of #698 (comment). Do you have any thoughts on the other paragraphs of that comment? |
Hey @snowman2 - I'm a bit of a geo-noob but I'm trying to use I tried then passing
Could you suggest how I can do this? |
@ciaransweet do you have a minimal reproducible example? https://stackoverflow.com/help/minimal-reproducible-example The main think to keep in mind is that the coordinates in the Dataset/DataArray are how
This is passed from the output of
This exists for caching the transform when coordinates do not exist or for single point rasters. |
Problem description
I am working with CMIP6 data and looking at utilizing
rioxarray
for possibly combining different data streams, so I am looking for a general approach through rioxarray. For this am using themerge_arrays()
function, with the hope of applying it to not just for these specific CMIP6 files. However, for these files I am encounteringrasterio.errors.WindowError: Bounds and transform are inconsistent
Errors which seem to be due to a wrong transformation being read from the src files. Theoutput_transform
is computed correctly and works, and therefore I was thinking about setting the transform beforehand to the array. However,write_transform()
does not change the transformation in this case, so I am wondering what I am missing or if there is another way to go about this. Data for the following example can be found here.Code Sample
Environment Information
rioxarray - 0.15.0
rasterio - 1.3.6
xarray - 2023.6.0
The text was updated successfully, but these errors were encountered: