Beispiel #1
0
def main(platform, product_type, min_lon, max_lon, min_lat, max_lat,
         red, green, blue, start_date, end_date, dc_config):
    """
    Description:
      Command-line mosaicking tool - creates a true color mosaic from the
        data retrieved by the Data Cube and save a GeoTIFF of the results
    Assumptions:
      The command-line tool assumes there is a measurement called cf_mask
    Inputs:
      platform (str)
      product_type (str)
      min_lon (str)
      max_lon (str)
      min_lat (str)
      max_lat (str)
      start_date (str)
      end_date (str)
      dc_config (str)
    """

    # Initialize data cube object
    dc = datacube.Datacube(config=dc_config,
                           app='dc-mosaicker')

    # Validate arguments
    products = dc.list_products()
    platform_names = set([product[6] for product in products.values])
    if platform not in platform_names:
        print 'ERROR: Invalid platform.'
        print 'Valid platforms are:'
        for name in platform_names:
            print name
        return

    product_names = [product[0] for product in products.values]
    if product_type not in product_names:
        print 'ERROR: Invalid product type.'
        print 'Valid product types are:'
        for name in product_names:
            print name
        return

    measurements = dc.list_measurements()
    index_1 = measurements.keys()[0] # Doesn't matter what the actual value is,
                                     # just need to get into the next layer of the
                                     # DataFrame.. better way?
    bands = set(measurements[index_1][product_type].keys())
    if not set([red, green, blue]).issubset(bands):
        print 'ERROR: Invalid product type.'
        print 'Valid product types are:'
        for band in bands:
            print band
        return

    try:
        min_lon = float(args.min_lon)
        max_lon = float(args.max_lon)
        min_lat = float(args.min_lat)
        max_lat = float(args.max_lat)
    except:
        print 'ERROR: Longitudes/Latitudes must be float values'
        return

    try:
        start_date_str = start_date
        end_date_str = end_date
        start_date = datetime.strptime(start_date, '%Y-%m-%d')
        end_date = datetime.strptime(end_date, '%Y-%m-%d')
    except:
        print 'ERROR: Invalid date format. Date format: YYYY-MM-DD'
        return

    if not os.path.exists(dc_config):
        print 'ERROR: Invalid file path for dc_config'
        return

    # Retrieve data from Data Cube
    dataset_in = dc.load(platform=platform,
                         product=product_type,
                         time=(start_date, end_date),
                         lon=(min_lon, max_lon),
                         lat=(min_lat, max_lat),
                         measurements=[red, green, blue, 'cf_mask'])

    # Get information needed for saving as GeoTIFF

    # Spatial ref
    crs = dataset_in.crs
    spatial_ref = utilities.get_spatial_ref(crs)

    # Upper left coordinates
    ul_lon = dataset_in.longitude.values[0]
    ul_lat = dataset_in.latitude.values[0]

    # Resolution
    products = dc.list_products()
    resolution = products.resolution[products.name == 'ls7_ledaps']
    lon_dist = resolution.values[0][1]
    lat_dist = resolution.values[0][0]

    # Rotation
    lon_rtn = 0
    lat_rtn = 0

    geotransform = (ul_lon, lon_dist, lon_rtn, ul_lat, lat_rtn, lat_dist)

    mosaic = create_mosaic(dataset_in)

    out_file = ( str(min_lon) + '_' + str(min_lat) + '_'
               + start_date_str + '_' + end_date_str
               + '_mosaic.tif' )

    utilities.save_to_geotiff(out_file, gdal.GDT_Float32, mosaic, geotransform, spatial_ref)
