xoa.cf.SGLocator.format_attrs

SGLocator.format_attrs(attrs, loc=None, standardize=True)[source]

Copy and format a dict of attributes

Parameters:
  • attrs (dict) –

  • loc ({True, None}, letter, {False, ""}) – If None, location is left unchanged; if a letter, it is set; else, it is removed.

  • standardize (bool) – If True, standardize root and loc values.

Returns:

dict

Example

In [1]: sg = SGLocator()

In [2]: attrs = dict(standard_name='sea_water_temperature_at_t_location',
   ...:              long_name='sea_water_temperature',
   ...:              other_attr=23.)
   ...: 

In [3]: sg.format_attrs(attrs, loc='t') # force t loc
Out[3]: 
{'standard_name': 'sea_water_temperature_at_t_location',
 'long_name': 'Sea water temperature at T location',
 'other_attr': 23.0}

In [4]: sg.format_attrs(attrs) # keep loc
Out[4]: 
{'standard_name': 'sea_water_temperature_at_t_location',
 'long_name': 'Sea water temperature',
 'other_attr': 23.0}

In [5]: sg.format_attrs(attrs, loc=False) # force no loc
Out[5]: 
{'standard_name': 'sea_water_temperature',
 'long_name': 'Sea water temperature',
 'other_attr': 23.0}