refactor code into modules

This commit is contained in:
Pim Nelissen
2026-01-31 09:42:21 +01:00
parent db6f859a60
commit 15b7e7e65e
8 changed files with 2 additions and 2 deletions

View File

@ -0,0 +1,49 @@
import logging
from pg_rad.objects import Object
from pg_rad.isotopes import Isotope
logger = logging.getLogger(__name__)
class PointSource(Object):
_id_counter = 1
def __init__(
self,
x: float,
y: float,
z: float,
activity: int,
isotope: Isotope,
name: str | None = None,
color: str = "red"):
"""A point source.
Args:
x (float): X coordinate.
y (float): Y coordinate.
z (float): Z coordinate.
activity (int): Activity A in MBq.
isotope (Isotope): The isotope.
name (str | None, optional): Can give the source a unique name.
Defaults to None, making the name sequential.
(Source-1, Source-2, etc.).
color (str, optional): Matplotlib compatible color string. Defaults to "red".
"""
self.id = PointSource._id_counter
PointSource._id_counter += 1
# default name derived from ID if not provided
if name is None:
name = f"Source {self.id}"
super().__init__(x, y, z, name, color)
self.activity = activity
self.isotope = isotope
self.color = color
logger.debug(f"Source created: {self.name}")
def __repr__(self):
return f"PointSource(name={self.name}, pos={(self.x, self.y, self.z)}, isotope={self.isotope.name}, A={self.activity} MBq)"