jdhuang-csm / bayes-drt Goto Github PK
View Code? Open in Web Editor NEWHierarchical Bayesian methods for inversion of electrochemical impedance spectroscopy (EIS) data
License: BSD 3-Clause "New" or "Revised" License
Hierarchical Bayesian methods for inversion of electrochemical impedance spectroscopy (EIS) data
License: BSD 3-Clause "New" or "Revised" License
I'm running Python 3.10.0, and am having an issue with Pickle5 working only through Python 3.7 (when I try to install the Inverter, I get the error "No module named 'pickle5'"). Is there a way to adapt this to work with more recent versions of python? The rest of my EIS code runs on 3.10, so it would be great to not have to switch.
Thanks for your help, this is a really useful package!
I think the frequencies of the secondary x axes output by plot_distribution are incorrect. The code under if freq_axis:
of plot_distribution
sets axes ticks and labels based on a fixed range of frequencies.
In a test case, substituting ax2 specification with below worked. Apologies if I've misinterpreted
def freq2tau(x):
return 1 / (2 * np.pi * x)
ax2 = ax.secondary_xaxis('top', functions=(freq2tau, freq2tau))`
Inverter() is not able to properly instantiate a pystan model when running in a virtual environment. Setting up C++ compiler, pystan, and bayes-drt in the exact same way but not in a virtual environment results in no errors. This implies the error is based on how the file path is automatically generated for accessing the 'stan_model_files' folder when calling Inverter in a virtual environment.
Error when running in a virtual environment:
"Fit the data"
# by default, the Inverter class is configured for the DRT
inv_hmc = Inverter()
inv_map = Inverter()
# Perform HMC fit
start = time.time()
inv_hmc.bayes_fit(freq,Z)
elapsed = time.time() - start
print('HMC fit time {:.2f}'.format(elapsed))
# Perform MAP fit
start = time.time()
inv_map.map_fit(freq,Z)
elapsed = time.time() - start
print('MAP fit time {:.2f}'.format(elapsed))
WARNING:pystan:No module named 'stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126'
WARNING:pystan:Something went wrong while unpickling the StanModel. Consider recompiling.
AttributeError Traceback (most recent call last)
in
6 # Perform HMC fit
7 start = time.time()
----> 8 inv_hmc.bayes_fit(freq,Z)
9 elapsed = time.time() - start
10 print('HMC fit time {:.2f}'.format(elapsed))~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\bayes_drt\inversion.py in bayes_fit(self, frequencies, Z, part, scale_Z, init_from_ridge, nonneg_drt, outliers, sigma_min, warmup, sample, chains, random_seed, inductance_scale, fitY, Yscale, SA, SASY)
802
803 # sample from posterior
--> 804 self._sample_result = model.sampling(dat,warmup=warmup,iter=warmup+sample,chains=chains,seed=random_seed,init=init,
805 control={'adapt_delta':0.9,'adapt_t0':10})
806~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\pystan\model.py in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs)
756 raise ValueError("Warmup samples must be greater than 0 when adaptation is enabled (adapt_engaged=True
)")
757 seed = pystan.misc._check_seed(seed)
--> 758 fit = self.fit_class(data, seed)
759
760 m_pars = fit._get_param_names()AttributeError: 'StanModel' object has no attribute 'fit_class'
It looks like the folder 'stan_model_files' or any of the contents are added to the local environment by the pip installer. Easy fix manually to just copy the folder from the repo into the local environment, but thought you should know about it.
FileNotFoundError Traceback (most recent call last)
in
8 import glob
9
---> 10 from bayes_drt.inversion import Inverter
11 from bayes_drt import eis_utils as gt
12~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\bayes_drt\inversion.py in
9 import pystan as stan
10 import warnings
---> 11 from .stan_models import load_pickle
12 import os
13 from copy import deepcopy~\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\lib\site-packages\bayes_drt\stan_models.py in
40 for pkl, code_file in model_dict.items():
41 if not os.path.exists(os.path.join(script_dir,'stan_model_files',pkl)):
---> 42 with open(os.path.join(script_dir,'stan_model_files',code_file)) as f:
43 model_code = f.read()
44 print(f'Compiling {code_file}...')FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\...\AppData\Local\Continuum\anaconda3\envs\impedance-analysis\Lib\site-packages\bayes_drt\stan_model_files\Series_modelcode.txt'
Hello! My name is Kyle Coughlin and I am working on a paper surveying multiple EIS-DRT methods. Your method is of great interest to me, but after trying both versions of your code I was unable to get set up. In version two I am not able to install cmdstan and in version one pystan fails to build. I believe these are issues with my proxy/company protections on my computer. Would you be able to produce some outputs for me? I can email you the generic data (Synthetic Zarc1 and Zarc2 with simulated error) and detail the outputs I would need.
I would appreciate it a lot!!!!
from bayes_drt.inversion import Inverter
with python 3.9.16 throws
TabError: inconsistent use of tabs and spaces in indentation
cause is line 1642 of inversion.py. The line is indented with tabs. Other lines in the file are indented with spaces.
from bayes_drt.inversion import Inverter
with python 3.9.16 throws
SyntaxWarning: "is" with a literal. Did you mean "=="?
if outliers is True or outliers is 'auto':
cause it line 1670 of inversion.py
Hello!
It looks like there is no 550C.0.5V.DTA dataset, which is necessary to finish tutorial #1 Basis frequencies, initialization, and non-negativity constraint, point 2b.
Please make this dataset available.
Best regards,
Artem Pushkarev
Hello. Great library you have here and I am very excited to try and use this library to fit and analyze my own data. I am running in a conda environment with all packages installed successfully, and have got to the point of running the first HMC fit simply following Tutorial 1. I obtain the following error below. I tried to look into it but honestly cannot find much. Any idea why this is the case?
start = time.time()
inv_hmc.bayes_fit(freq,Zc)
elapsed = time.time() - start
print('HMC sampling time: {:.2f} s'.format(elapsed))
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\Blackr\Anaconda3\envs\DRT\lib\multiprocessing\pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "C:\Users\Blackr\Anaconda3\envs\DRT\lib\multiprocessing\pool.py", line 44, in mapstar
return list(map(*args))
File "stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126.pyx", line 373, in stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126._call_sampler_star
File "stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126.pyx", line 406, in stanfit4anon_model_5e41d7ccbb68c66e26beba2b6307db0c_8841332859592360126._call_sampler
RuntimeError: no more scalars to read
"""
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
in
1 # Sample the posterior distribution
2 start = time.time()
----> 3 inv_hmc.bayes_fit(freq,Zc)
4 elapsed = time.time() - start
5 print('HMC sampling time: {:.2f} s'.format(elapsed))
~\Anaconda3\envs\DRT\lib\site-packages\bayes_drt-0.1-py3.7.egg\bayes_drt\inversion.py in bayes_fit(self, frequencies, Z, part, scale_Z, init_from_ridge, nonneg_drt, outliers, sigma_min, warmup, sample, chains, random_seed, inductance_scale, outlier_lambda, fitY, Yscale, SA, SASY)
811 # sample from posterior
812 self._sample_result = model.sampling(dat,warmup=warmup,iter=warmup+sample,chains=chains,seed=random_seed,init=init,
--> 813 control={'adapt_delta':0.9,'adapt_t0':10})
814
815 # extract coefficients
~\Anaconda3\envs\DRT\lib\site-packages\pystan\model.py in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs)
776 call_sampler_args = izip(itertools.repeat(data), args_list, itertools.repeat(pars))
777 call_sampler_star = self.module._call_sampler_star
--> 778 ret_and_samples = _map_parallel(call_sampler_star, call_sampler_args, n_jobs)
779 samples = [smpl for _, smpl in ret_and_samples]
780
~\Anaconda3\envs\DRT\lib\site-packages\pystan\model.py in _map_parallel(function, args, n_jobs)
83 try:
84 pool = multiprocessing.Pool(processes=n_jobs)
---> 85 map_result = pool.map(function, args)
86 finally:
87 pool.close()
~\Anaconda3\envs\DRT\lib\multiprocessing\pool.py in map(self, func, iterable, chunksize)
266 in a list that is returned.
267 '''
--> 268 return self._map_async(func, iterable, mapstar, chunksize).get()
269
270 def starmap(self, func, iterable, chunksize=None):
~\Anaconda3\envs\DRT\lib\multiprocessing\pool.py in get(self, timeout)
655 return self._value
656 else:
--> 657 raise self._value
658
659 def _set(self, i, obj):
I then tried the map fitting later on in the tutorial to see if that would work, and every time it causes the jupyter notebook kernal to just crash.
The tutorial notebooks need to be updated to reflect the refactor and illustrate the use of new functionality.
Simple issue where a line instantiating an Inverter variable was commented out.
"Fit the data"
# by default, the Inverter class is configured for the DRT
# inv_hmc = Inverter() <--------- PROBLEM
inv_map = Inverter()
# Perform HMC fit
start = time.time()
inv_hmc.bayes_fit(freq,Z)
elapsed = time.time() - start
print('HMC fit time {:.2f}'.format(elapsed))
# Perform MAP fit
start = time.time()
inv_map.map_fit(freq,Z)
elapsed = time.time() - start
print('MAP fit time {:.2f}'.format(elapsed))
NameError Traceback (most recent call last)
in
6 # Perform HMC fit
7 start = time.time()
----> 8 inv_hmc.bayes_fit(freq,Z)
9 elapsed = time.time() - start
10 print('HMC fit time {:.2f}'.format(elapsed))NameError: name 'inv_hmc' is not defined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.