1.2. The AerVis Variable Attributes Class (STASH) - wolfiex/AerVis GitHub Wiki
Summary
STASH codes are used within the UM to label the different variables within a simulations.
These are generated using the following files:
- stashmaster
- file_mapping
- stash from UMI
The variable reference class allows for a series of operations storing all the stash data in the form of a linked class. Here entries are saved as var_id_#
which are then referenced by both the stash code and short name of the variable. This structure means that an edit with either stash number or short name will persist across all values - something not possible with dual key dictionaries in python.
Once the stash information is loaded into the class, this can then be saved (dilled - a more powerful version of pickle). This means that future runs do not need to repopulate the stash class and can just load the data instead.
Example generation and saving of variable references (direct)
import aervis
__FILE_STASHmaster__ = '..'
__FILE_mapping__ = '..'
__FILE_STASH_From_UMUI__ = '..'
stashname = '¬'.join([ __FILE_STASHmaster__,__FILE_mapping__,__FILE_STASH_From_UMUI__ ]).replace('/','~')
var_ref = aervis.variable_dict.makeVR( stashname )
var_ref.save(stashname+'.dl')
Loading Variable References from a AerData file/class
First we load the netCDF data file
import aervis
d = aervis.AerData('<fileidentifier>')
Then we compute/load the variable reference class
d.vd()
Finally we can acess this as before
var_ref = d.vr
Check the reference of a VariableReference item
You can use the built-in .get
function to extract information using the stash key or short name of a variable.
In [23]: d.vr.get('m01s00i408')
Out[23]:
{'stash_code': 'm01s00i408',
'name': 'PRESSURE_AT_THETA_LEVELS_AFTER_TS',
'short_name': '',
'long_name': '',
'units': '',
'description': ''}
In [24]: d.vr.get('PRESSURE_AT_THETA_LEVELS_AFTER_TS')
Out[24]:
{'stash_code': 'm01s00i408',
'name': 'PRESSURE_AT_THETA_LEVELS_AFTER_TS',
'short_name': '',
'long_name': '',
'units': '',
'description': ''}
Find all items which contain a string
If the full name of a variable is forgotten or you want to select all variables with an indicator in their name, it is possible to use the match function.
In [19]: d.vr.match('air')
Out[19]:
['AGE_OF_AIR_(SEC)_ON_PRESS_LEVELS',
'AGE_OF_AIR_IN_SECONDS',
'AIR_MASS_DIAG(TROP)_ON_PRESSURE_LEVS',
'AIR_MASS_DIAG(WHOLE_ATM)_ON_PRS_LEV',
'AIR_MASS_DIAGNOSTIC_(TROP_ONLY)',
'AIR_MASS_DIAGNOSTIC_(WHOLE_ATMOS)',
'CLEAN-AIR_DOWNWARD_LW_FLUX_ON_LEVELS',
'CLEAN-AIR_DOWNWARD_SW_FLUX_ON_LEVELS',
'CLEAN-AIR_UPWARD_LW_FLUX_ON_LEVELS',
'CLEAN-AIR_UPWARD_SW_FLUX_ON_LEVELS']
In [20]: q.vr.get('CLEAN-AIR_UPWARD_LW_FLUX_ON_LEVELS')
Out[20]:
{'stash_code': 'm01s02i517',
'name': 'CLEAN-AIR_UPWARD_LW_FLUX_ON_LEVELS',
'short_name': '',
'long_name': '',
'units': '',
'description': ''}