Grid

class cosipy.cpkernel.grid.Grid(*args, **kwargs)[source]

Bases: Grid

A Grid structure controls and stores the numerical mesh.

The grid attribute consists of a list of nodes that each store information on an individual layer. The class provides various setter/getter functions to add, read, overwrite, merge, split, update or re-mesh the layers.

layer_heights

Height of the snowpack layers [m].

Type:

np.ndarray

layer_densities

Snow density of the snowpack layers [kg m -3].

Type:

np.ndarray

layer_temperatures

Layer temperatures [K].

Type:

np.ndarray

layer_liquid_water_content

Liquid water content of the layers [m w.e.].

Type:

np.ndarray

layer_ice_fraction

Volumetric ice fraction of the layers [-]. Default None.

Type:

np.ndarray

new_snow_height

Height of the fresh snow layer [m]. Default None.

Type:

float

new_snow_timestamp

Time elapsed since the last snowfall [s]. Default None.

Type:

float

old_snow_timestamp

Time elapsed between the last and penultimate snowfalls [s]. Default None.

Type:

float

grid

Numerical mesh for glacier data.

Type:

typed.List

number_nodes

Number of layers in the numerical mesh.

Type:

int

Attributes

class_type

Methods

__init__(layer_heights, layer_densities, ...)

adaptive_profile()

Remesh according to certain layer state criteria.

add_fresh_snow(height, density, temperature, ...)

Add a fresh snow layer (node).

check(name)

Check layer temperature and height are within a valid range.

check_layer_property(layer_property, name, ...)

correct_layer(idx, min_height)

Adjust the height of a given layer.

get_cold_content()

Get the cold content profile.

get_density()

Get the density profile.

get_depth()

Get a depth profile.

get_fresh_snow_props()

Get the first snow layer's properties.

get_height()

Get the heights of all the layers.

get_ice_fraction()

Get a profile of the ice fraction.

get_ice_heights()

Get the heights of the ice layers.

get_irreducible_water_content()

Get a profile of the irreducible water content.

get_liquid_water_content()

Get a profile of the liquid water content.

get_node_cold_content(idx)

Get a node's cold content.

get_node_density(idx)

Get a node's density.

get_node_depth(idx)

Get a node's depth relative to the surface.

get_node_height(idx)

Get a node's layer height.

get_node_ice_fraction(idx)

Get a node's ice fraction.

get_node_irreducible_water_content(idx)

Get a node's irreducible water content.

get_node_liquid_water_content(idx)

Get a node's liquid water content.

get_node_porosity(idx)

Get a node's porosity.

get_node_refreeze(idx)

Get the amount of refrozen water in a node.

get_node_specific_heat(idx)

Get a node's specific heat capacity (air+water+ice).

get_node_temperature(idx)

Get a node's temperature.

get_node_thermal_conductivity(idx)

Get a node's thermal conductivity.

get_node_thermal_diffusivity(idx)

Get a node's thermal diffusivity.

get_number_layers()

Get the number of layers.

get_number_snow_layers()

Get the number of snow layers (density<snow_ice_threshold).

get_porosity()

Get the porosity profile.

get_refreeze()

Get the profile of refrozen water.

get_snow_heights()

Get the heights of the snow layers.

get_specific_heat()

Get the specific heat capacity profile (air+water+ice).

get_temperature()

Get the temperature profile.

get_thermal_conductivity()

Get the thermal conductivity profile.

get_thermal_diffusivity()

Get the thermal diffusivity profile.

get_total_height([verbose])

Get the total domain height.

get_total_snowheight([verbose])

Get the total snowheight (density<snow_ice_threshold).

grid_check([level])

Check the grid for out of range values.

grid_info([n])

Print the state of the snowpack.

grid_info_screen([n])

Print the state of the snowpack.

info()

Print some information on grid.

init_grid()

Initialize the grid with the input data.

log_profile()

Remesh the layer heights logarithmically.

