# 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
    seconds = np.float64(pps_nc.variables['time'][::])  # from PPS often 0
    if 'seconds' in time_temp:
        if 'T' in time_temp:
            time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%dT%H:%M:%S+00:00')
        elif time_temp == u'seconds since 1970-01-01':
            time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%d')
        else:
            time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%d %H:%M:%S.%f +00:00')

        sec_since_1970 = calendar.timegm(time_obj)

        all_imager_obj.sec1970_start = (sec_since_1970 +
                                        np.float64(np.min(pps_nc.variables['time_bnds'][::])) +
                                        seconds)
        all_imager_obj.sec1970_end = (sec_since_1970 +
                                      np.float64(np.max(pps_nc.variables['time_bnds'][::])) +
                                      seconds)
    else:
        try:
            all_imager_obj.sec1970_start = calendar.timegm(time.strptime(pps_nc.variables['lon'].start_time,
                                                                         '%Y-%m-%d %H:%M:%S.%f'))
            all_imager_obj.sec1970_end = calendar.timegm(time.strptime(pps_nc.variables['lon'].end_time,
                                                                       '%Y-%m-%d %H:%M:%S.%f'))

        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)

# 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

    seconds = np.float64(pps_nc.variables['time'][::])  # from PPS often 0
    if 'seconds' in time_temp:
        if 'T' in time_temp:
            time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%dT%H:%M:%S+00:00')
        elif time_temp == u'seconds since 1970-01-01':
            time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%d')
        else:
            time_obj = time.strptime(time_temp, 'seconds since %Y-%m-%d %H:%M:%S.%f +00:00')

        sec_since_1970 = calendar.timegm(time_obj)

        all_imager_obj.sec1970_start = (sec_since_1970 +
                                        np.float64(np.min(pps_nc.variables['time_bnds'][::])) +
                                        seconds)
        all_imager_obj.sec1970_end = (sec_since_1970 +
                                      np.float64(np.max(pps_nc.variables['time_bnds'][::])) +
                                      seconds)
    else:
        try:
            all_imager_obj.sec1970_start = calendar.timegm(time.strptime(pps_nc.variables['lon'].start_time,
                                                                         '%Y-%m-%d %H:%M:%S.%f'))
            all_imager_obj.sec1970_end = calendar.timegm(time.strptime(pps_nc.variables['lon'].end_time,
                                                                       '%Y-%m-%d %H:%M:%S.%f'))

        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)