Beispiel #1
0
def on_run_button_clicked(b):
    global result,m,collection,count,timestamplist1, \
           w_startdate,w_enddate,w_orbitpass,w_changemap, \
           w_relativeorbitnumber,w_significance,w_median, \
           collectionmean
    try:
        w_text.value = 'running...'
        collection = ee.ImageCollection('COPERNICUS/S1_GRD') \
                  .filterBounds(poly) \
                  .filterDate(ee.Date(w_startdate.value), ee.Date(w_enddate.value)) \
                  .filter(ee.Filter.eq('transmitterReceiverPolarisation', ['VV','VH'])) \
                  .filter(ee.Filter.eq('resolution_meters', 10)) \
                  .filter(ee.Filter.eq('instrumentMode', 'IW')) \
                  .filter(ee.Filter.eq('orbitProperties_pass', w_orbitpass.value))   
        if w_relativeorbitnumber.value > 0:
            collection = collection.filter(ee.Filter.eq('relativeOrbitNumber_start', int(w_relativeorbitnumber.value)))   
        if w_platform.value != 'Both':
            collection = collection.filter(ee.Filter.eq('platform_number', w_platform.value))         
        collection = collection.sort('system:time_start') 

        acquisition_times = ee.List(collection.aggregate_array('system:time_start')).getInfo()
        count = len(acquisition_times) 
        if count<2:
            raise ValueError('Less than 2 images found')
        timestamplist = []
        for timestamp in acquisition_times:
            tmp = time.gmtime(int(timestamp)/1000)
            timestamplist.append(time.strftime('%x', tmp))  
#      make timestamps in YYYYMMDD format            
        timestamplist = [x.replace('/','') for x in timestamplist]  
        timestamplist = ['T20'+x[4:]+x[0:4] for x in timestamplist]
#      in case of duplicates add running integer
        timestamplist1 = [timestamplist[i] + '_' + str(i+1) for i in range(len(timestamplist))]    
        relativeorbitnumbers = map(int,ee.List(collection.aggregate_array('relativeOrbitNumber_start')).getInfo())
        rons = list(set(relativeorbitnumbers))
        txt = 'Images found: %i, platform: %s \n'%(count,w_platform.value)
        txt += 'Acquisition dates: '+timestamplist[0]+'...'+timestamplist[-1]+'\n'
        txt += 'Relative orbit numbers: '+str(rons)+'\n'
        if len(rons)==1:
            txt += 'Mean incidence angle: %f'%get_incidence_angle(collection.first())
        else:
            txt += 'Mean incidence angle: (select a rel. orbit)'
        w_text.value = txt
        pcollection = collection.map(get_vvvh)
        pList = pcollection.toList(100)   
        first = ee.Dictionary({'imlist':ee.List([]),'poly':poly}) 
        imList = ee.Dictionary(pList.iterate(clipList,first)).get('imlist')
        result = ee.Dictionary(omnibus(imList,w_significance.value,w_median.value))
        w_preview.disabled = False
#      display mean of the full collection                
        collectionmean = collection.mean() \
                               .select(0) \
                               .clip(poly) 
        if len(m.layers)>1:
            m.remove_layer(m.layers[1])
        m.add_layer(TileLayer(url=GetTileLayerUrl( collectionmean.visualize(min=-25, max=10,opacity = 1))))
    except Exception as e:
        w_text.value =  'Error: %s'%e
