namespace:getting_data
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| namespace:getting_data [2025/11/06 22:22] – created admin | namespace:getting_data [2025/11/06 22:26] (current) – [Gil/Dylan getting started to collect data] admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| {{ : | {{ : | ||
| + | |||
| + | =====Gil/ | ||
| + | |||
| + | |||
| + | ######## GIL’s SCRIPT ############ | ||
| + | |||
| + | from galadriel.control.exp_setup import Setup\\ | ||
| + | |||
| + | from galadriel.control.optimizations import FRODO_class\\ | ||
| + | from galadriel.analysis import image_calculations\\ | ||
| + | |||
| + | # Math\\ | ||
| + | import numpy as np\\ | ||
| + | import time\\ | ||
| + | from datetime import datetime\\ | ||
| + | import io\\ | ||
| + | from PIL import Image\\ | ||
| + | import os\\ | ||
| + | \\ | ||
| + | #%%\\ | ||
| + | class rasterrunner(): | ||
| + | def __init__(self): | ||
| + | | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | if self.setup.actuator_dict: | ||
| + | | ||
| + | #%% ESTABLISH NAMES FOR ALL THE STUFF I WANT TO TALK TO.\\ | ||
| + | opt = rasterrunner()\\ | ||
| + | #%%\\ | ||
| + | opt.setup.query.clear_query()\\ | ||
| + | lsn = opt.setup.query.get_last_shot_number()\\ | ||
| + | \\ | ||
| + | value_query_dict = {' | ||
| + | # | ||
| + | \\ | ||
| + | range_query_dict = {' | ||
| + | \\ | ||
| + | #First round:shit archive; 198060, 198573]\\ | ||
| + | opt.setup.query.query_data_range(range_query_dict)\\ | ||
| + | raw_res, proc_res = opt.setup.query.run_query(fetch_related_data = False, make_dict = True)\\ | ||
| + | #%%\\ | ||
| + | dataout = []\\ | ||
| + | \\ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ##### MY SCRIPT ######### | ||
| + | |||
| + | |||
| + | # | ||
| + | """ | ||
| + | A script to create overlaid histograms comparing the peak signal distribution | ||
| + | of all seven focus metrics for all four filtered channels (Cu, Al, Fe, Ni). | ||
| + | """ | ||
| + | import sys | ||
| + | import os | ||
| + | import matplotlib.pyplot as plt | ||
| + | import seaborn as sns | ||
| + | import numpy as np | ||
| + | |||
| + | # --- USER CONFIGURATION --- | ||
| + | # Use the confirmed path to the directory containing the ' | ||
| + | PATH_TO_PROJECT_FOLDER = '/ | ||
| + | |||
| + | # The folder where the new plots will be saved. | ||
| + | SAVE_DIRECTORY = '/ | ||
| + | # ----------------------------- | ||
| + | |||
| + | # --- Path Correction Block (Do not change) --- | ||
| + | sys.path.insert(0, | ||
| + | # --------------------------------------------- | ||
| + | |||
| + | try: | ||
| + | from exp_setup import Setup | ||
| + | except (ImportError, | ||
| + | print(f" | ||
| + | sys.exit() | ||
| + | |||
| + | class rasterrunner(): | ||
| + | def __init__(self): | ||
| + | super().__init__() | ||
| + | print(" | ||
| + | self.setup = Setup() | ||
| + | print(" | ||
| + | |||
| + | def plot_all_filter_histograms(self): | ||
| + | """ | ||
| + | Loops through all metrics, aggregates peak data, and creates | ||
| + | overlaid " | ||
| + | """ | ||
| + | os.makedirs(SAVE_DIRECTORY, | ||
| + | print(f" | ||
| + | |||
| + | metrics_to_plot = [ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | 'Spot size', | ||
| + | 'Top 50 pixels', | ||
| + | 'Sobel Tenengrad Operator' | ||
| + | ] | ||
| + | |||
| + | # Use a dictionary to store all peak data, organized by metric | ||
| + | all_metrics_data = {metric: [[] for _ in range(4)] for metric in metrics_to_plot} | ||
| + | |||
| + | for metric in metrics_to_plot: | ||
| + | print(f" | ||
| + | self.setup.query.clear_query() | ||
| + | value_query_dict = { | ||
| + | ' | ||
| + | ' | ||
| + | } | ||
| + | self.setup.query.query_data_value(value_query_dict) | ||
| + | |||
| + | raw_res, proc_res = self.setup.query.run_query(fetch_related_data=True, | ||
| + | |||
| + | if ' | ||
| + | print(f" | ||
| + | continue | ||
| + | |||
| + | matching_shots = sorted(list({doc[' | ||
| + | |||
| + | # Aggregate peak data for the current metric | ||
| + | for shot in matching_shots: | ||
| + | for i in range(1, 5): | ||
| + | ch_name, ch_key = f' | ||
| + | scope_doc = next((doc for doc in raw_res.get(ch_name, | ||
| + | if scope_doc: | ||
| + | trace_data = scope_doc[' | ||
| + | if trace_data: | ||
| + | all_metrics_data[metric][i-1].append(np.max(trace_data)) | ||
| + | |||
| + | # --- Create and Save Overlaid Plots --- | ||
| + | print(" | ||
| + | sns.set_theme(style=" | ||
| + | | ||
| + | # Plot for Copper Filter (Channel 1) | ||
| + | plt.figure(figsize=(10, | ||
| + | for metric in metrics_to_plot: | ||
| + | peak_data = all_metrics_data[metric][0] # Index 0 for Channel 1 | ||
| + | if peak_data: | ||
| + | plt.hist(peak_data, | ||
| + | plt.title(' | ||
| + | plt.xlabel(' | ||
| + | filename_cu = os.path.join(SAVE_DIRECTORY, | ||
| + | plt.savefig(filename_cu); | ||
| + | print(f" | ||
| + | |||
| + | # Plot for Aluminum Filter (Channel 2) | ||
| + | plt.figure(figsize=(10, | ||
| + | for metric in metrics_to_plot: | ||
| + | peak_data = all_metrics_data[metric][1] # Index 1 for Channel 2 | ||
| + | if peak_data: | ||
| + | plt.hist(peak_data, | ||
| + | plt.title(' | ||
| + | plt.xlabel(' | ||
| + | filename_al = os.path.join(SAVE_DIRECTORY, | ||
| + | plt.savefig(filename_al); | ||
| + | print(f" | ||
| + | |||
| + | # NEW: Plot for Iron Filter (Channel 3) | ||
| + | plt.figure(figsize=(10, | ||
| + | for metric in metrics_to_plot: | ||
| + | peak_data = all_metrics_data[metric][2] # Index 2 for Channel 3 | ||
| + | if peak_data: | ||
| + | plt.hist(peak_data, | ||
| + | plt.title(' | ||
| + | plt.xlabel(' | ||
| + | filename_fe = os.path.join(SAVE_DIRECTORY, | ||
| + | plt.savefig(filename_fe); | ||
| + | print(f" | ||
| + | |||
| + | # NEW: Plot for Nickel Filter (Channel 4) | ||
| + | plt.figure(figsize=(10, | ||
| + | for metric in metrics_to_plot: | ||
| + | peak_data = all_metrics_data[metric][3] # Index 3 for Channel 4 | ||
| + | if peak_data: | ||
| + | plt.hist(peak_data, | ||
| + | plt.title(' | ||
| + | plt.xlabel(' | ||
| + | filename_ni = os.path.join(SAVE_DIRECTORY, | ||
| + | plt.savefig(filename_ni); | ||
| + | print(f" | ||
| + | |||
| + | if __name__ == " | ||
| + | opt = rasterrunner() | ||
| + | opt.plot_all_filter_histograms() | ||
namespace/getting_data.1762467742.txt.gz · Last modified: by admin
