multiel-spectra


Namemultiel-spectra JSON
Version 0.0.28.6.4 PyPI version JSON
download
home_pagehttps://baltig.infn.it/fgarciaa/multiel_spectra
SummaryMulti-Element Fluorescence Xray Spectra Generator
upload_time2023-10-02 16:43:17
maintainer
docs_urlNone
authorFernando Garcia-Avello
requires_python>=3.6
license
keywords xray fluorescence pypi package
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Multiel_spectra

**Multi-element Spectra Generator**

Multiel_spectra is a Python package designed for simulating fluorescence X-ray spectra. It enables the simulation of photon transmission through multiple material layers generated by a source spectrum and incorporates detector effects.

## Name

Highly Scalable Multi-element Fluorescence X-ray Spectra Simulation.

## Description

Multiel_spectra is a package that approximates all steps in an X-ray Fluorescence measurement. It simulates the entire photon path, starting from the X-ray source to the detector, and accounts for transmission through various elemental layers. The primary objective of this package is to generate more accurate approximations of computer-simulated X-ray spectra to closely resemble real X-ray detected spectra. These generated spectra are valuable for various applications, including training artificial neural networks for tasks such as automatic element detection and denoising.


Multiel_spectra encompasses the following key elements in its simulation:

- **Incident Spectra (Source Spectra):** The incident spectra are simulated using the "spekpy" package, producing a tuple of arrays containing energy values (X) and spectrum fluence (Y). For detailed information, please refer to the "spekpy" documentation.

- **Fluorescence Spectra Transmission:** Multiel_spectra models elements in layers, requiring prior knowledge of the elemental composition of the probe. This composition is defined by the position of each element and its relative abundance within the probe. The fluorescence spectra generated by the source spectra are accurately transmitted through these different layers, with the option to remove the outermost layer (usually air). It's worth noting that only air has thickness, while the other layers are assumed to have a fixed thickness of 1 mm.

- **Detector Effects:** Multiel_spectra simulates various detector effects, including escape peaks, sum peaks, and detector efficiency.

## Approximations

Currently, Multiel_spectra makes certain approximations in its simulations:

**Source Spectra Transmission**: The current simulation assumes that the same source spectra arrives at all elements in different layers. It doesn't differentiate the source spectra for individual elements.

**Fluorescence Spectra Creation**: While SpectraGen accurately transmits different fluorescence spectra through various layers, it does not simulate the creation of new spectra using these transmitted fluorescence spectra as sources. This could be a potential enhancement for future versions.

**Photon Material Absorption**: SpectraGen approximates photon material absorption using perfect composited materials, without considering impurities or introducing noise. Exploring more realistic absorption models could be beneficial for increased accuracy. 


## Required Libraries 

Multiel_spectra relies on three main libraries:

Spekpy: A Python package used to simulate X-ray tube spectra, which serve as the incident spectra for generating X-ray fluorescence spectra.

Xraylarch: A Python package utilized to obtain mass attenuation coefficients for mixtures of compounds as a function of energy.

Scikit-beam: A Python package used to retrieve energies and cross sections for all X-ray lines in an element.

These libraries are integral to the functionality of Multiel_spectra. For further information you can refer to their documentation. 

## Installation

```python

pip install multiel_spectra

```
(At the monent and until parallelization development finishes torch will be an optional library in the installation) 

### Setting the environment and related packages: 

As the package makes use of skbeam, a install_skbeam.py (and install_spekpy.py) script is included with the package so run: " python install_skbeam.py" in order to isntall it (link to the skbeam documentation for all the different installation procedures, this one is the reccomended one). This files are typically lcoated: /opt/conda/lib/python3.10/site-packages/multiel_spectra when you download it. 

1. set conda environment named 'base' 
2. run: "python install_skbeam.py" in conda base environment
3. run: "python install spekpy.py"
4. install the rest of dependencies (torch, xraylarch, scipy..etc).  

The order is important since usually the packages created outside the conda environment will not be linked into the environment. 

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage


```python
#Generate the incident spectra
Prim, brem = ms.Primary_gen(30, 46, 0.1, "casim", "nist", 1, 9, "Mo", [('Be', 0.127), ('Air', 10)])
```

