mirror of
https://github.com/pim-n/pg-rad
synced 2026-04-24 17:58:11 +02:00
patch export to add also detector details
This commit is contained in:
@ -3,6 +3,7 @@ from typing import List
|
|||||||
from pg_rad.landscape.landscape import Landscape
|
from pg_rad.landscape.landscape import Landscape
|
||||||
from pg_rad.simulator.outputs import (
|
from pg_rad.simulator.outputs import (
|
||||||
CountRateOutput,
|
CountRateOutput,
|
||||||
|
DetectorOutput,
|
||||||
SimulationOutput,
|
SimulationOutput,
|
||||||
SourceOutput
|
SourceOutput
|
||||||
)
|
)
|
||||||
@ -31,11 +32,13 @@ class SimulationEngine:
|
|||||||
|
|
||||||
count_rate_results = self._calculate_count_rate_along_path()
|
count_rate_results = self._calculate_count_rate_along_path()
|
||||||
source_results = self._calculate_point_source_distance_to_path()
|
source_results = self._calculate_point_source_distance_to_path()
|
||||||
|
detector_results = self._generate_detector_output()
|
||||||
|
|
||||||
return SimulationOutput(
|
return SimulationOutput(
|
||||||
name=self.landscape.name,
|
name=self.landscape.name,
|
||||||
size=self.landscape.size,
|
size=self.landscape.size,
|
||||||
count_rate=count_rate_results,
|
count_rate=count_rate_results,
|
||||||
|
detector=detector_results,
|
||||||
sources=source_results
|
sources=source_results
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,3 +83,13 @@ class SimulationEngine:
|
|||||||
)
|
)
|
||||||
|
|
||||||
return source_output
|
return source_output
|
||||||
|
|
||||||
|
def _generate_detector_output(self) -> DetectorOutput:
|
||||||
|
return DetectorOutput(
|
||||||
|
name=self.detector.name,
|
||||||
|
type=self.detector.type,
|
||||||
|
is_isotropic=self.detector.is_isotropic,
|
||||||
|
field_eff=self.detector.get_efficiency(
|
||||||
|
self.landscape.point_sources[0].isotope.E
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@ -24,9 +24,18 @@ class SourceOutput:
|
|||||||
dist_from_path: float
|
dist_from_path: float
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DetectorOutput:
|
||||||
|
name: str
|
||||||
|
type: str
|
||||||
|
is_isotropic: bool
|
||||||
|
field_eff: float
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SimulationOutput:
|
class SimulationOutput:
|
||||||
name: str
|
name: str
|
||||||
size: tuple
|
size: tuple
|
||||||
|
detector: DetectorOutput
|
||||||
count_rate: CountRateOutput
|
count_rate: CountRateOutput
|
||||||
sources: List[SourceOutput]
|
sources: List[SourceOutput]
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from numpy import array, full_like, ndarray
|
from numpy import array, full_like, ndarray, bool_
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
from pg_rad.simulator.outputs import SimulationOutput
|
from pg_rad.simulator.outputs import SimulationOutput
|
||||||
@ -18,6 +18,8 @@ class NumpyEncoder(json.JSONEncoder):
|
|||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
if isinstance(obj, ndarray):
|
if isinstance(obj, ndarray):
|
||||||
return obj.tolist()
|
return obj.tolist()
|
||||||
|
elif isinstance(obj, bool_):
|
||||||
|
return bool(obj)
|
||||||
return super().default(obj)
|
return super().default(obj)
|
||||||
|
|
||||||
|
|
||||||
@ -44,8 +46,10 @@ def save_results(sim: SimulationOutput, folder_name: str) -> None:
|
|||||||
df = generate_df(sim)
|
df = generate_df(sim)
|
||||||
csv_name = generate_csv_name(sim)
|
csv_name = generate_csv_name(sim)
|
||||||
df.to_csv(f"{folder_name}/{csv_name}.csv", index=False)
|
df.to_csv(f"{folder_name}/{csv_name}.csv", index=False)
|
||||||
|
param_dict = generate_sim_param_dict(sim)
|
||||||
|
print(type(param_dict['detector']['is_isotropic']))
|
||||||
with open(f"{folder_name}/parameters.json", 'w') as f:
|
with open(f"{folder_name}/parameters.json", 'w') as f:
|
||||||
json.dump(generate_sim_param_dict(sim), f, cls=NumpyEncoder)
|
json.dump(param_dict, f, cls=NumpyEncoder)
|
||||||
logger.info(f"Simulation output saved to {folder_name}!")
|
logger.info(f"Simulation output saved to {folder_name}!")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user