コード例 #1
0
 def linear_to_dB(self):
     self.decibel_list = []
     for product in self.temporary_data_list:
         parameters = snappy.HashMap()
         parameters.put('sourceBands', 'Sigma0_VH,Sigma0_VV')
         decibel = GPF.createProduct("LinearToFromdB", parameters, product)
         self.decibel_list.append(decibel)
     self.temporary_data_list=self.decibel_list
     print("Linear to/from dB Conversion is done")
     return self.decibel_list
コード例 #2
0
 def speckle_filter(self):
     speckle_filtered_list = []
     for product in self.temporary_data_list:
         parameters = snappy.HashMap()
         parameters.put('filter', 'Refined Lee')
         speckle_filtered = snappy.GPF.createProduct('Speckle-Filter', parameters, product)
         speckle_filtered_list.append(speckle_filtered)
     self.temporary_data_list = speckle_filtered_list
     print('Speckle filtering is done!')
     return speckle_filtered_list
コード例 #3
0
 def thermal_noise_removel(self):
     thermal_noise_list = []
     for product in self.temporary_data_list:
         parameters = snappy.HashMap()
         parameters.put('removeThermalNoise', True)
         thermal_noise = snappy.GPF.createProduct("ThermalNoiseRemoval", parameters, product)
         thermal_noise_list.append(thermal_noise)
     self.temporary_data_list = thermal_noise_list
     print('Thermal noise removel is done!')
     return self.temporary_data_list
コード例 #4
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def linear_to_db(s1_read):
    """
    分贝化
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    s1_read = snappy.GPF.createProduct('LinearToFromdB', parameters, s1_read)
    print('LinearTo/FromdB succeed!')

    return s1_read
コード例 #5
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def add_land_cover(s1_read):
    """
    使用AddLandCover GPF module自动下载GlobCover
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    parameters.put("landCoverNames", "GlobCover")
    mask_with_land_cover = snappy.GPF.createProduct('AddLandCover', parameters,
                                                    s1_read)

    return mask_with_land_cover
コード例 #6
0
 def calibration(self):
     calibrated_list=[]
     for product in self.temporary_data_list:
         parameters = snappy.HashMap()
         parameters.put('outputSigmaBand', True)
         parameters.put('selectedPolarizations', 'VH,VV')
         parameters.put('outputImageScaleInDb', True)
         calibrated = snappy.GPF.createProduct("Calibration", parameters, product)
         calibrated_list.append(calibrated)
     print('Calibration is done!')
     self.temporary_data_list = calibrated_list
     return calibrated_list
コード例 #7
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def thermal_noise_removal(s1_read):
    """
    热噪声去除
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    parameters.put('removeThermalNoise', True)
    s1_read = snappy.GPF.createProduct('ThermalNoiseRemoval', parameters,
                                       s1_read)
    print('Thermal Noise Removal succeed!')

    return s1_read
コード例 #8
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def border_noise_removal(s1_read):
    """
    GRD border noise removal
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    parameters.put('selectedPolarisations', 'VH,VV')
    s1_read = snappy.GPF.createProduct('Remove-GRD-Border-Noise', parameters,
                                       s1_read)
    print('GRD border noise removal succeed!')

    return s1_read
コード例 #9
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def land_sea_mask(s1_read):
    """
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    parameters.put('landMask', False)
    parameters.put('useSRTM', True)
    landSeaMask = snappy.GPF.createProduct('Land-Sea-Mask', parameters,
                                           s1_read)
    print('mask the sea')

    return landSeaMask
コード例 #10
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def apply_orbit_file(s1_read):
    """
    精密轨道校正
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    parameters.put('orbitType', 'Sentinel Precise (Auto Download)')
    parameters.put('polyDegree', '3')
    parameters.put('continueOnFail', 'false')
    s1_read = snappy.GPF.createProduct('Apply-Orbit-File', parameters, s1_read)
    print('Apply Orbit File succeed!')

    return s1_read
