sicor.sensors.S2MSI package

Subpackages

Module contents

class sicor.sensors.S2MSI.GranuleDEM(fn, target_resolution=60, logger=None, sampling_to_shape={10.0: (10980, 10980), 20.0: (5490, 5490), 60.0: (1830, 1830)}, zoom_order=2, slice_x=slice(None, None, None), slice_y=slice(None, None, None), **kwargs)[source]

Bases: object

get digital elevation models for S2 MSI Granules from archive

Parameters:

fn (string) – filename of DEM archive (zip file or hdf5 file) or path to dem folder structure

Returns:

Dict like object which returns DEM for given granules if get_dem, [],or () are called

_get_dem_dir(tile)[source]
_get_dem_hdf5(tile)[source]
_get_dem_zip(tile)[source]
_to_arr(arr)[source]
_to_dtype(arr)[source]
_to_slice(arr)[source]
_to_target_resolution(arr)[source]
dem_to_file(tile, filename, driver_map={'tif': 'gtiff'}, lat_lon=None, extent=None)[source]

Write digital elevation data to file :param extent: :param lat_lon: :param driver_map: :param tile: S2 MSI tile name e.g. ‘32UMU’ :param filename: filename, string :return:None

class sicor.sensors.S2MSI.GranuleInfo(version='lite')[source]

Bases: dict

Dict like object with basic information’s about Sentinel2-MSI granules.

Parameters:

version (string with granule name, see keys() method for available names) – should be either “lite” or “full”

Returns:

dict like object, keys are S2 granule names (e.g. ‘32UVX’), data can be accessed via () and [] methods

:Example

>>> S2gi = GranuleInfo(version="full")
>>> S2gi["32UPV"]
    {u'country': [u'Germany'],
     u'epsg': 32632,
     u'name': u'32UPV',
     u'pos': {u'll': {u'lat': 48.6570271781,
       u'lon': 10.3579107698,
       u'x': 599999.9999970878,
       u'y': 5390220.000326163},
      u'lr': {u'lat': 48.6298215752,
       u'lon': 11.8474784519,
       u'x': 709800.0000132157,
       u'y': 5390220.000321694},
      u'tl': {u'lat': 49.644436702,
       u'lon': 10.3851737332,
       u'x': 600000.0000025682,
       u'y': 5500020.000361709},
      u'tr': {u'lat': 49.6162737214,
       u'lon': 11.9045727629,
       u'x': 709800.0000165974,
       u'y': 5500020.000351718}},
     u'region': [u'Europe'],
     u'zone': 32}
get_tile_data()[source]
class sicor.sensors.S2MSI.S2Image(granule_path, import_bands='all', namespace_candidate=None, aux_fields=None, default_u=1.0, target_resolution=None, dtype_float=<class 'numpy.float16'>, dtype_int=<class 'numpy.int16'>, unit='reflectance', interpolation_order=1, data_mode='dense', driver='OpenJpeg2000', call_cmd=None, logger=None, slice_x=slice(None, None, None), slice_y=slice(None, None, None), default_solar_irradiance={'B01': 1913.57, 'B02': 1941.63, 'B03': 1822.61, 'B04': 1512.79, 'B05': 1425.56, 'B06': 1288.32, 'B07': 1163.19, 'B08': 1036.39, 'B09': 813.04, 'B10': 367.15, 'B11': 245.59, 'B12': 85.25, 'B8A': 955.19}, **kwarg)[source]

Bases: RSImage

Load Sentinel-2 Level-1C or Level-2A product.

Reads Sentinel-2 MSI data into numpy array. Images for different channels are resampled to a common sampling :param granule_path: path to granule folder, folder should contain IMG_DATA folder and S2A_[..].xml file :param import_bands: list of bands to import, default: [‘B01’, ‘B02’, ‘B03’, ‘B04’, ‘B05’, ‘B06’, ‘B07’, ‘B08’,

‘B8A’, ‘B09’, ‘B10’, ‘B11’, ‘B12’,]

Parameters:
  • namespace_candidate – for XML file, or None, then several default namespaces are tested

  • target_resolution – spatial resolution in meter, or None for data not interpolated

  • interpolation_order – integer for interpolation 1,2,3

  • data_mode – either “dense” or “sparse”

  • aux_fields – either None or dict of to be loaded aux fields, e.g. {“cwv”:[ss],”spr”:[ss],”ozo”:[ss]} with ss being “mean” or iterable of spatial samplings, e.g. [20.0] or [20.0,60.0]

  • driver – should be “OpenJpeg2000” -> glymur, “kdu_expand”->shell command, “gdal_[driver] e.g. gdal_JP2ECW gdal_JPEG2000, gdal_JP2OpenJPEG,gdal_JP2KAK

..todo:: Real nodata mask

__rd()
__read_img(fn)
__read_jp2_kdu_app(call_cmd=None)
static _band_name_l1c(fn)[source]

S2 helper function, parse band name from jp2 file name :param fn: filename :return: string with band name

static _band_name_l2a(fn)[source]
static _spatial_sampling_msk(fn)[source]
bad_data_mask(image_data)[source]

Return mask of bad data :param image_data: numpy array :return: 2D boolean array

static find_in_xml(xml, *branch)[source]

S2 xml helper function :param xml: xml object :param branch: iterate to branches using find :return: xml object, None if nothing was found

static find_in_xml_root(namespace, xml_root, branch, *branches, findall=None)[source]

S2 xml helper function, search from root :param namespace: :param xml_root: :param branch: first branch, is combined with namespace :param branches: repeated find’s along these parameters :param findall: if given, at final a findall :return: found xml object, None if nothing was found

static gdal_read(fnjp, driver_name)[source]

Read image file using gdal.

static geotransform2mapinfo(gt, prj)[source]

Builds an ENVI map info from given GDAL GeoTransform and Projection :param gt: GDAL GeoTransform, e.g. (249885.0, 30.0, 0.0, 4578615.0, 0.0, -30.0) :param prj: GDAL Projection - WKT Format :returns: ENVI map info, e.g. [ UTM , 1 , 1 , 256785.0 , 4572015.0 , 30.0 , 30.0 , 43 , North , WGS-84 ] :rtype: list

get_granule_metadata_xml()[source]

Try to find metadata xml file for the granule.

static get_projection(file_name)[source]

:param file_name string, points to filename :return: return {“gt”:geotransform,”prj”:coordinate projections string} for filename :rtype dict

static get_values_from_xml(leaf, dtype=<class 'float'>)[source]

S2 xml helper function :param leaf: xml object which is searched for VALUES tag which are then composed into a numpy array :param dtype: dtype of returned numpy array :return: numpy array

static parse_s2_granule_xml(fn, namespace)[source]

parse XML file in granule folder and return metadata :param fn: full filename tile xml file :param namespace: xml namespace :return: dictionary with metadata

static parse_s2_product_xml(fn)[source]

S2 XML helper function to parse product xml file :param fn: file name of xml file :return: metadata dictionary

static read_aux_data(fn)[source]

Read grib file with aux data, return dictionary :param fn: path to granule :return: dict with data

static save_rgb_image(rgb_img, fn, dpi=100.0)[source]

Save image as RGB to file system.

static transform_utm_to_wgs84(easting, northing, zone, south=False)[source]

returns lon, lat, altitude