merge_nodes(idx)

Merge two consecutive nodes.

merge_snow_with_glacier(idx)

Merge a snow layer with an ice layer.

remove_melt_weq(melt[, idx])

Remove mass from a layer.

remove_node([idx])

Remove a layer (node) from the grid (node list).

set_fresh_snow_props(height)

Track the new snowheight.

set_fresh_snow_props_height(height)

Update the fresh snow layer height.

set_fresh_snow_props_to_old_props()

Revert the timestamp of fresh snow properties.

set_fresh_snow_props_update_time(seconds)

Update the timestamp of the snow properties.

set_height(height)

Set the height profile.

set_ice_fraction(ice_fraction)

Set the ice fraction profile.

set_liquid_water_content(liquid_water_content)

Set the liquid water content profile.

set_node_height(idx, height)

Set a node's height.

set_node_ice_fraction(idx, ice_fraction)

Set a node's ice fraction.

set_node_liquid_water_content(idx, ...)

Set a node's liquid water content.

set_node_refreeze(idx, refreeze)

Set the amount of refrozen water in a node.

set_node_temperature(idx, temperature)

Set the temperature of a layer (node) at location idx.

set_refreeze(refreeze)

Set the refrozen water profile.

set_temperature(temperature)

Set all layer temperatures.

split_node(pos)

Split node at position.

update_grid()

Remesh the layers (numerical grid).

update_node(idx, height, temperature, ...)

Update properties of a specific node.

__init__(layer_heights, layer_densities, layer_temperatures, layer_liquid_water_content, layer_ice_fraction=None, new_snow_height=None, new_snow_timestamp=None, old_snow_timestamp=None)[source]
adaptive_profile()[source]

Remesh according to certain layer state criteria.

This algorithm is an alternative to logarithmic remeshing. It checks the similarity of two consecutive layers. Layers are merged if:

  1. the density difference between one layer and the next is smaller than the user defined threshold.

  2. the temperature difference is smaller than the user defined threshold.

  3. the number of merges per time step does not exceed the user defined threshold.

The thresholds are defined by temperature_threshold_merging, density_threshold_merging, and merge_max in constants.py.

add_fresh_snow(height, density, temperature, liquid_water_content, dt)[source]

Add a fresh snow layer (node).

Adds a fresh snow layer to the beginning of the node list (upper layer).

Parameters:
  • height (float) – Layer height [m].

  • density (float) – Layer density [kg m -3].

  • temperature (float) – Layer temperature [K].

  • liquid_water_content (float) – Liquid water content of the layer [m w.e.].

  • dt (int) – Integration time [s].

check(name)[source]

Check layer temperature and height are within a valid range.

correct_layer(idx, min_height)[source]

Adjust the height of a given layer.

Adjusts the height of the layer at index idx to the given height min_height. First, the layers below are merged until the height is large enough to allow for the adjustment. Then the layer is merged with the following layer.

Parameters:
  • idx (int) – Index of the node to be removed.

  • min_height (float) – New layer height [m].

get_cold_content()[source]

Get the cold content profile.

Return type:

list

get_density()[source]

Get the density profile.

Return type:

list

get_depth()[source]

Get a depth profile.

Return type:

list

get_fresh_snow_props()[source]

Get the first snow layer’s properties.

This is used internally to track the albedo properties of the first snow layer.

Returns:

First snow layer’s updated height, time elapsed since the last snowfall, and the time elapsed between the last and penultimate snowfall.

Return type:

tuple

get_height()[source]

Get the heights of all the layers.

Return type:

list

get_ice_fraction()[source]

Get a profile of the ice fraction.

Return type:

list

get_ice_heights()[source]

Get the heights of the ice layers.

Return type:

list

get_irreducible_water_content()[source]

Get a profile of the irreducible water content.

Return type:

list

get_liquid_water_content()[source]

Get a profile of the liquid water content.

Return type:

