mapio package

Submodules

mapio.cloud module

class mapio.cloud.Cloud(lon, lat, data)[source]

Bases: mapio.dataset.DataSet

getBounds()[source]
getData()[source]
getValue(lat, lon, method='nearest')[source]
interpolateToGrid(geodict, method='linear')[source]
setData(data)[source]
trim(bounds)[source]

mapio.dataset module

class mapio.dataset.DataSet[source]

Bases: object

getBounds()[source]

Return the lon/lat range of the data.

Returns:Tuple of (lonmin,lonmax,latmin,latmax)
getData(getCopy=False)[source]

Return a reference to or copy of the data inside the Grid

Parameters:getCopy – True indicates that the user wants a copy of the data, not a reference to it.
Returns:A reference to or copy of a numpy array of data.
getValue(lat, lon, method='nearest', default=None)[source]

Return numpy array at given latitude and longitude (using given resampling method).

Parameters:
  • lat – Latitude (in decimal degrees) of desired data value.
  • lon – Longitude (in decimal degrees) of desired data value.
  • method – Interpolation method, one of (‘nearest’,’linear’,’cubic’,’quintic’)
  • default – Default value to return when lat/lon is outside of grid bounds.
Returns:

Value at input latitude,longitude position.

interpolateToGrid(geodict, method='linear')[source]

Given a geodict specifying a grid extent and resolution, resample current data set to match.

Parameters:
  • geodict – geodict dictionary from a grid whose extents are inside the extent of this grid.
  • method – Optional interpolation method - [‘linear’, ‘cubic’,’quintic’,’nearest’]
Raises:
  • DataSetException – If the Grid object upon which this function is being called is not completely contained by the grid to which this Grid is being resampled.
  • DataSetException – If the resulting interpolated grid shape does not match input geodict.

This function modifies the internal griddata and geodict object variables.

load(filename, bounds=None, resample=False, padValue=None)[source]

Load data into a Grid subclass. Parameters below are suggested for subclasses.

Parameters:
  • filename – File where data is stored
  • bounds – Optional tuple of (lonmin,lonmax,latmin,latmax) used to subset data from file.
  • resample – If subsetting data, True indicates that exact bounds are desired and data should be resampled to fit.
  • padValue – If asking for data outside bounds of grid, any value not None means fill in those cells with padValue. None means don’t pad the grid at all.
Raises NotImplementedError:
 

Always for this base class.

save(filename)[source]

Save the data contained in the grid to a format specific file. Other attributes may be required for format specific files.

Parameters:filename – Where file containing data should be written.
setData(data)[source]

Modify the data inside the Grid.

Parameters:data – numpy array of desired data.
trim(bounds, resample=False, method='linear')[source]

Trim data to a smaller set of bounds, resampling if requested. If not resampling, data will be trimmed to smallest grid boundary possible.

Parameters:
  • bounds – Tuple of (lonmin,lonmax,latmin,latmax)
  • resample – Boolean indicating whether the data should be resampled to exactly match input bounds.
  • method – If resampling, method used, one of (‘linear’,’nearest’,’cubic’,’quintic’)
exception mapio.dataset.DataSetException(value)[source]

Bases: exceptions.Exception

Class to represent errors in the DataSet class.

exception mapio.dataset.DataSetWarning(value)[source]

Bases: exceptions.Warning

Class to represent warnings in the DataSet class.

mapio.gdal module

class mapio.gdal.GDALGrid(data, geodict)[source]

Bases: mapio.grid2d.Grid2D

classmethod getBoundsWithin(filename, geodict)[source]

Return a geodict for a file that is guaranteed to be contained by an input geodict. :param filename:

Path to an ESRI grid file.
Parameters:geodict – Geodict defining a spatial extent that we want to envelope the returned geodict.
Returns:A geodict that is guaranteed to be contained by input geodict.
classmethod getFileGeoDict(filename)[source]

Get the spatial extent, resolution, and shape of grid inside ESRI grid file. :param filename:

