Skip to content

Commit

Permalink
set dir_output
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshempelmann committed Jan 10, 2019
1 parent 85da992 commit 5296c75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions eggshell/plot/plt_ncdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def plot_extend(resource, file_extension='png'):
return map_graphic


def spaghetti(resouces, variable=None, title=None, file_extension='png'):
def spaghetti(resouces, variable=None, title=None, file_extension='png', dir_output='.'):
"""
creates a png file containing the appropriate spaghetti plot as a field mean of the values.
Expand Down Expand Up @@ -108,7 +108,7 @@ def spaghetti(resouces, variable=None, title=None, file_extension='png'):
plt.title(title, fontsize=20)
plt.grid()

output_png = fig2plot(fig=fig, file_extension=file_extension)
output_png = fig2plot(fig=fig, file_extension=file_extension, dir_output=dir_output)

plt.close()
LOGGER.info('timeseries spaghetti plot done for %s with %s lines.' % (variable, c))
Expand All @@ -118,7 +118,7 @@ def spaghetti(resouces, variable=None, title=None, file_extension='png'):
return output_png


def uncertainty(resouces, variable=None, ylim=None, title=None, file_extension='png', window=None):
def uncertainty(resouces, variable=None, ylim=None, title=None, file_extension='png', window=None, dir_output='.'):
"""
creates a png file containing the appropriate uncertainty plot.
Expand Down Expand Up @@ -217,7 +217,7 @@ def uncertainty(resouces, variable=None, ylim=None, title=None, file_extension='
plt.title(title, fontsize=20)
plt.grid() # .grid_line_alpha=0.3

output_png = fig2plot(fig=fig, file_extension=file_extension)
output_png = fig2plot(fig=fig, file_extension=file_extension, dir_output=dir_output)
plt.close()
LOGGER.debug('timeseries uncertainty plot done for %s' % variable)
except Exception as err:
Expand Down
4 changes: 1 addition & 3 deletions eggshell/plot/plt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@

LOGGER = logging.getLogger("PYWPS")

work_dir = abspath(curdir)


def fig2plot(fig,
file_extension='png',
dir_output=work_dir,
dir_output='.',
bbox_inches='tight',
dpi=300, facecolor='w',
edgecolor='k', figsize=(20, 10)):
Expand Down
20 changes: 10 additions & 10 deletions eggshell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
LOGGER = logging.getLogger("EGGSHELL")


def archive(resources, format='tar', output_dir=None, mode=None):
def archive(resources, format='tar', dir_output=None, mode=None):
"""
Compresses a list of files into an archive.
:param resources: list of files to be stored in archive
:param format: archive format. Options: tar (default), zip
:param output_dir: path to output folder (default: tempory folder)
:param dir_output: path to output folder (default: tempory folder)
:param mode: for format='tar':
'w' or 'w:' open for writing without compression
'w:gz' open for writing with gzip compression
Expand All @@ -44,7 +44,7 @@ def archive(resources, format='tar', output_dir=None, mode=None):
:return str: archive path/filname.ext
"""
output_dir = output_dir or tempfile.gettempdir()
dir_output = dir_output or tempfile.gettempdir()
mode = mode or 'w'

if format not in ['tar', 'zip']:
Expand All @@ -57,7 +57,7 @@ def archive(resources, format='tar', output_dir=None, mode=None):
resources = list([resources])
resources = [x for x in resources if x is not None]

_, arch = tempfile.mkstemp(dir=output_dir, suffix='.{}'.format(format))
_, arch = tempfile.mkstemp(dir=dir_output, suffix='.{}'.format(format))

try:
if format == 'tar':
Expand Down Expand Up @@ -127,17 +127,17 @@ def download(url, cache=False):
return filename


def extract_archive(resources, output_dir=None):
def extract_archive(resources, dir_output=None):
"""
extracts archives (tar/zip)
:param resources: list of archive files (if netCDF files are in list,
they are passed and returnd as well in the return).
:param output_dir: define a directory to store the results (default: tempory folder).
:param dir_output: define a directory to store the results (default: tempory folder).
:return list: [list of extracted files]
"""
output_dir = output_dir or tempfile.gettempdir()
dir_output = dir_output or tempfile.gettempdir()

if not isinstance(resources, list):
resources = list([resources])
Expand All @@ -149,15 +149,15 @@ def extract_archive(resources, output_dir=None):
ext = os.path.basename(arch).split('.')[-1]

if ext == 'nc':
files.append(os.path.join(output_dir, arch))
files.append(os.path.join(dir_output, arch))
elif ext == 'tar':
with tarfile.open(arch, mode='r') as tar:
tar.extractall()
files.extend([os.path.join(output_dir, f) for f in tar.getnames()])
files.extend([os.path.join(dir_output, f) for f in tar.getnames()])
elif ext == 'zip':
with ZipFile(arch, mode='r') as zf:
zf.extractall()
files.extend([os.path.join(output_dir, f) for f in zf.filelist])
files.extend([os.path.join(dir_output, f) for f in zf.filelist])
else:
LOGGER.warning('file extention {} unknown'.format(ext))
except Exception as e:
Expand Down

0 comments on commit 5296c75

Please sign in to comment.