# Path: atrain_match/libs/extract_imager_along_track.py
# def get_data_from_array(array, matched):
#     if array is None:
#         return None
#     return np.array([array[matched['row'][idx], matched['col'][idx]]
#                      for idx in range(matched['row'].shape[0])])
# 
# Path: atrain_match/config.py
# NODATA = -9


from atrain_match.libs.extract_imager_along_track import get_data_from_array
from atrain_match.config import NODATA
    from atrain_match.libs.truth_imager_match import find_main_cloudproduct_file
    from pyhdf.SD import SD, SDC
import numpy as np
import os
import h5py
import logging
def read_modis_h5(filename):
    h5file = h5py.File(filename, 'r')
    modis_06 = MOD06Obj()
    modis_06.height = h5file['mod06']['Data Fields']['cloud_top_height_1km'][:]
    modis_06.temperature = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'][:]
    modis_06.pressure = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'][:]
    modis_06.lwp = h5file['mod06']['Data Fields']['Cloud_Water_Path'][:]
    modis_06.multilayer = h5file['mod06']['Data Fields']['Cloud_Multi_Layer_Flag'][:]
    modis_06.optical_depth = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'][:]
    modis_06.cloud_emissivity = h5file['mod06']['Data Fields']['cloud_emissivity_1km'][:].astype(np.float)
    modis_06.cloud_phase = h5file['mod06']['Data Fields']['Cloud_Phase_Infrared_1km'][:].astype(np.int)
    modis_06.latitude = h5file['mod06']['Geolocation Fields']['Latitude'][:].astype(np.float)
    modis_06.longitude = h5file['mod06']['Geolocation Fields']['Longitude'][:].astype(np.float)

    h_gain = h5file['mod06']['Data Fields']['cloud_top_height_1km'].attrs['scale_factor']
    h_intercept = h5file['mod06']['Data Fields']['cloud_top_height_1km'].attrs['add_offset']
    t_gain = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'].attrs['scale_factor']
    t_intercept = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'].attrs['add_offset']
    p_gain = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'].attrs['scale_factor']
    p_intercept = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'].attrs['add_offset']
    h_nodata = h5file['mod06']['Data Fields']['cloud_top_height_1km'].attrs['_FillValue']
    t_nodata = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'].attrs['_FillValue']
    p_nodata = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'].attrs['_FillValue']

    lwp_gain = h5file['mod06']['Data Fields']['Cloud_Water_Path'].attrs['scale_factor']
    lwp_intercept = h5file['mod06']['Data Fields']['Cloud_Water_Path'].attrs['add_offset']
    lwp_nodata = h5file['mod06']['Data Fields']['Cloud_Water_Path'].attrs['_FillValue']

    od_gain = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'].attrs['scale_factor']
    od_intercept = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'].attrs['add_offset']

# Path: atrain_match/libs/extract_imager_along_track.py
# def get_data_from_array(array, matched):
#     if array is None:
#         return None
#     return np.array([array[matched['row'][idx], matched['col'][idx]]
#                      for idx in range(matched['row'].shape[0])])
# 
# Path: atrain_match/config.py
# NODATA = -9


# Path: atrain_match/cloudproducts/read_modis_products.py
from atrain_match.libs.extract_imager_along_track import get_data_from_array
from atrain_match.config import NODATA
    from atrain_match.libs.truth_imager_match import find_main_cloudproduct_file
    from pyhdf.SD import SD, SDC
import numpy as np
import os
import h5py
import logging

def read_modis_h5(filename):
    h5file = h5py.File(filename, 'r')
    modis_06 = MOD06Obj()
    modis_06.height = h5file['mod06']['Data Fields']['cloud_top_height_1km'][:]
    modis_06.temperature = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'][:]
    modis_06.pressure = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'][:]
    modis_06.lwp = h5file['mod06']['Data Fields']['Cloud_Water_Path'][:]
    modis_06.multilayer = h5file['mod06']['Data Fields']['Cloud_Multi_Layer_Flag'][:]
    modis_06.optical_depth = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'][:]
    modis_06.cloud_emissivity = h5file['mod06']['Data Fields']['cloud_emissivity_1km'][:].astype(np.float)
    modis_06.cloud_phase = h5file['mod06']['Data Fields']['Cloud_Phase_Infrared_1km'][:].astype(np.int)
    modis_06.latitude = h5file['mod06']['Geolocation Fields']['Latitude'][:].astype(np.float)
    modis_06.longitude = h5file['mod06']['Geolocation Fields']['Longitude'][:].astype(np.float)

    h_gain = h5file['mod06']['Data Fields']['cloud_top_height_1km'].attrs['scale_factor']
    h_intercept = h5file['mod06']['Data Fields']['cloud_top_height_1km'].attrs['add_offset']
    t_gain = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'].attrs['scale_factor']
    t_intercept = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'].attrs['add_offset']
    p_gain = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'].attrs['scale_factor']
    p_intercept = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'].attrs['add_offset']
    h_nodata = h5file['mod06']['Data Fields']['cloud_top_height_1km'].attrs['_FillValue']
    t_nodata = h5file['mod06']['Data Fields']['cloud_top_temperature_1km'].attrs['_FillValue']
    p_nodata = h5file['mod06']['Data Fields']['cloud_top_pressure_1km'].attrs['_FillValue']

    lwp_gain = h5file['mod06']['Data Fields']['Cloud_Water_Path'].attrs['scale_factor']
    lwp_intercept = h5file['mod06']['Data Fields']['Cloud_Water_Path'].attrs['add_offset']
    lwp_nodata = h5file['mod06']['Data Fields']['Cloud_Water_Path'].attrs['_FillValue']

    od_gain = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'].attrs['scale_factor']
    od_intercept = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'].attrs['add_offset']

    od_nodata = h5file['mod06']['Data Fields']['Cloud_Optical_Thickness'].attrs['_FillValue']