The read_snowpack simulation reader

The read_snowpack module and especially the utils.read_snowpack.snowpack_reader class is designed to read profile files produced by SNOWPACK Swiss snow cover model.

This module is designed to provide tools to parse snowpack profiles as produced by the SNOWPACK snow cover model. See the snowpack website for more details on the production and structure of such files.

NB : For easier readability and maintainability of the code, this implementation requires a strict form of the data :

  • A blank line must separate two sections.

  • Comments are allowed only if the first non-space character of the line is #

  • Inline comments are not supported.

  • DATA is the last block that is parsed

Authored by Léo Viallon Galinier from previous work of Neige Calonne and WSL/SLF.

This script requires python>=3.8.

utils.read_snowpack.read_snowpack_profile(filepath, variables: dict = {'0500': 'time', '0501': 'height', '0502': 'density', '0503': 'temperature', '0504': 'lwc', '0508': 'dendricity', '0509': 'sphericity', '0510': 'coordination_number', '0511': 'bond_size', '0512': 'grain_size', '0513': 'grain_type', '0514': 'sh_at_surface', '0515': 'ice_content', '0516': 'air_content', '0517': 'stress', '0518': 'viscosity', '0520': 'temperature_gradient', '0521': 'thermal_conductivity', '0523': 'viscous_deformation_rate', '0530': 'stab_indices', '0531': 'stab_deformation_rate', '0532': 'sn38', '0533': 'sk38', '0534': 'hand_hardness', '0535': 'opt_equ_grain_size', '0540': 'date_of_birth', '0601': 'shear_strength', '0603': 'hardness_difference', '0604': 'ssi', '0606': 'crit_cut_length', '1501': 'height_nodes', '1532': 'sn38_nodes', '1533': 'sk38_nodes'}, soil: bool = False) dict[source]

Parse the snowpack output file ‘.pro’ and return the raw data

Parameters:
  • filepath (str or path-like object) – Path to the snowpack output PRO file (containing the profile)

  • variables (dict) – The variables to be parsed (if present): dictionnary associating the SNOWPACK code (on the form of a string) to the name to give to the variable (str).

  • soil (bool) – Wether or not to read soil information. If set to True, additional variables (suffixed by _soil will be created to store soil information

Return type:

dict

class utils.read_snowpack.snowpack_reader(filepath, variables={'0500': 'time', '0501': 'height', '0502': 'density', '0503': 'temperature', '0504': 'lwc', '0508': 'dendricity', '0509': 'sphericity', '0510': 'coordination_number', '0511': 'bond_size', '0512': 'grain_size', '0513': 'grain_type', '0514': 'sh_at_surface', '0515': 'ice_content', '0516': 'air_content', '0517': 'stress', '0518': 'viscosity', '0520': 'temperature_gradient', '0521': 'thermal_conductivity', '0523': 'viscous_deformation_rate', '0530': 'stab_indices', '0531': 'stab_deformation_rate', '0532': 'sn38', '0533': 'sk38', '0534': 'hand_hardness', '0535': 'opt_equ_grain_size', '0540': 'date_of_birth', '0601': 'shear_strength', '0603': 'hardness_difference', '0604': 'ssi', '0606': 'crit_cut_length', '1501': 'height_nodes', '1532': 'sn38_nodes', '1533': 'sk38_nodes'}, soil=False)[source]

Bases: object

The object that provide access to SNOWPACK profiles simulation output through an interface that is similar to the one provided by prosimu for the Crocus simulations.

Parse the snowpack output file ‘.pro’ and store/provide access to the parsed data.

Parameters:
  • filepath (str or path-like object) – Path to the snowpack output PRO file (containing the profile)

  • variables (dict) – The variables to be parsed (if present): dictionnary associating the SNOWPACK code (on the form of a string) to the name to give to the variable (str). Allow to reduce the amount of data parsed and stored and to parse additional variables that would not be parsed by default.

  • soil (bool) – Wether or not to read soil information. If set to True, additional variables (suffixed by _soil will be created to store soil information

Return type:

dict

get_time()[source]

Return the time dimension of the dataset on a similar form than provided by prosimu for Crocus model (numpy array of datetime.datetime objects).

NB : If you are interested by the same variable on the form of a numpy array of integers or np.datetime64 values, use read_var('time').

Returns:

time array

Return type:

numpy array (datetime.datetime objects)

listvar()[source]

Return the list of available variables

Returns:

List of available variables

Return type:

list

read_var(variable, time=None)[source]

Get the data for a specified variable. It is also possible to select a relevant time step.

Parameters:
  • variable (str) – The variable name

  • time (datetime.datetime) – A datetime object selecting the time step to get. If None (default), returns the values for the whole season.