mirror of
https://github.com/pim-n/pg-rad
synced 2026-02-02 14:33:09 +01:00
rename Source to PointSource and move to sources.py
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
import math
|
||||
from typing import Self
|
||||
|
||||
from pg_rad.isotope import Isotope
|
||||
|
||||
class Object:
|
||||
def __init__(
|
||||
self,
|
||||
@ -32,45 +30,4 @@ class Object:
|
||||
return math.dist(
|
||||
(self.x, self.y, self.z),
|
||||
(other.x, other.y, other.z),
|
||||
)
|
||||
|
||||
class Source(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 = Source._id_counter
|
||||
Source._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
|
||||
|
||||
def __repr__(self):
|
||||
return f"Source(name={self.name}, pos={(self.x, self.y, self.z)}, isotope={self.isotope.name}, A={self.activity} MBq)"
|
||||
)
|
||||
43
src/pg_rad/sources.py
Normal file
43
src/pg_rad/sources.py
Normal file
@ -0,0 +1,43 @@
|
||||
from pg_rad.objects import Object
|
||||
from pg_rad.isotope import Isotope
|
||||
|
||||
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
|
||||
|
||||
def __repr__(self):
|
||||
return f"PointSource(name={self.name}, pos={(self.x, self.y, self.z)}, isotope={self.isotope.name}, A={self.activity} MBq)"
|
||||
Reference in New Issue
Block a user