```python
#Compute a multiel-spectra with high number of counts and low noise
final_spectra, present_peaks, els_perc = ms.spectra_gen(np.array([38,25,13,0,8,7]), Prim, brem, s_counts = 30000,n_counts = 30000,b_counts = 1000, c_counts = 1000,  escape = True, sum = True, decal = True,  char_r = 15, brem_r = 15,noise_f = 1000 )
```
Output: 

![High count plot](./images/highcount.png)

The spectra is shown on blue, while on green are shown the elemental lines of the elements present on the spectra. Note that since spectra can be decalibrated the position of the peaks with respect the real energy position of the elemental lines may be displaced. 

```python
#Compute a multi-element spectra with low number of counts and high noise to signal ratio
final_spectra, present_peaks, els_perc = ms.spectra_gen(np.array([38,25,13,0,8,7]), Prim, brem, s_counts = 20,n_counts = 30,b_counts = 10, c_counts = 10,  escape = True, sum = True, decal = True, char_r = 1, brem_r = 1,noise_f = 1, prop = "" )
```
![low count plot](./images/lowcount.png)

Note that "Plot = True" by default and can be omitted, hence if a in interactive plot is not desired it must be explicitly be expressed in the input.

Interactive visualizations are provided trough Bokeh interface, but spectra histograms can be exported as arrays and used in other frameworks. 

(quizás poner un link a un google colab notebook donde haga todo)

## Support
fgarciaa@fi.infn.it

## Roadmap

* 3D photon path simulation 

* No approximation on transmission and excitation simulation 

* Material mix and impurities simulation

* ANN element detection 

* ANN denoising 

## Contributing

Contact the autor for contributions or suggestions. Open contributions will soon be available.

## Authors and acknowledgment

Thanks to the INFN-Firenze and Labec laboratory

