# Path: atrain_match/utils/runutils.py
# def do_some_geo_obj_logging(GeoObj):
#     import time
#     tim1 = time.strftime("%Y%m%d %H:%M",
#                          time.gmtime(GeoObj.sec1970_start))
#     tim2 = time.strftime("%Y%m%d %H:%M",
#                          time.gmtime(GeoObj.sec1970_end))
#     logger.debug("Starttime: %s, end time: %s", tim1, tim2)
#     logger.debug("Min lon: %f, max lon: %d",
#                  np.min(np.where(
#                      np.equal(GeoObj.longitude, GeoObj.nodata),
#                      99999,
#                      GeoObj.longitude)),
#                  np.max(GeoObj.longitude))
#     logger.debug("Min lat: %d, max lat: %d",
#                  np.min(np.where(
#                      np.equal(GeoObj.latitude, GeoObj.nodata),
#                      99999,
#                      GeoObj.latitude)),
#                  np.max(GeoObj.latitude))


from atrain_match.utils.runutils import do_some_geo_obj_logging
from datetime import datetime
import atrain_match.config as config
import numpy as np
import os
import netCDF4
import h5py
import logging
import time
import calendar
    import h5py
    import h5py
    import h5py
        except:    
            all_imager_obj.sec1970_start = calendar.timegm(time.strptime(pps_nc.start_time,  '%Y-%m-%d %H:%M:%S'))
            all_imager_obj.sec1970_end = calendar.timegm(time.strptime(pps_nc.end_time,  '%Y-%m-%d %H:%M:%S'))
    # print type(all_imager_obj.sec1970_start)
    all_imager_obj.sec1970_start = np.float64(all_imager_obj.sec1970_start)
    all_imager_obj.sec1970_end = np.float64(all_imager_obj.sec1970_end)
    do_some_geo_obj_logging(all_imager_obj)
    return all_imager_obj


def read_pps_geoobj_h5(filename):
    """Read geolocation and time info from filename hdf5."""
    h5file = h5py.File(filename, 'r')
    all_imager_obj = AllImagerData()
    in_fillvalue1 = h5file['where/lon/what'].attrs['nodata']
    in_fillvalue2 = h5file['where/lon/what'].attrs['missingdata']
    all_imager_obj.nodata = -999.0
    gain = h5file['where/lon/what'].attrs['gain']
    intercept = h5file['where/lon/what'].attrs['offset']
    all_imager_obj.longitude = h5file['where/lon']['data'].value*gain + intercept
    all_imager_obj.latitude = h5file['where/lat']['data'].value*gain + intercept

    all_imager_obj.longitude[h5file['where/lon']['data'].value == in_fillvalue1] = all_imager_obj.nodata
    all_imager_obj.latitude[h5file['where/lat']['data'].value == in_fillvalue1] = all_imager_obj.nodata
    all_imager_obj.longitude[h5file['where/lon']['data'].value == in_fillvalue2] = all_imager_obj.nodata
    all_imager_obj.latitude[h5file['where/lat']['data'].value == in_fillvalue2] = all_imager_obj.nodata

    all_imager_obj.num_of_lines = all_imager_obj.latitude.shape[0]
    all_imager_obj.sec1970_start = h5file['how'].attrs['startepochs']
    all_imager_obj.sec1970_end = h5file['how'].attrs['endepochs']

# Path: atrain_match/utils/runutils.py
# def do_some_geo_obj_logging(GeoObj):
#     import time
#     tim1 = time.strftime("%Y%m%d %H:%M",
#                          time.gmtime(GeoObj.sec1970_start))
#     tim2 = time.strftime("%Y%m%d %H:%M",
#                          time.gmtime(GeoObj.sec1970_end))
#     logger.debug("Starttime: %s, end time: %s", tim1, tim2)
#     logger.debug("Min lon: %f, max lon: %d",
#                  np.min(np.where(
#                      np.equal(GeoObj.longitude, GeoObj.nodata),
#                      99999,
#                      GeoObj.longitude)),
#                  np.max(GeoObj.longitude))
#     logger.debug("Min lat: %d, max lat: %d",
#                  np.min(np.where(
#                      np.equal(GeoObj.latitude, GeoObj.nodata),
#                      99999,
#                      GeoObj.latitude)),
#                  np.max(GeoObj.latitude))


# Path: atrain_match/cloudproducts/read_pps.py
from atrain_match.utils.runutils import do_some_geo_obj_logging
from datetime import datetime
import atrain_match.config as config
import numpy as np
import os
import netCDF4
import h5py
import logging
import time
import calendar
    import h5py
    import h5py
    import h5py

        except:    
            all_imager_obj.sec1970_start = calendar.timegm(time.strptime(pps_nc.start_time,  '%Y-%m-%d %H:%M:%S'))
            all_imager_obj.sec1970_end = calendar.timegm(time.strptime(pps_nc.end_time,  '%Y-%m-%d %H:%M:%S'))
    # print type(all_imager_obj.sec1970_start)
    all_imager_obj.sec1970_start = np.float64(all_imager_obj.sec1970_start)
    all_imager_obj.sec1970_end = np.float64(all_imager_obj.sec1970_end)
    do_some_geo_obj_logging(all_imager_obj)
    return all_imager_obj


def read_pps_geoobj_h5(filename):
    """Read geolocation and time info from filename hdf5."""
    h5file = h5py.File(filename, 'r')
    all_imager_obj = AllImagerData()
    in_fillvalue1 = h5file['where/lon/what'].attrs['nodata']
    in_fillvalue2 = h5file['where/lon/what'].attrs['missingdata']
    all_imager_obj.nodata = -999.0
    gain = h5file['where/lon/what'].attrs['gain']
    intercept = h5file['where/lon/what'].attrs['offset']
    all_imager_obj.longitude = h5file['where/lon']['data'].value*gain + intercept
    all_imager_obj.latitude = h5file['where/lat']['data'].value*gain + intercept

    all_imager_obj.longitude[h5file['where/lon']['data'].value == in_fillvalue1] = all_imager_obj.nodata
    all_imager_obj.latitude[h5file['where/lat']['data'].value == in_fillvalue1] = all_imager_obj.nodata
    all_imager_obj.longitude[h5file['where/lon']['data'].value == in_fillvalue2] = all_imager_obj.nodata
    all_imager_obj.latitude[h5file['where/lat']['data'].value == in_fillvalue2] = all_imager_obj.nodata

    all_imager_obj.num_of_lines = all_imager_obj.latitude.shape[0]
    all_imager_obj.sec1970_start = h5file['how'].attrs['startepochs']
    all_imager_obj.sec1970_end = h5file['how'].attrs['endepochs']

    do_some_geo_obj_logging(all_imager_obj)