예제 #1
0
파일: toa_sr.py 프로젝트: shrutijain90/eetc
def get_corr_coeffs(geometry, country, max_slope=1, start_date = ee.Date('2019-01-01'), end_date = ee.Date('2019-03-31'), num_pixels= 2):
    srtm = ee.Image("USGS/SRTMGL1_003")
    topog = ee.Algorithms.Terrain(srtm).select(['elevation', 'slope', 'aspect'],['ELEV', 'SLO', 'ASP'])
    slo = topog.select('SLO')
    mask = slo.lt(max_slope)
    mask = mask.clip(geometry)

    bandnames = ['AEROS','BLUE','GREEN','RED','RDED1','RDED2','RDED3','NIR','RDED4','VAPOR','SWIR1','SWIR2']
    s2coll_1c = s2_1c.Sentinel2TOA(geometry, start_date, end_date, addVIs=False, addCloudMasks=True).get_img_coll()
    s2coll_1c = s2coll_1c.map(lambda img: maskClouds_toa(img, bandnames))
    s2coll_2a = s2_2a.Sentinel2SR(geometry, start_date, end_date, addVIs=False, addCloudMasks=True).get_img_coll()
    s2coll_2a = s2coll_2a.map(lambda img: maskClouds_sr(img, bandnames))
    imgcoll = joincoll(s2coll_1c, s2coll_2a)
    imgcoll = ee.ImageCollection(imgcoll.toList(imgcoll.size()))

    sample_points = ee.FeatureCollection(imgcoll.map(lambda img: get_samples(img, num_pixels, geometry, mask))).flatten()
    coefficients = ee.FeatureCollection(ee.List([
        get_coeffs(sample_points, bandname, country) for bandname in bandnames
    ]))

    task = export_features(coefficients, f"s2_correction_coeffs/s2_corr_coeffs_{country}.csv", export_to='gcs', bucket_name='ag_common')
    
    return task

    
예제 #2
0
    def test_base_collection(self):
        """
        Test base collection (raw S2 assets).
        """
        # Generate base collection.
        s2base = sentinel2.Sentinel2TOA(self.roi, self.sdate, self.edate)
        testimg_base = ee.Image(s2base.coll.first())  # TODO tests should be agnostic to the underlying implementation

        expected_bands = [
            u'AEROS', u'BLUE', u'GREEN', u'RED', u'RDED1', u'RDED2', u'RDED3',
            u'NIR', u'RDED4', u'VAPOR', u'CIRRU', u'SWIR1', u'SWIR2', u'QA10',
            u'QA20', u'QA60'
        ]
        compare_bands(self, testimg_base, expected_bands, {'msg': 'Sentinel 2 base image had the wrong bands'})
예제 #3
0
    def test_cloud_mask(self):
        """
        Test Cloud masks.
        """
        # Get collection with extra bands.
        s2base = sentinel2.Sentinel2TOA(self.roi, self.sdate, self.edate)
        s2qa = s2base.get_img_coll(addVIs=True, addCloudMasks=True)
        testimg_s2qa = ee.Image(s2qa.first())

        expected_bands = [
            u'AEROS', u'BLUE', u'GREEN', u'RED', u'RDED1', u'RDED2', u'RDED3', u'NIR', u'RDED4', u'VAPOR',
            u'CIRRU', u'SWIR1', u'SWIR2', u'QA10', u'QA20', u'QA60', u'QA60_DECODED', u'DOY', u'QA_HOLLST',
            u'QA_FSEV1', u'NBR1', u'NBR2', u'STI', u'NDTI', u'CRC', u'REIP', u'GCVI', u'RDGCVI1', u'RDGCVI2',
            u'MTCI', u'MTCI2', u'WDRVI', u'GRWDRVI', u'RDWDRVI', u'RDNDVI1', u'RDNDVI2', u'NDVI'
        ]
        compare_bands(self, testimg_s2qa, expected_bands, {'msg': 'Sentinel 2 with VIs and cloud masks had the wrong bands'})
예제 #4
0
    def test_VIs_constructor(self):
        """
        Test VIs.
        """
        # Get collection with extra bands.
        s2base = sentinel2.Sentinel2TOA(
            self.roi, self.sdate, self.edate,
            addVIs=True, addCloudMasks=False,
        )
        s2extra = s2base.get_img_coll()
        testimg_s2extra = ee.Image(s2extra.first())

        expected_bands = [
            u'AEROS', u'BLUE', u'GREEN', u'RED', u'RDED1', u'RDED2', u'RDED3', u'NIR', u'RDED4',
            u'VAPOR', u'CIRRU', u'SWIR1', u'SWIR2', u'QA10', u'QA20', u'QA60', u'NBR1', u'NBR2',
            u'STI', u'NDTI', u'CRC', u'REIP', u'GCVI', u'RDGCVI1', u'RDGCVI2', u'MTCI', u'MTCI2',
            u'WDRVI', u'GRWDRVI', u'RDWDRVI', u'RDNDVI1', u'RDNDVI2', u'NDVI'
        ]
        compare_bands(self, testimg_s2extra, expected_bands, {'msg': 'Sentinel 2 with VIs had the wrong bands'})