@@ -149,11 +149,11 @@ def _get_axis_coord(
149149
150150 Parameters
151151 ----------
152- var : DataArray, Dataset
152+ var: DataArray, Dataset
153153 DataArray belonging to the coordinate to be checked
154- key : str, ["X", "Y", "Z", "T", "longitude", "latitude", "vertical", "time"]
154+ key: str, ["X", "Y", "Z", "T", "longitude", "latitude", "vertical", "time"]
155155 key to check for.
156- error : bool
156+ error: bool
157157 raise errors when key is not found or interpretable. Use False and provide default
158158 to replicate dict.get(k, None).
159159 default: Any
@@ -217,7 +217,24 @@ def _get_measure(
217217 da : xr .DataArray , key : str , error : bool = True , default : str = None
218218) -> Optional [str ]:
219219 """
220- Interprets 'cell_measures'.
220+ Translate from cell measures ("area" or "volume") to appropriate variable name.
221+ This function interprets the ``cell_measures`` attribute on DataArrays.
222+
223+ Parameters
224+ ----------
225+ da: DataArray
226+ DataArray belonging to the coordinate to be checked
227+ key: str, ["area", "volume"]
228+ key to check for.
229+ error: bool
230+ raise errors when key is not found or interpretable. Use False and provide default
231+ to replicate dict.get(k, None).
232+ default: Any
233+ default value to return when error is False.
234+
235+ Returns
236+ -------
237+ List[str], Variable name(s) in parent xarray object that matches axis or coordinate `key`
221238 """
222239 if not isinstance (da , DataArray ):
223240 raise NotImplementedError ("Measures not implemented for Datasets yet." )
@@ -254,6 +271,9 @@ def _get_measure(
254271
255272
256273#: Default mappers for common keys.
274+ # TODO: Make the values of this a tuple,
275+ # so that multiple mappers can be used for a single key
276+ # We need this for groupby("T.month") and groupby("latitude") for example.
257277_DEFAULT_KEY_MAPPERS : Mapping [str , Mapper ] = {
258278 "dim" : _get_axis_coord ,
259279 "dims_or_levels" : _get_axis_coord , # reset_index
@@ -280,7 +300,19 @@ def _filter_by_standard_names(ds: xr.Dataset, name: Union[str, List[str]]) -> Li
280300
281301
282302def _get_list_standard_names (obj : xr .Dataset ) -> List [str ]:
283- """ Returns a sorted list of standard names in Dataset. """
303+ """
304+ Returns a sorted list of standard names in Dataset.
305+
306+ Parameters
307+ ----------
308+
309+ obj: DataArray, Dataset
310+ Xarray objec to process
311+
312+ Returns
313+ -------
314+ list of standard names in dataset
315+ """
284316 names = []
285317 for k , v in obj .variables .items ():
286318 if "standard_name" in v .attrs :
@@ -332,15 +364,18 @@ def wrapper(*args, **kwargs):
332364
333365
334366class _CFWrappedClass :
367+ """
368+ This class is used to wrap any class in _WRAPPED_CLASSES.
369+ """
370+
335371 def __init__ (self , towrap , accessor : "CFAccessor" ):
336372 """
337- This class is used to wrap any class in _WRAPPED_CLASSES.
338-
339373 Parameters
340374 ----------
341375 towrap : Resample, GroupBy, Coarsen, Rolling, Weighted
342376 Instance of xarray class that is being wrapped.
343377 accessor : CFAccessor
378+ Parent accessor object
344379 """
345380 self .wrapped = towrap
346381 self .accessor = accessor
@@ -369,7 +404,10 @@ def __init__(self, obj, accessor):
369404
370405 def _plot_decorator (self , func ):
371406 """
372- This decorator is used to set kwargs on plotting functions.
407+ This decorator is used to set default kwargs on plotting functions.
408+
409+ For now, this is setting ``xincrease`` and ``yincrease``. It could set
410+ other arguments in the future.
373411 """
374412 valid_keys = self .accessor .get_valid_keys ()
375413
@@ -402,6 +440,9 @@ def _plot_wrapper(*args, **kwargs):
402440 return _plot_wrapper
403441
404442 def __call__ (self , * args , ** kwargs ):
443+ """
444+ Allows .plot()
445+ """
405446 plot = _getattr (
406447 obj = self ._obj ,
407448 attr = "plot" ,
@@ -411,6 +452,9 @@ def __call__(self, *args, **kwargs):
411452 return self ._plot_decorator (plot )(* args , ** kwargs )
412453
413454 def __getattr__ (self , attr ):
455+ """
456+ Wraps .plot.contour() for example.
457+ """
414458 return _getattr (
415459 obj = self ._obj .plot ,
416460 attr = attr ,
@@ -423,10 +467,21 @@ def __getattr__(self, attr):
423467
424468
425469class CFAccessor :
470+ """
471+ Common Dataset and DataArray accessor functionality.
472+ """
473+
426474 def __init__ (self , da ):
427475 self ._obj = da
428476
429- def _process_signature (self , func , args , kwargs , key_mappers ):
477+ def _process_signature (self , func : Callable , args , kwargs , key_mappers ):
478+ """
479+ Processes a function's signature, args, kwargs:
480+ 1. Binds *args so that everthing is a Mapping from kwarg name to values
481+ 2. Calls _rewrite_values to rewrite any special CF names to normal xarray names.
482+ This uses key_mappers
483+ 3. Unpacks arguments if necessary before returning them.
484+ """
430485 sig = inspect .signature (func , follow_wrapped = False )
431486
432487 # Catch things like .isel(T=5).
@@ -456,7 +511,24 @@ def _process_signature(self, func, args, kwargs, key_mappers):
456511 return arguments
457512
458513 def _rewrite_values (self , kwargs , key_mappers : dict , var_kws ):
459- """ rewrites 'dim' for example using 'mapper' """
514+ """
515+ Rewrites the values in a Mapping from kwarg to value.
516+
517+ Parameters
518+ ----------
519+ kwargs: Mapping
520+ Mapping from kwarg name to value
521+ key_mappers: Mapping
522+ Mapping from kwarg name to a Mapper function that will convert a
523+ given CF "special" name to an xarray name.
524+ var_kws: List[str]
525+ List of variable kwargs that need special treatment.
526+ e.g. **indexers_kwargs in isel
527+
528+ Returns
529+ -------
530+ dict of kwargs with fully rewritten values.
531+ """
460532 updates : dict = {}
461533
462534 # allow multiple return values here.
@@ -558,11 +630,17 @@ def _describe(self):
558630 return text
559631
560632 def describe (self ):
633+ """
634+ Print a string repr to screen.
635+ """
561636 print (self ._describe ())
562637
563638 def get_valid_keys (self ) -> Set [str ]:
564639 """
565- Returns valid keys for .cf[]
640+ Utility function that returns valid keys for .cf[].
641+
642+ This is useful for checking whether a key is valid for indexing, i.e.
643+ that the attributes necessary to allow indexing by that key exist.
566644
567645 Returns
568646 -------
0 commit comments