File name of ESRI grid file.
Returns:
  • GeoDict specifying spatial extent, resolution, and shape of grid inside ESRI grid file.
  • xvar array specifying X coordinates of data columns
  • yvar array specifying Y coordinates of data rows
Raises DataSetException:
 When the file contains a grid with more than one band.
classmethod load(filename, samplegeodict=None, preserve='dims', resample=False, method='linear', doPadding=False, padValue=nan)[source]

Create a GDALGrid object from a (possibly subsetted, resampled, or padded) GDAL-compliant grid file. :param filename:

Name of input file.
Parameters:
  • samplegeodict – GeoDict used to specify subset bounds and resolution (if resample is selected)
  • preserve – String (one of ‘dims’,’shape’) indicating whether xdim/ydim of input geodict should be preserved or nrows/ncols.
  • resample – Boolean used to indicate whether grid should be resampled from the file based on samplegeodict.
  • method – If resample=True, resampling method to use (‘nearest’,’linear’,’cubic’,’quintic’)
  • doPadding – Boolean used to indicate whether, if samplegeodict is outside bounds of grid, to pad values around the edges.
  • padValue – Value to fill in around the edges if doPadding=True.
Returns:

GDALgrid instance (possibly subsetted, padded, or resampled)

Raises DataSetException:
 

  • When sample bounds are outside (or too close to outside) the bounds of the grid and doPadding=False.
  • When the input file type is not recognized.

classmethod readGDAL(filename, bounds=None, firstColumnDuplicated=False)[source]
save(filename, format='EHdr')[source]
mapio.gdal.createSample(M, N)[source]
mapio.gdal

alias of mapio.gdal

mapio.gmt module

class mapio.gmt.BinCDFArray(array, nrows, ncols)[source]

Bases: object

class mapio.gmt.GMTGrid(data, geodict)[source]

Bases: mapio.grid2d.Grid2D

A class that implements a Grid2D object around GMT NetCDF/HDF/native gridded data sets.

classmethod getBoundsWithin(filename, geodict)[source]

Return a geodict for a file that is guaranteed to be contained by an input geodict. :param filename:

Path to an GMT grid file.
Parameters:geodict – Geodict defining a spatial extent that we want to envelope the returned geodict.
Returns:A geodict that is guaranteed to be contained by input geodict.
classmethod getFileGeoDict(filename)[source]

Get the spatial extent, resolution, and shape of grid inside NetCDF file. :param filename:

File name of NetCDF file.
Returns:GeoDict specifying spatial extent, resolution, and shape of grid inside NetCDF file.
Raises DataSetException:
 When the file is not detectable as one of the three flavors of GMT grids.
classmethod getFileType(grdfile)[source]

Get the GMT sub-format (netcdf, hdf, or GMT binary). :param grdfile:

File name of suspected GMT grid file.
Returns:One of ‘netcdf’ (NetCDF version 3), ‘hdf’ (NetCDF version 4), ‘native’ (so-called GMT native format), or ‘unknown’.
classmethod getHDFHeader(hdffile)[source]

Get the header information from a GMT NetCDF4 (HDF) file. :param fname:

File name of GMT NetCDF4 grid
Returns:GeoDict specifying spatial extent, resolution, and shape of grid inside NetCDF file.
classmethod getNativeHeader(fname, fmt=None)[source]

Get the header information from a GMT native grid file. :param fname:

File name of GMT native grid
Parameters:fmt
One of:
  • ‘h’ for 16 bit signed integer
  • ‘i’ for 32 bit signed integer
  • ‘f’ for 32 bit float
  • ‘d’ for 64 bit float
Returns:
  • GeoDict specifying spatial extent, resolution, and shape of grid inside NetCDF file.
  • xvar array specifying X coordinates of data columns
  • yvar array specifying Y coordinates of data rows
  • fmt If input fmt is None, this will be a best guess as to the data format in the file.
  • zscale Data multiplier
  • zoffset Value to be added to data
