Basic Usage — 1D Analyzer
In [4]:
Copied!
import matplotlib.pyplot as plt
import logging
from geecs_data_utils.config_roots import image_analysis_config
from geecs_data_utils.scan_data import ScanData, ScanPaths
from image_analysis.config import load_line_config
from image_analysis.analyzers.standard_1d_analyzer import Standard1DAnalyzer
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logging.getLogger("image_analysis").setLevel(logging.WARNING)
logging.getLogger("geecs_data_utils").setLevel(logging.WARNING)
image_analysis_config.set_base_dir(ScanPaths.paths_config.image_analysis_configs_path)
import matplotlib.pyplot as plt
import logging
from geecs_data_utils.config_roots import image_analysis_config
from geecs_data_utils.scan_data import ScanData, ScanPaths
from image_analysis.config import load_line_config
from image_analysis.analyzers.standard_1d_analyzer import Standard1DAnalyzer
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logging.getLogger("image_analysis").setLevel(logging.WARNING)
logging.getLogger("geecs_data_utils").setLevel(logging.WARNING)
image_analysis_config.set_base_dir(ScanPaths.paths_config.image_analysis_configs_path)
Out[4]:
PosixPath('/Users/samuelbarber/Desktop/Code/Github_repos/GEECS-Plugins-Configs-loader-api-refactor/scan_analysis_configs/analyzers')
In [2]:
Copied!
sd = ScanData.from_date(year=2025, month=8, day=7, number=7, experiment="Undulator")
sd = ScanData.from_date(year=2025, month=8, day=7, number=7, experiment="Undulator")
In [5]:
Copied!
dev_name = "Z_Test_Scope"
line_config = load_line_config(dev_name)
analyzer = Standard1DAnalyzer(line_config=line_config)
file_path = sd.data_frame[f"{dev_name}_expected_path"][1]
result = analyzer.analyze_image_file(file_path)
data = result.line_data
dev_name = "Z_Test_Scope"
line_config = load_line_config(dev_name)
analyzer = Standard1DAnalyzer(line_config=line_config)
file_path = sd.data_frame[f"{dev_name}_expected_path"][1]
result = analyzer.analyze_image_file(file_path)
data = result.line_data
In [6]:
Copied!
plt.plot(data[:, 0], data[:, 1])
plt.show()
plt.plot(data[:, 0], data[:, 1])
plt.show()
In [8]:
Copied!
sd = ScanData.from_date(
year=2025, month=9, day=24, number=10, experiment="Undulator", append_paths=False
)
dev_name = "U_BCaveICT"
line_config = load_line_config(dev_name)
analyzer = Standard1DAnalyzer(line_config=line_config)
file_path = sd.paths.get_device_shot_path(
tag=sd.paths.get_tag(), device_name=dev_name, shot_number=2, file_extension="tdms"
)
result = analyzer.analyze_image_file(file_path)
data = result.line_data
plt.plot(data[:, 0], data[:, 1])
plt.show()
sd = ScanData.from_date(
year=2025, month=9, day=24, number=10, experiment="Undulator", append_paths=False
)
dev_name = "U_BCaveICT"
line_config = load_line_config(dev_name)
analyzer = Standard1DAnalyzer(line_config=line_config)
file_path = sd.paths.get_device_shot_path(
tag=sd.paths.get_tag(), device_name=dev_name, shot_number=2, file_extension="tdms"
)
result = analyzer.analyze_image_file(file_path)
data = result.line_data
plt.plot(data[:, 0], data[:, 1])
plt.show()
In [13]:
Copied!
sd = ScanData.from_date(
year=2025, month=9, day=24, number=10, experiment="Undulator", append_paths=False
)
config_name = "BcaveMagSpecStitcherSpec"
dev_name = "U_BCaveMagSpec-interpSpec"
line_config = load_line_config(config_name)
analyzer = Standard1DAnalyzer(line_config=line_config)
file_path = sd.paths.get_device_shot_path(
tag=sd.paths.get_tag(), device_name=dev_name, shot_number=2, file_extension="txt"
)
# analyzer.line_config.roi.x_min = 0
# analyzer.line_config.roi.x_max = 0.1
file_path = file_path.parent / "Scan010_U_BCaveMagSpec_001.txt"
result = analyzer.analyze_image_file(file_path)
data = result.line_data
plt.plot(data[:, 0], data[:, 1])
# plt.xlabel(f"{result['analyzer_input_parameters']} ({result.x_units})")
# plt.ylabel(f"{result.y_label} ({result.y_units})")
plt.show()
result.metadata
sd = ScanData.from_date(
year=2025, month=9, day=24, number=10, experiment="Undulator", append_paths=False
)
config_name = "BcaveMagSpecStitcherSpec"
dev_name = "U_BCaveMagSpec-interpSpec"
line_config = load_line_config(config_name)
analyzer = Standard1DAnalyzer(line_config=line_config)
file_path = sd.paths.get_device_shot_path(
tag=sd.paths.get_tag(), device_name=dev_name, shot_number=2, file_extension="txt"
)
# analyzer.line_config.roi.x_min = 0
# analyzer.line_config.roi.x_max = 0.1
file_path = file_path.parent / "Scan010_U_BCaveMagSpec_001.txt"
result = analyzer.analyze_image_file(file_path)
data = result.line_data
plt.plot(data[:, 0], data[:, 1])
# plt.xlabel(f"{result['analyzer_input_parameters']} ({result.x_units})")
# plt.ylabel(f"{result.y_label} ({result.y_units})")
plt.show()
result.metadata
Out[13]:
{'line_name': 'U_BCaveMagSpec-interpSpec',
'data_type': <Data1DType.TSV: 'tsv'>,
'config_name': 'U_BCaveMagSpec-interpSpec',
'data_format': 'Charge density vs Energy',
'x_units': 'MeV',
'y_units': None,
'x_label': 'Momentum_GeV/c',
'y_label': 'ChargeDen_pC/GeV'}
Below is an example of using the ICT_1d_analyzer. The plot just shows the prepocessed trace (before applying the ICT analysis algorithm. The subsequent cells show how to how to use utilities in ict_algorithms to inspect and fine tune the relevant parameters to ensure the analysis result is being calculated as desired
In [22]:
Copied!
from image_analysis.analyzers.ict_1d_analyzer import ICT1DAnalyzer
config_name = "U_BCaveICT"
dev_name = "U_BCaveICT"
line_config = load_line_config(config_name)
analyzer = ICT1DAnalyzer(line_config=line_config)
sd = ScanData.from_date(year=2025, month=11, day=13, number=2, experiment="Undulator")
file_path = sd.data_frame[f"{dev_name}_expected_path"][34]
from image_analysis.analyzers.ict_1d_analyzer import ICT1DAnalyzer
config_name = "U_BCaveICT"
dev_name = "U_BCaveICT"
line_config = load_line_config(config_name)
analyzer = ICT1DAnalyzer(line_config=line_config)
sd = ScanData.from_date(year=2025, month=11, day=13, number=2, experiment="Undulator")
file_path = sd.data_frame[f"{dev_name}_expected_path"][34]
In [23]:
Copied!
# run the analyzer using the ict_analsis_parameters from the config
result = analyzer.analyze_image_file(file_path)
data = result.line_data
plt.plot(data[:, 0], data[:, 1])
plt.show()
# run the analyzer using the ict_analsis_parameters from the config
result = analyzer.analyze_image_file(file_path)
data = result.line_data
plt.plot(data[:, 0], data[:, 1])
plt.show()
In [24]:
Copied!
# detailed view of the analysis, tune the parameters of ict_analysis
from image_analysis.algorithms.ict_algorithms import apply_ict_analysis_with_details
res = apply_ict_analysis_with_details(
data[:, 1],
dt=4e-9,
butterworth_order=1,
butterworth_crit_f=0.75,
calibration_factor=0.1,
)
plt.plot(
res[1]["raw_data"][res[1]["signal_region_start"] : res[1]["signal_region_end"]]
)
plt.plot(
res[1]["cleaned_data"][res[1]["signal_region_start"] : res[1]["signal_region_end"]]
)
plt.show()
res[0]
# detailed view of the analysis, tune the parameters of ict_analysis
from image_analysis.algorithms.ict_algorithms import apply_ict_analysis_with_details
res = apply_ict_analysis_with_details(
data[:, 1],
dt=4e-9,
butterworth_order=1,
butterworth_crit_f=0.75,
calibration_factor=0.1,
)
plt.plot(
res[1]["raw_data"][res[1]["signal_region_start"] : res[1]["signal_region_end"]]
)
plt.plot(
res[1]["cleaned_data"][res[1]["signal_region_start"] : res[1]["signal_region_end"]]
)
plt.show()
res[0]
Out[24]:
5.617502363979413
In [ ]:
Copied!