-
Notifications
You must be signed in to change notification settings - Fork 155
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
save slp to netcdf #215
Comments
I am in the same boat. @fipoucat, have you been able to save a netcdf file using wrf-python? |
Still did not find a solution, hope someone will helP |
Hello,
you can use the xarray library. This function and the link can help you.
#91
def write_xarray_to_netcdf(xarray_array, output_path,mode='w',
format='NETCDF4', group=None, engine=None,
encoding=None):
"""writes and xarray in a netcdf format outputfile
Uses the xarray typical for wrf-python. The projection objects are
transformed into strings
to be able to use them as netcdf attributes
:param xarray_array: xarray.DataArray
:param output_path: str
:param format: 'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT' or
'NETCDF3_CLASSIC'
default: 'NETCDF4'
:param group: str, default None
:param engine: 'netcdf4', 'scipy' or 'h5netcdf'
:param encoding: dict, default: None
"""
xarray_array_out = xarray_array.copy(deep=True)
# coordinates are extracted from variable
del xarray_array_out.attrs['coordinates']
# wrf-python projection object cannot be processed
xarray_array_out.attrs['projection'] =
str(xarray_array_out.attrs['projection'])
xarray_array_out.to_netcdf(path=output_path, mode=mode, format=format,
group=group,
engine=engine,
encoding=encoding)
El mar, 23 ene 2024 a las 9:34, fipoucat ***@***.***>)
escribió:
… Still did not find a solution, hope someone will helP
—
Reply to this email directly, view it on GitHub
<#215 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AROHQY7CS6LCFV4BBE6L2RTYP6U5BAVCNFSM6AAAAAA3YJT72SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBVHE3DOMJWGM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I suspect they are running into encoding errors when they try: one would need to delete the variables with non-numeric data. Mostly this means the coordinates in which wrf-python stores the Cartopy, Basemap, or Proj representation of the geospatial map projection. One might be able to ask the object for a string to save as a coordinate or a dictionary one could save as attributes of a variable so one could re-create the projection later. EDIT: |
I extracted slp from wrf output using wrf-python. I can print the output but want to save it in a netcdf file.
I wonder how to do it within wrf-python?
The text was updated successfully, but these errors were encountered: