예제 #1
0
def test_geobox():
    points_list = [
        [(148.2697, -35.20111), (149.31254, -35.20111),
         (149.31254, -36.331431), (148.2697, -36.331431)],
        [(148.2697, 35.20111), (149.31254, 35.20111), (149.31254, 36.331431),
         (148.2697, 36.331431)],
        [(-148.2697, 35.20111), (-149.31254, 35.20111),
         (-149.31254, 36.331431), (-148.2697, 36.331431)],
        [(-148.2697, -35.20111), (-149.31254, -35.20111),
         (-149.31254, -36.331431), (-148.2697, -36.331431),
         (148.2697, -35.20111)],
    ]
    for points in points_list:
        polygon = geometry.polygon(points, crs=CRS('EPSG:3577'))
        resolution = (-25, 25)
        geobox = GeoBox.from_geopolygon(polygon, resolution)

        assert abs(resolution[0]) > abs(geobox.extent.boundingbox.left -
                                        polygon.boundingbox.left)
        assert abs(resolution[0]) > abs(geobox.extent.boundingbox.right -
                                        polygon.boundingbox.right)
        assert abs(resolution[1]) > abs(geobox.extent.boundingbox.top -
                                        polygon.boundingbox.top)
        assert abs(resolution[1]) > abs(geobox.extent.boundingbox.bottom -
                                        polygon.boundingbox.bottom)
예제 #2
0
def test_write_dataset_to_netcdf(tmpnetcdf_filename):
    affine = Affine.scale(0.1, 0.1) * Affine.translation(20, 30)
    geobox = GeoBox(100, 100, affine, CRS(GEO_PROJ))
    dataset = xarray.Dataset(attrs={
        'extent': geobox.extent,
        'crs': geobox.crs
    })
    for name, coord in geobox.coordinates.items():
        dataset[name] = (name, coord.labels, {'units': coord.units})

    dataset['B10'] = (geobox.dimensions,
                      numpy.arange(10000).reshape(geobox.shape), {
                          'nodata': 0,
                          'units': '1'
                      })

    write_dataset_to_netcdf(dataset, {'foo': 'bar'},
                            {'B10': {
                                'attrs': {
                                    'abc': 'xyz'
                                }
                            }}, Path(tmpnetcdf_filename))

    with netCDF4.Dataset(tmpnetcdf_filename) as nco:
        nco.set_auto_mask(False)
        assert 'B10' in nco.variables
        var = nco.variables['B10']
        assert (var[:] == dataset['B10'].values).all()

        assert 'foo' in nco.ncattrs()
        assert nco.getncattr('foo') == 'bar'

        assert 'abc' in var.ncattrs()
        assert var.getncattr('abc') == 'xyz'
예제 #3
0
def check_open_with_api(index):
    from datacube.api.core import Datacube
    datacube = Datacube(index=index)

    input_type_name = 'ls5_nbar_albers'
    input_type = datacube.index.datasets.types.get_by_name(input_type_name)

    geobox = GeoBox(200, 200, Affine(25, 0.0, 1500000, 0.0, -25, -3900000), CRS('EPSG:3577'))
    observations = datacube.product_observations(product='ls5_nbar_albers', geopolygon=geobox.extent)
    sources = datacube.product_sources(observations, lambda ds: ds.center_time, 'time',
                                       'seconds since 1970-01-01 00:00:00')
    data = datacube.product_data(sources, geobox, input_type.measurements.values())
    assert data.blue.shape == (1, 200, 200)
예제 #4
0
    def ingest_work(tile_index, sources):
        geobox = GeoBox.from_grid_spec(grid_spec, tile_index)
#        print ("in ingest.py in ingest_word")
        data = Datacube.product_data(sources, geobox, measurements)

        nudata = data.rename(namemap)

        file_path = file_path_template.format(tile_index=tile_index,
                                              start_time=to_datetime(sources.time.values[0]).strftime('%Y%m%d%H%M%S%f'),
                                              end_time=to_datetime(sources.time.values[-1]).strftime('%Y%m%d%H%M%S%f'))
        # TODO: algorithm params
        print ("Writing product")
        nudatasets = write_product(nudata, sources, output_type,
                                   config['global_attributes'], variable_params, Path(file_path))
        return nudatasets
예제 #5
0
def check_open_with_api(index):
    from datacube import Datacube
    dc = Datacube(index=index)

    input_type_name = 'ls5_nbar_albers'
    input_type = dc.index.products.get_by_name(input_type_name)

    geobox = GeoBox(200, 200, Affine(25, 0.0, 1500000, 0.0, -25, -3900000),
                    CRS('EPSG:3577'))
    observations = dc.find_datasets(product='ls5_nbar_albers',
                                    geopolygon=geobox.extent)
    group_by = query_group_by('time')
    sources = dc.group_datasets(observations, group_by)
    data = dc.load_data(sources, geobox, input_type.measurements.values())
    assert data.blue.shape == (1, 200, 200)
예제 #6
0
def test_geobox():
    points_list = [
        [(148.2697, -35.20111), (149.31254, -35.20111), (149.31254, -36.331431), (148.2697, -36.331431)],
        [(148.2697, 35.20111), (149.31254, 35.20111), (149.31254, 36.331431), (148.2697, 36.331431)],
        [(-148.2697, 35.20111), (-149.31254, 35.20111), (-149.31254, 36.331431), (-148.2697, 36.331431)],
        [(-148.2697, -35.20111), (-149.31254, -35.20111), (-149.31254, -36.331431), (-148.2697, -36.331431)],
        ]
    for points in points_list:
        polygon = GeoPolygon(points, CRS('EPSG:3577'))
        resolution = (-25, 25)
        geobox = GeoBox.from_geopolygon(polygon, resolution)

        assert abs(resolution[0]) > abs(geobox.extent.boundingbox.left - polygon.boundingbox.left)
        assert abs(resolution[0]) > abs(geobox.extent.boundingbox.right - polygon.boundingbox.right)
        assert abs(resolution[1]) > abs(geobox.extent.boundingbox.top - polygon.boundingbox.top)
        assert abs(resolution[1]) > abs(geobox.extent.boundingbox.bottom - polygon.boundingbox.bottom)
예제 #7
0
    def ingest_work(tile_index, sources):
        geobox = GeoBox.from_grid_spec(grid_spec, tile_index)
        #        print ("in ingest.py in ingest_word")
        data = Datacube.product_data(sources, geobox, measurements)

        nudata = data.rename(namemap)

        file_path = file_path_template.format(
            tile_index=tile_index,
            start_time=to_datetime(
                sources.time.values[0]).strftime('%Y%m%d%H%M%S%f'),
            end_time=to_datetime(
                sources.time.values[-1]).strftime('%Y%m%d%H%M%S%f'))
        # TODO: algorithm params
        print("Writing product")
        nudatasets = write_product(nudata, sources, output_type,
                                   config['global_attributes'],
                                   variable_params, Path(file_path))
        return nudatasets