コード例 #11
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def speckle_filter(s1_read):
    """
    斑点噪声去除
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    # 使用改进型Lee滤波器
    parameters.put('filter', 'Refined Lee')
    parameters.put('filterSizeX', 5)
    parameters.put('filterSizeY', 5)
    s1_read = snappy.GPF.createProduct('Speckle-Filter', parameters, s1_read)
    print('Speckle Filter succeed!')

    return s1_read
コード例 #12
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def calibration(s1_read):
    """
    辐射校正
    :param s1_read:
    :return:
    """
    parameters = snappy.HashMap()
    # 以标准后向散射系数sigma0的方式定标
    parameters.put('outputSigmaBand', True)
    parameters.put('sourceBands', 'Intensity_VH,Intensity_VV')
    parameters.put('selectedPolarisations', 'VH,VV')
    # 没有分贝化
    parameters.put('outputImageScaleInDb', False)
    s1_read = snappy.GPF.createProduct('Calibration', parameters, s1_read)
    print('Calibration succeed!')

    return s1_read
コード例 #13
0
    def geo_subset(self):
        subset_list=[]
        lake_coordinates = os.path.join(self.lake_coordinates, 'aktas')
        data = open(lake_coordinates)
        data_string = data.read().replace("\n", " ")
        data.close()

        # snappy part
        for product in self.temporary_data_list:
            parameters = snappy.HashMap()
            parameters.put('copyMetadata', True)
            parameters.put('geoRegion', data_string)
            subset = snappy.GPF.createProduct("Subset", parameters, product)
            subset_list.append(subset)
            list(subset.getBandNames())
        self.temporary_data_list = subset_list
        print('Subsetting is done!')
        return subset_list
コード例 #14
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def subset(s1_read, subsetx, subsety, subsetw, subseth):
    """
    裁剪
    :param s1_read:
    :param subsetx:
    :param subsety:
    :param subsetw:
    :param subseth:
    :return:
    """

    parameters = snappy.HashMap()
    parameters.put('copyMetadata', True)
    parameters.put('region',
                   '%s, %s, %s, %s' % (subsetx, subsety, subsetw, subseth))
    s1_read = snappy.GPF.createProduct('Subset', parameters, s1_read)
    print('Subset succeed!')

    return s1_read
コード例 #15
0
    def apply_threshold_to_product(self):
        self.temporary_data_binary = []
        snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
        BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
        targetBand = BandDescriptor()
        targetBand.name = 'band1'
        targetBand.type = 'float32'
        targetBand.expression = 'Sigma0_VV_db < -16.5 '
        targetBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1)
        targetBands[0] = targetBand

        for product in self.temporary_data_list:
            parameters = snappy.HashMap()
            parameters.put('name', 'Sigma0_VV_db_Threshold')
            parameters.put('targetBands', targetBands)
            binary = snappy.GPF.createProduct('BandMaths', parameters, product)
            self.temporary_data_binary.append(binary)

        self.temporary_data_list = self.temporary_data_binary
        return self.temporary_data_binary
コード例 #16
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def generate_binary_water(s1_read):
    """
    依靠GlobCover的分类来生成水体
    :param s1_read:
    :return:
    """
    BandDescriptor = snappy.jpy.get_type(
        'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
    parameters = snappy.HashMap()
    targetBand = BandDescriptor()
    targetBand.name = 'BinaryWater'
    targetBand.type = 'uint8'
    targetBand.expression = '(land_cover_GlobCover == 210) ? 0 : 1'
    targetBands = snappy.jpy.array(
        'org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1)
    targetBands[0] = targetBand
    parameters.put('targetBands', targetBands)
    water_mask = snappy.GPF.createProduct('BandMaths', parameters, s1_read)
    print('get GlobCover water mask!')

    return water_mask
コード例 #17
0
ファイル: preprocess.py プロジェクト: xyt556/RemoteSensing-1
def terrain_correction(s1_read, demFile):
    """
    地形校正
    :param s1_read:
    :param demFile:
    :return:
    """
    # 地形校正需要获取投影参数WKT文本表示
    proj = """GEOGCS["WGS84(DD)", 
                  DATUM["WGS84", 
                    SPHEROID["WGS84", 6378137.0, 298.257223563]], 
                  PRIMEM["Greenwich", 0.0], 
                  UNIT["degree", 0.017453292519943295], 
                  AXIS["Geodetic longitude", EAST], 
                  AXIS["Geodetic latitude", NORTH]]"""
    parameters = snappy.HashMap()
    if demFile:
        parameters.put('deName', 'External DEM')
        parameters.put('externalDEMFile', demFile)
        parameters.put('externalDEMNoDataValue', 0.0)
        print('using external DEM file')
    else:
        # 使用‘SRTM 3Sec’DEM
        parameters.put('deName', 'SRTM 3Sec')
        print('using SRTM 3Sec DEM')
    parameters.put('imgResamplingMethod', 'BILINEAR_INTERPOLATION')
    # 设置分辨率
    parameters.put('pixelSpacingInMeter', 10.0)
    parameters.put('mapProjection', proj)
    # 对海域无高程部分不使用掩膜
    parameters.put('nodataValueAtSea', False)
    parameters.put('saveSelectedSourceBand', True)
    s1_read = snappy.GPF.createProduct('Terrain-Correction', parameters,
                                       s1_read)
    print('Terrain Correction succeed!')

    return s1_read
コード例 #18
0
    subprocess.Popen(['gpt', '-h', 'Write'],
                     stdout=subprocess.PIPE,
                     universal_newlines=True).communicate()[0])

path = r'F:\Studium_Trier\Masterarbeit\Datensaetze\atmoCorrected'
images = [
    os.path.join(path, f) for f in os.listdir(path) if f.endswith(".SAFE")
]
print(len(images))

for i, item in enumerate(images):
    # read products
    inputS2 = snappy.ProductIO.readProduct(item)

    # resample to 10 m resolution
    params = snappy.HashMap()
    params.put('referenceBand', 'B2')
    params.put('upsampling', 'Nearest')
    resample = snappy.GPF.createProduct('Resample', params, inputS2)

    # subset to given bands and extent of NHH
    wkt = "POLYGON ((6.96598264600004 49.5994875390001,6.96598264600004 49.798110884,7.29804284600004 49.798110884,7.29804284600004 49.5994875390001,6.96598264600004 49.5994875390001))"
    bands = "B2,B3,B4,B5,B6,B7,B8,B8A,B11,B12,quality_cloud_confidence,quality_scene_classification"
    parameters = snappy.HashMap()
    parameters.put('copyMetadata', True)
    parameters.put('geoRegion', wkt)
    parameters.put('sourceBands', bands)
    subset = snappy.GPF.createProduct('Subset', parameters, resample)

    # write GeoTIFF
    # ToDo: include check if file already exists
コード例 #19
0
    def terrain_correction(self):
        proj_wgs84 = '''GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]'''
        proj_wgs84_36n = '''PROJCS["WGS 84 / UTM zone 36N",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",33],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","32636"]]'''
        proj_wgs84_35n = '''PROJCS["WGS 84 / UTM zone 35N",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",27],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","32635"]]'''


        proj_wgs84_32n = '''PROJCS["WGS 84 / UTM zone 32N",
        GEOGCS["WGS 84",
            DATUM["WGS_1984",
                SPHEROID["WGS 84",6378137,298.257223563,
                    AUTHORITY["EPSG","7030"]],
                AUTHORITY["EPSG","6326"]],
            PRIMEM["Greenwich",0,
                AUTHORITY["EPSG","8901"]],
            UNIT["degree",0.01745329251994328,
                AUTHORITY["EPSG","9122"]],
            AUTHORITY["EPSG","4326"]],
        UNIT["metre",1,
            AUTHORITY["EPSG","9001"]],
        PROJECTION["Transverse_Mercator"],
        PARAMETER["latitude_of_origin",0],
        PARAMETER["central_meridian",9],
        PARAMETER["scale_factor",0.9996],
        PARAMETER["false_easting",500000],
        PARAMETER["false_northing",0],
        AUTHORITY["EPSG","32632"],
        AXIS["Easting",EAST],
        AXIS["Northing",NORTH]]'''

        terrain_corrected_list = []
        for product in self.temporary_data_list:
            parameters = snappy.HashMap()
            parameters.put('demName', 'SRTM 1Sec HGT')
            parameters.put('imgResamplingMethod', 'BILINEAR_INTERPOLATION')
            parameters.put('pixelSpacingInMeter', 10.0)
            parameters.put('mapProjection', proj_wgs84_35n)
            parameters.put('nodataValueAtSea', False)
            parameters.put('saveSelectedSourceBand', True)
            terrain_corrected = snappy.GPF.createProduct('Terrain-Correction', parameters, product)
            terrain_corrected_list.append(terrain_corrected)

        print('Terrain correction is done!')
        self.temporary_data_list = terrain_corrected_list
        return self.temporary_data_list
コード例 #20
0
subsets = []  #keeps the list of all subsets objects

for product in products:
    subset = GPF.createProduct('Subset', sub_parameters, product)
    subsets.append(subset)
    print("output_bands:",list(subset.getBandNames()))
    # write file in linear units
    splits = product.getName().split("_")
    outsub = splits[0] + '_' +splits[4][:7] +'_sub'
   # snappy.ProductIO.writeProduct(subset, os.path.join(outpath, outsub), 'GeoTIFF')  #iskljuci

#********** 4   Apply orbit file    *********************
#****************************************************

aof_parameters = snappy.HashMap()
aof_parameters.put('Apply-Orbit-File', True)
aofs=[]
for sub in subsets:
    apply_orbit = snappy.GPF.createProduct('Apply-Orbit-File',aof_parameters,sub)
    aofs.append(apply_orbit)
    print("output_bands:",list(apply_orbit.getBandNames()))

#******    5. Thermal Noise Removeal  ************************
#**************************************************************

tnr = []  #bucket to store objects of TNR
TNR_parameters = snappy.HashMap()
TNR_parameters.put('removeThermalNoise', True)
for aof in aofs:
    thermal_noise = snappy.GPF.createProduct('ThermalNoiseRemoval',TNR_parameters,aof)