list

get_node_cold_content(idx)[source]

Get a node’s cold content.

Parameters:

idx (int)

get_node_density(idx)[source]

Get a node’s density.

Parameters:

idx (int)

get_node_depth(idx)[source]

Get a node’s depth relative to the surface.

Parameters:

idx (int)

get_node_height(idx)[source]

Get a node’s layer height.

Parameters:

idx (int)

get_node_ice_fraction(idx)[source]

Get a node’s ice fraction.

Parameters:

idx (int)

get_node_irreducible_water_content(idx)[source]

Get a node’s irreducible water content.

Parameters:

idx (int)

get_node_liquid_water_content(idx)[source]

Get a node’s liquid water content.

Parameters:

idx (int)

get_node_porosity(idx)[source]

Get a node’s porosity.

Parameters:

idx (int)

get_node_refreeze(idx)[source]

Get the amount of refrozen water in a node.

Parameters:

idx (int)

get_node_specific_heat(idx)[source]

Get a node’s specific heat capacity (air+water+ice).

Parameters:

idx (int)

get_node_temperature(idx)[source]

Get a node’s temperature.

Parameters:

idx (int)

get_node_thermal_conductivity(idx)[source]

Get a node’s thermal conductivity.

Parameters:

idx (int)

get_node_thermal_diffusivity(idx)[source]

Get a node’s thermal diffusivity.

Parameters:

idx (int)

get_number_layers()[source]

Get the number of layers.

get_number_snow_layers()[source]

Get the number of snow layers (density<snow_ice_threshold).

get_porosity()[source]

Get the porosity profile.

Return type:

list

get_refreeze()[source]

Get the profile of refrozen water.

Return type:

list

get_snow_heights()[source]

Get the heights of the snow layers.

Return type:

list

get_specific_heat()[source]

Get the specific heat capacity profile (air+water+ice).

Return type:

list

get_temperature()[source]

Get the temperature profile.

Return type:

list

get_thermal_conductivity()[source]

Get the thermal conductivity profile.

Return type:

list

get_thermal_diffusivity()[source]

Get the thermal diffusivity profile.

Return type:

list

get_total_height(verbose=False)[source]

Get the total domain height.

get_total_snowheight(verbose=False)[source]

Get the total snowheight (density<snow_ice_threshold).

grid_check(level=1)[source]

Check the grid for out of range values.

Parameters:

level (int) – Level number.

grid_info(n=-999)[source]

Print the state of the snowpack.

Parameters:

n (int) – Number of nodes to plot from the top. Default -999.

grid_info_screen(n=-999)[source]

Print the state of the snowpack.

Parameters:

n (int) – Number of nodes to plot from the top. Default -999.

info()[source]

Print some information on grid.

init_grid()[source]

Initialize the grid with the input data.

log_profile()[source]

Remesh the layer heights logarithmically.

This algorithm remeshes the layer heights (numerical grid) logarithmically using a given stretching factor and first layer height. Both are defined in constants.py:

  • The stretching factor is defined by layer_stretching.

  • The first layer height is defined by first_layer_height.

E.g. for the stretching factor, a value of 1.1 corresponds to a 10% stretching from one layer to the next.

merge_nodes(idx)[source]

Merge two consecutive nodes.

Merges the two nodes at location idx and idx+1. The node at idx is updated with the new properties (height, liquid water content, ice fraction, temperature). The node at idx+1 is deleted after merging.

Parameters:

idx (int) – Index of the node to be removed. The first node is removed if no index is provided.

merge_snow_with_glacier(idx)[source]

Merge a snow layer with an ice layer.

Merges a snow layer at location idx (density smaller than the snow_ice_threshold value in constants.py) with an ice layer at location idx+1.

Parameters:

idx (int) – Index of the snow layer.

remove_melt_weq(melt, idx=0)[source]

Remove mass from a layer.

Reduces the mass/height of layer idx by the available melt energy.

