easyclimate.wrf.interface¶
WRF-python interface
See also
This is the built-in compiled wrf-python package. Please refer to the User API in the wrf-python package for related routines.
Functions¶
|
Open WRF (Weather Research and Forecasting) Model Output data. |
|
Transfer WRF data from |
Module Contents¶
- easyclimate.wrf.interface.open_wrf_data(filename: str | os.PathLike, mode: Literal['r', 'w', 'r+', 'a', 'x', 'rs', 'ws', 'r+s', 'as'] = 'r', clobber: bool = True, format: Literal['NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_CLASSIC', 'NETCDF3_64BIT_OFFSET', 'NETCDF3_64BIT_DATA'] = 'NETCDF4', diskless: bool = False, persist: bool = False, keepweakref: bool = False, memory: typing_extensions.Buffer | int | None = None, encoding: str | None = None, parallel: bool = False, comm: Any = None, info: Any = None, auto_complex: bool = False, **kwargs) netCDF4.Dataset¶
Open WRF (Weather Research and Forecasting) Model Output data.
Parameters¶
- filename:
str. Name of netCDF file to hold dataset. Can also be a python 3 pathlib instance or the URL of an OpenDAP dataset. When memory is set this is just used to set the filepath().
- mode: [“r”, “w”, “r+”, “a”, “x”, “rs”, “ws”, “r+s”, “as”], default: “r”.
access mode.
rmeans read-only; no data can be modified.wmeans write; a new file is created, an existing file with the same name is deleted.xmeans write, but fail if an existing file with the same name already exists.aandr+mean append; an existing file is opened for reading and writing, if file does not exist already, one is created. Appendingsto modesr,w,r+or a will enable unbuffered shared access toNETCDF3_CLASSIC,NETCDF3_64BIT_OFFSETorNETCDF3_64BIT_DATAformatted files. Unbuffered access may be useful even if you don’t need shared access, since it may be faster for programs that don’t access data sequentially. This option is ignored forNETCDF4andNETCDF4_CLASSICformatted files.- clobber:
bool, default:True. If True (default), opening a file with
mode='w'will clobber an existing file with the same name. If False, an exception will be raised if a file with the same name already exists.mode=xis identical tomode=wwithclobber=False.- format: [“NETCDF4”, “NETCDF4_CLASSIC”, “NETCDF3_CLASSIC”, “NETCDF3_64BIT_OFFSET”, “NETCDF3_64BIT_DATA”], default: “NETCDF4”.
underlying file format (one of
'NETCDF4','NETCDF4_CLASSIC','NETCDF3_CLASSIC','NETCDF3_64BIT_OFFSET'or'NETCDF3_64BIT_DATA'. Only relevant ifmode = 'w'(ifmode = 'r','a'or'r+'the file format is automatically detected). Default'NETCDF4', which means the data is stored in an HDF5 file, using netCDF 4 API features. Settingformat='NETCDF4_CLASSIC'will create an HDF5 file, using only netCDF 3 compatible API features. netCDF 3 clients must be recompiled and linked against the netCDF 4 library to read files inNETCDF4_CLASSICformat.'NETCDF3_CLASSIC'is the classic netCDF 3 file format that does not handle 2+ Gb files.'NETCDF3_64BIT_OFFSET'is the 64-bit offset version of the netCDF 3 file format, which fully supports 2+ GB files, but is only compatible with clients linked against netCDF version 3.6.0 or later.'NETCDF3_64BIT_DATA'is the 64-bit data version of the netCDF 3 file format, which supports 64-bit dimension sizes plus unsigned and 64 bit integer data types, but is only compatible with clients linked against netCDF version 4.4.0 or later.- diskless:
bool, default:False. If
True, create diskless (in-core) file. This is a feature added to the C library after the netcdf-4.2 release. If you need to access the memory buffer directly, use the in-memory feature instead (seememorykwarg).- persist:
bool, default:False. if
diskless=True, persist file to disk when closed (defaultFalse).- keepweakref:
bool, default:False. if
True, child Dimension and Variable instances will keep weak references to the parent Dataset or Group object. Default isFalse, which means strong references will be kept. Having Dimension and Variable instances keep a strong reference to the parent Dataset instance, which in turn keeps a reference to child Dimension and Variable instances, creates circular references. Circular references complicate garbage collection, which may mean increased memory usage for programs that create may Dataset instances with lots of Variables. It also will result in the Dataset object never being deleted, which means it may keep open files alive as well. Settingkeepweakref=Trueallows Dataset instances to be garbage collected as soon as they go out of scope, potentially reducing memory usage and open file handles. However, in many cases this is not desirable, since the associated Variable instances may still be needed, but are rendered unusable when the parent Dataset instance is garbage collected.- memory: Buffer or
int. if not
None, create or open an in-memory Dataset. If mode =r, the memory kwarg must contain a memory buffer object (an object that supports the python buffer interface). The Dataset will then be created with contents taken from this block of memory. If mode =w, the memory kwarg should contain the anticipated size of the Dataset in bytes (used only for NETCDF3 files). A memory buffer containing a copy of the Dataset is returned by theDataset.close()method. Requires netcdf-c version 4.4.1 for mode=``r`` netcdf-c 4.6.2 for mode=``w``. To persist the file to disk, the raw bytes from the returned buffer can be written into a binary file. The Dataset can also be re-opened using this memory buffer.- encoding:
str. encoding used to encode filename string into bytes. Default is None (
sys.getdefaultfileencoding()is used).- parallel:
bool, default:False. open for parallel access using MPI (requires mpi4py and parallel-enabled netcdf-c and hdf5 libraries). Default is
False. IfTrue,commandinfokwargs may also be specified.- comm: Any.
MPI_Comm object for parallel access. Default
None, which means MPI_COMM_WORLD will be used. Ignored ifparallel=False.- info: Any.
MPI_Info object for parallel access. Default
None, which means MPI_INFO_NULL will be used. Ignored ifparallel=False.- auto_complex:
bool, default:False. if
True, then automatically convert complex number types.
Returns¶
Data (
netCDF4.Dataset).- filename:
- easyclimate.wrf.interface.transfer_xarray2nctype(ds: xarray.Dataset) netCDF4.Dataset¶
Transfer WRF data from
xarray.DatasettonetCDF4.Dataset.Parameters¶
- ds:
xarray.Dataset. WRF data read by xarray engine.
Returns¶
Data (
netCDF4.Dataset).- ds: