You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about the regridding of global datasets.
My code so far was built like this:
defregrid_to_lat_lon(
ds: xr.Dataset,
target_res_lat: float=1,
target_res_lon: float=1,
) ->xr.Dataset:
""" Regrid any grid to a res_lat x res_lon degree lat lon grid. Parameters ---------- ds : xr.Dataset Input dataset to be regridded. target_res_lat : float, optional Target resolution in degrees for latitude, by default 1. target_res_lon : float, optional Target resolution in degrees for longitude, by default 1. Returns ------- xr.Dataset Regridded dataset. """ds_out=xe.util.grid_global(target_res_lat, target_res_lon)
regridder=xe.Regridder(
ds,
ds_out,
"bilinear",
periodic=True,
)
dr_out=regridder(ds, keep_attrs=True)
dr_out["x"] =dr_out["lon"].isel(y=0).datadr_out["y"] =dr_out["lat"].isel(x=0).datadr_out=dr_out.drop(["lat", "lon"])
dr_out=dr_out.rename({"y": "latitude", "x": "longitude"})
returndr_out
I just realized, when I use ds_out = xe.util.grid_global(target_res_lat, target_res_lon, cf=True), I do not have to use the lower part of my code, where I drop not needed values from my dr_out. The outputs are equal (dr_out_cf.equals(dr_out_notcf) = True) (except for the one coordinate I am asking about below).
I could not find a lot of information about this on the Docs. The search is also not working there for me at the moment.
The only difference is, that ds_out (the grid) and dr_out (the regridded ds) calculated with cf=True contain a coordinate latitude_longitude which is nan. ds_out:
And is my new approach the better one for my use case?
And additionally, would it be possible to specify the latitude and longitude names used by xe.util.grid_global? Normally, my latitude and longitude coords have the names latitude_bins and longitude_bins, which does not work with xesmf.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a question about the regridding of global datasets.
My code so far was built like this:
I just realized, when I use
ds_out = xe.util.grid_global(target_res_lat, target_res_lon, cf=True)
, I do not have to use the lower part of my code, where I drop not needed values from mydr_out
. The outputs are equal (dr_out_cf.equals(dr_out_notcf) = True
) (except for the one coordinate I am asking about below).I could not find a lot of information about this on the Docs. The search is also not working there for me at the moment.
The only difference is, that
ds_out
(the grid) anddr_out
(the regridded ds) calculated withcf=True
contain a coordinatelatitude_longitude
which isnan
.ds_out
:Is this coordinate required in the output?
And is my new approach the better one for my use case?
And additionally, would it be possible to specify the latitude and longitude names used by
xe.util.grid_global
? Normally, my latitude and longitude coords have the names latitude_bins and longitude_bins, which does not work withxesmf
.Beta Was this translation helpful? Give feedback.
All reactions