Skip to content
Snippets Groups Projects
main.py 2.11 KiB
Newer Older
import ruamel_yaml as yml
import numpy as np

import read_data as rd
import tests

    datapath = '/ships19/hercules/pveglio/neige_data/snpp_test_input'
    fname_l1b = 'VNP02MOD.A2014213.1548.001.2017301015346.uwssec.bowtie_restored_scaled.nc'
    fname_geo = 'VNP03MOD.A2014213.1548.001.2017301015705.uwssec.nc'
    thresh_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'

    viirs_data = rd.read_data('viirs', f'{datapath}/{fname_l1b}', f'{datapath}/{fname_geo}')

    with open(thresh_file) as f:
        text = f.read()
    thresholds = yml.safe_load(text)

    confidence = np.zeros((3, viirs_data['M01'].shape[0], viirs_data['M01'].shape[1]))

    confidence[0, :, :] = tests.test_11um(viirs_data.M15.values, thresholds['Daytime_Ocean'])
    confidence[1, :, :] = tests.test_11_4diff(viirs_data.M15.values, viirs_data.M13.values,
                                              thresholds['Daytime_Ocean'], viirs_data,
                                              thresholds['Sun_Glint']['bounds'][3])

    confidence[2, :, :] = tests.nir_refl_test(viirs_data.M07.values, thresholds['Daytime_Ocean'],
                                              thresholds['Sun_Glint'], viirs_data)

    return confidence


def test_main():

    rad1 = [[255, 260, 265, 248, 223],
            [278, 285, 270, 268, 256],
            [275, 273, 266, 254, 259]]
    rad2 = [[270, 273, 271, 268, 265],
            [277, 286, 275, 277, 269],
            [280, 281, 272, 270, 267]]
    thresh_file = '/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml'

    with open(thresh_file) as f:
        text = f.read()

    rad1 = np.array(rad1)
    rad2 = np.array(rad2)

    confidence = np.zeros((2, rad1.shape[0], rad1.shape[1]))

    thresholds = yml.safe_load(text)

    confidence[0, :, :] = tests.test_11um(rad1, thresholds['Daytime_Ocean'])
    confidence[1, :, :] = tests.test_11_4diff(rad1, rad2, thresholds['Daytime_Ocean'])

    print(f'Confidence[0,:,:]: \n {confidence[0, :, :]}')
    print(f'Confidence[1,:,:]: \n {confidence[1, :, :]}')

    return confidence


if __name__ == "__main__":