mmaster_tools¶
pymmaster.mmaster_tools provides most of the routines used for removing jitter-related bias in ASTER DEMs produced using MicMac ASTER.
-
pymmaster.mmaster_tools.
calculate_dH
(mst_dem, slv_dem, pts)[source]¶ Calculate difference between master and slave DEM. Master and slave DEMs must have the same shape. First, differences are calculated, then data are filtered using a 5x5 median filter, and differences greater than 100 m, or differences on high (>50deg) or low (< 0.5deg) slopes are removed.
Parameters: - mst_dem – master DEM (i.e., external DEM/ICESat data)
- slv_dem – slave DEM (i.e., ASTER scene)
- pts – True if master DEM is ICESat data, False if master DEM is a DEM.
Returns: dH: filtered elevation differences between master and slave DEMs.
-
pymmaster.mmaster_tools.
fitfun_sumofsin
(xx, p)[source]¶ The Base function for the sum of sines fitting to elevation differences in the along track (xx) direction of the ASTER flightpath. DEPRECATED - uses only one angle instead of two. see fitfun_sumofsin_2angle
-
pymmaster.mmaster_tools.
fitfun_sumofsin_2angle
(xxn, xxb, p)[source]¶ Fit sum of sines function for two track angles.
Parameters: - xxn (array-like) – along-track distance in nadir direction
- xxb – along-track distance in back-looking direction
- p (array-like) – sum of sines parameters
Returns sum_of_sines: sum of sines evaluated at the given along-track distances.
-
pymmaster.mmaster_tools.
get_aster_footprint
(gran_name, proj4='+units=m +init=epsg:4326', indir=None, polyout=True)[source]¶ Create shapefile of ASTER footprint from .met file
Parameters: - gran_name (str) – ASTER granule name to use; assumed to also be the folder in which .met file(s) are stored.
- proj4 (str, dict) – proj4 representation for coordinate system to use [default: ‘+units=m +init=epsg:4326’, WGS84 Lat/Lon].
- indir (str) – Directory to search in [default: current working directory].
- polyout (bool) – Create a shapefile of the footprint in the input directory [True].
Returns footprint: shapely Polygon representing ASTER footprint, reprojected to given CRS.
-
pymmaster.mmaster_tools.
get_atrack_coord
(mst_dem, myangN, myangB)[source]¶ Createx numpy arrays for along- and cross-track distances from DEM and angle maps.
Parameters: - dem (pybob GeoImg) – DEM to get x,y positions from
- myangN (pybob GeoImg) – MMASTER 3N track angle (i.e., track angle in nadir image)
- myangB (pybob GeoImg) – MMASTER 3B track angle (i.e., track angle in back-looking image)
Returns yyn, yyb: along-track distances in 3N and 3B track directions.
-
pymmaster.mmaster_tools.
get_fit_variables
(mst_dem, slv_dem, xxn, pts, xxb=None)[source]¶ Get input variables for bias fitting.
Parameters: - mst_dem (pybob GeoImg, ICESat) – Master DEM to use for fitting
- slv_dem (pybob GeoImg) – Slave DEM to use for fitting
- xxn (array-like) – along- or cross-track distance in the nadir track direction
- pts (bool) – True if mst_dem is ICESat points, False if mst_dem is a GeoImg.
- xxb (array-like) – along- or cross-track direction in the back-looking track direction. If not provided, fit variables are provided only for one angle.
Returns xx, dH, grp_xx, grp_dH, xx2, grp_sts: track distance, elevation differences, group distances, group median dH group values, group distances in the back-looking direction, group statistics.
-
pymmaster.mmaster_tools.
get_group_statistics
(invar, indata, indist=500)[source]¶ Calculate statistics of groups of pixels grouped by along-track distance.
Parameters: - invar (array-like) – Input array that determines how to group data (i.e., along-track distance)
- indata (array-like) – Data to calculate group statistics for.
- indist (float) – Distance by which to group pixels.
Returns grp_stats: group statistics for input data.
-
pymmaster.mmaster_tools.
get_track_angle
(fprint, track_dist)[source]¶ Calculate the angle made by the ASTER flight track from scene footprint.
Parameters: - fprint (shapely Polygon) – Footprint of ASTER scene
- track_dist (float) – Distance along flight track within scene at which to calculate angle.
Returns track_angle: angle, in degrees, of flight track
-
pymmaster.mmaster_tools.
get_xy_rot
(dem, myang)[source]¶ Rotate x, y axes of image to get along- and cross-track distances.
Parameters: - dem (pybob GeoImg) – DEM to get x,y positions from.
- myang (float) – angle by which to rotate axes
Returns xxr, yyr: arrays corresponding to along (x) and cross (y) track distances.
-
pymmaster.mmaster_tools.
make_group_id
(inmat, grpid)[source]¶ Make a unique ID for statistical analysis.
Parameters: - inmat (array-like) – Input array to create ID for.
- grpid (array-like) – Array of input group IDs
Returns outmat: Output of group IDs
-
pymmaster.mmaster_tools.
make_mask
(inpoly, pts, raster_out=False)[source]¶ Create a True/False mask to determine whether input points are within a polygon.
Parameters: - inpoly (shapely Polygon) – Input polygon to use to create mask.
- pts (array-like, pybob.GeoImg) – Either a list of (x,y) coordinates, or a GeoImg. If a list of (x,y) coordinates, make_mask uses shapely.polygon.contains to determine if the point is within inpoly. If pts is a GeoImg, make_mask uses ogr and gdal to “rasterize” inpoly to the GeoImg raster.
- raster_out (bool) – Kind of output to return. If True, pts must be a GeoImg.
Returns mask: An array which is True where pts lie within inpoly and False elsewhere.
-
pymmaster.mmaster_tools.
mask_raster_threshold
(rasname, maskname, outfilename, threshold=50, datatype=<MagicMock id='139924155742248'>)[source]¶ Filter values in an input raster if the correlation mask raster falls below a threshold value. Removes noise from low-correlation areas (i.e., clouds) using a binary opening operation.
Parameters: - rasname (str, pybob.GeoImg) – path to raster (i.e., DEM) to mask, or GeoImg object.
- maskname (str, pybob.GeoImg) – path to correlation raster to determine mask values, or GeoImg object.
- outfilename (str) – filename to write masked raster to.
- threshold (float) – correlation value to determine masked values.
- datatype (numpy datatype) – datatype to save raster as.
Returns masked_ras: GeoImg of masked input raster.
-
pymmaster.mmaster_tools.
mmaster_bias_removal
(mst_dem, slv_dem, glacmask=None, landmask=None, pts=False, work_dir='.', tmp_dir=None, out_dir=None, return_geoimg=True, write_log=False, zipped=False, robust=True)[source]¶ Removes cross track and along track biases from MMASTER DEMs.
Parameters: - mst_dem (str, pybob.GeoImg, pybob.ICESat) – Path to filename or GeoImg dataset representing “master” DEM or ICESat.
- slv_dem (str, pybob.GeoImg) – Path to filename or GeoImg dataset representing “slave” DEM (developed for ASTER).
- glacmask (str) – Path to shapefile representing points to exclude from co-registration consideration (i.e., glaciers).
- landmask (str) – Path to shapefile representing points to include in co-registration consideration (i.e., stable ground/land).
- pts (bool) – If True, program assumes that masterDEM represents point data (i.e., ICESat), as opposed to raster data. Slope/aspect are then calculated from slaveDEM. masterDEM should be a string representing an HDF5 file continaing ICESat data.
- work_dir (str) – Location where output files and directory should be saved [.]
- tmp_dir – Location where files are processed
- out_dir (str) – Location to save bias removal outputs.
- return_geoimg (bool) – Return GeoImg objects of the corrected slave DEM and the co-registered master DEM [True]
- write_log (bool) – Re-direct stdout, stderr to a log file in the work directory [False]
- zipped (bool) – extract from zip archive, keep a minimum of output files (logs and pdfs only) [False]
- robust (bool) – solve low-frequency and jitter components of along-track bias separately. If spatial sampling is limited, this is a better approach than solving along-track as one single step.
Returns slv_corr, mst_coreg: corrected MMASTER DEM, co-registered master DEM (if return_geoimg)
-
pymmaster.mmaster_tools.
nmad
(data)[source]¶ Calculate the Normalized Median Absolute Deviation (NMAD) of the input dataset.
Parameters: data (array-like) – input data on which to calculate NMAD Returns nmad: NMAD of input dataset.
-
pymmaster.mmaster_tools.
orient_footprint
(fprint)[source]¶ Orient ASTER footprint coordinates to be clockwise, with upper left coordinate first.
Parameters: fprint (shapely polygon) – footprint to orient Returns o_fprint: re-oriented copy of input footprint.
-
pymmaster.mmaster_tools.
plot_bias
(xx, dH, grp_xx, grp_dH, title, pp, pmod=None, smod=None, plotmin=None, txt=None)[source]¶ data : original data as numpy array (:,2), x = 1col,y = 2col gdata : grouped data as numpy array (:,2) pmod,smod are two model options to plot, numpy array (:,1)
-
pymmaster.mmaster_tools.
polynomial_fit
(x, y)[source]¶ [DEPRECATED] A polynomial search function for orders 1-6 given dependent (x) and independent (y) variables. Uses the numpy polynomial package.
-
pymmaster.mmaster_tools.
preprocess
(mst_dem, slv_dem, glacmask=None, landmask=None, work_dir='.', out_dir='biasrem', pts=False)[source]¶ Pre-process ASTER scene to enable cross- and along-track corrections. Co-registers the ASTER (slave) and external (master) DEMs/ICESat, and shifts the orthoimage and correlation mask based on the offset calculated. Results are saved by default in a folder called ‘coreg’ which is moved to the ‘bias_removal’ folder at the end of this function
Parameters: - mst_dem (str, pybob.Geoimg, pybob.ICESat) – Path to filename or GeoImg dataset representing external “master” DEM or ICESat dataset.
- slv_dem (str, pybob.GeoImg) – Path to filename or GeoImg dataset representing ASTER DEM
- glacmask (str) – Path to shapefile representing areas to exclude from co-registration consideration (i.e., glaciers).
- landmask (str) – Path to shapefile representing areas to include in co-registration consideration (i.e., stable ground/land).
- work_dir – Working directory to use [Assumes ‘.’].
- out_dir (str) – Output directory for the new coregistration folder
- pts – True if mst_dem is point data, False if mst_dem is a DEM.
Returns mst_coreg, slv_coreg, shift_params: co-registered master, slave datasets, as well as a tuple containing x,y,z shifts calculated during co-registration process.
-
pymmaster.mmaster_tools.
reproject_geometry
(src_data, src_crs, dst_crs)[source]¶ Reproject a geometry object from one coordinate system to another.
Parameters: - src_data (shapely geometry) – geometry object to reproject
- src_crs (str, dict) – proj4 description of source CRS
- dst_crs (str, dict) – proj4 description of destination CRS
Returns dst_data: reprojected data.
-
pymmaster.mmaster_tools.
robust_polynomial_fit
(xx, yy)[source]¶ Given sample data xx, yy, compute a robust polynomial fit to the data. Order is chosen automatically by comparing residuals for multiple fit orders.
Parameters: - xx (array-like) – input x data (typically across-track distance)
- yy (array-like) – input y data (typically elevation differences)
Returns coefs, order: polynomial coefficients and order for the best-fit polynomial