classmethod getNetCDFHeader(filename)[source]

Get the header information from a GMT NetCDF3 file. :param fname:

File name of GMT NetCDF3 grid
Returns:
  • GeoDict specifying spatial extent, resolution, and shape of grid inside NetCDF file.
  • xvar array specifying X coordinates of data columns
  • xvar array specifying Y coordinates of data rows
classmethod load(gmtfilename, samplegeodict=None, preserve='dims', resample=False, method='linear', doPadding=False, padValue=nan)[source]

Create a GMTGrid object from a (possibly subsetted, resampled, or padded) GMT grid file. :param gmtfilename:

Name of input file.
Parameters:
  • samplegeodict – GeoDict used to specify subset bounds and resolution (if resample is selected)
  • preserve – String (one of ‘dims’,’shape’) indicating whether xdim/ydim of input geodict should be preserved or nrows/ncols.
  • resample – Boolean used to indicate whether grid should be resampled from the file based on samplegeodict.
  • method – If resample=True, resampling method to use (‘nearest’,’linear’,’cubic’,’quintic’)
  • doPadding – Boolean used to indicate whether, if samplegeodict is outside bounds of grid, to pad values around the edges.
  • padValue – Value to fill in around the edges if doPadding=True.
Returns:

GMTgrid instance (possibly subsetted, padded, or resampled)

Raises DataSetException:
 

  • When sample bounds are outside (or too close to outside) the bounds of the grid and doPadding=False.
  • When the input file type is not recognized.

classmethod readGMTNative(fname, bounds=None, firstColumnDuplicated=False, fmt=None)[source]

Read the data and geo-referencing information from a GMT native grid file, subsetting if requested. http://gmt.soest.hawaii.edu/doc/5.1.2/GMT_Docs.html#native-binary-grid-files :param fname:

File name of GMT native grid
Parameters:
  • bounds – Tuple of (xmin,xmax,ymin,ymax)
  • firstColumnDuplicated – Boolean - is this a file where the last column of data is the same as the first (for grids that span entire globe).
  • fmt
    Data width, one of:
    • ‘i’ (16 bit signed integer)
    • ‘l’ (32 bit signed integer)
    • ‘f’ (32 bit float)
    • ‘d’ (64 bit float)

    Strictly speaking, this is only necessary when the data file is 32 bit float or 32 bit integer, as there is no sure way to tell from the header or data which data type is contained in the file. If fmt is None, then the code will try to guess as best it can from the data whether it is integer or floating point data. Caveat emptor!

Returns:

Tuple of data (2D numpy array of data, possibly subsetted from file) and geodict (see above).

Raises NotImplementedError:
 

For any bounds not None (we’ll get to it eventually!)

classmethod readHDF(hdffile, bounds=None, firstColumnDuplicated=False)[source]

Read the data and geo-referencing information from a GMT NetCDF4 (HDF) grid file, subsetting if requested. :param hdffile:

File name of GMT NetCDF4 grid
Parameters:bounds – Tuple of (xmin,xmax,ymin,ymax)
Returns:Tuple of data (2D numpy array of data, possibly subsetted from file) and geodict (see above).
classmethod readNetCDF(filename, bounds=None, firstColumnDuplicated=False)[source]

Read the data and geo-referencing information from a GMT NetCDF3 grid file, subsetting if requested. :param filename:

File name of GMT NetCDF3 grid
Parameters:bounds – Tuple of (xmin,xmax,ymin,ymax)
Returns:Tuple of data (2D numpy array of data, possibly subsetted from file) and geodict (see above).
save(filename, format='netcdf')[source]

Save a GMTGrid object to a file. :param filename:

Name of desired output file.
Parameters:format – One of ‘netcdf’,’hdf’ or ‘native’.
Raises DataSetException:
 When format not one of (‘netcdf,’hdf’,’native’)
mapio.gmt.createSampleGrid(M, N)[source]

Used for internal testing - create an NxN grid with lower left corner at 0.5,0.5, xdim/ydim = 1.0 :param M:

