Reputation: 491
I have two .nc
files, which have similar lat and lon dimensions, CRS and everything else.
Dimensions: (lat: 62, lon: 94)
Coordinates:
* lat (lat) float64 58.46 58.79 59.12 59.44 ... 77.45 77.78 78.11 78.44
* lon (lon) float64 -150.0 -149.4 -148.9 -148.3 ... -98.56 -98.0 -97.43
When I then add these two files together, the whole dimension changes:
dem = xr.open_dataset(path + 'DEM.nc')
dc = xr.open_dataset(path + 'DC.nc')
X = 1 / (1 + np.exp(-(-2.2432e+01 + (dem.Band1 * 1.97521e-06) + (dc.Band1 * 5.97414e-04))))
print(X)
<xarray.DataArray 'Band1' (lat: 11, lon: 94)>
* lat (lat) float64 65.01 65.34 65.67 65.99 ... 73.52 74.18 77.78 78.44
* lon (lon) float64 -150.0 -149.4 -148.9 -148.3 ... -98.56 -98.0 -97.43
What happens? Why does this addition change the whole dimension?
NB. the dc
file has some grid cells without data nan
. Does that influence it?
EDIT: With the answer given, I still do not think it is purely because of missing data, look at the image of the datasets individually and the datasets combined:
Upvotes: 1
Views: 58
Reputation: 1786
You have given the answer to yourself with
the dc file has some grid cells without data nan. Does that influence it?
Yes because xarray is looking to the coordinates too instead of just doing vectorized operations. Check out the documentation to find out more about it.
The work around is very simple: Let numpy do the job for you!
X = 1 / (1 + np.exp(-(-2.2432e+01 + (dem.Band1.values * 1.97521e-06) + (dc.Band1.values * 5.97414e-04))))
data_array = xarray.DataArray(X, coords={'lat': dem.lat, 'lon': dem.lon}, dims=['lat', 'lon'])
dem['combined'] = data_array
Upvotes: 1