def main(classifier, platform, product_type, min_lon, max_lon, min_lat,
         max_lat, start_date, end_date, dc_config):
    """
    Description:
      Command-line water detection tool - creates a time-series from
        water analysis performed on data retrieved by the Data Cube,
        shows plots of the normalized water observations (total water
        observations / total clear observations), total water observations,
        and total clear observations, and saves a GeoTIFF of the results
    Assumptions:
      The command-line tool assumes there is a measurement called cf_mask
    Inputs:
      classifier (str)
      platform (str)
      product_type (str)
      min_lon (str)
      max_lon (str)
      min_lat (str)
      max_lat (str)
      start_date (str)
      end_date (str)
      dc_config (str)
    """

    # Initialize data cube object
    dc = datacube.Datacube(config=dc_config, app='dc-mosaicker')

    # Validate arguments
    if classifier not in ['cfmask', 'ledaps', 'wofs']:
        print(
            'ERROR: Unknown water classifier. Classifier options: cfmask, ledaps, wofs'
        )
        return

    products = dc.list_products()
    platform_names = set([product[6] for product in products.values])
    if platform not in platform_names:
        print('ERROR: Invalid platform.')
        print('Valid platforms are:')
        for name in platform_names:
            print(name)
        return

    product_names = [product[0] for product in products.values]
    if product_type not in product_names:
        print('ERROR: Invalid product type.')
        print('Valid product types are:')
        for name in product_names:
            print(name)
        return

    try:
        min_lon = float(args.min_lon)
        max_lon = float(args.max_lon)
        min_lat = float(args.min_lat)
        max_lat = float(args.max_lat)
    except:
        print('ERROR: Longitudes/Latitudes must be float values')
        return

    try:
        start_date_str = start_date
        end_date_str = end_date
        start_date = datetime.strptime(start_date, '%Y-%m-%d')
        end_date = datetime.strptime(end_date, '%Y-%m-%d')
    except:
        print('ERROR: Invalid date format. Date format: YYYY-MM-DD')
        return

    if not os.path.exists(dc_config):
        print('ERROR: Invalid file path for dc_config')
        return

    # Retrieve data from Data Cube
    dataset_in = dc.load(platform=platform,
                         product=product_type,
                         time=(start_date, end_date),
                         lon=(min_lon, max_lon),
                         lat=(min_lat, max_lat))

    # Get information needed for saving as GeoTIFF

    # Spatial ref
    crs = dataset_in.crs
    spatial_ref = utilities.get_spatial_ref(crs)

    # Upper left coordinates
    ul_lon = dataset_in.longitude.values[0]
    ul_lat = dataset_in.latitude.values[0]

    # Resolution
    products = dc.list_products()
    resolution = products.resolution[products.name == 'ls7_ledaps']
    lon_dist = resolution.values[0][1]
    lat_dist = resolution.values[0][0]

    # Rotation
    lon_rtn = 0
    lat_rtn = 0

    geotransform = (ul_lon, lon_dist, lon_rtn, ul_lat, lat_rtn, lat_dist)

    # Run desired classifier
    water_class = None
    if classifier == 'cfmask':  #TODO: implement when cfmask_classify is refactored
        return
    elif classifier == 'ledaps':  #TODO: implement when cfmask_classify is refactored
        return
    elif classifier == 'wofs':
        water_class = wofs_classify(dataset_in)

    dataset_out = utilities.perform_timeseries_analysis(water_class)

    print(dataset_out)

    out_file = (str(min_lon) + '_' + str(min_lat) + '_' + start_date_str +
                '_' + end_date_str + '_' + classifier + '_.tif')

    utilities.save_to_geotiff(out_file, gdal.GDT_Float32, dataset_out,
                              geotransform, spatial_ref)
Beispiel #3
0
def main(platform, product_type, min_lon, max_lon, min_lat, max_lat, red,
         green, blue, start_date, end_date, dc_config):
    """
    Description:
      Command-line mosaicking tool - creates a true color mosaic from the
        data retrieved by the Data Cube and save a GeoTIFF of the results
    Assumptions:
      The command-line tool assumes there is a measurement called cf_mask
    Inputs:
      platform (str)
      product_type (str)
      min_lon (str)
      max_lon (str)
      min_lat (str)
      max_lat (str)
      start_date (str)
      end_date (str)
      dc_config (str)
    """

    # Initialize data cube object
    dc = datacube.Datacube(config=dc_config, app='dc-mosaicker')

    # Validate arguments
    products = dc.list_products()
    platform_names = set([product[6] for product in products.values])
    if platform not in platform_names:
        print 'ERROR: Invalid platform.'
        print 'Valid platforms are:'
        for name in platform_names:
            print name
        return

    product_names = [product[0] for product in products.values]
    if product_type not in product_names:
        print 'ERROR: Invalid product type.'
        print 'Valid product types are:'
        for name in product_names:
            print name
        return

    measurements = dc.list_measurements()
    index_1 = measurements.keys()[
        0]  # Doesn't matter what the actual value is,
    # just need to get into the next layer of the
    # DataFrame.. better way?
    bands = set(measurements[index_1][product_type].keys())
    if not set([red, green, blue]).issubset(bands):
        print 'ERROR: Invalid product type.'
        print 'Valid product types are:'
        for band in bands:
            print band
        return

    try:
        min_lon = float(args.min_lon)
        max_lon = float(args.max_lon)
        min_lat = float(args.min_lat)
        max_lat = float(args.max_lat)
    except:
        print 'ERROR: Longitudes/Latitudes must be float values'
        return

    try:
        start_date_str = start_date
        end_date_str = end_date
        start_date = datetime.strptime(start_date, '%Y-%m-%d')
        end_date = datetime.strptime(end_date, '%Y-%m-%d')
    except:
        print 'ERROR: Invalid date format. Date format: YYYY-MM-DD'
        return

    if not os.path.exists(dc_config):
        print 'ERROR: Invalid file path for dc_config'
        return

    # Retrieve data from Data Cube
    dataset_in = dc.load(platform=platform,
                         product=product_type,
                         time=(start_date, end_date),
                         lon=(min_lon, max_lon),
                         lat=(min_lat, max_lat),
                         measurements=[red, green, blue, 'cf_mask'])

    # Get information needed for saving as GeoTIFF

    # Spatial ref
    crs = dataset_in.crs
    spatial_ref = utilities.get_spatial_ref(crs)

    # Upper left coordinates
    ul_lon = dataset_in.longitude.values[0]
    ul_lat = dataset_in.latitude.values[0]

    # Resolution
    products = dc.list_products()
    resolution = products.resolution[products.name == 'ls7_ledaps']
    lon_dist = resolution.values[0][1]
    lat_dist = resolution.values[0][0]

    # Rotation
    lon_rtn = 0
    lat_rtn = 0

    geotransform = (ul_lon, lon_dist, lon_rtn, ul_lat, lat_rtn, lat_dist)

    mosaic = create_mosaic(dataset_in)

    out_file = (str(min_lon) + '_' + str(min_lat) + '_' + start_date_str +
                '_' + end_date_str + '_mosaic.tif')

    utilities.save_to_geotiff(out_file, gdal.GDT_Float32, mosaic, geotransform,
                              spatial_ref)
