Commit 39431e78 authored by BorjaEst's avatar BorjaEst
Browse files

Add log text at utils module

parent 2dc2df7b
...@@ -4,6 +4,9 @@ import os ...@@ -4,6 +4,9 @@ import os
import yaml import yaml
import netCDF4 import netCDF4
import xarray as xr import xarray as xr
import logging
logger = logging.getLogger('o3skim.utils')
@contextmanager @contextmanager
...@@ -12,15 +15,18 @@ def cd(newdir): ...@@ -12,15 +15,18 @@ def cd(newdir):
prevdir = os.getcwd() prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir)) os.chdir(os.path.expanduser(newdir))
try: try:
logger.debug("Temp dir change to: '%s'", newdir)
yield yield
finally: finally:
os.chdir(prevdir) os.chdir(prevdir)
logger.debug("Restore directory: '%s'", prevdir)
def load(yaml_file): def load(yaml_file):
"""Loads the .yaml file with the sources configurations""" """Loads the .yaml file with the sources configurations"""
with open(yaml_file, "r") as ymlfile: with open(yaml_file, "r") as ymlfile:
return yaml.load(ymlfile) config = yaml.load(ymlfile)
logging.debug("Configuration data: %s", config)
return config
def create_empty_netCDF(fname): def create_empty_netCDF(fname):
...@@ -34,5 +40,6 @@ def to_netcdf(path, name, dataset): ...@@ -34,5 +40,6 @@ def to_netcdf(path, name, dataset):
"""Creates or appends data to named netcdf files""" """Creates or appends data to named netcdf files"""
years, dsx = zip(*dataset.groupby("time.year")) years, dsx = zip(*dataset.groupby("time.year"))
fnames = [path + "/" + name + "_%s.nc" % y for y in years] fnames = [path + "/" + name + "_%s.nc" % y for y in years]
logging.info("Save dataset into: %s", fnames)
[create_empty_netCDF(fn) for fn in fnames if not os.path.isfile(fn)] [create_empty_netCDF(fn) for fn in fnames if not os.path.isfile(fn)]
xr.save_mfdataset(dsx, fnames, mode='a') xr.save_mfdataset(dsx, fnames, mode='a')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment