コード例 #1
0
def test_radiance_wrong_shape():
    band = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1]]).astype('float32')

    # wrong ML shape
    with pytest.raises(ValueError):
        radiance.radiance(band, np.array([[1, 2, 3], [4, 5, 6]]), -0.00000001)

    # wrong AL shape
    with pytest.raises(ValueError):
        radiance.radiance(band, 35.1, np.array([1, 3]))
コード例 #2
0
def test_radiance():
    band = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1]]).astype('float32')

    ML = 0.2
    AL = -0.1

    assert np.array_equal(
        radiance.radiance(band, ML, AL),
        np.array([[0., 0., 0.], [0., 0.1, 0.1], [0.1, 0.,
                                                 0.1]]).astype(np.float32))
コード例 #3
0
def test_calculate_radiance2(test_data):
    tif, tif_meta, tif_output, tif_shape, tif_output_meta, mtl = test_data
    M = toa_utils._load_mtl_key(
        mtl,
        ['L1_METADATA_FILE', 'RADIOMETRIC_RESCALING', 'RADIANCE_MULT_BAND_'],
        5)
    A = toa_utils._load_mtl_key(
        mtl,
        ['L1_METADATA_FILE', 'RADIOMETRIC_RESCALING', 'RADIANCE_ADD_BAND_'], 5)

    toa = toa_utils.rescale(radiance.radiance(tif, M, A), 55000, np.uint16)
    assert toa.dtype == np.uint16
    assert np.all(toa) < 1.5
    assert np.all(toa) >= 0.0
コード例 #4
0
ファイル: brightness_temp.py プロジェクト: plschoon/rio-toa
def brightness_temp(img, ML, AL, K1, K2, src_nodata=0):
    """Calculate brightness temperature of Landsat 8
    as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php

    T = K2 / np.log((K1 / L)  + 1)

    and

    L = ML * Q + AL

    where:
        T  = At-satellite brightness temperature (degrees kelvin)
        L  = TOA spectral radiance (Watts / (m2 * srad * mm))
        ML = Band-specific multiplicative rescaling factor from the metadata
             (RADIANCE_MULT_BAND_x, where x is the band number)
        AL = Band-specific additive rescaling factor from the metadata
             (RADIANCE_ADD_BAND_x, where x is the band number)
        Q  = Quantized and calibrated standard product pixel values (DN)
             (ndarray img)
        K1 = Band-specific thermal conversion constant from the metadata
             (K1_CONSTANT_BAND_x, where x is the thermal band number)
        K2 = Band-specific thermal conversion constant from the metadata
             (K1_CONSTANT_BAND_x, where x is the thermal band number)


    Parameters
    -----------
    img: ndarray
        array of input pixels
    ML: float
        multiplicative rescaling factor from scene metadata
    AL: float
        additive rescaling factor from scene metadata
    K1: float
        thermal conversion constant from scene metadata
    K2: float
        thermal conversion constant from scene metadata

    Returns
    --------
    ndarray:
        float32 ndarray with shape == input shape
    """
    L = radiance.radiance(img, ML, AL, src_nodata=0)
    L[img == src_nodata] = np.NaN

    T = K2 / np.log((K1 / L) + 1)

    return T
コード例 #5
0
def test_calculate_radiance(test_data):
    tif, tif_meta, tif_output, tif_shape, tif_output_meta, mtl = test_data

    M = toa_utils._load_mtl_key(
        mtl,
        ['L1_METADATA_FILE', 'RADIOMETRIC_RESCALING', 'RADIANCE_MULT_BAND_'],
        5)
    A = toa_utils._load_mtl_key(
        mtl,
        ['L1_METADATA_FILE', 'RADIOMETRIC_RESCALING', 'RADIANCE_ADD_BAND_'], 5)

    assert isinstance(M, float)
    toa = radiance.radiance(tif, M, A)
    toa_rescaled = toa_utils.rescale(toa, 255, np.uint8)
    scale = float(np.iinfo(np.uint16).max) / float(np.iinfo(np.uint8).max)
    tif_out_rescaled = np.clip((tif_output / scale), 0,
                               np.iinfo(np.uint8).max).astype(np.uint8)
    assert toa_rescaled.dtype == np.uint8
    assert np.min(tif_out_rescaled) == np.min(toa_rescaled)
    assert int(np.max(tif_out_rescaled)) == int(np.max(toa_rescaled))
コード例 #6
0
def test_radiance_wrong_type():
    band = np.array([[9931., 9872., 9939.], [0., 5000., 100.],
                     [10000.1, 0., 100002.]]).astype('float32')

    with pytest.raises(TypeError):
        radiance.radiance(band, '45sldf', -0.1, 65.0)