Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Continuous Integration

on:
push:
branches:
- '*'
tags:
- '*'
pull_request:

jobs:
tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Python 3.6
os: ubuntu-latest
python: '3.6'
- name: Python 3.7
os: ubuntu-latest
python: '3.7'
- name: Python 3.8
os: ubuntu-latest
python: '3.8'
- name: Python 3.9
os: ubuntu-latest
python: '3.9'
- name: Python 3.10
os: ubuntu-latest
python: '3.10'
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: 'true'
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install HDF5 and MPI
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get install libhdf5-serial-dev libmpich-dev
- name: Install Hyperion Fortran executables
run: |
./configure
make serial
sudo make install
- name: Install Hyperion Python package
run: pip install -e .[test]
- name: Run tests
run: pytest hyperion
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions hyperion/grid/amr_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np

from ..util.meshgrid import meshgrid_nd
from ..util.functions import FreezableClass, link_or_copy
from ..util.functions import FreezableClass, link_or_copy, as_str
from astropy import log as logger
from .grid_helpers import single_grid_dims

Expand Down Expand Up @@ -245,7 +245,7 @@ def read_geometry(self, group):
'''

# Check that grid is indeed AMR
if group.attrs['grid_type'].decode('utf-8') != 'amr':
if as_str(group.attrs['grid_type']) != 'amr':
raise Exception("Grid is not an AMR grid")

# Initialize levels list
Expand Down Expand Up @@ -285,7 +285,7 @@ def read_geometry(self, group):
grid.nz = int(g_grid.attrs['n3'])

# Check that advertised hash matches real hash
if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id():
if as_str(group.attrs['geometry']) != self.get_geometry_id():
raise Exception("Calculated geometry hash does not match hash in file")

def read_quantities(self, group, quantities='all'):
Expand Down
6 changes: 3 additions & 3 deletions hyperion/grid/cartesian_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy import log as logger

from ..util.meshgrid import meshgrid_nd
from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy
from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy, as_str
from .grid_helpers import single_grid_dims


Expand Down Expand Up @@ -252,15 +252,15 @@ def read_geometry(self, group):
The HDF5 group to read the grid geometry from.
'''

if group.attrs['grid_type'].decode('utf-8') != 'car':
if as_str(group.attrs['grid_type']) != 'car':
raise ValueError("Grid is not cartesian")

self.set_walls(group['walls_1']['x'],
group['walls_2']['y'],
group['walls_3']['z'])

# Check that advertised hash matches real hash
if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id():
if as_str(group.attrs['geometry']) != self.get_geometry_id():
raise Exception("Calculated geometry hash does not match hash in file")

def read_quantities(self, group, quantities='all'):
Expand Down
6 changes: 3 additions & 3 deletions hyperion/grid/cylindrical_polar_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from ..util.meshgrid import meshgrid_nd
from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy
from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy, as_str
from astropy import log as logger
from .grid_helpers import single_grid_dims

Expand Down Expand Up @@ -280,15 +280,15 @@ def read_geometry(self, group):
The HDF5 group to read the grid geometry from.
'''

if group.attrs['grid_type'].decode('utf-8') != 'cyl_pol':
if as_str(group.attrs['grid_type']) != 'cyl_pol':
raise ValueError("Grid is not cylindrical polar")

self.set_walls(group['walls_1']['w'],
group['walls_2']['z'],
group['walls_3']['p'])

# Check that advertised hash matches real hash
if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id():
if as_str(group.attrs['geometry']) != self.get_geometry_id():
raise Exception("Calculated geometry hash does not match hash in file")

def read_quantities(self, group, quantities='all'):
Expand Down
6 changes: 3 additions & 3 deletions hyperion/grid/octree_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import h5py
import numpy as np

from ..util.functions import FreezableClass, is_numpy_array, link_or_copy
from ..util.functions import FreezableClass, is_numpy_array, link_or_copy, as_str
from astropy import log as logger
from .grid_helpers import single_grid_dims

Expand Down Expand Up @@ -341,7 +341,7 @@ def read_geometry(self, group):
The HDF5 group to read the grid geometry from.
'''

if group.attrs['grid_type'].decode('utf-8') != 'oct':
if as_str(group.attrs['grid_type']) != 'oct':
raise ValueError("Grid is not an octree")

self.set_walls(group.attrs['x'],
Expand All @@ -353,7 +353,7 @@ def read_geometry(self, group):
group['cells']['refined'].astype(bool))

# Check that advertised hash matches real hash
if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id():
if as_str(group.attrs['geometry']) != self.get_geometry_id():
raise Exception("Calculated geometry hash does not match hash in file")

def read_quantities(self, group, quantities='all'):
Expand Down
6 changes: 3 additions & 3 deletions hyperion/grid/spherical_polar_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from ..util.meshgrid import meshgrid_nd
from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy
from ..util.functions import FreezableClass, is_numpy_array, monotonically_increasing, link_or_copy, as_str
from astropy import log as logger
from .grid_helpers import single_grid_dims

Expand Down Expand Up @@ -290,15 +290,15 @@ def read_geometry(self, group):
The HDF5 group to read the grid geometry from.
'''

if group.attrs['grid_type'].decode('utf-8') != 'sph_pol':
if as_str(group.attrs['grid_type']) != 'sph_pol':
raise ValueError("Grid is not spherical polar")

self.set_walls(group['walls_1']['r'],
group['walls_2']['t'],
group['walls_3']['p'])

# Check that advertised hash matches real hash
if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id():
if as_str(group.attrs['geometry']) != self.get_geometry_id():
raise Exception("Calculated geometry hash does not match hash in file")

def read_quantities(self, group, quantities='all'):
Expand Down
16 changes: 8 additions & 8 deletions hyperion/grid/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import six

from ...util.functions import random_id
from ...util.functions import virtual_file
from .. import (CartesianGrid,
CylindricalPolarGrid,
SphericalPolarGrid,
Expand Down Expand Up @@ -75,7 +75,7 @@ def setup_method(self, method):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_empty(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
g.write(f)
h = self.grid_empty[grid_type]()
h.read(f)
Expand All @@ -85,7 +85,7 @@ def test_write_read_empty(self, grid_type):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_single(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
g['density'] = []
g['density'].append(self.density[grid_type])
g.write(f)
Expand All @@ -101,7 +101,7 @@ def test_write_read_single(self, grid_type):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_double(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
g['density'] = []
g['density'].append(self.density[grid_type])
g['density'].append(self.density[grid_type])
Expand All @@ -118,7 +118,7 @@ def test_write_read_double(self, grid_type):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_double_multiple(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
g['density'] = []
g['density'].append(self.density[grid_type])
g['density'].append(self.density[grid_type])
Expand All @@ -140,7 +140,7 @@ def test_write_read_double_multiple(self, grid_type):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_type_mismatch(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
g['density'] = []
g['density'].append(self.density[grid_type])
g.write(f)
Expand All @@ -162,7 +162,7 @@ def test_write_read_type_mismatch(self, grid_type):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_hash_mismatch(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
g['density'] = []
g['density'].append(self.density[grid_type])
g.write(f)
Expand All @@ -176,7 +176,7 @@ def test_write_read_hash_mismatch(self, grid_type):
@pytest.mark.parametrize(('grid_type'), ALL_GRID_TYPES)
def test_write_read_groups_exist(self, grid_type):
g = self.grid[grid_type]
f = h5py.File(random_id(), driver='core', backing_store=False)
f = virtual_file()
f.create_group('Geometry')
f.create_group('Quantities')
g['density'] = []
Expand Down
6 changes: 3 additions & 3 deletions hyperion/grid/voronoi_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from astropy import log as logger
from astropy.table import Table

from ..util.functions import FreezableClass, is_numpy_array, link_or_copy
from ..util.functions import FreezableClass, is_numpy_array, link_or_copy, as_str
from .grid_helpers import single_grid_dims


Expand Down Expand Up @@ -362,7 +362,7 @@ def read_geometry(self, group):
The HDF5 group to read the grid geometry from.
'''

if group.attrs['grid_type'].decode('utf-8') != 'vor':
if as_str(group.attrs['grid_type']) != 'vor':
raise ValueError("Grid is not an voronoi")

coords = group['cells']['coordinates']
Expand All @@ -373,7 +373,7 @@ def read_geometry(self, group):
zmin=group.attrs['zmin'], zmax=group.attrs['zmax'])

# Check that advertised hash matches real hash
if group.attrs['geometry'].decode('utf-8') != self.get_geometry_id():
if as_str(group.attrs['geometry']) != self.get_geometry_id():
raise Exception("Calculated geometry hash does not match hash in file")

# Avoid re-computing Voronoi table
Expand Down
9 changes: 8 additions & 1 deletion hyperion/util/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def random_id(length=32):


def virtual_file():
return h5py.File(random_id(), driver='core', backing_store=False)
return h5py.File(random_id(), driver='core', backing_store=False, mode='w')


def str2bool(value):
Expand All @@ -32,6 +32,13 @@ def bool2str(value):
return np.string_('yes'.encode('utf-8')) if value else np.string_('no'.encode('utf-8'))


def as_str(value):
if isinstance(value, bytes):
return value.decode('utf-8')
else:
return value


def link_or_copy(group, name, link, copy, absolute_paths=False):
'''
Link or copy a dataset or group
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = Monte-Carlo Radiative Transfer Code
zip_safe = True
packages = find:
include_package_data = True
setup_requires = numpy>=1.11
setup_requires = oldest-supported-numpy
install_requires =
numpy>=1.11
matplotlib>=1.5
Expand Down