# 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
# class AllImagerData(object):
#     """Class to hold all imager cloudproduct data."""
# 
#     def __init__(self, array_dict=None):
#         """Init with data from array_dict, or empty."""
#         self.latitude = None
#         self.longitude = None
#         self.nodata = None  # latlon nodata
#         self.sec1970_end = None
#         self.sec1970_start = None
#         self.time = None
#         self.num_of_lines = None
#         self.instrument = "imager"
#         # self.imager_geo = None
#         self.imager_angles = None
#         self.imager_channeldata = None
#         self.ctype = None
#         self.cma = None
#         self.ctth = None
#         self.aux = AuxiliaryObj({'surftemp': None})
#         self.cpp = None
#         self.nwp_segments = None
#         if array_dict is not None:
#             self.__dict__.update(array_dict)
# 
# class CtypeObj:
#     """Class to hold imager data for cloud type."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.cloudtype = None
#         self.ct_statusflag = None
#         self.ct_quality = None
#         self.ct_conditions = None
#         self.phaseflag = None  # v2012
# 
# class CtthObj:
#     """Class to hold imager data for CTTH."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.height = None
#         self.height_corr = None
#         self.temperature = None
#         self.pressure = None
#         self.ctth_statusflag = None
# 
# class CmaObj:
#     """Class to hold imager data for CMA and CMAPROB."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.cma_ext = None
#         self.cma_quality = None
#         self.cma_bin = None
#         self.cma_prob = None
#         self.cma_aflag = None
#         self.cma_testlist0 = None  # new in v2018
#         self.cma_testlist1 = None  # new in v2018
#         self.cma_testlist2 = None  # new in v2018
#         self.cma_testlist3 = None  # new in v2018
#         self.cma_testlist4 = None  # new in v2018
#         self.cma_testlist5 = None  # new in v2018
# 
# class ImagerAngObj(object):
#     """Class to hold imager angle data."""
# 
#     def __init__(self):
#         self.satz = SmallDataObject()
#         self.sunz = SmallDataObject()
#         self.satazimuth = SmallDataObject()
#         self.sunazimuth = SmallDataObject()
#         self.azidiff = SmallDataObject()


import atrain_match.config as config
import os
import netCDF4
import numpy as np
import calendar
import logging
from atrain_match.utils.runutils import do_some_geo_obj_logging
from atrain_match.cloudproducts.read_pps import (
    AllImagerData,
    CtypeObj, CtthObj, CmaObj,
    ImagerAngObj)
from datetime import datetime
from datetime import timedelta
    from pyhdf.SD import SD, SDC
    seconds = frac_hour*60*60.0
    cloudproducts.time = seconds + patmosx_nc.variables['time']
    do_some_geo_obj_logging(cloudproducts)
    return cloudproducts


def patmosx_read_all_hdf(filename, cross, SETTINGS):
    """Read geolocation, angles info, ctth, and cma."""
    # from pyhdf.HDF import HDF, HC
    # import pyhdf.VS
    patmosx_hdf = SD(filename, SDC.READ)
    logger.info("Opening file %s", filename)
    logger.info("Reading longitude, latitude and time ...")
    cloudproducts = read_patmosx_geoobj_hdf(patmosx_hdf, filename, cross, SETTINGS)
    logger.info("Reading angles ...")
    cloudproducts.imager_angles = read_patmosx_angobj_hdf(patmosx_hdf)
    logger.info("Reading cloud type ...")
    # , angle_obj)
    ctype, cma, ctth = read_patmosx_ctype_cmask_ctth_hdf(patmosx_hdf)
    cloudproducts.ctype = ctype
    cloudproducts.cma = cma
    cloudproducts.ctth = ctth
    logger.info("Not reading surface temperature")
    logger.info("Not reading cloud microphysical properties")
    logger.info("Not reading channel data")
    return cloudproducts


def read_patmosx_ctype_cmask_ctth_hdf(patmosx_hdf):
    """Read cloudtype and flag info from filename."""

