-
Notifications
You must be signed in to change notification settings - Fork 18
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
Set a spatial_ref value to 0 instead of EPSG code for better compatibility with rioxarray #164
Comments
@simonreise When using In your case just change: - pan_masked = pan.where(mask_rep == 0, 0)
+ pan_masked = pan.where(mask_rep.data == 0, 0) But sure, the value stored in the When mask is an |
@simonreise can you please check if forcing odc-geo/odc/geo/_xr_interop.py Lines 216 to 221 in 78577dc
replace |
Both of your suggestions worked: adding |
Short description
I use
odc-geo
to reproject and match Landsat 8 QA mask raster to the resolution of the panchromatic band. All the other operations with data are performed usingrioxarray
.The issue is that
rioxarray
setsspatial_ref
value to 0 by default, but thenodc-geo
re-sets that value to the EPSG code of the projection, and, when I mask the original panchromatic band (that was loaded by rioxarray) with QA band (that was reprojected by odc-geo) usingxarray.where
,spatial_ref
coordinate is being dropped.Libraries import
Loading the panchromatic band with rioxarray
Loading the QA raster with rioxarray
Checking the coordinates of the panchromatic band
Coordinates:
spatial_ref int32 4B 0
More detailed look into
spatial_ref
The value is 0, and all the data is stored in the attrs.
array(0)
Coordinates:
spatial_ref () int32 0
Indexes: (0)
Attributes: (18)
Checking the coordinates of the QA band
Coordinates:
spatial_ref int32 4B 0
More detailed look into
spatial_ref
The value is also 0, and all the data is stored in the attrs.
array(0)
Coordinates:
spatial_ref () int32 0
Indexes: (0)
Attributes: (18)
Reprojecting the QA band
We reproject the QA band to match the geobox of the panchromatic band.
Checking the coordinates of the reprojected QA band
Coordinates:
spatial_ref int32 4B 32646
More detailed look into
spatial_ref
The value is 32646 - the EPSG code of the projection. More detailed data is still stored in the attrs.
array(32646)
Coordinates:
spatial_ref () int32 32646
Indexes: (0)
Attributes: (18)
Masking the panchromatic band
Then we use our reprojected mask (
mask_rep
) to mask the panchromatic band. IRL the function is more complicated, but this minimum example still shows the problem.Checking the coordinates
The
spatial_ref
is gone. It must be because the coordinates from two arrays had different values.Coordinates:
If we use two xarrays loaded with rioxarray, the problem does not appear. If we just simply reassign the coord to 0, (
pan_w = pan.where(mask_rep.assign_coords(spatial_ref=0) == 0, 0)
) the problem does not appear.To sum up
Is it really necessary to have a EPSG code of a CRS as a default value for
spatial_ref
? Maybe just use 0 as a default value like rioxarray does, as the actual CRS data anyway is mostly stored in the attributes, not in the coordinate value itself? Or convince rioxarray devs to also use EPSG code as a default value? I think there should be a common convention for both libraries.I can still manually assign the
spatial_ref
, but it looks like a really dirty fix.Env
The text was updated successfully, but these errors were encountered: