Skip to content

Commit

Permalink
Some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tberlok committed Apr 18, 2024
1 parent 4e67ee1 commit 219bea4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
28 changes: 16 additions & 12 deletions paicos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# HDF5 file writers
from .writers.paicos_writer import PaicosWriter, PaicosTimeSeriesWriter
from .writers.arepo_image import ArepoImage
from .writers.arepo_image import ImageWriter, ArepoImage

# Image creators
from .image_creators.image_creator import ImageCreator
Expand Down Expand Up @@ -250,28 +250,31 @@ def import_user_settings():
:meta private:
"""
data_dir = None
if os.path.exists(root_dir + 'data/'):
data_dir = root_dir + 'data/'
if os.path.exists(code_dir + '/paicos_user_settings.py'):
from . import paicos_user_settings
if hasattr(paicos_user_settings, 'data_dir'):
data_dir = paicos_user_settings.data_dir
if os.path.exists(home_dir + '/.paicos_user_settings.py'):
filepath = home_dir + '/.paicos_user_settings.py'
import importlib
spec = importlib.util.spec_from_file_location('paicos_settings',
location=filepath)
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
if hasattr(foo, 'data_dir'):
data_dir = foo.data_dir


import_user_settings()

if os.path.exists(root_dir + 'data/'):
data_dir = root_dir + 'data/'
else:
try:
from .paicos_user_settings import data_dir
if data_dir is not None:
if data_dir[-1] != '/':
data_dir += '/'
except: # noqa: E722
data_dir = None

return data_dir


data_dir = import_user_settings()


# Import of GPU functionality only if
Expand All @@ -296,7 +299,8 @@ def gpu_init(gpu_num=0):
import cupy as cp
from numba import cuda

cp.cuda.Device(gpu_num).use()
if gpu_num != 0:
cp.cuda.Device(gpu_num).use()

@cuda.jit
def my_kernel(io_array):
Expand Down
8 changes: 6 additions & 2 deletions paicos/readers/paicos_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,13 @@ def find_unit(self, name, field):

if unit is False:
msg = ('\n\nUnit for field:{}, blockname:{} not implemented!'
+ '\nPlease add it to unit_specifications '
+ '\nYou can get rid of this error by changing your '
+ 'settings, i.e.,\n\npa.settings.strict_units = False\n\n'
+ 'However, this means that this quantity will not be read in. '
+ 'If you need this quantity, then the best way forward is to '
+ 'add it to the unit_specifications '
+ 'by using the pa.add_user_units '
+ 'function. You can also add the pa.add_user_units call to your'
+ 'function. You can also add the pa.add_user_units call to your '
+ 'Paicos user settings to avoid having to do this more than once. '
+ 'Alternatively, please create an issue on GitHub if you think '
+ 'others could benefit from that.'
Expand Down
3 changes: 3 additions & 0 deletions paicos/writers/arepo_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ def _perform_extra_consistency_checks(self):
np.testing.assert_array_equal(widths, self.widths)

assert f['image_info'].attrs['direction'] == self.direction


ImageWriter = ArepoImage

0 comments on commit 219bea4

Please sign in to comment.