Number of rows in output grid
Parameters:N – Number of columns in output grid
Returns:GMTGrid object where data values are an NxN array of values from 0 to N-squared minus 1, and geodict lower left corner is at 0.5/0.5 and cell dimensions are 1.0.
mapio.gmt.createSampleXRange(M, N, filename, bounds=None, xdim=None, ydim=None)[source]
mapio.gmt.indexArray(array, shp, i1, i2, j1, j2)[source]
mapio.gmt.sub2ind(shape, subtpl)[source]

Convert 2D subscripts into 1D index. @param shape: Tuple indicating size of 2D array. @param subtpl: Tuple of (possibly) numpy arrays of row,col values. @return: 1D array of indices.

mapio.grid2d module

class mapio.grid2d.Grid2D(data=None, geodict=None)[source]

Bases: mapio.gridbase.Grid

A partially abstract class to represent 2D lat/lon gridded datasets. Some basic methods are implemented here, enough so that all functions of working with data (aside from loading and saving) can be used with this class. Grids are assumed to be pixel-registered - that is, grid coordinates represent the value at the center of the cells.

classmethod copyFromGrid(grid)[source]
getBounds()[source]

Return the lon/lat range of the data.

Returns:Tuple of (lonmin,lonmax,latmin,latmax)
getData()[source]

Return a reference to the data inside the Grid :returns:

A reference to a 2D numpy array.
getGeoDict()[source]

Return a reference to the geodict inside the Grid :returns:

A reference to a dictionary (see constructor).
getLatLon(row, col)[source]

Return geographic coordinates (lat/lon decimal degrees) for given data row and column.

Parameters:
  • row – Row dimension index into internal data array.
  • col – Column dimension index into internal data array.
Returns:

Tuple of latitude and longitude.

getRowCol(lat, lon, returnFloat=False)[source]

Return data row and column from given geographic coordinates (lat/lon decimal degrees).

Parameters:
  • lat – Input latitude.
  • lon – Input longitude.
  • returnFloat – Boolean indicating whether floating point row/col coordinates should be returned.
Returns:

Tuple of row and column.

getValue(lat, lon, method='nearest', default=None)[source]

Return numpy array at given latitude and longitude (using nearest neighbor).

Parameters:
  • lat – Latitude (in decimal degrees) of desired data value.
  • lon – Longitude (in decimal degrees) of desired data value.
  • method – Interpolation method, one of (‘nearest’,’linear’,’cubic’,’quintic’)
  • default – Default value to return when lat/lon is outside of grid bounds.
Returns:

Value at input latitude,longitude position.

interpolateToGrid(geodict, method='linear')[source]

Given a geodict specifying another grid extent and resolution, resample current grid to match.

Parameters:
  • geodict – geodict dictionary from another grid whose extents are inside the extent of this grid.
  • method – Optional interpolation method - [‘linear’, ‘cubic’,’nearest’]
Raises:
  • DataSetException – If the Grid object upon which this function is being called is not completely contained by the grid to which this Grid is being resampled.
  • DataSetException – If the method is not one of [‘nearest’,’linear’,’cubic’] If the resulting interpolated grid shape does not match input geodict.

This function modifies the internal griddata and geodict object variables.

load(filename, bounds=None, resample=False, padValue=None)[source]
classmethod rasterizeFromGeometry(shapes, samplegeodict, burnValue=1.0, fillValue=nan, allTouched=True, attribute=None)[source]

Create a Grid2D object from vector shapes, where the presence of a shape (point, line, polygon) inside a cell turns that cell “on”. :param shapes:

