tdem_tools

pymmaster.tdem_tools provides tools to post-process DEM stacks: volume integration over specific outlines, comparison to point data, spatial aggregation…

pyddem.tdem_tools.add_base_to_int(df, fn_base, reg)[source]

Use “base” RGI file to check whether all glaciers are covered before aggregation, and to remove nominal glaciers and CL2 glacier estimates

Parameters:
  • df – DataFrame of integrated volume time series
  • fn_base – Filename of “base” RGI file
  • reg – RGI region number: 20 corresponds to Alaska and WNA combined, 21 corresponds to HMA combined (necessary for some uncertainty calculations as those are contiguous)
Returns:

DataFrame of integrated volume time series with nominal, CL2 glaciers removed and not-covered glaciers added with nodata

pyddem.tdem_tools.aggregate_all_to_period(df, list_tlim=None, mult_ann=None, fn_tarea=None, frac_area=None, list_tag=None)[source]

Temporal integration of volume change time series into rates for a specific period and error propagation For regions, we can account for time-varying areas by approximated per-region annual areas (Zemp et al. (2019))

Parameters:
  • df – DataFrame of volume time series
  • list_tlim – List of tuples or early and late date to integrate over
  • mult_ann – Ignore tuples, integrate over all successive multi-annual periods of this length (e.g., four successive 5-year rates)
  • fn_tarea – Filename of DataFrame with temporally-varying areas
  • frac_area – Use only a corresponding fraction of the regional area to estimate time-varying areas (e.g., subset of Greenland, or other)
  • list_tag – Tag a naming to each integration period
Returns:

DataFrame of volume change rates for all successive periods fitting the year length

pyddem.tdem_tools.aggregate_df_int_time(infile, tlim=None, rate=False)[source]

Temporal integration over any period, choice between cumulative or rate

Parameters:
  • infile – Filename of DataFrame with volume change time series
  • tlim – Time limits for integration
  • rate – Boolean, add rates
Returns:

pyddem.tdem_tools.aggregate_indep_regions(df_p)[source]

Aggregate regions with independent assumptions for uncertainty propagation :param df_p: :return:

pyddem.tdem_tools.aggregate_int_to_all(df, nproc=1, get_corr_err=True)[source]

Aggregate spatially per-glaciers volume changes time series and propagate errors

Parameters:
  • df – DataFrame of integrated volume time series
  • nproc – Number of cores used for multiprocessing [1]
  • get_corr_err – Derive correlated error (long): currently forced to annual only, because seasonal biases are not accounted for and can be complex
Returns:

DataFrame of aggregated volume time series

pyddem.tdem_tools.comp_stacks_icebridge(list_fn_stack, fn_icebridge, gla_mask=None, inc_mask=None, exc_mask=None, nproc=1, read_filt=False)[source]

Compare IceBridge data with elevation time series

Parameters:
  • list_fn_stack – List of filename of netCDF to compare to
  • fn_icebridge – Filename of IceBridge post-processed into .csv
  • gla_mask – Filename of glacier shapefile
  • inc_mask – Filename of inclusion shapefile (e.g. land)
  • exc_mask – Filename of exclusion shapeifle (e.g. ocean)
  • nproc – Number of cores used for multiprocessing [1]
  • read_filt – Boolean, read boolean data cube of valid observation
Returns:

Arranged output data (see_comp_stacks_icesat)

pyddem.tdem_tools.comp_stacks_icesat(list_fn_stack, fn_icesat, gla_mask=None, inc_mask=None, exc_mask=None, nproc=1, read_filt=False, shift=None)[source]

Compare ICESat data with elevation time series

Parameters:
  • list_fn_stack – List of filename of netCDF to compare to
  • fn_icesat – Filename of ICESat HDF5 file
  • gla_mask – Filename of glacier shapefile
  • inc_mask – Filename of inclusion shapefile (e.g. land)
  • exc_mask – Filename of exclusion shapeifle (e.g. ocean)
  • nproc – Number of cores used for multiprocessing [1]
  • read_filt – Boolean, read boolean data cube of valid observation
Returns:

Arranged output data (see_comp_stacks_icesat)

pyddem.tdem_tools.df_all_base_to_tile(list_fn_int_base, fn_base, tile_size=1, nproc=1, sort_tw=True)[source]

Integrate all per-glacier volume change time series on a global tiling of certain size, for all possible 1-,2-,4-,5-,10- and 20-year periods, with error propagation

Parameters:
  • list_fn_int_base – List of filename of DataFrame of per-glacier volume change time series with base RGIID info added
  • fn_base – Filename of “base” RGI file
  • tile_size – Size of tiling in lat/lon degrees
  • nproc – Number of cores used for multiprocessing [1]
  • sort_tw – Sort between marine-terminating and land-terminating glaciers
Returns:

pyddem.tdem_tools.df_int_to_base(infile, fn_base=None)[source]

Wrapper for adding base RGI info to DataFrame per glacier to all regions separately and write to .csv

Parameters:
  • infile – DataFrame of integrated volume time series
  • fn_base – Filename of “base” RGI file
Returns:

pyddem.tdem_tools.df_int_to_reg(infile, nproc=1)[source]

Wrapper for integrating volume change time series per region (based on RGI number) and write to .csv

Parameters:
  • infile – DataFrame of integrated volume time series
  • nproc – Number of cores used for multiprocessing [1]
Returns:

pyddem.tdem_tools.df_region_to_multann(infile_reg, fn_tarea=None, frac_area=None)[source]

Wrapper for temporal integration of regional volume change time series for all possible 1-,2-,4-,5-,10- and 20-year periods and write to .csv

Parameters:
  • infile_reg – DataFrame of regional, integrated volume time series
  • fn_tarea – Filename of DataFrame with temporally-varying areas
  • frac_area – Use only a corresponding fraction of the regional area to estimate time-varying areas (e.g., subset of Greenland, or other)
Returns:

pyddem.tdem_tools.get_base_df_inventory(dir_shp, outfile)[source]

Create a “base” dataframe which contains characteristics of RGIIds features (this is done separately to avoid duplicating that info in GBs of data into elevation time series, as those are 2D DataFrames) :param dir_shp: Directory containing RGI shapefiles :param outfile: Output .csv file containing dataframe

pyddem.tdem_tools.get_dt_closest_valid(ds_filt, dates)[source]

Derive data cube of time lag to closest valid observation based on the date vector of the time series and a boolean data cube of valid observation at original dates :param ds_filt: Boolean data cube of valid observations :param dates: Time vector of time series

Returns:Data cube indexed to time vector with time lags to observation, Data cube with count of valid observation between time index, Data cube with yearly count of valid observation at the first yearly time index
pyddem.tdem_tools.hypsocheat_postproc_stacks_tvol(list_fn_stack, fn_shp, feat_id='RGIId', tlim=None, nproc=1, outfile='int_dh.csv')[source]

Hypsometric cheat volume integration of elevation time series The objective of the “cheat” is to highly decrease processing time by allowing to combine parts of shapefile features (e.g., glaciers) which are projected in different georeferencing systems in the stacks (projected in UTM), without having to merge the stacks into the same projection Because integration is hypsometric (based on reference elevation of the glacier), we do not need the information of spatial structure of the glacier

Parameters:
  • list_fn_stack – List of filenames of netCDF elevation time series
  • fn_shp – Filename of shapefile
  • feat_id – Feature name of interest
  • tlim – Time limits for integration
  • nproc – Number of cores used for multiprocessing [1]
  • outfile – Filename of output .csv
Returns:

pyddem.tdem_tools.icesat_comp_wrapper(argsin)[source]

Multiprocessing wrapper to compare ICESat data with elevation time series

Parameters:argsin – Tuple of arranged data (see comp_stacks_icesat)
Returns:Arranged output data (see_comp_stacks_icesat)
pyddem.tdem_tools.int_dc(dc, mask, **kwargs)[source]

Wrapper to for classic integration of elevation time series into volume change time series

Parameters:
  • dc – xarray Dataset (subset)
  • mask – Raster boolean mask
Returns:

DataFrame of integrated elevation change

pyddem.tdem_tools.inters_feat_shp_stacks(fn_shp, list_fn_stack, feat_field_name)[source]

Find all intersecting stacks for features of a shapefile, for a list of netCDF stacks (tiles for example)

Parameters:
  • fn_shp – Filename of shapefile
  • list_fn_stack – List of filenames of netCDF stacks
  • feat_field_name – Name of shapefile feature to sort by (e.g., RGIIDs for RGI glaciers)
Returns:

List of all features found, Corresponding list of intersecting stacks per feature

pyddem.tdem_tools.saga_aspect_slope_curvature(dem_in, topo_out, method_nb=5)[source]

Derive maximum curvature using SAGA (command line)

Parameters:
  • dem_in – dem input
  • topo_out – raster out (3 bands: aspect, slope, curvature)
  • method_nb – algorithm used, see function description
Returns:

requirement: SAGA 2.X with X>3

#ref:http://www.saga-gis.org/saga_tool_doc/2.2.3/ta_morphometry_0.html

aspect, slope, curvature methods methods number [0] maximum slope (Travis et al. 1975) [1] maximum triangle slope (Tarboton 1997) [2] least squares fitted plane (Horn 1981, Costa-Cabral & Burgess 1996) [3] 6 parameter 2nd order polynom (Evans 1979) [4] 6 parameter 2nd order polynom (Heerdegen & Beran 1982) [5] 6 parameter 2nd order polynom (Bauer, Rohdenburg, Bork 1985) [6] 9 parameter 2nd order polynom (Zevenbergen & Thorne 1987) [7] 10 parameter 3rd order polynom (Haralick 1983)

unit slope 0=rad, 1=deg, 2=percent unit aspect 0=rad, 1=deg

pyddem.tdem_tools.sel_dc(ds, tlim, mask)[source]

Subset datacube in space and time with a spatial mask and time limits

Parameters:
  • ds – xarray Dataset
  • tlim – Time limits
  • mask – Raster boolean mask
Returns:

Subset Dataset, Subset boolean mask, Spatial index slices (to identify subset position in the original datacube, for instance)

pyddem.tdem_tools.sel_int_hypsocheat(argsin)[source]

Multiprocessing wrapper by shapefile feature for “hypsometric cheat” volume integration of elevation time series

Parameters:argsin – Tuple with: list of filename of netCDF stacks, shapefile parameters (see hypsocheat_postproc_stacks_tvol), time limits, processing index
Returns:Three dataframes of volume change (see hypso_dc in volint_tools.py)