Beispiel #4
0
def main(platform, product_type, min_lon, max_lon, min_lat, max_lat,
         start_date, end_date, dc_config):
    """
    Description:
      Command-line fractional coverage tool - TODO
    Assumptions:
      The command-line tool assumes there is a measurement called cf_mask
    Inputs:
      platform (str)
      product_type (str)
      min_lon (str)
      max_lon (str)
      min_lat (str)
      max_lat (str)
      start_date (str)
      end_date (str)
      dc_config (str)
    """

    # Initialize data cube object
    dc = datacube.Datacube(config=dc_config, app='dc-frac-cov')

    products = dc.list_products()
    platform_names = set([product[6] for product in products.values])
    if platform not in platform_names:
        print('ERROR: Invalid platform.')
        print('Valid platforms are:')
        for name in platform_names:
            print(name)
        return

    product_names = [product[0] for product in products.values]
    if product_type not in product_names:
        print('ERROR: Invalid product type.')
        print('Valid product types are:')
        for name in product_names:
            print(name)
        return

    try:
        min_lon = float(args.min_lon)
        max_lon = float(args.max_lon)
        min_lat = float(args.min_lat)
        max_lat = float(args.max_lat)
    except:
        print('ERROR: Longitudes/Latitudes must be float values')
        return

    try:
        start_date_str = start_date
        end_date_str = end_date
        start_date = datetime.strptime(start_date, '%Y-%m-%d')
        end_date = datetime.strptime(end_date, '%Y-%m-%d')
    except:
        print('ERROR: Invalid date format. Date format: YYYY-MM-DD')
        return

    if not os.path.exists(dc_config):
        print('ERROR: Invalid file path for dc_config')
        return

    # Retrieve data from Data Cube
    dataset_in = dc.load(platform=platform,
                         product=product_type,
                         time=(start_date, end_date),
                         lon=(min_lon, max_lon),
                         lat=(min_lat, max_lat))

    # Get information needed for saving as GeoTIFF

    # Spatial ref
    crs = dataset_in.crs
    spatial_ref = utilities.get_spatial_ref(crs)

    # Upper left coordinates
    ul_lon = dataset_in.longitude.values[0]
    ul_lat = dataset_in.latitude.values[0]

    # Resolution
    products = dc.list_products()
    resolution = products.resolution[products.name == 'ls7_ledaps']
    lon_dist = resolution.values[0][1]
    lat_dist = resolution.values[0][0]

    # Rotation
    lon_rtn = 0
    lat_rtn = 0

    geotransform = (ul_lon, lon_dist, lon_rtn, ul_lat, lat_rtn, lat_dist)

    dataset_out = frac_coverage_classify(dataset_in)

    out_file = (str(min_lon) + '_' + str(min_lat) + '_' + start_date_str +
                '_' + end_date_str + '_frac_coverage.tif')

    utilities.save_to_geotiff(out_file, gdal.GDT_Float32, dataset_out,
                              geotransform, spatial_ref)