- [INFN-Firenze](https://www.infn.it/)
- [Labec Laboratory](https://labec.fi.it/)

## License

MIT license. 

## Project status

**Note:** As of now, the project is in the final stages of developing the first working prototype. Development has been active and focused on achieving this milestone.

If you are interested in contributing to or maintaining this project, your involvement is welcome and highly appreciated. Whether you have ideas for improvements, want to help with documentation, or take on a more active role as a maintainer, your support can help ensure the project's continued success.

Feel free to reach out or submit pull requests if you'd like to get involved in shaping the future of this project.

Your update provides transparency about the project's current status and invites potential contributors or maintainers to participate in its development.

            

Raw data

            {
    "_id": null,
    "home_page": "https://baltig.infn.it/fgarciaa/multiel_spectra",
    "name": "multiel-spectra",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "xray,fluorescence,pypi,package",
    "author": "Fernando Garcia-Avello",
    "author_email": "fgarciaa@fi.infn.it",
    "download_url": "https://files.pythonhosted.org/packages/68/f7/e09d350e488f7f9e302269a2ae64397465c2cc0f2b7383825cd8ffafda35/multiel_spectra-0.0.28.6.4.tar.gz",
    "platform": null,
    "description": "# Multiel_spectra\r\n\r\n**Multi-element Spectra Generator**\r\n\r\nMultiel_spectra is a Python package designed for simulating fluorescence X-ray spectra. It enables the simulation of photon transmission through multiple material layers generated by a source spectrum and incorporates detector effects.\r\n\r\n## Name\r\n\r\nHighly Scalable Multi-element Fluorescence X-ray Spectra Simulation.\r\n\r\n## Description\r\n\r\nMultiel_spectra is a package that approximates all steps in an X-ray Fluorescence measurement. It simulates the entire photon path, starting from the X-ray source to the detector, and accounts for transmission through various elemental layers. The primary objective of this package is to generate more accurate approximations of computer-simulated X-ray spectra to closely resemble real X-ray detected spectra. These generated spectra are valuable for various applications, including training artificial neural networks for tasks such as automatic element detection and denoising.\r\n\r\n\r\nMultiel_spectra encompasses the following key elements in its simulation:\r\n\r\n- **Incident Spectra (Source Spectra):** The incident spectra are simulated using the \"spekpy\" package, producing a tuple of arrays containing energy values (X) and spectrum fluence (Y). For detailed information, please refer to the \"spekpy\" documentation.\r\n\r\n- **Fluorescence Spectra Transmission:** Multiel_spectra models elements in layers, requiring prior knowledge of the elemental composition of the probe. This composition is defined by the position of each element and its relative abundance within the probe. The fluorescence spectra generated by the source spectra are accurately transmitted through these different layers, with the option to remove the outermost layer (usually air). It's worth noting that only air has thickness, while the other layers are assumed to have a fixed thickness of 1 mm.\r\n\r\n- **Detector Effects:** Multiel_spectra simulates various detector effects, including escape peaks, sum peaks, and detector efficiency.\r\n\r\n## Approximations\r\n\r\nCurrently, Multiel_spectra makes certain approximations in its simulations:\r\n\r\n**Source Spectra Transmission**: The current simulation assumes that the same source spectra arrives at all elements in different layers. It doesn't differentiate the source spectra for individual elements.\r\n\r\n**Fluorescence Spectra Creation**: While SpectraGen accurately transmits different fluorescence spectra through various layers, it does not simulate the creation of new spectra using these transmitted fluorescence spectra as sources. This could be a potential enhancement for future versions.\r\n\r\n**Photon Material Absorption**: SpectraGen approximates photon material absorption using perfect composited materials, without considering impurities or introducing noise. Exploring more realistic absorption models could be beneficial for increased accuracy. \r\n\r\n\r\n## Required Libraries \r\n\r\nMultiel_spectra relies on three main libraries:\r\n\r\nSpekpy: A Python package used to simulate X-ray tube spectra, which serve as the incident spectra for generating X-ray fluorescence spectra.\r\n\r\nXraylarch: A Python package utilized to obtain mass attenuation coefficients for mixtures of compounds as a function of energy.\r\n\r\nScikit-beam: A Python package used to retrieve energies and cross sections for all X-ray lines in an element.\r\n\r\nThese libraries are integral to the functionality of Multiel_spectra. For further information you can refer to their documentation. \r\n\r\n## Installation\r\n\r\n```python\r\n\r\npip install multiel_spectra\r\n\r\n```\r\n(At the monent and until parallelization development finishes torch will be an optional library in the installation) \r\n\r\n### Setting the environment and related packages: \r\n\r\nAs the package makes use of skbeam, a install_skbeam.py (and install_spekpy.py) script is included with the package so run: \" python install_skbeam.py\" in order to isntall it (link to the skbeam documentation for all the different installation procedures, this one is the reccomended one). This files are typically lcoated: /opt/conda/lib/python3.10/site-packages/multiel_spectra when you download it. \r\n\r\n1. set conda environment named 'base' \r\n2. run: \"python install_skbeam.py\" in conda base environment\r\n3. run: \"python install spekpy.py\"\r\n4. install the rest of dependencies (torch, xraylarch, scipy..etc).  \r\n\r\nThe order is important since usually the packages created outside the conda environment will not be linked into the environment. \r\n\r\nWithin a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.\r\n\r\n## Usage\r\n\r\n\r\n```python\r\n#Generate the incident spectra\r\nPrim, brem = ms.Primary_gen(30, 46, 0.1, \"casim\", \"nist\", 1, 9, \"Mo\", [('Be', 0.127), ('Air', 10)])\r\n```\r\n\r\n```python\r\n#Compute a multiel-spectra with high number of counts and low noise\r\nfinal_spectra, present_peaks, els_perc = ms.spectra_gen(np.array([38,25,13,0,8,7]), Prim, brem, s_counts = 30000,n_counts = 30000,b_counts = 1000, c_counts = 1000,  escape = True, sum = True, decal = True,  char_r = 15, brem_r = 15,noise_f = 1000 )\r\n```\r\nOutput: \r\n\r\n![High count plot](./images/highcount.png)\r\n\r\nThe spectra is shown on blue, while on green are shown the elemental lines of the elements present on the spectra. Note that since spectra can be decalibrated the position of the peaks with respect the real energy position of the elemental lines may be displaced. \r\n\r\n```python\r\n#Compute a multi-element spectra with low number of counts and high noise to signal ratio\r\nfinal_spectra, present_peaks, els_perc = ms.spectra_gen(np.array([38,25,13,0,8,7]), Prim, brem, s_counts = 20,n_counts = 30,b_counts = 10, c_counts = 10,  escape = True, sum = True, decal = True, char_r = 1, brem_r = 1,noise_f = 1, prop = \"\" )\r\n```\r\n![low count plot](./images/lowcount.png)\r\n\r\nNote that \"Plot = True\" by default and can be omitted, hence if a in interactive plot is not desired it must be explicitly be expressed in the input.\r\n\r\nInteractive visualizations are provided trough Bokeh interface, but spectra histograms can be exported as arrays and used in other frameworks. \r\n\r\n(quiz\u00e1s poner un link a un google colab notebook donde haga todo)\r\n\r\n## Support\r\nfgarciaa@fi.infn.it\r\n\r\n## Roadmap\r\n\r\n* 3D photon path simulation \r\n\r\n* No approximation on transmission and excitation simulation \r\n\r\n* Material mix and impurities simulation\r\n\r\n* ANN element detection \r\n\r\n* ANN denoising \r\n\r\n## Contributing\r\n\r\nContact the autor for contributions or suggestions. Open contributions will soon be available.\r\n\r\n## Authors and acknowledgment\r\n\r\nThanks to the INFN-Firenze and Labec laboratory\r\n\r\n- [INFN-Firenze](https://www.infn.it/)\r\n- [Labec Laboratory](https://labec.fi.it/)\r\n\r\n## License\r\n\r\nMIT license. \r\n\r\n## Project status\r\n\r\n**Note:** As of now, the project is in the final stages of developing the first working prototype. Development has been active and focused on achieving this milestone.\r\n\r\nIf you are interested in contributing to or maintaining this project, your involvement is welcome and highly appreciated. Whether you have ideas for improvements, want to help with documentation, or take on a more active role as a maintainer, your support can help ensure the project's continued success.\r\n\r\nFeel free to reach out or submit pull requests if you'd like to get involved in shaping the future of this project.\r\n\r\nYour update provides transparency about the project's current status and invites potential contributors or maintainers to participate in its development.\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Multi-Element Fluorescence Xray Spectra Generator",
    "version": "0.0.28.6.4",
    "project_urls": {
        "Bug Reports": "https://baltig.infn.it/fgarciaa/multiel_spectra",
        "Documentation": "https://baltig.infn.it/fgarciaa/multiel_spectra",
        "Homepage": "https://baltig.infn.it/fgarciaa/multiel_spectra",
        "Source Code": "https://baltig.infn.it/fgarciaa/multiel_spectra"
    },
    "split_keywords": [
        "xray",
        "fluorescence",
        "pypi",
        "package"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9079de5036140eb5680883d79f86ef13966008053c4546d935d2d83aed5a992d",
                "md5": "37db9faafd8e6c9d69c373d3945e1832",
                "sha256": "e30349e9ba5425495aac7a37e71ced163d42dae387d93f0dbf0ae8bce9e59ba3"
            },
            "downloads": -1,
            "filename": "multiel_spectra-0.0.28.6.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "37db9faafd8e6c9d69c373d3945e1832",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 32106,
            "upload_time": "2023-10-02T16:43:15",
            "upload_time_iso_8601": "2023-10-02T16:43:15.437120Z",
            "url": "https://files.pythonhosted.org/packages/90/79/de5036140eb5680883d79f86ef13966008053c4546d935d2d83aed5a992d/multiel_spectra-0.0.28.6.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68f7e09d350e488f7f9e302269a2ae64397465c2cc0f2b7383825cd8ffafda35",
                "md5": "143ca0b3c190259645641f61d24d67be",
                "sha256": "3d031bc78ec7254cec132b7b845592c604d2fd9647eb8dafff2ee4167f6c2be5"
            },
            "downloads": -1,
            "filename": "multiel_spectra-0.0.28.6.4.tar.gz",
            "has_sig": false,
            "md5_digest": "143ca0b3c190259645641f61d24d67be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 225685,
            "upload_time": "2023-10-02T16:43:17",
            "upload_time_iso_8601": "2023-10-02T16:43:17.621860Z",
            "url": "https://files.pythonhosted.org/packages/68/f7/e09d350e488f7f9e302269a2ae64397465c2cc0f2b7383825cd8ffafda35/multiel_spectra-0.0.28.6.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-02 16:43:17",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "multiel-spectra"
}
        
Elapsed time: 0.12346s