Esempio n. 1
0
def test_sun_elev_calc(sun_elev_test_data):
    for d in sun_elev_test_data:
        pred_sun_el = sun_utils.sun_elevation(BoundingBox(*d['bbox']),
                                              (10, 10), d['date_acquired'],
                                              d['scene_center_time'])
        assert pred_sun_el.max() > d['mtl_sun_elevation']
        assert pred_sun_el.min() < d['mtl_sun_elevation']
Esempio n. 2
0
def _reflectance_worker(open_files, window, ij, g_args):
    """rio mucho worker for reflectance. It reads input
    files and perform reflectance calculations on each window.

    Parameters
    ------------
    open_files: list of rasterio open files
    window: tuples
    g_args: dictionary

    Returns
    ---------
    out: None
        Output is written to dst_path

    """
    data = riomucho.utils.array_stack([
      src.read(window=window).astype(np.float32)
      for src in open_files
    ])

    depth, rows, cols = data.shape

    if g_args['pixel_sunangle']:
        bbox = BoundingBox(
                    *warp.transform_bounds(
                        g_args['src_crs'],
                        {'init': u'epsg:4326'},
                        *open_files[0].window_bounds(window)))

        E = sun_utils.sun_elevation(
                        bbox,
                        (rows, cols),
                        g_args['date_collected'],
                        g_args['time_collected_utc']).reshape(rows, cols, 1)

    else:
        # We're doing whole-scene (instead of per-pixel) sunangle:
        E = np.array([g_args['E'] for i in range(depth)])

    output = toa_utils.rescale(
        reflectance(
            data,
            g_args['M'],
            g_args['A'],
            E,
            g_args['src_nodata']),
        g_args['rescale_factor'],
        g_args['dst_dtype'],
        clip=g_args['clip'])

    return output
Esempio n. 3
0
def test_sun_angle3(test_data):
    # South, Winter
    mtl = test_data[2]
    mtl_sun = mtl['L1_METADATA_FILE']['IMAGE_ATTRIBUTES']['SUN_ELEVATION']
    bbox = BoundingBox(*toa_utils._get_bounds_from_metadata(
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']))

    sunangles = sun_utils.sun_elevation(
        bbox, (100, 100),
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']['DATE_ACQUIRED'],
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']['SCENE_CENTER_TIME'])

    assert sunangles[49][49] - mtl_sun < 5
Esempio n. 4
0
def test_sun_angle2(test_data):
    # North, Summer
    mtl = test_data[1]
    mtl_sun = mtl['L1_METADATA_FILE']['IMAGE_ATTRIBUTES']['SUN_ELEVATION']
    bbox = BoundingBox(*toa_utils._get_bounds_from_metadata(
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']))

    sunangles = sun_utils.sun_elevation(
        bbox, (100, 100),
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']['DATE_ACQUIRED'],
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']['SCENE_CENTER_TIME'])

    assert np.mean(sunangles[0, :]) < np.mean(
        sunangles[-1, :]), "In N, Nrow should < Srow"
    assert sunangles.max() > mtl_sun
    assert sunangles.min() < mtl_sun
Esempio n. 5
0
def test_calculate_reflectance2(test_data):
    tif_b, tif_shape, mtl = test_data[0], test_data[4], test_data[-1]

    M = toa_utils._load_mtl_key(mtl, [
        'L1_METADATA_FILE', 'RADIOMETRIC_RESCALING', 'REFLECTANCE_MULT_BAND_'
    ], 5)
    A = toa_utils._load_mtl_key(
        mtl,
        ['L1_METADATA_FILE', 'RADIOMETRIC_RESCALING', 'REFLECTANCE_ADD_BAND_'],
        5)
    date_collected = toa_utils._load_mtl_key(
        mtl, ['L1_METADATA_FILE', 'PRODUCT_METADATA', 'DATE_ACQUIRED'])
    time_collected_utc = toa_utils._load_mtl_key(
        mtl, ['L1_METADATA_FILE', 'PRODUCT_METADATA', 'SCENE_CENTER_TIME'])
    bounds = BoundingBox(*toa_utils._get_bounds_from_metadata(
        mtl['L1_METADATA_FILE']['PRODUCT_METADATA']))
    E = sun_utils.sun_elevation(bounds, tif_shape, date_collected,
                                time_collected_utc)
    toa = reflectance.reflectance(tif_b, M, A, E)
    toa_rescaled = toa_utils.rescale(toa, 55000.0, np.uint16)
    assert toa_rescaled.dtype == np.uint16
    assert np.all(toa_rescaled) < 1.5
    assert np.all(toa_rescaled) >= 0.0