generic

input-output of mapdata

dhdt.generic.mapping_io.make_geo_im(Z, R, crs, fName, meta_descr='project Eratosthenes', no_dat=nan, sun_angles='az:360-zn:90', date_created='-0276-00-00')

Create georeferenced tiff file (a GeoTIFF)

Parameters
  • Z (numpy.array, size=(m,n)) – band image

  • R (list, size=(1,6)) – GDAL georeference transform of an image

  • crs (string) – coordinate reference string

  • fname (string) – filename for the image with extension

  • no_dat (datatype, integer) – no data value

  • sun_angles (string) – string giving meta data about the illumination angles

  • date_created (string) – string given the acquistion date in +YYYY-MM-DD

Examples

>>> import os
>>> fpath = os.path.join(os.getcwd(), "data.jp2")
>>> (I, spatialRef, geoTransform, targetPrj) = read_geo_image(fpath)
>>> Z_ones = np.zeros(Z.shape, dtype=bool)
>>> make_geo_im(Z_ones, geoTransformM, spatialRefM, 'ones.tif')
dhdt.generic.mapping_io.make_multispectral_vrt(df, fpath=None, fname='multispec.vrt')

virtual raster tile (VRT) is a description of datasets written in an XML format, it eases the display of multi-spectral data or other means.

Parameters
  • df (pandas.DataFrame) – organization of the different spectral bands

  • fpath (string) – path of the directory of interest

  • fname (string) – file name of the virtual raster tile

Examples

>>> s2_df = list_central_wavelength_msi()
>>> s2_df = s2_df[s2_df['gsd']==10]
>>> s2_df, datastrip_id = get_s2_image_locations(IM_PATH, s2_df)

create file in directory where imagery is situated >>> make_multispectral_vrt(s2_df, fname=’multi_spec.vrt’)

dhdt.generic.mapping_io.read_geo_image(fname, boi=array([], dtype=float64), no_dat=None)

This function takes as input the geotiff name and the path of the folder that the images are stored, reads the image and returns the data as an array

Parameters
  • fname (string) – geotiff file name and path.

  • boi (numpy.array, size=(k,1)) – bands of interest, if a multispectral image is read, a selection can be specified

  • no_dat ({integer,float}) – no data value

Returns

  • data ({numpy.array, numpy.masked.array}, size=(m,n), ndim=2) – data array of the band

  • spatialRef (string) – osr.SpatialReference in well known text

  • geoTransform (tuple, size=(8,)) – affine transformation coefficients.

  • targetprj (osgeo.osr.SpatialReference() object) – coordinate reference system (CRS)

See also

make_geo_im

basic function to write out geographic data

read_geo_info

basic function to get meta data of geographic imagery

read_nc_im

basic function to read geographic raster out of nc-file

Examples

>>> import os
>>> from dhdt.generic.mapping_io import read_geo_image
>>> fpath = os.path.join(os.getcwd(), "data.jp2" )
>>> I, spatialRef, geoTransform, targetPrj = read_geo_image(fpath)
>>> I_ones = np.zeros(I.shape, dtype=bool)
>>> make_geo_im(I_ones, geoTransformM, spatialRefM, "ones.tif")
dhdt.generic.mapping_io.read_geo_info(fname)

This function takes as input the geotiff name and the path of the folder that the images are stored, reads the geographic information of the image

Parameters

fname (string) – path and file name of a geotiff image

Returns

  • spatialRef (string) – osr.SpatialReference in well known text

  • geoTransform (tuple, size=(8,1)) – affine transformation coefficients, but also giving the image dimensions

  • targetprj (osgeo.osr.SpatialReference() object) – coordinate reference system (CRS)

  • rows (integer, {x ∈ ℕ | x ≥ 0}) – number of rows in the image, that is its height

  • cols (integer, {x ∈ ℕ | x ≥ 0}) – number of collumns in the image, that is its width

  • bands (integer, {x ∈ ℕ | x ≥ 1}) – number of bands in the image, that is its depth

See also

read_geo_image

basic function to import geographic imagery data

handle Sentinel-2 imagery

dhdt.generic.handler_sentinel2.get_crs_from_mgrs_tile(tile_code)
Parameters

tile_code (string) – US Military Grid Reference System (MGRS) tile code

Returns

crs – target projection system

Return type

osgeo.osr.SpatialReference

See also

