Repository: RemDelaporteMathurin/h-transport-materials

Issue:
Inf pre-exponential factor on mean permeabilities
On HTM 0.13.1:

```python
import h_transport_materials as htm

perm = htm.permeabilities.filter(material="steel").mean()

print(perm)
```


```
C:\Users\remidm\AppData\Roaming\Python\Python311\site-packages\numpy\core\_methods.py:53: RuntimeWarning: overflow encountered in reduce
  return umr_prod(a, axis, dtype, out, keepdims, initial, where)

        Author:
        Material:
        Year: None
        Isotope: None
        Pre-exponential factor: inf particle/Pa⁰⋅⁵/m/s
        Activation energy: 5.73×10⁻¹ eV/particle
```

Discussion:

Patch:
diff --git a/h_transport_materials/properties_group.py b/h_transport_materials/properties_group.py
index 60ba476..590fe85 100644
--- a/h_transport_materials/properties_group.py
+++ b/h_transport_materials/properties_group.py
@@ -94,7 +94,11 @@ class PropertiesGroup(list):
 
         # geometric mean of pre-exponential factor
         pre_exps = np.array([prop.pre_exp.magnitude for prop in self])
-        pre_exp = pre_exps.prod() ** (1.0 / len(pre_exps))
+        scaling_factor = np.max(pre_exps)
+        pre_exps = pre_exps / scaling_factor  # scale pre-exps to avoid inf
+
+        pre_exp = pre_exps.prod() ** (1.0 / len(pre_exps))  # compute mean
+        pre_exp = pre_exp * scaling_factor  # re-scale
 
         # arithmetic mean of activation energy
         act_energy = np.array([prop.act_energy.magnitude for prop in self]).mean()


Test patch:
diff --git a/tests/test_properties_group.py b/tests/test_properties_group.py
index 711d54f..84f1b21 100644
--- a/tests/test_properties_group.py
+++ b/tests/test_properties_group.py
@@ -215,3 +215,10 @@ def test_cannot_compute_mean_on_mixed_groups():
 
     with pytest.raises(ValueError, match="Can't compute mean on mixed units groups"):
         my_group.mean()
+
+
+def test_mean_of_large_numbers_properties():
+    """This test catches bug reported in issue #242"""
+
+    perm = htm.permeabilities.filter(material="steel").mean()
+    assert not np.isinf(perm.pre_exp)