CalebBell / thermo

Thermodynamics and Phase Equilibrium component of Chemical Engineering Design Library (ChEDL)
MIT License
594 stars 114 forks source link

Incompatibility with Scipy 1.0.0 #10

Closed andreubernadserra closed 6 years ago

andreubernadserra commented 6 years ago

Hi,

For some reason the thermo package doesn't work when the Scipy library is upgraded. In my case I tried to upgrade it from 0.18.1 to 1.0.0; causing thermo to crash.

Here I paste the error I'm getting:

from thermo import chemical /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/thermo/__init__.py", line 25, in <module> from . import chemical File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/thermo/chemical.py", line 42, in <module> from thermo.viscosity import ViscosityLiquid, ViscosityGas, ViscosityLiquidMixture, ViscosityGasMixture, viscosity_index File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/thermo/viscosity.py", line 2359, in <module> viscosity_converters_to_nu[key] = UnivariateSpline(values, nus, k=3, s=0) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/interpolate/fitpack2.py", line 176, in __init__ raise ValueError('x must be strictly increasing') ValueError: x must be strictly increasing

I solved the error by using pip and reinstalling Scipy 0.18.1:

pip install scipy==0.18.1

Does anyone know a better solution than using an old version of the library?

Thank you in advance, Andreu

CalebBell commented 6 years ago

Hello Andreu,

Thank you for reporting a bug. The bug you're observing is due to a single set of values which were being used to convert viscosity in degrees Barbey to other viscosity units. The UnivariateSpline method requires the x-values to be continuously increasing or it could not perform an interpolation. For only Barbey out of 47 viscosity scales supported, the scale is an inverse and so the degrees Barbey decreased while viscosity increased. In previous versions of SciPy the error would only be raised if an interpolation was tried, not on creation, and I never tried a conversion with Barbey as I was developing the converter. I have added custom handling for it.

After fixing that, there is also the removal of SciPy's C2K and friends I had to fix. This project cannot make use of the new convert_temperature method introduced in SciPy 0.18 as it supports older versions of SciPy. I have vendorized those functions in a new release of fluids.core, increasing the version of fluids that is required to use thermo to 0.1.68; its upgrade will be automatically installed when thermo is upgraded.

Note this release includes some big changes (which should not be user-facing) in the identifiers.py file, to lazy-load portions of the chemical database for faster startup and reduced memory use. Please report any breaks from previous behavior this may have introduced; I was not planning on a new release right now but I'd rather get a release out to fix this issue anyway. The new thermo version is in PyPi, 0.1.38. Please close this bug if you can confirm thermo is working with SciPy 1.0.

Sincerely, Caleb

andreubernadserra commented 6 years ago

Dear Caleb,

In the first place I would like to thank you for both your fast answer and the quality of it. Your library has been a game changing for me in terms of thermodynamic calculations.

Regarding the bug, your patch fixed the issue with Scipy 1.0.0. If I come across more bugs I'll do my best to report them.

Thank you again, Andreu