get_utmzone_from_mgrs_tile, get_utmzone_from_mgrs_tile

Notes

The tile structure is a follows “AABCC”
  • “AA” utm zone number, starting from the East, with steps of 8 degrees

  • “B” latitude zone, starting from the South, with steps of 6 degrees

dhdt.generic.handler_sentinel2.get_epsg_from_mgrs_tile(tile_code)
Parameters

tile_code (string, e.g.: '05VMG') – MGRS tile coding

Returns

epsg – code used to denote a certain database entry

Return type

integer

See also

dhdt.generic.get_utmzone_from_mgrs_tile, dhdt.generic.get_crs_from_mgrs_tile

Notes

The tile structure is a follows “AABCC”
  • “AA” utm zone number, starting from the East, with steps of 8 degrees

  • “B” latitude zone, starting from the South, with steps of 6 degrees

The following acronyms are used:

  • CRS : coordinate reference system

  • EPSG : european petroleum survey group (a coordinate refenence database)

  • MGRS : US military grid reference system

  • UTM : universal transverse mercator

  • WGS : world geodetic system

dhdt.generic.handler_sentinel2.get_generic_s2_raster(tile_code, spac=10, tile_path=None)

Create spatial metadata of a Sentinel-2, so no downloading is needed.

Parameters
  • tile_code (string) – mgrs tile coding, which is also given in the filename (“TXXXXX”)

  • spac (integer, {10,20,60}, unit=m) – pixel spacing of the raster

  • tile_path (string) – path to the MGRS tiling file

Returns

  • tuple – georeference transform of an image, including shape

  • pyproj.crs.crs.CRS – coordinate reference system (CRS)

Notes

The tile structure is a follows “AABCC”
  • “AA” utm zone number, starting from the East, with steps of 8 degrees

  • “B” latitude zone, starting from the South, with steps of 6 degrees

The following acronyms are used:

  • CRS : coordinate reference system

  • MGRS : US military grid reference system

  • s2 : Sentinel-2

dhdt.generic.handler_sentinel2.get_s2_dict(s2_df)

given a dataframe with a filename within, create a dictionary with scene and satellite specific metadata.

Parameters

s2_df (pd.dataframe) – metadata and general multi spectral information about the MSI instrument that is onboard Sentinel-2

Returns

s2_dict – dictionary with scene specific meta data, giving the following information: * ‘COSPAR’ : string

id of the satellite

  • ’NORAD’string

    id of the satellite

  • ’instruments’{‘MSI’}

    specific instrument

  • ’launch_date’: string, e.g.:’+2015-06-23’

    date when the satellite was launched into orbit

  • ’orbit’: string

    specifies the type of orbit

  • ’full_path’: string

    the location where the root folder is situated

  • ’MTD_DS_path’: string

    the location where metadata about the datastrip is present

  • ’MTD_TL_path’: string

    the location where metadata about the tile is situated

  • ’QI_DATA_path’: string

    the location where metadata about detector readings are present

  • ’IMG_DATA_path’: string

    the location where the imagery is present

  • ’date’: string, e.g.: ‘+2019-10-25’

    date of acquisition

  • ’tile_code’: string, e.g.: ‘05VMG’

    MGRS tile coding

  • ’relative_orbit’: integer, {x ∈ ℕ}

    orbit from which the imagery were taken

Return type

dictionary

Notes

The metadata is scattered over a folder structure for Sentinel-2, it has typically the following set-up:

* S2X_MSIL1C_20XX...   <- path is given in s2_dict["full_path"]
├ AUX_DATA
├ DATASTRIP
│  └ DS_XXX_XXXX...    <- path is given in s2_dict["MTD_DS_path"]
│     └ QI_DATA
│        └ MTD_DS.xml  <- metadata about the data-strip
├ GRANULE
│  └ L1C_TXXXX_XXXX... <- path is given in s2_dict["MTD_TL_path"]
│     ├ AUX_DATA
│     ├ IMG_DATA
│     │  ├ TXXX_X..XXX.jp2
│     │  └ TXXX_X..XXX.jp2
│     ├ QI_DATA
│     └ MTD_TL.xml     <- metadata about the tile
├ HTML
├ rep_info
├ manifest.safe
├ INSPIRE.xml
└ MTD_MSIL1C.xml       <- metadata about the product

