Skip to content

Commit

Permalink
Spectrum refactoring, Spectrum2DCollection (#305)
Browse files Browse the repository at this point in the history
A Spectrum2DCollection class is introduced, with a similar interface to Spectrum1DCollection.

- Common features of the two classes are broken out into a multiple-inheritance "mixin" class, so that Spectrum remains the common base of all spectra: Spectrum1D, Spectrum2D, Spectrum1DCollection and Spectrum2DCollection are all "children" on the same level and will not `isinstance` with each other.

- Some of the metadata handling has been refactored for legibility and robustness: select(), group_by() and internal methods

  - Some of this work uses toolz, which becomes a dependency for the main package. We don't anticipate that causing a lot of problems; it is a small, stable, pure-python library also available on conda-forge. Mantid core team were warned of this intention a month or two ago and seem happy enough.

- `iter_metadata` method is provided to allow iteration over spectrum indices (using enumerate) without the relatively slow overhead of creating new spectra (encounted when iterating over the collection object).

  - i.e. `list(collection.iter_metadata())` is much faster than `[spectrum.metadata for spectrum in collection]` because it avoids unnecessarily copying data and twiddling units.


Co-authored-by: Jacob Wilkins <46597752+oerc0122@users.noreply.github.com>
  • Loading branch information
ajjackson and oerc0122 authored Sep 26, 2024
1 parent 8268881 commit ada9e25
Show file tree
Hide file tree
Showing 9 changed files with 2,332 additions and 298 deletions.
904 changes: 608 additions & 296 deletions euphonic/spectra.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def run_setup():
'seekpath>=1.1.0',
'spglib>=1.9.4',
'pint>=0.22',
'threadpoolctl>=3.0.0'
'threadpoolctl>=3.0.0',
'toolz>=0.12.1',
],
extras_require={
'matplotlib': ['matplotlib>=3.8.0'],
Expand Down
1 change: 1 addition & 0 deletions tests_and_analysis/minimum_euphonic_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ matplotlib==3.8
h5py==3.6
PyYAML==6.0
threadpoolctl==3.0.0
toolz==0.12.1
267 changes: 267 additions & 0 deletions tests_and_analysis/test/data/spectrum2d/quartz_fuzzy_map_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"__euphonic_class__": "Spectrum2D",
"__euphonic_version__": "1.3.2+33.gd8680c2.dirty",
"metadata": {
"common": "yes",
"direction": 0
},
"x_data": [
0.0,
0.1111111111111111,
0.2222222222222222,
0.3333333333333333,
0.4444444444444444,
0.5555555555555556,
0.6666666666666666,
0.7777777777777777,
0.8888888888888888,
1.0
],
"x_data_unit": "1 / angstrom",
"x_tick_labels": [
[
0,
"$\\Gamma$"
],
[
9,
""
]
],
"y_data": [
0.0,
5.2631578947368425,
10.526315789473685,
15.789473684210527,
21.05263157894737,
26.315789473684212,
31.578947368421055,
36.8421052631579,
42.10526315789474,
47.36842105263158,
52.631578947368425,
57.89473684210527,
63.15789473684211,
68.42105263157896,
73.6842105263158,
78.94736842105263,
84.21052631578948,
89.47368421052633,
94.73684210526316,
100.0
],
"y_data_unit": "millielectron_volt",
"z_data": [
[
0.0,
0.0,
0.0,
0.042222222222222223,
0.0,
0.021111111111111094,
0.04222222222222224,
0.0,
0.06333333333333335,
0.021111111111111094,
0.04222222222222224,
0.04222222222222215,
0.0,
0.0,
0.0,
0.0,
0.04222222222222215,
0.0,
0.04222222222222224
],
[
0.06333333333333331,
0.0,
0.0,
0.042222222222222223,
0.0,
0.021111111111111094,
0.04222222222222224,
0.021111111111111094,
0.04222222222222224,
0.021111111111111094,
0.04222222222222224,
0.04222222222222215,
0.0,
0.0,
0.0,
0.0,
0.04222222222222215,
0.0,
0.04222222222222224
],
[
0.0211111111111111,
0.0422222222222222,
0.0,
0.042222222222222223,
0.0,
0.021111111111111094,
0.04222222222222224,
0.04222222222222219,
0.0,
0.04222222222222219,
0.04222222222222224,
0.04222222222222215,
0.0,
0.0,
0.0,
0.021111111111111074,
0.021111111111111074,
0.0,
0.04222222222222224
],
[
0.0,
0.06333333333333331,
0.0,
0.042222222222222223,
0.0,
0.04222222222222219,
0.02111111111111112,
0.04222222222222219,
0.0,
0.04222222222222219,
0.04222222222222224,
0.04222222222222215,
0.0,
0.0,
0.0,
0.021111111111111074,
0.021111111111111074,
0.0,
0.02111111111111112
],
[
0.0,
0.0211111111111111,
0.0422222222222222,
0.021111111111111112,
0.021111111111111112,
0.04222222222222219,
0.0,
0.06333333333333328,
0.0,
0.06333333333333328,
0.02111111111111112,
0.021111111111111074,
0.02111111111111112,
0.0,
0.0,
0.021111111111111074,
0.0,
0.021111111111111164,
0.02111111111111112
],
[
0.0,
0.0211111111111111,
0.0211111111111111,
0.042222222222222223,
0.021111111111111112,
0.04222222222222219,
0.02111111111111112,
0.04222222222222219,
0.0,
0.06333333333333328,
0.02111111111111112,
0.021111111111111074,
0.02111111111111112,
0.0,
0.02111111111111112,
0.0,
0.0,
0.021111111111111164,
0.02111111111111112
],
[
0.0,
0.0211111111111111,
0.0211111111111111,
0.042222222222222223,
0.021111111111111112,
0.04222222222222219,
0.02111111111111112,
0.021111111111111094,
0.02111111111111112,
0.06333333333333328,
0.04222222222222224,
0.0,
0.02111111111111112,
0.0,
0.02111111111111112,
0.0,
0.0,
0.021111111111111164,
0.02111111111111112
],
[
0.0,
0.0,
0.0422222222222222,
0.021111111111111112,
0.042222222222222223,
0.04222222222222219,
0.04222222222222224,
0.0,
0.04222222222222224,
0.04222222222222219,
0.04222222222222224,
0.0,
0.0,
0.04222222222222224,
0.0,
0.0,
0.0,
0.021111111111111164,
0.04222222222222224
],
[
0.0,
0.0,
0.0422222222222222,
0.021111111111111112,
0.042222222222222223,
0.04222222222222219,
0.04222222222222224,
0.0,
0.08444444444444447,
0.0,
0.04222222222222224,
0.0,
0.0,
0.04222222222222224,
0.0,
0.0,
0.0,
0.021111111111111164,
0.06333333333333335
],
[
0.0,
0.0211111111111111,
0.0211111111111111,
0.021111111111111112,
0.042222222222222223,
0.04222222222222219,
0.04222222222222224,
0.0,
0.04222222222222224,
0.04222222222222219,
0.04222222222222224,
0.0,
0.02111111111111112,
0.0,
0.02111111111111112,
0.0,
0.0,
0.021111111111111164,
0.04222222222222224
]
],
"z_data_unit": "1 / millielectron_volt"
}
Loading

0 comments on commit ada9e25

Please sign in to comment.