Exemplo n.º 1
0
def interp_atm_lut(atm_lut_RHO, atm_lut_WVC, atm_lut_VZA, atm_lut_RAA, atm_lut,
                   rho, wvc, vza, raa):
    """ Interpolate the atmospheric lookup table for visibility estimation.

    Parameters
    ----------
    atm_lut_RHO, atm_lut_WVC, atm_lut_VZA, atm_lut_RAA: list of floats
        Atmospheric lookup table grids.
    atm_lut: ndarray
        Atmospheric lookup table, shape=(RHO, WVC, VIS, VZA, RAA).

    Returns
    -------
    interp_rdn: 1D array
        Interpolated radiance.
    """

    from AtmLUT import get_interp_range, combos

    # Get water vapor column interpolation range
    rho_dict = get_interp_range(atm_lut_RHO, rho)
    wvc_dict = get_interp_range(atm_lut_WVC, wvc)
    vza_dict = get_interp_range(atm_lut_VZA, vza)
    raa_dict = get_interp_range(atm_lut_RAA, raa)

    # Update interpolated radiance
    interp_rdn = np.zeros(atm_lut.shape[2])
    index_combos = combos([
        list(rho_dict.keys()),
        list(wvc_dict.keys()),
        list(vza_dict.keys()),
        list(raa_dict.keys())
    ])
    for index_combo in index_combos:
        rho_index, wvc_index, vza_index, raa_index = index_combo
        interp_rdn += atm_lut[
            rho_index, wvc_index, :, vza_index,
            raa_index] * rho_dict[rho_index] * wvc_dict[wvc_index] * vza_dict[
                vza_index] * raa_dict[raa_index]

    return interp_rdn
Exemplo n.º 2
0
def interp_atm_lut(atm_lut_file, WVC, VIS, VZA, RAA):
    """ Interpolate atmosphere look-up-table to different water vapor columns (WVC),
        visibilities (VIS), view zenith angles (VZA) and relative azimuth angles (RAA).

    Parameters
    ----------
    atm_lut_file: str
        Atmosphere look-up-table filename.
    WVC, VIS, VZA, RAA: list of floats
        Water vapor column, visibility, view zenith angles and relative azimuth angles.

    Returns
    -------
    WAVE: array
        Wavelengths of the atmosphere look-up-table radiance.
    lut_rdn: 2D array
        Interpolated path radiance (albedo=0.0, 0.5, 1.0).
    """

    from AtmLUT import read_binary_metadata, get_interp_range, combos

    # Read atmospheric lookup table grids
    atm_lut_metadata = read_binary_metadata(atm_lut_file + '.meta')
    atm_lut_metadata['shape'] = tuple(
        [int(v) for v in atm_lut_metadata['shape']])
    atm_lut_WVC = np.array([float(v) for v in atm_lut_metadata['WVC']])
    atm_lut_VIS = np.array([float(v) for v in atm_lut_metadata['VIS']])
    atm_lut_VZA = np.array([float(v) for v in atm_lut_metadata['VZA']])
    atm_lut_RAA = np.array([float(v) for v in atm_lut_metadata['RAA']])
    atm_lut_WAVE = np.array([float(v) for v in atm_lut_metadata['WAVE']])

    # Read atmospheric lookup table data
    atm_lut = np.memmap(atm_lut_file,
                        dtype=atm_lut_metadata['dtype'],
                        mode='r',
                        shape=atm_lut_metadata['shape']
                        )  # shape=(RHO, WVC, VIS, VZA, RAA, WAVE)

    # Initialize interpolated radiance
    interp_rdn = np.zeros((len(WVC), len(atm_lut_WAVE)), dtype='float32')

    # Do interpolation
    for i in range(len(WVC)):
        wvc, vis, vza, raa = WVC[i], VIS[i], VZA[i], RAA[i]

        # Get interpolation ranges
        wvc_dict = get_interp_range(atm_lut_WVC, wvc)
        vis_dict = get_interp_range(atm_lut_VIS, vis)
        vza_dict = get_interp_range(atm_lut_VZA, vza)
        raa_dict = get_interp_range(atm_lut_RAA, raa)

        # Get combos
        index_combos = combos([
            list(wvc_dict.keys()),
            list(vis_dict.keys()),
            list(vza_dict.keys()),
            list(raa_dict.keys())
        ])

        # Update interpolated radiance
        for index_combo in index_combos:
            wvc_index, vis_index, vza_index, raa_index = index_combo
            interp_rdn[i, :] += atm_lut[
                1, wvc_index, vis_index, vza_index,
                raa_index, :] * wvc_dict[wvc_index] * vis_dict[
                    vis_index] * vza_dict[vza_index] * raa_dict[raa_index]
        del index_combo, index_combos

    # Clear atmosphere look-up table
    atm_lut.flush()
    del atm_lut

    return atm_lut_WAVE, interp_rdn