コード例 #1
0
 def test_open_cube_with_illegal_kwargs(self):
     with self.assertRaises(ValueError) as cm:
         open_cube(
             cube_config=cube_config,
             sentinel_hub=SentinelHub(),
             api_url=
             "https://creodias.sentinel-hub.com/api/v1/catalog/collections")
     self.assertEqual('unexpected keyword-arguments: api_url',
                      f'{cm.exception}')
コード例 #2
0
def request_save_cubes(start_date: str,
                       end_date: str,
                       lat: float,
                       lon: float,
                       data_chips_dir: str,
                       RADIUS: int = 500,
                       dataset_name: str = 'S2L1C',
                       band_names: List = ['B03', 'B08', 'CLP'],
                       max_cloud_proba: float = 0.1,
                       time_period: str = '1D'):
    """

    :param start_date: '2019-01-01'
    :param end_date: '2019-06-30'
    :param lat: latitude
    :param lon: longitude
    :param data_chips_dir: download image will be saved to this dir like 'data/chips'
    :param RADIUS: radius in meter
    :param dataset_name: either S2L1C or S2L2A
    :param band_names: a list of bands to be saved
    :param max_cloud_proba: maximum probability of cloud
    :param time_period: 1D
    :return:
    """
    from xcube_sh.cube import open_cube
    from xcube_sh.observers import Observers
    bbox = bbox_from_point(lat=lat, lon=lon, r=RADIUS)
    cube_config = CubeConfig(
        dataset_name=dataset_name,
        band_names=band_names,  # GREEN + NIR + Clouds
        tile_size=[2 * RADIUS // 10, 2 * RADIUS // 10],
        geometry=bbox,
        time_range=[start_date, end_date],
        time_period=time_period,
    )
    request_collector = Observers.request_collector()
    cube = open_cube(cube_config, observer=request_collector)

    cube, background_ndwi = preprocess(cube,
                                       max_cloud_proba=max_cloud_proba,
                                       nans_how='any',
                                       verbose=1,
                                       plot_NDWI=False)
    save_cubes(cube,
               background_ndwi,
               lat_lon=(lat, lon),
               data_dir=Path(data_chips_dir),
               verbose=False)
コード例 #3
0
def coords2counts(model,
                  coords,
                  time_window,
                  time_period='5D',
                  max_cloud_proba=0.2):
    '''
    Args:
        model: pytorch model
        coords: list or tuple, lat and lon.
        time_window: list or tuple, start and end dates.
        time_period: str, example '5D'
        max_cloud_proba: float, max cloud coverage
    Returns:
        traffic: dict, timestamps and counts
    '''
    lat, lon, radius = coords[0], coords[1], coords[2]
    bbox = bbox_from_point(lat=lat, lon=lon, r=radius)  # WGS84 coordinates
    cube_config = CubeConfig(
        dataset_name='S2L1C',
        band_names=['B03', 'B08', 'CLP'],
        tile_size=[2 * radius // 10, 2 * radius // 10],
        geometry=bbox,
        time_range=time_window,
        time_period=time_period,
    )
    cube = open_cube(cube_config, max_cache_size=2**30)
    x, timestamps = cube2tensor(
        cube,
        max_cloud_proba=max_cloud_proba,
        nans_how='any',
        verbose=0,
        plot_NDWI=False
    )  # Convert Cube to tensor (NIR + BG_NDWI) and metadata.
    heatmaps, counts = model.chip_and_count(
        x,
        filter_peaks=True,
        downsample=True,
        water_NDWI=0.4,
        plot_heatmap=True,
        timestamps=timestamps,
        plot_indicator=True)  # Detect and count boats!

    ##### Save AOI, timestamps, counts to geodB. Cache Results.
    traffic = OrderedDict()
    for timestamp, count in zip(timestamps, counts):
        traffic[timestamp] = float(count)
    return traffic
コード例 #4
0
        date_y = dates[1]
    else:
        data = "2020"
        date_x = dates[2]
        date_y = dates[3]
    IPython.display.GeoJSON(shapely.geometry.box(*aoi).__geo_interface__)
    cube_con = CubeConfig(
        dataset_name=dataset,
        band_names=band_names,
        tile_size=[512, 512],
        geometry=aoi,  # area of interest
        spatial_res=spatial_res,  #0.00009
        time_range=[date_x, date_y],
        time_period=time_period)  # what is time tolerance

    cube = open_cube(cube_con, **hc)
    scl = MaskSet(cube.SCL)

    #cube = cube.where((scl.clouds_high_probability) == 0) #shows weird errors

    cube = cube.where(
        (scl.clouds_high_probability + scl.clouds_medium_probability +
         scl.clouds_low_probability_or_unclassified + scl.cirrus) == 0)
    date = dates[0]
    t1 = cube.sel(time=cube.time[0])
    B02 = t1.B02
    B03 = t1.B03
    B04 = t1.B04
    B08 = t1.B08
    B11 = t1.B11
コード例 #5
0
IPython.display.GeoJSON(shapely.geometry.box(*aoi).__geo_interface__)

## Do Calculation for one time stamp

pixels = []

# Get Sentinel-2 L2A data

cube_con = CubeConfig(dataset_name=dataset,
                      band_names=band_names,
                      tile_size=[512, 512],
                      geometry=aoi,
                      spatial_res=spatial_res,
                      time_range=[dates[0], dates[1]],
                      time_period=time_period)
cube = open_cube(cube_con)

# Mask out clouds
scl = MaskSet(cube.SCL)
cube = cube.where(
    (scl.clouds_high_probability + scl.clouds_medium_probability +
     scl.clouds_low_probability_or_unclassified + scl.cirrus) == 0)

dates = cube.time.values

for date in dates:

    # Display status
    number = np.where(dates == date)[0][0]
    print('Computing image ' + str(number) + '/' + str(len(dates)))
コード例 #6
0
aoi = aoi_ruhr

IPython.display.GeoJSON(shapely.geometry.box(*aoi).__geo_interface__)

## Do Calculation for one time stamp

# Get Sentinel-2 L2A data

cube_con = CubeConfig(dataset_name=dataset,
                      band_names=band_names,
                      tile_size=[512, 512],
                      geometry=aoi,
                      spatial_res=spatial_res,
                      time_range=[dates[0], dates[1]],
                      time_period=time_period)
cube = open_cube(cube_con)
scl = MaskSet(cube.SCL)
cube = cube.where((scl.clouds_high_probability) == 0)

#date = dates[-1] # do exmaple calculation for last timestamp of dates
date = dates[0]
#timestamp1 = cube.sel(time = cube.time[-1])
timestamp1 = cube.sel(time=cube.time[0])
timestamp1.B02.plot.imshow(vmin=0, vmax=0.2, figsize=[16, 8])

# Compute a roads mask using band ratios and thresholds

B02 = timestamp1.B02
B03 = timestamp1.B03
B04 = timestamp1.B04
B08 = timestamp1.B08
コード例 #7
0
 def test_open_cube(self):
     cube = open_cube(cube_config=cube_config)
     self.assertIsInstance(cube, xr.Dataset)
コード例 #8
0
ファイル: vehicles.py プロジェクト: roshinim3107/Impact
        date_x = dates[0]
        date_y = dates[1]
    else:
        data= "2020"
        date_x = dates[2]
        date_y = dates[3] 
    
    cube_con = CubeConfig(dataset_name = dataset,
            band_names = bandNames, 
            tile_size = [512, 512],
            geometry = aoi, # area of interest
            spatial_res= spatialRes, #0.00009
            time_range = [date_x, date_y],
            time_period = timePeriod)

    cube = open_cube(cube_con, **hc) #  **hc -> Sentinel Hub Credentials 
    scl = MaskSet(cube.SCL) 
    cube= cube.where((scl.clouds_high_probability + scl.clouds_medium_probability + scl.clouds_low_probability_or_unclassified + scl.cirrus) == 0)
    date = dates[0]
    t= cube.sel(time = cube.time[0])
    B02 = t.B02
    B03 = t.B03
    B04 = t.B04
    B08 = t.B08
    B11 = t.B11
    ndvi_mask = ((B08 - B04) / (B08 + B04)) < max_ndvi
    ndwi_mask = ((B02 - B11) / (B02 + B11)) < max_ndwi
    ndsi_mask = ((B03 - B11) / (B03 + B11)) < max_ndsi
    low_rgb_mask = (B02 > min_rgb) * (B03 > min_rgb) * (B04 > min_rgb)
    high_rgb_mask = (B02 < max_blue) * (B03 < max_green) * (B04 < max_red)
    b11_mask = ((B11 - B03) / (B11 + B03)) < max_b11