Skip to content

Commit

Permalink
Update doc strings in grib2io source.
Browse files Browse the repository at this point in the history
Did add show_table() method to Grib2Metadata class to provide a
quick way for a user to see other values in the related tabled.
  • Loading branch information
EricEngle-NOAA committed Nov 15, 2023
1 parent 275da91 commit 2cadd5d
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 125 deletions.
8 changes: 4 additions & 4 deletions grib2io/_grib2io.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def tell(self):
return self.current_message


def select(self,**kwargs):
def select(self, **kwargs):
"""
Select GRIB2 messages by `Grib2Message` attributes.
"""
Expand Down Expand Up @@ -494,7 +494,7 @@ def flush(self):
self._filehandle.flush()


def levels_by_var(self,name):
def levels_by_var(self, name):
"""
Return a list of level strings given a variable shortName.
Expand All @@ -510,7 +510,7 @@ def levels_by_var(self,name):
return list(sorted(set([msg.level for msg in self.select(shortName=name)])))


def vars_by_level(self,level):
def vars_by_level(self, level):
"""
Return a list of variable shortName strings given a level.
Expand Down Expand Up @@ -1611,7 +1611,7 @@ def shape(self):
return (self.ny, self.nx)


def _adjust_array_shape_for_interp(a,grid_def_in,grid_def_out):
def _adjust_array_shape_for_interp(a, grid_def_in, grid_def_out):
"""
Adjust shape of input data array to conform to the dimensionality
the NCEPLIBS-ip interpolation subroutine arguments for grids.
Expand Down
63 changes: 39 additions & 24 deletions grib2io/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ def get_table(table, expand=False):
Parameters
----------
**`table`**: Code table number (e.g. '1.0'). NOTE: Code table '4.1' requires a 3rd value
representing the product discipline (e.g. '4.1.0').
**`table : str`**
Code table number (e.g. '1.0'). NOTE: Code table '4.1' requires a 3rd value
representing the product discipline (e.g. '4.1.0').
**`expand`**: If `True`, expand output dictionary where keys are a range.
**`expand : bool, optional`**
If `True`, expand output dictionary where keys are a range.
Returns
-------
**`dict`**
Table as a **`dict`**.
"""
if len(table) == 3 and table == '4.1':
raise Exception('GRIB2 Code Table 4.1 requires a 3rd value representing the discipline.')
Expand Down Expand Up @@ -56,11 +58,14 @@ def get_value_from_table(value, table, expand=False):
Parameters
----------
**`value`**: `int` or `str` code table value.
**`value : int or str`**
Code table value.
**`table`**: `str` code table number.
**`table : str`**
Code table number.
**`expand`**: If `True`, expand output dictionary where keys are a range.
**`expand : bool, optional`**
If `True`, expand output dictionary where keys are a range.
Returns
-------
Expand All @@ -87,22 +92,26 @@ def get_varinfo_from_table(discipline,parmcat,parmnum,isNDFD=False):
Parameters
----------
**`discipline`**: `int` or `str` of Discipline code value of a GRIB2 message.
**`discipline : int or str`**
Discipline code value of a GRIB2 message.
**`parmcat`**: `int` or `str` of Parameter Category value of a GRIB2 message.
**`parmcat : int or str`**
Parameter Category value of a GRIB2 message.
**`parmnum`**: `int` or `str` of Parameter Number value of a GRIB2 message.
**`parmnum : int or str`**
Parameter Number value of a GRIB2 message.
**`isNDFD`**: If `True`, signals function to try to get variable information
from the supplemental NDFD tables.
**`isNDFD : bool, optional`**
If `True`, signals function to try to get variable information from
the supplemental NDFD tables.
Returns
-------
**`list`**: containing variable information. "Unknown" is given for item of
**`list`** containing variable information. "Unknown" is given for item of
information if variable is not found.
- list[0] = full name
- list[1] = units
- list[2] = short name (abbreviated name)
- list[0] = full name
- list[1] = units
- list[2] = short name (abbreviated name)
"""
if isNDFD:
try:
Expand Down Expand Up @@ -132,11 +141,14 @@ def get_shortnames(discipline=None, parmcat=None, parmnum=None, isNDFD=False):
Parameters
----------
**`discipline : int`** GRIB2 discipline code value.
**`discipline : int`**
GRIB2 discipline code value.
**`parmcat : int`** GRIB2 parameter category value.
**`parmcat : int`**
GRIB2 parameter category value.
**`parmnum`**: `int` or `str` of Parameter Number value of a GRIB2 message.
**`parmnum : int or str`**
Parameter Number value of a GRIB2 message.
Returns
-------
Expand Down Expand Up @@ -180,7 +192,8 @@ def get_metadata_from_shortname(shortname):
Parameters
----------
**`shortname : str`** GRIB2 variable shortName.
**`shortname : str`**
GRIB2 variable shortName.
Returns
-------
Expand All @@ -200,7 +213,7 @@ def get_metadata_from_shortname(shortname):
return metadata


def get_wgrib2_level_string(pdtn,pdt):
def get_wgrib2_level_string(pdtn, pdt):
"""
Return a string that describes the level or layer of the GRIB2 message. The
format and language of the string is an exact replica of how wgrib2 produces
Expand All @@ -212,13 +225,15 @@ def get_wgrib2_level_string(pdtn,pdt):
Parameters
----------
**`pdtn`**: GRIB2 Product Definition Template Number
**`pdtn : int`**
GRIB2 Product Definition Template Number
**`pdt`**: sequence containing GRIB2 Product Definition Template (Section 4).
**`pdt : list or array_like`**
Sequence containing GRIB2 Product Definition Template (Section 4).
Returns
-------
**`str`**: wgrib2-formatted level/layer string.
wgrib2-formatted level/layer string.
"""
if pdtn == 48:
idxs = slice(20,26)
Expand Down
Loading

0 comments on commit 2cadd5d

Please sign in to comment.