Beispiel #2
0
def on_run_button_clicked(b):
    global result,collection,count,timestamplist1, \
           w_startdate,w_enddate,w_orbitpass,w_changemap, \
           w_relativeorbitnumber,w_significance,w_median
    try:
        collection = ee.ImageCollection('COPERNICUS/S1_GRD') \
                  .filterBounds(poly) \
                  .filterDate(ee.Date(w_startdate.value), ee.Date(w_enddate.value)) \
                  .filter(ee.Filter.eq('transmitterReceiverPolarisation', ['VV','VH'])) \
                  .filter(ee.Filter.eq('resolution_meters', 10)) \
                  .filter(ee.Filter.eq('instrumentMode', 'IW')) \
                  .filter(ee.Filter.eq('orbitProperties_pass', w_orbitpass.value))
        if w_relativeorbitnumber.value > 0:
            collection = collection.filter(
                ee.Filter.eq('relativeOrbitNumber_start',
                             int(w_relativeorbitnumber.value)))
        collection = collection.sort('system:time_start')

        acquisition_times = ee.List(
            collection.aggregate_array('system:time_start')).getInfo()
        count = len(acquisition_times)
        if count < 2:
            raise ValueError('Less than 2 images found')
        timestamplist = []
        for timestamp in acquisition_times:
            tmp = time.gmtime(int(timestamp) / 1000)
            timestamplist.append(time.strftime('%x', tmp))
    #  make timestamps in YYYYMMDD format
        timestamplist = [x.replace('/', '') for x in timestamplist]
        timestamplist = ['T20' + x[4:] + x[0:4] for x in timestamplist]
        #  in case of duplicates add running integer
        timestamplist1 = [
            timestamplist[i] + '_' + str(i + 1)
            for i in range(len(timestamplist))
        ]
        relativeorbitnumbers = str(
            map(
                int,
                ee.List(collection.aggregate_array(
                    'relativeOrbitNumber_start')).getInfo()))
        print 'Images found: %i' % count
        print 'Acquistion dates'
        print timestamplist
        print 'Relative orbit numbers'
        print relativeorbitnumbers
        pcollection = collection.map(get_vvvh)
        pList = pcollection.toList(100)
        first = ee.Dictionary({'imlist': ee.List([]), 'poly': poly})
        imList = ee.Dictionary(pList.iterate(clipList, first)).get('imlist')
        result = ee.Dictionary(
            omnibus(imList, w_significance.value, w_median.value))
    except Exception as e:
        print 'An error occurred in Omnibus: %s' % e
Beispiel #3
0
def on_collect_button_clicked(b):
    global result,collection,count,imList,poly,timestamplist1,timestamps2, \
           s2_image,rons,mean_incidence,collectionmean,archive_crs,coords,wc
    try:
        if (w_collection.value == 'COPERNICUS/S1_GRD') or (w_collection.value
                                                           == ''):
            w_text.value = 'running on GEE archive COPERNICUS/S1_GRD ...'
            coords = ee.List(poly.bounds().coordinates().get(0))
            collection = getS1collection(coords)
            if w_relativeorbitnumber.value > 0:
                collection = collection.filter(
                    ee.Filter.eq('relativeOrbitNumber_start',
                                 int(w_relativeorbitnumber.value)))
            if w_platform.value != 'Both':
                collection = collection.filter(
                    ee.Filter.eq('platform_number', w_platform.value))
            collection = collection.sort('system:time_start')
            acquisition_times = ee.List(
                collection.aggregate_array('system:time_start')).getInfo()
            count = len(acquisition_times)
            if count < 2:
                raise ValueError('Less than 2 images found')
            timestamplist = []
            for timestamp in acquisition_times:
                tmp = time.gmtime(int(timestamp) / 1000)
                timestamplist.append(time.strftime('%x', tmp))
    #      make timestamps in YYYYMMDD format
            timestamplist = [x.replace('/', '') for x in timestamplist]
            timestamplist = ['T20' + x[4:] + x[0:4] for x in timestamplist]
            timestamplist = timestamplist[::int(w_stride.value)]
            #      in case of duplicates add running integer
            timestamplist1 = [
                timestamplist[i] + '_' + str(i + 1)
                for i in range(len(timestamplist))
            ]
            count = len(timestamplist)
            if count < 2:
                raise ValueError('Less than 2 images found, decrease stride')
            relativeorbitnumbers = map(
                int,
                ee.List(collection.aggregate_array(
                    'relativeOrbitNumber_start')).getInfo())
            rons = list(set(relativeorbitnumbers))
            txt = 'running on GEE archive ...'
            txt += 'Images found: %i, platform: %s \n' % (count,
                                                          w_platform.value)
            txt += 'Number of 10m pixels contained: %i \n' % math.floor(
                poly.area().getInfo() / 100.0)
            txt += 'Acquisition dates: %s\n' % str(timestamplist)
            txt += 'Relative orbit numbers: ' + str(rons) + '\n'
            if len(rons) == 1:
                mean_incidence = get_incidence_angle(collection.first())
                txt += 'Mean incidence angle: %f' % mean_incidence
            else:
                mean_incidence = 'undefined'
                txt += 'Mean incidence angle: (select one rel. orbit)'
            pcollection = collection.map(get_vvvh)
            collectionfirst = ee.Image(pcollection.first())
            w_exportscale.value = collectionfirst.projection().nominalScale(
            ).getInfo()
            pList = pcollection.toList(500)
            first = ee.Dictionary({
                'imlist': ee.List([]),
                'poly': poly,
                'enl': ee.Number(w_enl.value),
                'ctr': ee.Number(0),
                'stride': ee.Number(int(w_stride.value))
            })
            imList = ee.List(
                ee.Dictionary(pList.iterate(clipList, first)).get('imlist'))
            #          get a vorschau as collection mean
            collectionmean = collection.mean().select(0, 1).clip(poly).rename(
                'b0', 'b1')
            percentiles = collectionmean.reduceRegion(
                ee.Reducer.percentile([2, 98]),
                scale=w_exportscale.value,
                maxPixels=10e9)
            mn = ee.Number(percentiles.get('b0_p2'))
            mx = ee.Number(percentiles.get('b0_p98'))
            vorschau = collectionmean.select(0).visualize(
                min=mn, max=mx, opacity=w_opacity.value)
        else:
            txt = 'running on local collection %s ...\n' % w_collection.value
            collection = ee.ImageCollection(w_collection.value)
            count = collection.size().getInfo()
            txt += 'Images found: %i\n' % count
            collectionfirst = ee.Image(collection.first())
            poly = collectionfirst.geometry()
            coords = ee.List(poly.bounds().coordinates().get(0))
            center = poly.centroid().coordinates().getInfo()
            center.reverse()
            m.center = center
            w_exportscale.value = collectionfirst.projection().nominalScale(
            ).getInfo()
            if collectionfirst.get('system:time_start').getInfo() is not None:
                acquisition_times = ee.List(
                    collection.aggregate_array('system:time_start')).getInfo()
                timestamplist1 = []
                for timestamp in acquisition_times:
                    tmp = time.gmtime(int(timestamp) / 1000)
                    timestamplist1.append(time.strftime('%x', tmp))
                timestamplist1 = [x.replace('/', '') for x in timestamplist1]
                timestamplist1 = [
                    'T20' + x[4:] + x[0:4] for x in timestamplist1
                ]
                txt += 'Acquisition dates: %s' % str(timestamplist1)
            else:
                timestamplist1 = ['T%i' % (i + 1) for i in range(count)]
                txt += 'No time property available: acquisitions: %s' % str(
                    timestamplist1)
#          get a vorschau from collection mean
            collectionmean = collection.mean().clip(poly)
            percentiles = collectionmean.select(0).rename('b0').reduceRegion(
                ee.Reducer.percentile([2, 98]),
                scale=w_exportscale.value,
                maxPixels=10e9)
            mn = ee.Number(percentiles.get('b0_p2'))
            mx = ee.Number(percentiles.get('b0_p98'))
            vorschau = collectionmean.select(0).visualize(
                min=mn, max=mx, opacity=w_opacity.value)
            imList = collection.toList(100)


#      get GEE S1 archive crs for eventual image series export
        archive_crs = ee.Image(getS1collection(coords).first()).select(
            0).projection().crs().getInfo()
        #      run the algorithm
        result = omnibus(imList, w_significance.value, w_enl.value,
                         w_median.value)
        w_preview.disabled = False
        w_export_atsf.disabled = True
        s2_image = None
        #      display collection or S2
        if len(m.layers) > 3:
            m.remove_layer(m.layers[3])
        if w_S2.value:
            #          display sentinel-2 if available
            collection2 = getS2collection(coords)
            count1 = collection2.size().getInfo()
            if count1 > 0:
                s2_image = ee.Image(collection2.first()).select(
                    ['B8', 'B4', 'B3']).clip(poly)
                percentiles = s2_image.reduceRegion(ee.Reducer.percentile(
                    [2, 98]),
                                                    scale=w_exportscale.value,
                                                    maxPixels=10e9)
                mn = percentiles.values(['B8_p2', 'B4_p2', 'B3_p2'])
                mx = percentiles.values(['B8_p98', 'B4_p98', 'B3_p98'])
                vorschau = s2_image.visualize(min=mn,
                                              max=mx,
                                              opacity=w_opacity.value)
                timestamp = s2_image.get('system:time_start').getInfo()
                timestamp = time.gmtime(int(timestamp) / 1000)
                timestamp = time.strftime('%x', timestamp).replace('/', '')
                timestamps2 = '20' + timestamp[4:] + timestamp[0:4]
                txt += '\nSentinel-2 from %s' % timestamps2
        w_text.value = txt
        m.add_layer(TileLayer(url=GetTileLayerUrl(vorschau)))
    except Exception as e:
        w_text.value = 'Error: %s' % e