MCPcopy Create free account
hub / github.com/NCAR/wrf-python / extract_dim

Function extract_dim

src/wrf/util.py:892–930  ·  view source on GitHub ↗

Return the dimension size for the specified dimension name. Args: wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \ iterable): WRF-ARW NetCDF data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile` or an iterable sequence of the aforeme

(wrfin, dim)

Source from the content-addressed store, hash-verified

890
891
892def extract_dim(wrfin, dim):
893 """Return the dimension size for the specified dimension name.
894
895 Args:
896
897 wrfin (:class:`netCDF4.Dataset`, :class:`Nio.NioFile`, or an \
898 iterable): WRF-ARW NetCDF
899 data as a :class:`netCDF4.Dataset`, :class:`Nio.NioFile`
900 or an iterable sequence of the aforementioned types.
901
902 dim (:obj:`str`): The dimension name.
903
904 Returns:
905
906 :obj:`int`: The dimension size.
907
908 """
909 if is_multi_file(wrfin):
910 if not is_mapping(wrfin):
911 wrfin = next(iter(wrfin))
912 else:
913 entry = wrfin[next(iter(viewkeys(wrfin)))]
914 return extract_dim(entry, dim)
915
916 d = wrfin.dimensions[dim]
917 if not isinstance(d, int):
918 try:
919 return len(d) # netCDF4
920 except TypeError: # scipy.io.netcdf
921 # Scipy can't handled unlimited dimensions, so now we have to
922 # figure it out
923 try:
924 s = wrfin.variables["P"].shape
925 except Exception:
926 raise ValueError("unsupported NetCDF reader")
927 else:
928 return s[-4]
929
930 return d # PyNIO
931
932
933def _combine_dict(wrfdict, varname, timeidx, method, meta, _key):

Callers 5

_find_max_time_sizeFunction · 0.85
_find_forwardFunction · 0.85
_find_reverseFunction · 0.85
_join_filesFunction · 0.85
is_staggeredFunction · 0.85

Calls 3

is_multi_fileFunction · 0.85
is_mappingFunction · 0.85
viewkeysFunction · 0.85

Tested by

no test coverage detected