# 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
# class AllImagerData(object):
#     """Class to hold all imager cloudproduct data."""
# 
#     def __init__(self, array_dict=None):
#         """Init with data from array_dict, or empty."""
#         self.latitude = None
#         self.longitude = None
#         self.nodata = None  # latlon nodata
#         self.sec1970_end = None
#         self.sec1970_start = None
#         self.time = None
#         self.num_of_lines = None
#         self.instrument = "imager"
#         # self.imager_geo = None
#         self.imager_angles = None
#         self.imager_channeldata = None
#         self.ctype = None
#         self.cma = None
#         self.ctth = None
#         self.aux = AuxiliaryObj({'surftemp': None})
#         self.cpp = None
#         self.nwp_segments = None
#         if array_dict is not None:
#             self.__dict__.update(array_dict)
# 
# class CtypeObj:
#     """Class to hold imager data for cloud type."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.cloudtype = None
#         self.ct_statusflag = None
#         self.ct_quality = None
#         self.ct_conditions = None
#         self.phaseflag = None  # v2012
# 
# class CtthObj:
#     """Class to hold imager data for CTTH."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.height = None
#         self.height_corr = None
#         self.temperature = None
#         self.pressure = None
#         self.ctth_statusflag = None
# 
# class CmaObj:
#     """Class to hold imager data for CMA and CMAPROB."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.cma_ext = None
#         self.cma_quality = None
#         self.cma_bin = None
#         self.cma_prob = None
#         self.cma_aflag = None
#         self.cma_testlist0 = None  # new in v2018
#         self.cma_testlist1 = None  # new in v2018
#         self.cma_testlist2 = None  # new in v2018
#         self.cma_testlist3 = None  # new in v2018
#         self.cma_testlist4 = None  # new in v2018
#         self.cma_testlist5 = None  # new in v2018
# 
# class ImagerAngObj(object):
#     """Class to hold imager angle data."""
# 
#     def __init__(self):
#         self.satz = SmallDataObject()
#         self.sunz = SmallDataObject()
#         self.satazimuth = SmallDataObject()
#         self.sunazimuth = SmallDataObject()
#         self.azidiff = SmallDataObject()


# Path: atrain_match/cloudproducts/read_patmosx.py
import atrain_match.config as config
import os
import netCDF4
import numpy as np
import calendar
import logging
from atrain_match.utils.runutils import do_some_geo_obj_logging
from atrain_match.cloudproducts.read_pps import (
    AllImagerData,
    CtypeObj, CtthObj, CmaObj,
    ImagerAngObj)
from datetime import datetime
from datetime import timedelta
    from pyhdf.SD import SD, SDC

    seconds = frac_hour*60*60.0
    cloudproducts.time = seconds + patmosx_nc.variables['time']
    do_some_geo_obj_logging(cloudproducts)
    return cloudproducts


def patmosx_read_all_hdf(filename, cross, SETTINGS):
    """Read geolocation, angles info, ctth, and cma."""
    # from pyhdf.HDF import HDF, HC
    # import pyhdf.VS
    patmosx_hdf = SD(filename, SDC.READ)
    logger.info("Opening file %s", filename)
    logger.info("Reading longitude, latitude and time ...")
    cloudproducts = read_patmosx_geoobj_hdf(patmosx_hdf, filename, cross, SETTINGS)
    logger.info("Reading angles ...")
    cloudproducts.imager_angles = read_patmosx_angobj_hdf(patmosx_hdf)
    logger.info("Reading cloud type ...")
    # , angle_obj)
    ctype, cma, ctth = read_patmosx_ctype_cmask_ctth_hdf(patmosx_hdf)
    cloudproducts.ctype = ctype
    cloudproducts.cma = cma
    cloudproducts.ctth = ctth
    logger.info("Not reading surface temperature")
    logger.info("Not reading cloud microphysical properties")
    logger.info("Not reading channel data")
    return cloudproducts


def read_patmosx_ctype_cmask_ctth_hdf(patmosx_hdf):
    """Read cloudtype and flag info from filename."""

    ctth = CtthObj()