# Path: AC_tools/bpch2netCDF.py
# def convert_to_netCDF(folder=None, filename='ctm.nc', bpch_file_list=None,
#                       remake=False, hemco_file_list=None, verbose=True,
#                       bpch_file_type="*.ctm.nc"):
#     """
#     Converts GEOS-Chem outputs to netCDF
# 
#     Parameters
#     ----------
#     folder (str): specify the folder you want to use - defaults to cwd
#     filename (str):  specific the netCDF filename you want to use
#     bpch_file_list (list): list the bpch files you want to use
#     remake (bool): Overwrite any old files (default=False)
# 
#     Notes
#     -----
#     Setup for:
#     - bpch_to_netCDF
#     - hemco_to_netCDF
#     - planeflight_to_netCDF
#     """
#     logging.debug("Convert to netCDF called with folder={},".format(folder) +
#                   " bpch_file_type={}/filename={}".format(bpch_file_type, filename))
# 
# #    try:
#     bpch_to_netCDF(folder=folder, filename=filename,
#                    bpch_file_list=bpch_file_list, remake=remake,
#                    file_type=bpch_file_type, verbose=verbose)
# #    except:
# #        logging.error("Could not convert bpch to netCDF in {_dir}"\
# #                .format(_dir=folder))
# #    try:
# #        hemco_to_netCDF( folder, hemco_file_list, remake)
# #    except:
# #        logging.warning("Could not convert hemco to netCDF in {_dir}"\
# #                .format(_dir=folder))
# 
#     return


import os
import sys
import csv
import glob
        import pygchem
            import pygchem.diagnostics as gdiag
                import pygchem.datafields as datasets
import pandas as pd
import xarray as xr
import re
        import iris
import logging
import numpy as np
import scipy.stats as stats
import math
import time
import calendar
import datetime as datetime
        import os
        import inspect
    import os
    import xarray as xr
    import inspect
            import glob
        import os.path
    import os
    import sys
    import time
    import gc
    import glob
    import shutil
    import shutil
    import os
                from pygchem import datasets
from netCDF4 import Dataset
from time import mktime
from datetime import datetime as datetime_
from .core import *
from .generic import *
from .AC_time import *
from .planeflight import *
from .variables import *
from .bpch2netCDF import convert_to_netCDF
from . obsolete.plotting_REDUNDANT import *
from . obsolete.variables_REDUNDANT import *
from . obsolete.misc_REDUNDANT import *
            from .bpch2netCDF import hemco_to_netCDF
            from .bpch2netCDF import convert_to_netCDF
        from .bpch2netCDF import convert_to_netCDF
        from .bpch2netCDF import convert_to_netCDF
    from calendar import monthrange
    from .bpch2netCDF import convert_to_netCDF

def get_gc_datetime(wd=None, spec='O3', cat='IJ-AVG-$',
                    filename='ctm.nc',
                    date_str='hours since %Y-%m-%d %H:%M:%S',
                    verbose=False, debug=False):
    """
    Return list of months in GEOS-Chem output (ctm.bpch or NetCDF)

    Parameters
    ----------
    cat (str): GAMAP species category
    debug (bool): legacy debug option, replaced by python logging
    filename (Str): name of NetCDF file (e.g. ctm.nc or ts_ctm.nc)
    spec (str): species/tracer/variable name
    ver (str): The GEOS-Chem halogen version that is being used
    wd (str): Specify the wd to get the results from a run.

    Returns
    -------
    (list)

    Notes
    -----
    """
    logging.info('get_gc_datetime called @: {} with file: {}'.format(wd,
                                                                     filename))
    # Extract datetime from cube
    # Create NetCDf if not created.
    fname = wd + '/'+filename
    if not os.path.isfile(fname):

# Path: AC_tools/bpch2netCDF.py
# def convert_to_netCDF(folder=None, filename='ctm.nc', bpch_file_list=None,
#                       remake=False, hemco_file_list=None, verbose=True,
#                       bpch_file_type="*.ctm.nc"):
#     """
#     Converts GEOS-Chem outputs to netCDF
# 
#     Parameters
#     ----------
#     folder (str): specify the folder you want to use - defaults to cwd
#     filename (str):  specific the netCDF filename you want to use
#     bpch_file_list (list): list the bpch files you want to use
#     remake (bool): Overwrite any old files (default=False)
# 
#     Notes
#     -----
#     Setup for:
#     - bpch_to_netCDF
#     - hemco_to_netCDF
#     - planeflight_to_netCDF
#     """
#     logging.debug("Convert to netCDF called with folder={},".format(folder) +
#                   " bpch_file_type={}/filename={}".format(bpch_file_type, filename))
# 
# #    try:
#     bpch_to_netCDF(folder=folder, filename=filename,
#                    bpch_file_list=bpch_file_list, remake=remake,
#                    file_type=bpch_file_type, verbose=verbose)
# #    except:
# #        logging.error("Could not convert bpch to netCDF in {_dir}"\
# #                .format(_dir=folder))
# #    try:
# #        hemco_to_netCDF( folder, hemco_file_list, remake)
# #    except:
# #        logging.warning("Could not convert hemco to netCDF in {_dir}"\
# #                .format(_dir=folder))
# 
#     return


# Path: AC_tools/GEOSChem_bpch.py
import os
import sys
import csv
import glob
        import pygchem
            import pygchem.diagnostics as gdiag
                import pygchem.datafields as datasets
import pandas as pd
import xarray as xr
import re
        import iris
import logging
import numpy as np
import scipy.stats as stats
import math
import time
import calendar
import datetime as datetime
        import os
        import inspect
    import os
    import xarray as xr
    import inspect
            import glob
        import os.path
    import os
    import sys
    import time
    import gc
    import glob
    import shutil
    import shutil
    import os
                from pygchem import datasets
from netCDF4 import Dataset
from time import mktime
from datetime import datetime as datetime_
from .core import *
from .generic import *
from .AC_time import *
from .planeflight import *
from .variables import *
from .bpch2netCDF import convert_to_netCDF
from . obsolete.plotting_REDUNDANT import *
from . obsolete.variables_REDUNDANT import *
from . obsolete.misc_REDUNDANT import *
            from .bpch2netCDF import hemco_to_netCDF
            from .bpch2netCDF import convert_to_netCDF
        from .bpch2netCDF import convert_to_netCDF
        from .bpch2netCDF import convert_to_netCDF
    from calendar import monthrange
    from .bpch2netCDF import convert_to_netCDF


def get_gc_datetime(wd=None, spec='O3', cat='IJ-AVG-$',
                    filename='ctm.nc',
                    date_str='hours since %Y-%m-%d %H:%M:%S',
                    verbose=False, debug=False):
    """
    Return list of months in GEOS-Chem output (ctm.bpch or NetCDF)

    Parameters
    ----------
    cat (str): GAMAP species category
    debug (bool): legacy debug option, replaced by python logging
    filename (Str): name of NetCDF file (e.g. ctm.nc or ts_ctm.nc)
    spec (str): species/tracer/variable name
    ver (str): The GEOS-Chem halogen version that is being used
    wd (str): Specify the wd to get the results from a run.

    Returns
    -------
    (list)

    Notes
    -----
    """
    logging.info('get_gc_datetime called @: {} with file: {}'.format(wd,
                                                                     filename))
    # Extract datetime from cube
    # Create NetCDf if not created.
    fname = wd + '/'+filename
    if not os.path.isfile(fname):

        convert_to_netCDF(wd)