diff --git a/.gitignore b/.gitignore index 4d04522..1070006 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ test-results.xml -# ASTERIA User areas +# ASTERIA User areas, ignore all files in these directories other than the gitignores scratch/* +!scratch/.gitignore data/processed/* +!data/processed/.gitignore # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/data/processed/.gitignore b/data/processed/.gitignore new file mode 100644 index 0000000..f5b0070 --- /dev/null +++ b/data/processed/.gitignore @@ -0,0 +1,5 @@ +# Ignore all files in this directory +* + +# Do not ignore this .gitignore +!.gitignore \ No newline at end of file diff --git a/python/asteria/IO.py b/python/asteria/IO.py index 72464e3..a135db1 100644 --- a/python/asteria/IO.py +++ b/python/asteria/IO.py @@ -1,4 +1,4 @@ -from os.path import isfile +from os.path import isfile, isdir, dirname from .neutrino import Flavor import numpy as np @@ -197,7 +197,10 @@ def find(group, Interactions, Hierarchy, Flavors, Enu, time): def save(config, Interactions, Hierarchy, Flavors, Enu, time, result, force=False): h5path = '/'.join([config.abs_base_path, config.IO.table.path]) - + + if not isdir(dirname(h5path)): + raise NotADirectoryError('Directory {0} not found, aborting.'.format(dirname(h5path))) + # Test file existence if not isfile(h5path): print('Creating file: {}'.format(h5path)) diff --git a/python/asteria/__init__.py b/python/asteria/__init__.py index 394ccc8..0b6f69d 100644 --- a/python/asteria/__init__.py +++ b/python/asteria/__init__.py @@ -9,18 +9,3 @@ """ from __future__ import absolute_import from ._version import __version__ -import os - - -src_path = os.path.realpath(__path__[0]) -base_path = os.sep.join(src_path.split(os.sep)[:-2]) - -# Test for existence of scratch directory -scratch_path = os.path.join(base_path, 'scratch') -if not os.path.isdir(scratch_path): - os.mkdir(scratch_path) - -# Test for existence of processed directory -processed_path = os.path.join(base_path, 'data', 'processed') -if not os.path.isdir(processed_path): - os.mkdir(processed_path) diff --git a/scratch/.gitignore b/scratch/.gitignore new file mode 100644 index 0000000..f5b0070 --- /dev/null +++ b/scratch/.gitignore @@ -0,0 +1,5 @@ +# Ignore all files in this directory +* + +# Do not ignore this .gitignore +!.gitignore \ No newline at end of file