stack_tools

pymmaster.stack_tools provides tools to create stacks of DEM data, usually MMASTER DEMs.

pyddem.stack_tools.create_crs_variable(epsg, nco=None)[source]

Given an EPSG code, create a CRS variable for a NetCDF file. Return collections.OrderedDict object if nco is None

Parameters:
  • epsg (int) – EPSG code for chosen CRS.
  • nco (netCDF4.Dataset) – NetCDF file to create CRS variable for.
Returns crso:

NetCDF variable representing the CRS.

pyddem.stack_tools.create_mmaster_stack(filelist, extent=None, res=None, epsg=None, outfile='mmaster_stack.nc', clobber=False, uncert=False, coreg=False, ref_tiles=None, exc_mask=None, inc_mask=None, outdir='tmp', filt_dem=None, add_ref=False, add_corr=False, latlontile_nodata=None, filt_mm_corr=False, l1a_zipped=False, y0=1900, tmptag=None)[source]

Given a list of DEM files, create a stacked NetCDF file.

Parameters:
  • filelist (array-like) – List of DEM filenames to stack.
  • extent (array-like) – Spatial extent of DEMs to limit stack to [xmin, xmax, ymin, ymax].
  • res (float) – Output spatial resolution of DEMs.
  • epsg (int) – EPSG code of output CRS.
  • outfile (str) – Filename for output NetCDF file.
  • clobber (bool) – clobber existing dataset when creating NetCDF file.
  • uncert (bool) – Include uncertainty variable in the output NetCDF.
  • coreg (bool) – Co-register DEMs to an input DEM (given by a shapefile of tiles).
  • ref_tiles (str) – Filename of input reference DEM tiles.
  • exc_mask (str) – Filename of exclusion mask (i.e., glaciers) to use in co-registration
  • inc_mask (str) – Filename of inclusion mask (i.e., land) to use in co-registration.
  • outdir (str) – Output directory for temporary files.
  • filt_dem (str) – Filename of DEM to filter elevation differences to.
  • add_ref (bool) – Add reference DEM as a stack variable
  • add_corr (bool) – Add correlation masks as a stack variable
  • latlontile_nodata (str) – Apply nodata for a lat/lon tile footprint to avoid overlapping and simplify xarray merging
  • filt_mm_corr (bool) – Filter MMASTER DEM with correlation mask out of mmaster_tools when stacking (disk space),
  • l1a_zipped (bool) – Use if files have been zipped to save on space.
  • y0 (float) – Year 0 to reference NetCDF time variable to.
  • tmptag (str) – string to append to temporary files.
Returns nco:

NetCDF Dataset of stacked DEMs.

pyddem.stack_tools.create_nc(img, outfile='mmaster_stack.nc', clobber=False, t0=None)[source]

Create a NetCDF dataset with x, y, and time variables.

Parameters:
  • img (pybob.GeoImg) – Input GeoImg to base shape of x, y variables on.
  • outfile (str) – Filename for output NetCDF file.
  • clobber (bool) – clobber existing dataset when creating NetCDF file.
  • t0 (np.datetime64) – Initial time for creation of time variable. Default is 01 Jan 1900.
Returns nco, to, xo, yo:
 

output NetCDF dataset, time, x, and y variables.

pyddem.stack_tools.get_footprints(filelist, proj4=None)[source]

Get a list of footprints, given a filelist of DEMs.

Parameters:
  • filelist (array-like) – List of DEMs to create footprints for.
  • proj4 (str, int) – proj4 representation of output CRS. If None, the CRS is chosen from the first DEM loaded. Can also supply an EPSG code as an integer.
Returns fprints, this_crs:
 

A list of footprints and a proj4 string (or dict) representing the output CRS.

pyddem.stack_tools.make_geoimg(ds, band=0, var='z')[source]

Create a GeoImg representation of a given band from an xarray dataset.

Parameters:
  • ds (xarray.Dataset) – xarray dataset to read shape, extent, CRS values from.
  • band (int) – band number of xarray dataset to use
  • var (string) – variable of xarray dataset to use
Returns geoimg:

GeoImg representation of the given band.