Skip to content

Commit

Permalink
Merge pull request #14 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Only adding mat: prefix if not already present
  • Loading branch information
shimwell authored Mar 23, 2022
2 parents 5a4ed64 + e6538eb commit 8baf258
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/anaconda-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:
jobs:
build:
runs-on: ubuntu-latest
# This container includes libgl1-mesa-glx, anaconda-client and conda-build
# https://github.com/shimwell/miniconda3_docker_image/blob/main/Dockerfile
container: ghcr.io/shimwell/miniconda
container: continuumio/miniconda3:4.10.3

steps:
- uses: actions/checkout@v2

- name: Set up conda
run: |
apt-get --allow-releaseinfo-change update
conda install -y anaconda-client conda-build
conda config --set anaconda_upload no
- name: Build and publish to conda
env:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
- name: install package
run: |
conda install -c conda-forge moab
pip install .
python -c "import stl_to_h5m"
- name: install package with tests
run: |
pip install .[tests]
- name: Run test_utils
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/conda-build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: conda-build-test

on:
workflow_dispatch:
pull_request:
branches:
- develop
- main

jobs:
build:
runs-on: ubuntu-latest
container: continuumio/miniconda3:4.10.3

steps:
- uses: actions/checkout@v2

- name: Set up conda
run: |
apt-get --allow-releaseinfo-change update
conda install -y anaconda-client conda-build
conda config --set anaconda_upload no
- name: Build and test
env:
GIT_DESCRIBE_TAG: 0.1
run: |
conda build conda -c fusion-energy -c conda-forge --config-file conda/conda_build_config.yaml
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[![Upload Python Package](https://github.com/fusion-energy/stl_to_h5m/actions/workflows/python-publish.yml/badge.svg)](https://github.com/fusion-energy/stl_to_h5m/actions/workflows/python-publish.yml)
[![anaconda-publish](https://github.com/fusion-energy/stl_to_h5m/actions/workflows/anaconda-publish.yml/badge.svg)](https://github.com/fusion-energy/stl_to_h5m/actions/workflows/anaconda-publish.yml)


[![conda-publish](https://anaconda.org/fusion-energy/stl_to_h5m/badges/version.svg)](https://anaconda.org/fusion-energy/stl_to_h5m)
[![PyPI](https://img.shields.io/pypi/v/stl-to-h5m?color=brightgreen&label=pypi&logo=grebrightgreenen&logoColor=green)](https://pypi.org/project/stl_to_h5m/)

This is a minimal Python package that provides a Python API interfaces for converting multiple STL files into a DAGMC h5m file ready for use in simulation.

Expand All @@ -15,18 +16,20 @@ Convert STL files to a DAGMC h5m file complete with material tags and ready for
**warning** this approach does not imprint and merge the geometry and therefore
requires that the STL files do not overlap. Overlaps could lead to particles
being lost during transport. If imprinting and merging is required consider
using [cad-to-h5m](https://github.com/fusion-energy/cad_to_h5m).
using [Paramak export_dagmc_h5m()](https://paramak.readthedocs.io/en/main/)
method or [cad-to-h5m](https://github.com/fusion-energy/cad_to_h5m) to make the
DAGMC geometry.

It is strongly advised to used the DAGMC overlap checker to check the
resulting h5m file (see checking for overlaps secton below).
resulting h5m file (see checking for overlaps section below).


# Installation - Conda

This single line command should install the package and dependencies (including moab)

```bash
conda install -c fusion-energy -c conda-forge stl_to_h5m
conda install -c fusion-energy -c fusion-energy stl_to_h5m
```

# Installation - Pip + Conda
Expand Down
2 changes: 0 additions & 2 deletions conda/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ python:
- 3.9
- 3.8
- 3.7
moab:
- 5.3.1
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ packages = find:
python_requires= >=3.6
install_requires=
numpy >= 1.21.1
# moab is required as well but installed via conda
# moab is required as well but not available on pypi
# moab can be installed via conda

[options.extras_require]
tests =
Expand Down
5 changes: 4 additions & 1 deletion stl_to_h5m/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def _add_stl_to_moab_core(

# reflective is a special case that should not have mat: in front
if not material_name == "reflective":
dag_material_tag = "mat:{}".format(material_name)
if material_name.startswith("mat:"):
dag_material_tag = material_name
else:
dag_material_tag = "mat:{}".format(material_name)
else:
dag_material_tag = material_name

Expand Down
20 changes: 18 additions & 2 deletions tests/test_python_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import tarfile
import unittest
import urllib.request
from pathlib import Path

from stl_to_h5m import stl_to_h5m
Expand Down Expand Up @@ -68,3 +66,21 @@ def test_h5m_file_creation_and_contents_from_multiple_h5m_files(self):
1: "mat1",
2: "mat2",
}

def test_tagnames_in_h5m_file(self):
"""Checks that a h5m file is created with the correct tag names"""

test_h5m_filename = "test_dagmc.h5m"
os.system(f"rm {test_h5m_filename}")

returned_filename = stl_to_h5m(
files_with_tags=[("tests/part2.stl", "mat:mat1")],
h5m_filename=test_h5m_filename,
)

assert Path(test_h5m_filename).is_file()
assert Path(returned_filename).is_file()
assert test_h5m_filename == returned_filename
assert di.get_volumes_from_h5m(test_h5m_filename) == [1]
assert di.get_materials_from_h5m(test_h5m_filename) == ["mat1"]
assert di.get_volumes_and_materials_from_h5m(test_h5m_filename) == {1: "mat1"}

0 comments on commit 8baf258

Please sign in to comment.