Repository: RemDelaporteMathurin/h-transport-materials

Issue:
.value() method should work with units
Users should be able to do:

```python
import h_transport_materials as htm

ureg = htm.ureg

T = ureg.Quantity(900, ureg.K)

D = htm.Diffusivity(1 * ureg.m**2 * ureg.s**-1, 0.1 * ureg.eV)

value = D.value(T)

value.to(ureg.mm**2 * ureg.s**-1)
```

- .value() should return a pint.Quantity object
- .value() should accept a pint.Quantity object for argument

Discussion:

Patch:
diff --git a/h_transport_materials/plotting.py b/h_transport_materials/plotting.py
index 3c904ac..35cb638 100644
--- a/h_transport_materials/plotting.py
+++ b/h_transport_materials/plotting.py
@@ -1,7 +1,8 @@
 import matplotlib.pyplot as plt
 import numpy as np
 from numpy.typing import ArrayLike
-from h_transport_materials import Property, PropertiesGroup
+import pint
+from h_transport_materials import Property, PropertiesGroup, ureg
 import math
 import matplotlib as mpl
 from typing import Union
@@ -37,6 +38,8 @@ def plot(
         else:
             range = prop.range
         T = np.linspace(*range, num=50)
+        if not isinstance(T, pint.Quantity):
+            T *= ureg.K
         if inverse_temperature:
             plt.xlabel("1/T (K$^{-1}$)")
             x = (1 / T)[::-1]
diff --git a/h_transport_materials/properties_group.py b/h_transport_materials/properties_group.py
index ac2fc03..09ed69f 100644
--- a/h_transport_materials/properties_group.py
+++ b/h_transport_materials/properties_group.py
@@ -1,8 +1,10 @@
 import numpy as np
 import json
 from pybtex.database import BibliographyData
+import pint
 
 from h_transport_materials.fitting import fit_arhenius
+from h_transport_materials import ureg
 
 
 class PropertiesGroup(list):
@@ -96,6 +98,8 @@ class PropertiesGroup(list):
                 if prop.range == None:
                     T_range = default_range
                 prop_T = np.linspace(T_range[0], T_range[1], num=samples_per_line)
+                if not isinstance(prop_T, pint.Quantity):
+                    prop_T = ureg.Quantity(prop_T, ureg.K)
                 prop_y = prop.value(prop_T)
 
             data_T = np.concatenate((data_T, prop_T))
@@ -103,7 +107,6 @@ class PropertiesGroup(list):
 
         # fit all the data
         pre_exp, act_energy = fit_arhenius(data_y, data_T)
-
         return pre_exp, act_energy
 
     def export_bib(self, filename: str):
diff --git a/h_transport_materials/property.py b/h_transport_materials/property.py
index 870dcd7..4f7a54f 100644
--- a/h_transport_materials/property.py
+++ b/h_transport_materials/property.py
@@ -297,7 +297,15 @@ class ArrheniusProperty(Property):
         self.range = (self.data_T.min(), self.data_T.max())
 
     def value(self, T, exp=np.exp):
-        return self.pre_exp * exp(-self.act_energy / k_B / T)
+        if not isinstance(T, pint.Quantity):
+            warnings.warn(f"no units were given with T, assuming {ureg.K}")
+            T = T * ureg.K
+        if not isinstance(self.pre_exp, pint.Quantity):
+            pre_exp = self.pre_exp * self.units
+        if not isinstance(self.act_energy, pint.Quantity):
+            act_energy = self.act_energy * DEFAULT_ENERGY_UNITS
+        k_B_u = k_B * ureg.eV * ureg.particle**-1 * ureg.K**-1
+        return pre_exp * exp(-act_energy / k_B_u / T)
 
 
 class Solubility(ArrheniusProperty):


Test patch:
diff --git a/tests/test_arhenius_property.py b/tests/test_arhenius_property.py
index 75e3256..1264756 100644
--- a/tests/test_arhenius_property.py
+++ b/tests/test_arhenius_property.py
@@ -2,6 +2,7 @@ import pytest
 import numpy as np
 
 import h_transport_materials as htm
+import pint
 
 
 @pytest.mark.parametrize(
@@ -100,3 +101,14 @@ def test_data_y_removes_nan(data):
         data_y=data * htm.ureg.dimensionless,
     )
     assert np.count_nonzero(np.isnan(my_prop.data_y)) == 0
+
+
+def test_value_returns_pint_quantity():
+    my_prop = htm.ArrheniusProperty(
+        pre_exp=1 * htm.ureg.m**2 * htm.ureg.s**-1,
+        act_energy=0.1 * htm.ureg.eV * htm.ureg.particle**-1,
+    )
+
+    T = htm.ureg.Quantity(400, htm.ureg.K)
+
+    assert isinstance(my_prop.value(T), pint.Quantity)