The following acronyms are used:

  • AUX : auxiliary

  • COSPAR : committee on space research international designator

  • DS : datastrip

  • IMG : imagery

  • L1C : product specification,i.e.: level 1, processing step C

  • MGRS : military grid reference system

  • MTD : metadata

  • MSI : multi spectral instrument

  • NORAD : north american aerospace defense satellite catalog number

  • TL : tile

  • QI : quality information

  • s2 : Sentinel-2

See also

dhdt.generic.get_s2_image_locations

dhdt.generic.handler_sentinel2.get_s2_image_locations(fname, s2_df)

The Sentinel-2 imagery are placed within a folder structure, where one folder has an ever changing name. Fortunately this function finds the path from the metadata

Parameters
  • fname (string) – path string to the Sentinel-2 folder

  • s2_df (pandas.dataframe) – index of the bands of interest

Returns

  • s2_df_new (pandas.dataframe) – dataframe series with relative folder and file locations of the bands

  • datastrip_id (string) – folder name of the metadata

Examples

>>> import os
>>> fpath = '/Users/Data/'
>>> sname = 'S2A_MSIL1C_20200923T163311_N0209_R140_T15MXV_20200923T200821.SAFE'
>>> fname = 'MTD_MSIL1C.xml'
>>> full_path = os.path.join(fpath, sname, fname)
>>> im_paths,datastrip_id = get_s2_image_locations(full_path)
>>> im_paths
['GRANULE/L1C_T15MXV_A027450_20200923T163313/IMG_DATA/T15MXV_20200923T163311_B01',
 'GRANULE/L1C_T15MXV_A027450_20200923T163313/IMG_DATA/T15MXV_20200923T163311_B02']
>>> datastrip_id
'S2A_OPER_MSI_L1C_DS_VGS1_20200923T200821_S20200923T163313_N02.09'
dhdt.generic.handler_sentinel2.get_utmzone_from_tile_code(tile_code)
Parameters

tile_code (string, e.g.: '05VMG') – MGRS tile coding

Returns

utmzone – code used to denote the number of the projection column of UTM

Return type

integer

Notes

The tile structure is a follows “AABCC”
  • “AA” utm zone number, starting from the East, with steps of 8 degrees

  • “B” latitude zone, starting from the South, with steps of 6 degrees

The following acronyms are used:

  • CRS : coordinate reference system

  • MGRS : US military grid reference system

  • UTM : universal transverse mercator

  • WGS : world geodetic system

dhdt.generic.handler_sentinel2.meta_s2string(s2_str)

get meta information of the Sentinel-2 file name

Parameters

s2_str (string) – filename of the L1C data

Returns

  • s2_time (string) – date “+YYYY-MM-DD”

  • s2_orbit (string) – relative orbit “RXXX”

  • s2_tile (string) – tile code “TXXXXX”

Examples

>>> s2_str = 'S2A_MSIL1C_20200923T163311_N0209_R140_T15MXV_20200923T200821.SAFE'
>>> s2_time, s2_orbit, s2_tile = meta_s2string(s2_str)
>>> s2_time
'+2020-09-23'
>>> s2_orbit
'R140'
>>> s2_tile
'T15MXV'

handle Landsat imagery

dhdt.generic.handler_landsat.get_wrs_url(version=2)

get the location where the geometric data of Landsats path-row footprints are situated, for info see [wwwUSGS]

References

wwwUSGS

https://www.usgs.gov/media/files/landsat-wrs-2-descending-path-row-shapefile

dhdt.generic.handler_landsat.meta_LSstring(LSstr)

get meta data of the Landsat file name input: LSstr string filename of the L1TP data output: LStime string date “+YYYY-MM-DD”

LSpath string satellite path “PXXX” LSrow string tile row “RXXX”

handle RapidEye imagery

dhdt.generic.handler_rapideye.meta_REstring(REstr)

get meta information of the RapidEye file name

Parameters

REstr (string) – filename of the rapideye data

Returns

  • REtime (string) – date “+YYYY-MM-DD”

  • REtile (string) – tile code “TXXXXX”

  • REsat (string) – which RapedEye satellite

Examples

>>> REstr = '568117_2012-09-10_RE2_3A_Analytic.tif'
>>> REtime, REtile, REsat = meta_REstring(REstr)
>>> REtime
'+2012-09-10'
>>> REtile
'568117'
>>> REsat
'RE2'