Simultipac 2.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env python3
2
+ """Python dual-logging setup (console and log file).
3
+
4
+ It supports different log levels and colorized output.
5
+
6
+ Created by Fonic <https://github.com/fonic>
7
+ Date: 04/05/20 - 02/07/23
8
+
9
+ Based on:
10
+ https://stackoverflow.com/a/13733863/1976617
11
+ https://uran198.github.io/en/python/2016/07/12/colorful-python-logging.html
12
+ https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
13
+
14
+ """
15
+ import logging
16
+ import subprocess
17
+ import sys
18
+ from importlib.metadata import PackageNotFoundError, version
19
+ from pathlib import Path
20
+ from typing import Literal
21
+
22
+
23
+ def _get_package_version(package_name: str) -> str:
24
+ """Get the package version."""
25
+ try:
26
+ return version(package_name)
27
+ except PackageNotFoundError:
28
+ return "Unknown version"
29
+
30
+
31
+ def _get_last_commit_hash() -> str:
32
+ """Get the last Git commit hash.
33
+
34
+ .. todo::
35
+ Will look for the script commit number, not for the code commit number!
36
+
37
+ """
38
+ try:
39
+ return (
40
+ subprocess.check_output(["git", "rev-parse", "HEAD"])
41
+ .decode("utf-8")
42
+ .strip()
43
+ )
44
+ except subprocess.CalledProcessError:
45
+ return "Unknown commit"
46
+
47
+
48
+ def _log_header(package_name: str) -> str:
49
+ """Create a header for the log file."""
50
+ package_version = _get_package_version(package_name)
51
+ commit_hash = _get_last_commit_hash()
52
+ header_message = (
53
+ f"Starting log for {package_name} - Version: {package_version}, "
54
+ f"Commit: {commit_hash}"
55
+ )
56
+ return header_message
57
+
58
+
59
+ def _console_handler(
60
+ output: str, level: str, color: bool, line_template: str
61
+ ) -> logging.Handler:
62
+ """Set up the console handler."""
63
+ output_stream = sys.stdout if output.lower() == "stdout" else sys.stderr
64
+ console_handler = logging.StreamHandler(output_stream)
65
+ console_handler.setLevel(level.upper())
66
+ console_formatter = LogFormatter(fmt=line_template, color=color)
67
+ console_handler.setFormatter(console_formatter)
68
+ return console_handler
69
+
70
+
71
+ def _file_handler(
72
+ file: Path,
73
+ level: str,
74
+ color: bool,
75
+ line_template: str,
76
+ mode: Literal["a", "w"] = "w",
77
+ ) -> logging.Handler | Literal[False]:
78
+ """Set up the file handler."""
79
+ try:
80
+ logfile_handler = logging.FileHandler(file, mode=mode)
81
+ except Exception as e:
82
+ print(f"Failed to set up log file: {e}")
83
+ return False
84
+
85
+ logfile_handler.setLevel(level.upper())
86
+ logfile_formatter = LogFormatter(fmt=line_template, color=color)
87
+ logfile_handler.setFormatter(logfile_formatter)
88
+ return logfile_handler
89
+
90
+
91
+ class LogFormatter(logging.Formatter):
92
+ """Logging formatter supporting colorized output."""
93
+
94
+ COLOR_CODES = {
95
+ # bright/bold magenta
96
+ logging.CRITICAL: "\033[1;35m",
97
+ # bright/bold red
98
+ logging.ERROR: "\033[1;31m",
99
+ # bright/bold yellow
100
+ logging.WARNING: "\033[1;33m",
101
+ # white / light gray
102
+ logging.INFO: "\033[0;37m",
103
+ # bright/bold black / dark gray
104
+ logging.DEBUG: "\033[1;30m",
105
+ }
106
+
107
+ RESET_CODE = "\033[0m"
108
+
109
+ def __init__(self, color: bool, *args, **kwargs) -> None:
110
+ super().__init__(*args, **kwargs)
111
+ self.color = color
112
+
113
+ def format(self, record: logging.LogRecord, *args, **kwargs) -> str:
114
+ if self.color and record.levelno in self.COLOR_CODES:
115
+ record.color_on = self.COLOR_CODES[record.levelno]
116
+ record.color_off = self.RESET_CODE
117
+ else:
118
+ record.color_on = ""
119
+ record.color_off = ""
120
+ return super().format(record, *args, **kwargs)
121
+
122
+
123
+ def set_up_logging(
124
+ package_name: str,
125
+ console_log_output: str = "stdout",
126
+ console_log_level: str = "INFO",
127
+ console_log_color: bool = True,
128
+ console_log_line_template: str = "%(color_on)s[%(levelname)-8s] [%(filename)-20s]%(color_off)s %(message)s",
129
+ logfile_file: Path = Path("simultipac.log"),
130
+ logfile_log_level: str = "INFO",
131
+ logfile_log_color: bool = False,
132
+ logfile_line_template: str = "%(color_on)s[%(asctime)s] [%(levelname)-8s] [%(filename)-20s]%(color_off)s %(message)s",
133
+ logfile_mode: Literal["a", "w"] = "w",
134
+ ) -> bool:
135
+ """Set up logging with both console and file handlers."""
136
+ # Remove previous logger
137
+ for handler in logging.root.handlers[:]:
138
+ handler.close()
139
+ logging.root.removeHandler(handler)
140
+
141
+ logger = logging.getLogger()
142
+ logger.setLevel(logging.DEBUG)
143
+
144
+ logger.addHandler(
145
+ _console_handler(
146
+ console_log_output,
147
+ console_log_level,
148
+ console_log_color,
149
+ console_log_line_template,
150
+ )
151
+ )
152
+
153
+ logfile_handler = _file_handler(
154
+ logfile_file,
155
+ logfile_log_level,
156
+ logfile_log_color,
157
+ logfile_line_template,
158
+ mode=logfile_mode,
159
+ )
160
+ if not logfile_handler:
161
+ return False
162
+ logger.addHandler(logfile_handler)
163
+ logger.info(_log_header(package_name))
164
+
165
+ return True
166
+
167
+
168
+ def main():
169
+ """Main function."""
170
+ if not set_up_logging(
171
+ package_name="Simultipac",
172
+ console_log_output="stdout",
173
+ console_log_level="warning",
174
+ console_log_color=True,
175
+ logfile_file=Path("simultipac.log"),
176
+ logfile_log_level="INFO",
177
+ logfile_log_color=False,
178
+ ):
179
+ print("Failed to set up logging, aborting.")
180
+ return 1
181
+
182
+ # Sample log messages
183
+ logging.debug("Debug message")
184
+ logging.info("Info message")
185
+ logging.warning("Warning message")
186
+ logging.error("Error message")
187
+ logging.critical("Critical message")
188
+ return 0
189
+
190
+
191
+ if __name__ == "__main__":
192
+ sys.exit(main())
@@ -0,0 +1,16 @@
1
+ """Define a base singleton pattern class."""
2
+
3
+ from abc import ABC
4
+
5
+
6
+ class SingletonMeta(type, ABC):
7
+ """Define singleton template to inherit from."""
8
+
9
+ _instances = {}
10
+
11
+ def __call__(cls, *args, **kwargs):
12
+ """Create instance only if not already exists."""
13
+ if cls not in cls._instances:
14
+ cls._instances[cls] = super().__call__(*args, **kwargs)
15
+
16
+ return cls._instances[cls]
@@ -0,0 +1,103 @@
1
+ Metadata-Version: 2.4
2
+ Name: Simultipac
3
+ Version: 2.0.3
4
+ Summary: Treat data from CST Particle Studio and SPARK3D for multipactor
5
+ Author-email: Adrien Plaçais <placais@lpsc.in2p3.fr>
6
+ Project-URL: changelog, https://github.com/AdrienPlacais/Simulia_Multipactor_lib/blob/main/CHANGELOG.md
7
+ Project-URL: documentation, https://simultipac.readthedocs.io/en/latest/
8
+ Project-URL: homepage, https://github.com/AdrienPlacais/Simulia_Multipactor_lib
9
+ Project-URL: tracker, https://github.com/AdrienPlacais/Simulia_Multipactor_lib/issues
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Physics
16
+ Requires-Python: >=3.12
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: matplotlib<4,>=3.9.1
20
+ Requires-Dist: numpy<3,>=2
21
+ Requires-Dist: pandas<3,>=2.2
22
+ Requires-Dist: palettable<4,>=3.3.3
23
+ Requires-Dist: pre-commit<5,>=4
24
+ Requires-Dist: scipy<2,>=1.15
25
+ Requires-Dist: vedo<2026,>=2025.5
26
+ Provides-Extra: docs
27
+ Requires-Dist: myst-parser<5,>=4; extra == "docs"
28
+ Requires-Dist: nbsphinx<1,>=0.9.6; extra == "docs"
29
+ Requires-Dist: sphinx-autodoc-typehints<4,>=3.0.1; extra == "docs"
30
+ Requires-Dist: sphinx-rtd-theme<4,>=3; extra == "docs"
31
+ Requires-Dist: sphinx-tabs<4,>=3.4; extra == "docs"
32
+ Requires-Dist: sphinxcontrib-bibtex<3,>=2.6; extra == "docs"
33
+ Provides-Extra: k3d
34
+ Requires-Dist: jupyter; extra == "k3d"
35
+ Requires-Dist: k3d<3,>=2.16; extra == "k3d"
36
+ Requires-Dist: notebook<8,>=7; extra == "k3d"
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest<9,>=8.3.2; extra == "test"
39
+ Requires-Dist: pytest-mock<4,>=3.14; extra == "test"
40
+ Dynamic: license-file
41
+
42
+ # About this package
43
+ This package is a set of utils oriented towards multipacting analysis.
44
+ In particular:
45
+ - Load parameter sweeps and PIC Position Monitor data from CST Particle Studio.
46
+ - Load results from SPARK3D.
47
+ - Post-treat electron vs time results from these tools: multipactor trend, (TODO: multipactor order).
48
+ - Post-treat CST's PIC Position Monitor:
49
+ - Distribution of emission energies.
50
+ - Distribution of impact energies.
51
+ - Distribution of impact angles.
52
+ - Visualise trajectories.
53
+
54
+ # Installation
55
+ ## Requirements
56
+ You will need a recent version of Python (at least 3.12).
57
+
58
+ ## Installation
59
+ ### Simple installation
60
+ ```
61
+ pip install simultipac
62
+ ```
63
+
64
+ ### Building form source
65
+ 1. Navigate to the library installation folder.
66
+ 2. `git clone git@github.com:AdrienPlacais/Simulia_Multipactor_lib.git` (or download it a `zip`).
67
+ 3. Navigate to `Simulia_Multipactor_lib`
68
+ 4. Create a dedicated python environment.
69
+ 5. `pip install -e .`
70
+
71
+ # How to use
72
+ ## Documentation
73
+ Documentation is available at [this link](https://simultipac.readthedocs.io/en/latest/).
74
+
75
+ ## Tutorial
76
+ Examples are provided in the `examples` folder and [in the documentation](https://simultipac.readthedocs.io/en/latest/manual/examples_jupyter_notebooks.html).
77
+
78
+ # Gallery
79
+ ## Compute exponential growth factor
80
+ ### From SPARK3D
81
+ ![Evolution of exponential growth factor with accelerating field](docs/manual/images/exp_growth_spark.png)
82
+
83
+ ### From CST
84
+ Results of a parametric study on the number of seed electrons.
85
+ ![Evolution of exponential growth factor with accelerating field](docs/manual/images/exp_growth_cst.png)
86
+
87
+ ## Treat CST PIC Monitor data
88
+ ### Emission energies
89
+ ![Distribution of emission energies](docs/manual/images/emission_energy_distribution.png)
90
+
91
+ ### Collision energies
92
+ ![Distribution of collision energies](docs/manual/images/collision_energy_distribution.png)
93
+
94
+ ### Collision angles
95
+ ![Distribution of collision angles](docs/manual/images/collision_angle_distribution.png)
96
+
97
+ ### Trajectory plots
98
+ Here we represented in red the collision points and in green the emission points.
99
+ Electrons without a green point are seed electrons.
100
+ ![Plot of some trajectories](docs/manual/images/trajectories_1.png)
101
+
102
+ ![Plot of some trajectories](docs/manual/images/trajectories_2.png)
103
+
@@ -0,0 +1,31 @@
1
+ simultipac/__init__.py,sha256=AuINUOSVZIzpjOdkYm9Z_Oxxq07zkQGHEdzFzmZ0cgo,340
2
+ simultipac/constants.py,sha256=7yViMFv-pTLg-HDnHptXb7dl8jMCG-NXkp8vFXJYe6A,492
3
+ simultipac/types.py,sha256=aUqad3c2iXbJLP-8T9rZezGIFyXX34F8UFKbs6Ruy-0,1216
4
+ simultipac/cst/__init__.py,sha256=cxHE9vS8o0JDd1itxIQwkLim_yIg9ch2Ef5Txq4yOa0,55
5
+ simultipac/cst/helper.py,sha256=LTo4D_4tcmcRdT1EVtq1tYYC_Zc_XWNtr7EE0a0Wno0,4532
6
+ simultipac/cst/simulation_results.py,sha256=Bf0rP5HV9PPkM0dAhOwlqhizPEEUQXu9-6rtAv6vuXg,15815
7
+ simultipac/particle_monitor/__init__.py,sha256=lSoxzjsEjUue89nh9Gw2dFbr1z_Spo20mAIIsn0oVdM,159
8
+ simultipac/particle_monitor/converters.py,sha256=ZsKPV8HpE57WmQL_W8UvuVqm2TJnrH1QlP2Tia3ooEo,2422
9
+ simultipac/particle_monitor/particle.py,sha256=viW3Z8PEmz0CFNhPoDBmVgx4T5_Lxo8sjmoann4Dks8,13957
10
+ simultipac/particle_monitor/particle_monitor.py,sha256=pa1TOKoCitp33tzLHsGKrE-Oy0GV_HDDyfg0gZ79KlY,23069
11
+ simultipac/particle_monitor/vector.py,sha256=ls5Kt12TQRhRTEq_tNWkRoyOgs-k3k_BTG8iIXV86E8,6832
12
+ simultipac/particle_monitor/collisions/__init__.py,sha256=C6p7UACCRADvTgbCq7jKPNIMt6LLBhFOBSNrnFwKldY,66
13
+ simultipac/particle_monitor/collisions/util.py,sha256=yVtY7uNCJEUXtvbnBmrfNPE68cEjPb2SMqQXivHlVOI,3573
14
+ simultipac/particle_monitor/collisions/vedo_mesh_collisions.py,sha256=ZsGIBFfSp8OJJ6czvyNey5Cg3aqRLq_hla6rkRYrVCU,976
15
+ simultipac/plotter/__init__.py,sha256=7BzCQI2w9wwnlSliLBeg--kSCSP6noSyZrvfhrsWNic,47
16
+ simultipac/plotter/default.py,sha256=-IpxUbUlnAibavoc4541mlrA5mXt84JKSEPq3le0C8w,12407
17
+ simultipac/plotter/plotter.py,sha256=_sHQXsAVy2z-NCsgV08x_RnpGCXk1qUyUV82E-hqeuM,4761
18
+ simultipac/simulation_results/__init__.py,sha256=eynVQRPnSNzPq5T-f1Q5P2EMKjzb-3mqmgkHq63Ij4o,52
19
+ simultipac/simulation_results/simulation_results.py,sha256=cnzG31Elt77zTUknBDQc626Z4Y_uynps2kAC9O54vYc,11719
20
+ simultipac/simulation_results/simulations_results.py,sha256=0Rnu1N6MrdHci0HGJ4so3yUES6jdzwxbfKBZ-7V7k00,23479
21
+ simultipac/spark3d/__init__.py,sha256=ygQkwLSEVgwmznyeFaNkH2SS61PUhgjvy-i4h_-c6JA,59
22
+ simultipac/spark3d/simulation_results.py,sha256=CB9MG2zmaUWIQHpKzXpsE3vgZB1-Io1OARYwvZsgq3o,5274
23
+ simultipac/util/__init__.py,sha256=4l5Vi8aMnxVDCK3Wz62hCCeDE9-sbh6SHl2PkTGv-8Q,119
24
+ simultipac/util/exponential_growth.py,sha256=z89_-2OuRH5Wcds6636GgaF0AI0BJ1Qt6FBkiMREqAw,11319
25
+ simultipac/util/log_manager.py,sha256=ZZAHAFxTecQNKHfuVL61KIIthu7EIF__AvyqljzlH3Q,5593
26
+ simultipac/util/singleton.py,sha256=x3UfXkJjJGBGq6ZSQvliL91PHTV_-vtiIzj7JVYefdA,415
27
+ simultipac-2.0.3.dist-info/licenses/LICENSE,sha256=Gmnq_v2LSXzbHSnBCw_D1n9nBFZ6O4jmH_y7wll5Uf0,1072
28
+ simultipac-2.0.3.dist-info/METADATA,sha256=tkVK_jUTqxIPlCBSYp1svfTFVK7Bz1smgvfcKHnIgAE,4036
29
+ simultipac-2.0.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
30
+ simultipac-2.0.3.dist-info/top_level.txt,sha256=9PrhW3nhRQZda-NS0eVxa2zpJvva3q_Q1w6gLQHpWIk,11
31
+ simultipac-2.0.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Adrien Plaçais
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ simultipac