# 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 CppObj:
#     """Class to hold imager data for CPP."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.cpp_cot = None
#         self.cpp_cwp = None
#         self.cpp_dcot = None
#         self.cpp_dcwp = None
#         self.cpp_lwp = None
#         self.cpp_iwp = None
#         self.cpp_quality = None
#         self.cpp_status_flag = None
#         self.cpp_conditions = None
#         self.cpp_phase = None
#         self.cpp_phase_extended = None
#         self.cpp_reff = None
# 
# 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/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.cloudproducts.read_pps import (
    AllImagerData, CppObj,
    CtthObj, CmaObj,
    ImagerAngObj)
from atrain_match.utils.runutils import do_some_geo_obj_logging
import atrain_match.config as config
import os
import netCDF4
import numpy as np
import calendar
import datetime
import logging
    """
    logger.info("Opening file %s", filename)
    cci_nc = netCDF4.Dataset(filename, 'r', format='NETCDF4')
    cloudproducts = read_cci_geoobj(cci_nc)
    logger.debug("Reading ctth ...")
    cloudproducts.ctth = read_cci_ctth(cci_nc)
    logger.debug("Reading angles ...")
    cloudproducts.imager_angles = read_cci_angobj(cci_nc)
    logger.debug("Reading cloud type ...")
    cloudproducts.cma = read_cci_cma(cci_nc)

    logger.debug("Reading longitude, latitude and time ...")
    cloudproducts.instrument = "imager"
    for imager in ["avhrr", "viirs", "modis", "seviri"]:
        if imager in os.path.basename(filename).lower():
            cloudproducts.instrument = imager
    logger.debug("Not reading surface temperature")
    logger.debug("Reading cloud phase")
    cloudproducts.cpp = read_cci_phase(cci_nc)
    logger.debug("Reading LWP")
    cloudproducts.cpp = read_cci_lwp(cci_nc, cloudproducts.cpp)
    logger.debug("Not reading channel data")
    if cci_nc:
        cci_nc.close()
    return cloudproducts


def read_cci_cma(cci_nc):
    """Read cloudtype and flag info from filename
    """

# 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 CppObj:
#     """Class to hold imager data for CPP."""
# 
#     def __init__(self):
#         """Init all datasets to None."""
#         self.cpp_cot = None
#         self.cpp_cwp = None
#         self.cpp_dcot = None
#         self.cpp_dcwp = None
#         self.cpp_lwp = None
#         self.cpp_iwp = None
#         self.cpp_quality = None
#         self.cpp_status_flag = None
#         self.cpp_conditions = None
#         self.cpp_phase = None
#         self.cpp_phase_extended = None
#         self.cpp_reff = None
# 
# 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/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_cci.py
from atrain_match.cloudproducts.read_pps import (
    AllImagerData, CppObj,
    CtthObj, CmaObj,
    ImagerAngObj)
from atrain_match.utils.runutils import do_some_geo_obj_logging
import atrain_match.config as config
import os
import netCDF4
import numpy as np
import calendar
import datetime
import logging

    """
    logger.info("Opening file %s", filename)
    cci_nc = netCDF4.Dataset(filename, 'r', format='NETCDF4')
    cloudproducts = read_cci_geoobj(cci_nc)
    logger.debug("Reading ctth ...")
    cloudproducts.ctth = read_cci_ctth(cci_nc)
    logger.debug("Reading angles ...")
    cloudproducts.imager_angles = read_cci_angobj(cci_nc)
    logger.debug("Reading cloud type ...")
    cloudproducts.cma = read_cci_cma(cci_nc)

    logger.debug("Reading longitude, latitude and time ...")
    cloudproducts.instrument = "imager"
    for imager in ["avhrr", "viirs", "modis", "seviri"]:
        if imager in os.path.basename(filename).lower():
            cloudproducts.instrument = imager
    logger.debug("Not reading surface temperature")
    logger.debug("Reading cloud phase")
    cloudproducts.cpp = read_cci_phase(cci_nc)
    logger.debug("Reading LWP")
    cloudproducts.cpp = read_cci_lwp(cci_nc, cloudproducts.cpp)
    logger.debug("Not reading channel data")
    if cci_nc:
        cci_nc.close()
    return cloudproducts


def read_cci_cma(cci_nc):
    """Read cloudtype and flag info from filename
    """

    cma = CmaObj()