Grid
- class cosipy.cpkernel.grid.Grid(*args, **kwargs)[source]
Bases:
GridA
Gridstructure 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_typeMethods
__init__(layer_heights, layer_densities, ...)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 the cold content profile.
Get the density profile.
Get a depth profile.
Get the first snow layer's properties.
Get the heights of all the layers.
Get a profile of the ice fraction.
Get the heights of the ice layers.
Get a profile of the irreducible water content.
Get a profile of the liquid water content.
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 a node's ice fraction.
Get a node's irreducible water content.
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 a node's specific heat capacity (air+water+ice).
get_node_temperature(idx)Get a node's temperature.
Get a node's thermal conductivity.
Get a node's thermal diffusivity.
Get the number of layers.
Get the number of snow layers (density<snow_ice_threshold).
Get the porosity profile.
Get the profile of refrozen water.
Get the heights of the snow layers.
Get the specific heat capacity profile (air+water+ice).
Get the temperature profile.
Get the thermal conductivity profile.
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.
Initialize the grid with the input data.
Remesh the layer heights logarithmically.
merge_nodes(idx)Merge two consecutive nodes.
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.
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.
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:
the density difference between one layer and the next is smaller than the user defined threshold.
the temperature difference is smaller than the user defined threshold.
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, andmerge_maxinconstants.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].
- correct_layer(idx, min_height)[source]
Adjust the height of a given layer.
Adjusts the height of the layer at index
idxto the given heightmin_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_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_irreducible_water_content()[source]
Get a profile of the irreducible water content.
- Return type:
list
- 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_specific_heat(idx)[source]
Get a node’s specific heat capacity (air+water+ice).
- Parameters:
idx (int)
- get_node_thermal_conductivity(idx)[source]
Get a node’s thermal conductivity.
- Parameters:
idx (int)
- get_specific_heat()[source]
Get the specific heat capacity profile (air+water+ice).
- Return type:
list
- 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.
- 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
idxandidx+1. The node atidxis updated with the new properties (height, liquid water content, ice fraction, temperature). The node atidx+1is 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 thesnow_ice_thresholdvalue inconstants.py) with an ice layer at locationidx+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
idxby 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_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_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_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
posinto two similar nodes. The new nodes at locationposandpos+1will 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:
log_profile
adaptive_profile
The log-profile algorithm arranges the mesh logarithmically. The user specifies the stretching factor
layer_stretchinginconstants.pyto determine the increase in layer heights.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_merginganddensity_threshold_merginginconstants.py. The maximum number of merging steps per time step is specified bymerge_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, andliquid_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.].