One of:
  • One shapely geometry object (Point, Polygon, etc.) or a sequence of such objects
  • One GeoJSON like object or sequence of such objects. (http://geojson.org/)
  • A tuple of (geometry,value) or sequence of (geometry,value).
Parameters:
  • samplegeodict – GeoDict with at least xmin,xmax,ymin,ymax,xdim,ydim values set.
  • burnValue – Optional value which will be used to set the value of the pixels if there is no value in the geometry field.
  • fillValue – Optional value which will be used to fill the cells not touched by any geometry.
  • allTouched – Optional boolean which indicates whether the geometry must touch the center of the cell or merely be inside the cell in order to set the value.
Raises DataSetException:
 

When geometry input is not a subclass of shapely.geometry.base.BaseGeometry.

Returns:

Grid2D object.

This method is a thin wrapper around rasterio->features->rasterize(), documented here: https://github.com/mapbox/rasterio/blob/master/docs/features.rst

which is itself a Python wrapper around the functionality found in gdal_rasterize, documented here: http://www.gdal.org/gdal_rasterize.html

reqfields = set(['ymax', 'ncols', 'xdim', 'nrows', 'xmax', 'xmin', 'ymin', 'ydim'])
save(filename)[source]
trim(bounds, resample=False, method='linear')[source]

Trim data to a smaller set of bounds, resampling if requested. If not resampling, data will be trimmed to largest grid boundary possible.

Parameters:
  • bounds – Tuple of (lonmin,lonmax,latmin,latmax)
  • resample – Boolean indicating whether the data should be resampled to exactly match input bounds.
  • method – If resampling, method used, one of (‘linear’,’nearest’,’cubic’,’quintic’)
mapio.grid2d.testGeoJSON(obj)[source]

mapio.gridbase module

class mapio.gridbase.Grid[source]

Bases: mapio.dataset.DataSet

An abstract class to represent lat/lon gridded datasets. Grids are assumed to be pixel-registered - that is, grid coordinates represent the value at the center of the cells.

blockmean(geodict)[source]

Abstract method to calculate average values for cells of larger size than the current grid. :param geodict:

Geodict that defines the new coarser grid.
classmethod checkGeoDict(geodict)[source]
classmethod fixGeoDict(bounds, xdim, ydim, nrows, ncols, preserve='dims')[source]
getBoundsWithin(filename, geodict)[source]

Abstract method to return a geodict for this file that is guaranteed to be inside the input geodict defined, without resampling. :param filename:

The name of the file whose resolution/extent should be used.
Parameters:geodict – The geodict which is used as the base for finding the bounds for this file guaranteed to be inside of this geodict.
Raises NotImplementedError:
 Always in base class
getFileGeoDict(filename)[source]

Abstract method to return the bounding box, resolution, and shape of a file in whatever Grid format. :param filename:

The path to the filename of whatever grid format this is being implemented in.
Returns:A geodict specifying the bounding box, resolution, and shape of the data in a file.
getGeoDict()[source]

Return a reference to the geodict inside the Grid

Returns:A reference to a dictionary (see constructor).
getLatLon(row, col)[source]

Return geographic coordinates (lat/lon decimal degrees) for given data row and column.

Parameters:
  • row – Row dimension index into internal data array.
  • col – Column dimension index into internal data array.
Returns:

Tuple of latitude and longitude.

static getLatLonMesh(geodict)[source]
getRowCol(lat, lon, returnFloat=False)[source]

Return data row and column from given geographic coordinates (lat/lon decimal degrees).

Parameters:
  • lat – Input latitude.
  • lon – Input longitude.
  • returnFloat – Boolean indicating whether floating point row/col coordinates should be returned.
Returns:

Tuple of row and column.

loadFromCloud(cloud, geodict)[source]

Create a grid from a Cloud instance (scattered XY data). :param cloud:

A Cloud instance containing scattered XY data.
Parameters:geodict – A geodict object where nrows/ncols are optional (will be calculated from bounds/cell dimensions)
Returns:An instance of a Grid object.

mapio.multihaz module

class mapio.multihaz.MultiHazardGrid(layers, geodict, origin, header, metadata=None)[source]

Bases: mapio.multiple.MultiGrid

getHeader()[source]

Return the header dictionary. :returns:

Header dictionary (see setHeader()).
getMetadata()[source]

Return the dictionary of arbitrary metadata dictionaries. :returns:

A dictionary of dictionaries containing arbitrary metadata.
getOrigin()[source]

Return the origin dictionary. :returns:

Origin dictionary (see setOrigin()).
classmethod load(filename)[source]

Load data from an HDF file into a MultiHazardGrid object. :param filename:

HDF file containing data and metadata for ShakeMap or Secondary Hazards data.
Returns:MultiHazardGrid object.
save(filename)[source]

Save MultiHazardGrid object to HDF file. Georeferencing information will be saved as datasets “x” and “y”. Layers will be saved as datasets named by layer keys. Dictionaries contained in “origin”, and “header” will be saved in groups of those same names. Dictionaries contained in the “metadata” dictionary will be contained in a series of recursive groups under a group called “metadata”. :param filename:

Output desired filename (HDF format).
setHeader(header)[source]

Set the header dictionary. :param header:

Dictionary with elements:
  • type Type of multi-layer earthquake induced hazard (‘shakemap’,’gfe’)
  • version Integer product version (1)
  • process_time Python datetime indicating when data was created.
  • code_version String version of code that created this file (i.e.,‘4.0’)
  • originator String representing network that created the hazard grid.
  • product_id String representing the ID of the product (may be different from origin ID)
  • map_status String, one of RELEASED, ??
  • event_type String, one of [‘ACTUAL’,’SCENARIO’]
setMetadata(metadata)[source]

Set the metadata dictionary. :param metadata:

Dictionary of dictionaries of metadata. Each dictionary can contain any of the following types: str,unicode,int,float,long,list,tuple,np.ndarray,dict,datetime.datetime,collections.OrderedDict.
setOrigin(origin)[source]

Set the origin dictionary. Dictionary with elements:

  • id String of event ID (i.e., ‘us2015abcd’)
  • source String containing originating network (‘us’)
  • time Float event magnitude
  • lat Float event latitude
  • lon Float event longitude
  • depth Float event depth
  • magnitude Datetime object representing event origin time.

mapio.multiple module

class mapio.multiple.MultiGrid(layers, descriptions=None)[source]

Bases: mapio.gridbase.Grid

getBounds()[source]

Return the lat/lon range of the data.

Returns:Tuple of (lonmin,lonmax,latmin,latmax)
getData()[source]

Return the OrderedDict of data layers contained in MultiGrid.

Returns:OrderedDict of Grid2D objects.
getGeoDict()[source]

Return the geodict object which defines the extent and resolution of all the grids.

Returns:geodict dictionary (see constructor)
getLatLon(row, col)[source]

Return geographic coordinates (lat/lon decimal degrees) for given data row and column.

Parameters:
  • row – Row dimension index into internal data array.
  • col – Column dimension index into internal data array.
Returns:

Tuple of latitude and longitude.

getLayer(name)[source]

Retrieve the 2D associated with a layer name.

Parameters:name – Name of data layer.
Returns:Grid2D object.
Raises DataSetException:
 When name is not found in list of layer names.
getLayerNames()[source]

Return the list of layer names contained in the MultiGrid. :returns:

List of layer names.
getRowCol(lat, lon, returnFloat=False)[source]

Return data row and column from given geographic coordinates (lat/lon decimal degrees).

Parameters:
  • lat – Input latitude.
  • lon – Input longitude.
  • returnFloat – Boolean indicating whether floating point row/col coordinates should be returned.
Returns:

Tuple of row and column.

getValue(lat, lon, layername, method='nearest', default=None)[source]

Return numpy array at given latitude and longitude (using nearest neighbor).

Parameters:
  • lat – Latitude (in decimal degrees) of desired data value.
  • lon – Longitude (in decimal degrees) of desired data value.
  • layername – Name of layer from which to retrieve data.
  • method – Interpolation method, one of (‘nearest’,’linear’,’cubic’,’quintic’)
  • default – Default value to return when lat/lon is outside of grid bounds.
Returns:

Value at input latitude,longitude position.

interpolateToGrid(geodict, method='linear')[source]

Given a geodict specifying another grid extent and resolution, resample all grids to match.

Parameters:
  • geodict – geodict dictionary from another grid whose extents are inside the extent of this grid.
  • method – Optional interpolation method - [‘linear’, ‘cubic’,’quintic’,’nearest’]
Raises:
  • DataSetException – If the Grid object upon which this function is being called is not completely contained by the grid to which this Grid is being resampled.
  • DataSetException – If the resulting interpolated grid shape does not match input geodict.

This function modifies the internal griddata and geodict object variables.

load(filename)[source]

Load layers of data from a file :param filename:

File to load data from.
reqfields = set(['ymax', 'ncols', 'xdim', 'nrows', 'xmax', 'xmin', 'ymin', 'ydim'])
save(filename)[source]

Save layers of data to a file

Parameters:filename – File to save data to.
setData(layers, descriptions=None)[source]

Return the OrderedDict of data layers contained in MultiGrid.

Parameters:layers – OrderedDict of Grid2D objects.
setLayer(name, data, desc=None)[source]

Add a 2D layer of data to a MultiGrid object.

Parameters:
  • name – String which will be used to retrieve the data.
  • data – 2D numpy array of data
  • desc – Optional text description of layer
Raises DataSetException:
 

If the data layer dimensions don’t match the geodict.

trim(bounds, resample=False, method='linear')[source]

Trim all data layers to a smaller set of bounds, resampling if requested. If not resampling, data will be trimmed to smallest grid boundary possible.

Parameters:
  • bounds – Tuple of (lonmin,lonmax,latmin,latmax)
  • resample – Boolean indicating whether the data should be resampled to exactly match input bounds.
  • method – If resampling, method used, one of (‘linear’,’nearest’,’cubic’,’quintic’)

mapio.shake module

class mapio.shake.ShakeGrid(layers, geodict, eventDict, shakeDict, uncertaintyDict)[source]

Bases: mapio.multiple.MultiGrid

A class that implements a MultiGrid object around ShakeMap grid.xml data sets.

classmethod getFileGeoDict(shakefilename)[source]

Get the spatial extent, resolution, and shape of grids inside ShakeMap grid file. :param filename:

File name of ShakeMap grid file.
Returns:GeoDict specifying spatial extent, resolution, and shape of grids inside ShakeMap grid file.
classmethod load(shakefilename, samplegeodict=None, resample=False, method='linear', doPadding=False, padValue=nan)[source]

Create a ShakeGrid object from a ShakeMap grid.xml file. :param shakefilename:

File name or File-like object of ShakeMap grid.xml file.
Parameters:
  • samplegeodict – GeoDict used to specify subset bounds and resolution (if resample is selected)
  • resample – Boolean used to indicate whether grid should be resampled from the file based on samplegeodict.
  • method – If resample=True, resampling method to use (‘nearest’,’linear’,’cubic’,’quintic’)
  • doPadding – Boolean used to indicate whether, if samplegeodict is outside bounds of grid, to pad values around the edges.
  • padValue – Value to fill in around the edges if doPadding=True.
Returns:

ShakeGrid object.

save(filename, version=1)[source]

Save a ShakeGrid object to the grid.xml format. :param filename:

File name or file-like object.
Parameters:version – Integer Shakemap version number.
mapio.shake.readShakeFile(fileobj)[source]

Reads in the data and metadata for a ShakeMap object (can be passed to ShakeGrid constructor). :param fileobj:

File-like object representing an open ShakeMap grid file.
Returns:
Tuple containing:
  • Ordered Dictionary with the data layers in ShakeMap (MMI, PGA, PGV, etc.)
  • Geo dictionary describing the spatial extent and resolution of all the layers.
  • Dictionary representing the event element in the ShakeMap header.
  • Dictionary representing the grid element in the ShakeMap header.
  • Dictionary representing the list of event_specific_uncertainty elements in the ShakeMap header.

mapio.testgmt module

Module contents