Skip to content

Commit 14d5a11

Browse files
updated docs with pypi
Added sort_compass_files function Sort compass filenames and associated tests Using absolute path for compass_data Update libra_toolbox/neutron_detection/activation_foils/compass.py Co-authored-by: Rémi Delaporte-Mathurin <40028739+RemDelaporteMathurin@users.noreply.github.com> Update libra_toolbox/neutron_detection/activation_foils/compass.py Co-authored-by: Rémi Delaporte-Mathurin <40028739+RemDelaporteMathurin@users.noreply.github.com> Added full set of test files Reduced filesize Added new test cases to test_compass Reformatted with black Deleted old test files removed large files
1 parent d06cc63 commit 14d5a11

5 files changed

Lines changed: 135 additions & 18 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,8 @@ cython_debug/
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163163

164-
**/_version.py
164+
**/_version.py
165+
166+
# Compass binary file
167+
*.DS_Store
168+
settings.xml

docs/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To install libra-toolbox, use pip:
3434

3535
.. code-block:: bash
3636
37-
pip install git+https://github.com/LIBRA-project/libra-toolbox
37+
pip install libra-toolbox
3838
3939
For more details, see the :ref:`installation` page.
4040

@@ -45,9 +45,10 @@ Roadmap
4545

4646
- :strike:`Tritium model: 0D model for tritium release`
4747
- :strike:`Neutron detection: tools and scripts for neutron detection post processing`
48-
- Neutronics: tools to facilitate building `OpenMC <https://docs.openmc.org/en/stable/>`_ models
48+
- :strike:`Neutronics: tools to facilitate building OpenMC models`
4949
- Tritium transport: tools to facilitate building `FESTIM <https://github.com/festim-dev/festim>`_ tritium transport models
5050
- :strike:`Code coverage with Codecov`
51+
- Conda package
5152

5253

5354
.. toctree::

docs/installation.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
Installation
44
============
55

6-
``libra-toolbox`` relies on python. You can install it from the official website: https://www.python.org/downloads/
6+
``libra-toolbox`` relies on Python. You can install it from the official website: https://www.python.org/downloads/
77

8-
To install ``libra-toolbox``, use pip:
8+
To install ``libra-toolbox`` from PyPI, use pip:
99

1010
.. code-block:: bash
1111
12-
pip install git+https://github.com/LIBRA-project/libra-toolbox
12+
pip install libra-toolbox
1313
1414
This will install the latest version of the code along with all the dependencies (``numpy``, ``pint``, ``scipy``...).
1515

1616
To install a specific version of the code:
1717

1818
.. code-block:: bash
1919
20-
pip install git+https://github.com/LIBRA-project/libra-toolbox@v0.1
20+
pip install libra-toolbox==0.6.1
2121
22-
Here, ``v0.1`` is the version number. You can replace it with the version you want to install.
22+
Here, ``0.6.1`` is the version number. You can replace it with the version you want to install.
2323

2424
To install the code in editable mode (i.e. the code is installed in the current directory and any changes to the code are immediately available to the user):
2525

@@ -29,11 +29,17 @@ To install the code in editable mode (i.e. the code is installed in the current
2929
cd libra-toolbox
3030
pip install -e .
3131
32-
To install the code alongside with the optional dependencies for the neutronics module, first [install OpenMC](https://docs.openmc.org/en/stable/quickinstall.html) with conda:
32+
To install the code alongside the optional dependencies for the neutronics module, first install `OpenMC <https://docs.openmc.org/en/stable/quickinstall.html>`_ with conda:
3333

34-
```
35-
conda install -c conda-forge openmc>=0.14.0
36-
```
34+
.. code-block:: bash
35+
36+
conda install -c conda-forge openmc>=0.14.0
37+
38+
Then install the code with the optional dependencies:
39+
40+
.. code-block:: bash
41+
42+
pip install libra-toolbox[neutronics]
3743
3844
To uninstall the package:
3945

libra_toolbox/neutron_detection/activation_foils/compass.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
import os
13

24

35
def get_channel(filename):
@@ -23,4 +25,33 @@ def get_channel(filename):
2325
return int(filename.split('@')[0][7:])
2426

2527

28+
def sort_compass_files(directory: str) -> dict:
29+
""" Gets Compass csv data filenames
30+
and sorts them according to channel and ending number.
31+
The filenames need to be sorted by ending number because only
32+
the first csv file for each channel contains a header.
33+
34+
Example of sorted filenames in directory:
35+
1st file: Data_CH4@...22.CSV
36+
2nd file: Data_CH4@...22_1.CSV
37+
3rd file: Data_CH4@...22_2.CSV """
38+
39+
filenames = os.listdir(directory)
40+
data_filenames = {}
41+
for filename in filenames:
42+
if filename.lower().endswith('.csv'):
43+
ch = get_channel(filename)
44+
# initialize filenames for each channel
45+
if ch not in data_filenames.keys():
46+
data_filenames[ch] = []
47+
48+
data_filenames[ch].append(filename)
49+
# Sort filenames by number at end
50+
for ch in data_filenames.keys():
51+
data_filenames[ch] = np.sort(data_filenames[ch])
52+
53+
return data_filenames
54+
55+
56+
2657

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,87 @@
11
import pytest
2+
import numpy as np
3+
import os
24
from libra_toolbox.neutron_detection.activation_foils import compass
35

4-
@pytest.mark.parametrize("filename, expected_channel", [
5-
("Data_CH14@V1725_292_Background_250322.CSV", 14),
6-
("Data_CH7@V1725_123_Background_250322.CSV", 7),
7-
("Data_CH21@V1725_456_Background_250322.CSV", 21),
8-
])
6+
7+
@pytest.mark.parametrize(
8+
"filename, expected_channel",
9+
[
10+
("Data_CH14@V1725_292_Background_250322.CSV", 14),
11+
("Data_CH7@V1725_123_Background_250322.CSV", 7),
12+
("Data_CH21@V1725_456_Background_250322.CSV", 21),
13+
],
14+
)
915
def test_get_channel(filename, expected_channel):
1016
ch = compass.get_channel(filename)
1117
assert ch == expected_channel
12-
18+
19+
20+
def create_empty_csv_files(directory, base_name, count, channel):
21+
"""
22+
Creates empty CSV files in a specified directory with a specific pattern.
23+
24+
Args:
25+
directory (str): The directory where the files will be created.
26+
base_name (str): The base name of the file (e.g., "Data_CH14").
27+
count (int): The number of files to generate.
28+
29+
Returns:
30+
list: A list of file paths for the created CSV files.
31+
"""
32+
if not os.path.exists(directory):
33+
os.makedirs(directory)
34+
35+
file_paths = []
36+
for i in range(count):
37+
if i == 0:
38+
filename = f"Data_CH{channel}@{base_name}.csv"
39+
else:
40+
filename = f"Data_CH{channel}@{base_name}_{i}.csv"
41+
file_path = os.path.join(directory, filename)
42+
with open(file_path, "w") as f:
43+
pass # Create an empty file
44+
file_paths.append(file_path)
45+
46+
return file_paths
47+
48+
49+
@pytest.mark.parametrize(
50+
"base_name, expected_filenames",
51+
[
52+
(
53+
"base",
54+
{
55+
4: [
56+
"Data_CH4@base.csv",
57+
"Data_CH4@base_1.csv",
58+
"Data_CH4@base_2.csv",
59+
"Data_CH4@base_3.csv",
60+
],
61+
1: [
62+
"Data_CH1@base.csv",
63+
],
64+
},
65+
),
66+
],
67+
)
68+
def test_sort_compass_files(tmpdir, base_name: str, expected_filenames: dict):
69+
for ch, list_of_filenames in expected_filenames.items():
70+
create_empty_csv_files(
71+
tmpdir, base_name, count=len(list_of_filenames), channel=ch
72+
)
73+
74+
data_filenames = compass.sort_compass_files(tmpdir)
75+
76+
assert isinstance(data_filenames, dict)
77+
78+
# Check if dictionaries have the same keys, length of filenames array, and
79+
# the same overall filenames array
80+
for key in expected_filenames:
81+
assert key in data_filenames
82+
assert len(data_filenames[key]) == len(expected_filenames[key])
83+
for a, b in zip(data_filenames[key], expected_filenames[key]):
84+
if isinstance(a, np.ndarray) and isinstance(b, np.ndarray):
85+
assert np.array_equal(a, b)
86+
else:
87+
assert a == b

0 commit comments

Comments
 (0)