Parameters:
  • melt (float) – Snow water equivalent of melt [m w.e.].

  • idx (int) – Index of the layer. If no value is given, the function acts on the first layer.

Returns:

Liquid water content from removed layers.

Return type:

float

remove_node(idx=None)[source]

Remove a layer (node) from the grid (node list).

Parameters:

idx (list) – Indices of the node to be removed. The first node is removed if empty or None. Default None.

set_fresh_snow_props(height)[source]

Track the new snowheight.

Parameters:

height (float) – Height of the fresh snow layer [m].

set_fresh_snow_props_height(height)[source]

Update the fresh snow layer height.

This is used internally to track the albedo properties of the first snow layer.

Parameters:

height (float)

set_fresh_snow_props_to_old_props()[source]

Revert the timestamp of fresh snow properties.

Reverts the timestamp of fresh snow properties to that of the underlying snow layer. This is used internally to track the albedo properties of the first snow layer.

set_fresh_snow_props_update_time(seconds)[source]

Update the timestamp of the snow properties.

Parameters:

seconds (float) – seconds without snowfall [s].

set_height(height)[source]

Set the height profile.

Parameters:

height (ndarray)

set_ice_fraction(ice_fraction)[source]

Set the ice fraction profile.

Parameters:

ice_fraction (ndarray)

set_liquid_water_content(liquid_water_content)[source]

Set the liquid water content profile.

Parameters:

liquid_water_content (ndarray)

set_node_height(idx, height)[source]

Set a node’s height.

Parameters:
  • idx (int)

  • height (float)

set_node_ice_fraction(idx, ice_fraction)[source]

Set a node’s ice fraction.

Parameters:
  • idx (int)

  • ice_fraction (float)

set_node_liquid_water_content(idx, liquid_water_content)[source]

Set a node’s liquid water content.

Parameters:
  • idx (int)

  • liquid_water_content (float)

set_node_refreeze(idx, refreeze)[source]

Set the amount of refrozen water in a node.

Parameters:
  • idx (int)

  • refreeze (float)

set_node_temperature(idx, temperature)[source]

Set the temperature of a layer (node) at location idx.

Parameters:
  • idx (int) – Index of the layer.

  • temperature (float) – Layer’s new temperature [K].

set_refreeze(refreeze)[source]

Set the refrozen water profile.

Parameters:

refreeze (ndarray)

set_temperature(temperature)[source]

Set all layer temperatures.

Parameters:

temperature (ndarray) – New layer temperatures [K].

split_node(pos)[source]

Split node at position.

Splits a node at a location index pos into two similar nodes. The new nodes at location pos and pos+1 will have the same properties (height, liquid water content, ice fraction, temperature).

Parameters:

pos (int) – Index of the node to split.

update_grid()[source]

Remesh the layers (numerical grid).

Two algorithms are currently implemented to remesh layers:

  1. log_profile

  2. adaptive_profile

  1. The log-profile algorithm arranges the mesh logarithmically. The user specifies the stretching factor layer_stretching in constants.py to determine the increase in layer heights.

  2. Profile adjustment uses layer similarity. Layers with very similar temperature and density states are joined. Similarity is determined from the user-specified threshold values temperature_threshold_merging and density_threshold_merging in constants.py. The maximum number of merging steps per time step is specified by merge_max.

update_node(idx, height, temperature, ice_fraction, liquid_water_content)[source]

Update properties of a specific node.

Updates a layer’s attributes for height, temperature, ice_fraction, and liquid_water_content. The density cannot be updated as it is derived from air porosity, liquid water content, and ice fraction.

Parameters:
  • idx (int) – Index of the layer to be updated.

  • height (float) – Layer’s new snowpack height [m].

  • temperature (float) – Layer’s new temperature [K].

  • ice_fraction (float) – Layer’s new ice fraction [-].

  • liquid_water_content (float) – Layer’s new liquid water content [m w.e.].