assessing-trpl-with-bayesian-inference_and-mcmc
https://github.com/manuelkoberczerny/assessing-trpl-with-bayesian-inference_and-mcmc
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.4%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: manuelkoberczerny
- License: mit
- Language: Jupyter Notebook
- Default Branch: main
- Size: 7.96 MB
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 2
Metadata Files
README.md
Fitting Time-Resolved Photoluminescence Data with Bayesian Inference and a Markov-Chain Monte-Carlo Sampler
This is the code that was used in: M. Kober-Czerny, A. Dasgupta, S. Seo, F.M. Rombach, D.P. McMeekin, H. Jin, H.J. Snaith, "Determining Material Parameters of Metal Halide Perovskites Using Time-resolved Photoluminescence".
The theory and physical model used is described in the publication in detail.
This code is written for data obtained by a picoquant setup. There are instructions below on how to adapt the code to your own data format.
Disclaimer
Information inferred from data through this method is only as good as the model that is used. If the model is flawed, so are the inferred parameters. We hence strongly advise against over-interpretation of the results and recommend double-checking parameter values with another methodology in a first instance.
Getting Started
Installation and Usage
Install the Pymc5 package in a new Python (version 3.10) environment using conda-forge (replace <name_env> with your own):
conda create -n <name_env> pymc -c conda-forge
conda activate <name_env>
Then install jupyter notebook using
conda install notebook -c conda-forge
Using the command line, navigate to the cloned repository and run
jupyter notebook
Then open 1-BayesMCMCalgorithm/Setup_inference.ipynb to run an inference.
Running Inference
To run the inference, create a .csv file with the columns:
file name (no .txt) | thickness (nm) | side (1 or 2) | alpha (cm-1) | reflectance | Intensity | max_time (ns)
Add the file path to the jupyter notebook and run the inference. The MCMC sampler will take a few minutes to start. A typical run is between 1-3 hours.
Analysis of the Results
After the inference is complete, open 2-ExtractParameters/ExtractParameters.ipynb. Add the path and name of the trace_*.nc file (the file encodes the sample name, date and time). A plot showing the raw data and median 'fit' curve, as well as histograms for all parameters is shown.
Trouble Shooting
| Issue | Tip |
|---|---|
| Sampler crashes with message 'Bad initial energy...' | 1. open Manuel_BayesTRPL_model.py 2. navigate to ```sigma = sigmas * (2+99*pm.Beta('sigma_fact', 3,3))``` 3. change '3,3' to larger nmbers (like '5,5') |
| Sampler continues to crash with message 'Bad initial energy...' | 1. open Manuel_BayesTRPL_model.py 2. uncomment ```#trace = pm.sample(step=pm.Metropolis()...)``` 3. comment ```trace = pm.sample(...)``` |
| ... | ... |
Adapting the Code or Model
Different TRPL setup
If you have a different TRPL setup, the output data may be different. In our case, most metadata (laser rep-rate, laser wavelength, etc.) is stored in the header of the datafile. This information is extracted in ManuelBayesTRPLUtilities.py in he functions unpack_info() and Fluence_Calc(). Skip these two, if you have other means of obtaining this information.
In our setup, the laser pulse is registered at approximately 30-40 ns on the real-time axis, but for the analysis we want it to be at t = 0. The functions unpack_Data() and make_Dataframe() are used to extract the raw data, shift the time-axis and normalize the data. They are then stored in a pandas dataframe.
If you want to write your own Utils-code, the function Bayes_TRPL_Utils needs to output:
return df, pile_up, sample_name, Fluence, Thickness, Surface, Absorption_coeff, amax
where df is the dataframe containing the columns 'Time'| 1 | 2 | 3 | ...
samplename is the name of the sample, Fluence is in cm^2, Thickness is in nm, Surface is either 0 (for one surface) or 1 (for the other surface), Absorptioncoeff is in cm^-1, amax is the last timepoint in ns.
Changing the Model
To change the model, open ManuelBayesTRPLmodel.py and navigate to model_in_pytensor(). To understand, how to add or change parameters, refer to the Pymc documentation.
All functions are written in either numpy or PyTensor. For functions, such as 'for'-loops, we use PyTensors scan function instead (see documentation). The use of PyTensor throughout the model enables a more straightforward use of gradient-based MCMC samplers, such as NUTS.
Owner
- Name: Manuel Kober-Czerny
- Login: manuelkoberczerny
- Kind: user
- Location: Oxford
- Company: University of Oxford
- Website: https://www.physics.ox.ac.uk/our-people/kober-czerny
- Repositories: 1
- Profile: https://github.com/manuelkoberczerny
Citation (CITATION.cff)
cff-version: 1.1.0 message: "If you use this software, please cite it as below." authors: - family-names: Kober-Czerny given-names: Manuel orcid: https://orcid.org/0000-0002-7807-3133 title: Assessing TRPL with Bayesian Inference and MCMC version: initial_release date-released: 2024-12-08
GitHub Events
Total
- Release event: 5
- Watch event: 2
- Delete event: 1
- Issue comment event: 1
- Public event: 1
- Push event: 38
- Pull request event: 4
- Create event: 5
Last Year
- Release event: 5
- Watch event: 2
- Delete event: 1
- Issue comment event: 1
- Public event: 1
- Push event: 38
- Pull request event: 4
- Create event: 5