You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
================================================================= ERRORS =================================================================
________________________________________________ ERROR at setup of test_map_plot_default _________________________________________________
@pytest.fixture()
def test_data():
from ..GEOSChem_bpch import get_GC_output
def get_GC_output(wd, vars=None, species=None, category=None, r_cubes=False,
r_res=False, restore_zero_scaling=True, r_list=False, trop_limit=False,
dtype=np.float32, use_NetCDF=True, verbose=False, debug=False):
"""
Return data from a directory containing NetCDF/ctm.bpch files via PyGChem (>= 0.3.0 )
Parameters
----------
vars (list): variables to extract (in NetCDF form, e.g. ['IJ_AVG_S__CO'])
( alterately provide a single species and category through named input variables )
species (str): species/tracer/variable (gamap) name
category (str): diagnostic category (gamap) name
r_cubes (bool): To return Iris Cubes, set to True
r_res (bool): To return resolution of model NetCDF set to True
r_list (bool): To return data as list of arrays rather than a single array
restore_zero_scaling(Boolean): restores scale to ctm.bpch standard (e.g. v/v not pptv)
trop_limit(bool): limit to "chemical troposphere" (level 38 of model)
dtype (type): type of variable to be returned
use_NetCDF(bool): set==True to use NetCDF rather than iris cube of output
verbose (bool): legacy debug option, replaced by python logging
debug (bool): legacy debug option, replaced by python logging
Returns
-------
(np.array) of requested output or object of data (iris cube)
Notes
-----
- Core functionality of function:
ctm.bpch files are extracted for a given directory (to a NetCDF in the directory),
with only the specific category and species returned. This can either be as a Iris
Cube (retaining metadata) or as a numpy array.
- Credit for PyGChem: Ben Bovy - https://github.com/benbovy/PyGChem
- Examples and use of pygchem is discussed on Ben Bovy's GITHib
( https://github.com/benbovy/PyGChem_examples/blob/master/Tutorials/Datasets.ipynb )
- This replaces the now defunct AC_tools functions: open_ctm_bpch and get_gc_data_np
- For simplicity use variable names (species, category) as used in
the iris cube ( e.g. IJ_AVG_S__CO). if variable is unknown, just
print full dataset extracted to screen to see active diagnostics.
- Species and category variables are maintained ( and translated ) to allow for
backwards compatibility with functions written for pygchem version 0.2.0
"""
# bjn
# This function is not completly clear to me, and could do with a re-write
# The try command would probably be useful here for large parts.
# logging would also be good for replacing debug.
logging.info("Called get_GC_output")
logging.debug("get_GC_output inputs:")
logging.debug(locals())
if not isinstance(vars, type(None)):
logging.info('Opening >{}<, for var: >{}<'.format(wd, ','.join(vars)) +
'(extra) gamap variables provided: >{}< + >{}<'.format(category,
species))
# Also option to use gamap names ( species + category ) to and func converts these
# to iris cube names
if any([(not isinstance(i, type(None))) for i in (species, category)]):
# convert to Iris Cube name
if (category == None) and (vars == None):
category = "IJ-AVG-$"
if (species == None) and (vars == None):
species = 'O3'
# remove scaling for 'IJ-AVG-$' - KLUDGE - needed for all ?
if category == 'IJ-AVG-$':
category = diagnosticname_gamap2iris(category)
E NameError: name 'diagnosticname_gamap2iris' is not defined
def test_get_GC_output():
arr = get_GC_output(wd=wd, species='O3', category='IJ_AVG_S')
assert isinstance(arr, np.ndarray), 'GC output is not a numpy array'
assert round(arr.sum(), 6) == round(
0.14242639, 6), "The ozone budget doesnt seem correct({bud})".format(bud=arr.sum())
E AssertionError: The ozone budget doesnt seem correct(0.14242638647556305)
E assert 0.142426 == 0.142426
E + where 0.142426 = round(0.14242639, 6)
E + where 0.14242639 = <built-in method sum of numpy.ndarray object at 0x7f0bc868abc0>()
E + where <built-in method sum of numpy.ndarray object at 0x7f0bc868abc0> = array([[[[2.4482466e-08],\n [2.4782828e-08],\n [2.5001304e-08],\n ...,\n [1.0980792e-06],\n...877e-08],\n ...,\n [1.0854923e-06],\n [2.3876410e-07],\n [6.5473643e-08]]]], dtype=float32).sum
E + and 0.142426 = round(0.14242639, 6)
def hemco_to_netCDF(folder, hemco_file_list=None, remake=False):
"""
Conbine HEMCO diagnostic output files to a single NetCDF file.
Parameters
----------
remake (bool): overwrite existing NetCDF file
"""
if __package__ is None:
from .bpch2netCDF import get_folder
else:
from .bpch2netCDF import get_folder
folder = get_folder(folder)
output_file = os.path.join(folder, 'hemco.nc')
# If the hemco netCDF file already exists then quit unless remake=True
if not remake:
if os.path.exists(output_file):
logging.warning(output_file + ' already exists, not remaking')
return
logging.info("Combining hemco diagnostic files")
# By default look for any files that look like hemco diagnostic files:
# Look for all hemco netcdf files then remove the restart files.
if hemco_file_list == None:
hemco_files = glob.glob(folder + '/*HEMCO*.nc')
for filename in hemco_files:
if "restart" in filename:
hemco_files.remove(filename)
else:
file_list = []
for hemco_file in hemco_file_list:
full_path = os.path.join(folder, hemco_file)
if not os.path.exists(full_path):
logging.error(full_path + " could not be found")
raise IOError(
"{path} could not be found".format(path=full_path))
file_list.append(full_path)
hemco_files = file_list
if len(hemco_files) == 0:
logging.warning("No hemco diagnostic files found in {_dir}"
.format(_dir=folder))
else:
logging.debug("The following hemco files were found:")
logging.debug(str(hemco_files))
# Use iris cubes to combine the data into an output file
hemco_data = iris.load(hemco_files)
E NameError: name 'iris' is not defined
../bpch2netCDF.py:126: NameError
----------------------------------------------------------- Captured log call ------------------------------------------------------------
GEOSChem_bpch.py 497 INFO Called get hemco output.
bpch2netCDF.py 96 INFO Combining hemco diagnostic files
bpch2netCDF.py 121 DEBUG The following hemco files were found:
bpch2netCDF.py 122 DEBUG ['../../data/HEMCO_Diagnostics.nc']
____________________________________________________________ test_get_folder _____________________________________________________________
def get_folder(folder):
"""
Get name of folder that contains ctm.bpch data from command line
"""
if isinstance(folder, type(None)):
# getting the folder location from system argument
if len(sys.argv) <= 1:
logging.warning("No folder location specified for the data")
folder = os.getcwd()
else:
folder = str(sys.argv[1])
# Check folder exists
if not os.path.exists(folder):
print("Folder does not exist")
print(folder)
sys.exit()
E SystemExit
../bpch2netCDF.py:284: SystemExit
---------------------------------------------------------- Captured stdout call ----------------------------------------------------------
Folder does not exist
../data
----------------------------------------------------------- Captured log call ------------------------------------------------------------
test_bpch2netCDF.py 82 INFO beginning test
============================================================ warnings summary ============================================================
test_GEOSChem_bpch.py:8
/mnt/lustre/users/ts551/labbook/Python_progs/AC_tools/AC_tools/Tests/test_GEOSChem_bpch.py:8: PytestDeprecationWarning: the pytest.config global is deprecated. Please use request.config or pytest_configure (if you're a pytest plugin) instead.
not pytest.config.getoption("--slow"),
test_bpch2netCDF.py:17
/mnt/lustre/users/ts551/labbook/Python_progs/AC_tools/AC_tools/Tests/test_bpch2netCDF.py:17: PytestDeprecationWarning: the pytest.config global is deprecated. Please use request.config or pytest_configure (if you're a pytest plugin) instead.
not pytest.config.getoption("--slow"),
test_plotting.py:12
/mnt/lustre/users/ts551/labbook/Python_progs/AC_tools/AC_tools/Tests/test_plotting.py:12: PytestDeprecationWarning: the pytest.config global is deprecated. Please use request.config or pytest_configure (if you're a pytest plugin) instead.
not pytest.config.getoption("--slow"),
Running test suite now raises errors. This is the case since updating the module structure.
e.g.
py.test
yields the following output:
The text was updated successfully, but these errors were encountered: