User Tools

Site Tools


namespace:getting_data

moria_database_manual.pdf

Gil/Dylan getting started to collect data

######## 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):\\ super().__init__()\\ self.setup = Setup()\\ print(self.setup.acquisition_dict)\\ print(self.setup.actuator_dict)\\ if self.setup.actuator_dict: print(self.setup.input_map)\\ print('')\\ # 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 = {'metadata' : {'experiment' :['20250304_especcalibration']}}#,\\ #value_query_dict = {'metadata' : {'experiment' :['20250304_especcalibration']}}#,\\ \\ range_query_dict = {'metadata' : {'shot_number' : [lsn-200, lsn]}} #198579#198066\\ \\ #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 #########

#!/usr/bin/env python3 “”“ 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 'exp_setup.py' file. PATH_TO_PROJECT_FOLDER = '/home/dahlked/galadriel/galadriel/control'

# The folder where the new plots will be saved. SAVE_DIRECTORY = '/home/dahlked/envs/MetricPeakOscilloscopeDistributionPlots' # —————————–

# — Path Correction Block (Do not change) — sys.path.insert(0, PATH_TO_PROJECT_FOLDER) # ———————————————

try:

  from exp_setup import Setup

except (ImportError, KeyError) as e:

  print(f"Import Error: Could not import Setup. Error: {e}")
  sys.exit()

class rasterrunner():

  def __init__(self):
      super().__init__()
      print("Initializing connection...")
      self.setup = Setup()
      print("Connection successful.")
  def plot_all_filter_histograms(self):
      """
      Loops through all metrics, aggregates peak data, and creates
      overlaid "step" histograms for all four channels.
      """
      os.makedirs(SAVE_DIRECTORY, exist_ok=True)
      print(f"Plots will be saved to: {SAVE_DIRECTORY}")
      metrics_to_plot = [
          'Intensity only',
          'Variance only',
          'Laplacian only',
          'Brenner Gradient',
          '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"\n--- Processing Metric: {metric} ---")
          self.setup.query.clear_query()
          value_query_dict = {
              'metadata': {'process': ['FRODO']},
              'data': {'Metric Used': [metric]}
          }
          self.setup.query.query_data_value(value_query_dict)
          raw_res, proc_res = self.setup.query.run_query(fetch_related_data=True, make_dict=True)
          if 'FRODO' not in proc_res or not proc_res['FRODO']:
              print(f"No shots found for metric '{metric}'. Skipping.")
              continue
          matching_shots = sorted(list({doc['metadata']['shot_number'] for doc in proc_res['FRODO']}))
          # Aggregate peak data for the current metric
          for shot in matching_shots:
              for i in range(1, 5):
                  ch_name, ch_key = f'oscilloscope_ch{i}', f'channel_{i}'
                  scope_doc = next((doc for doc in raw_res.get(ch_name, []) if 'data' in doc and doc['metadata']['shot_number'] == shot), None)
                  if scope_doc:
                      trace_data = scope_doc['data'].get(ch_key)
                      if trace_data:
                          all_metrics_data[metric][i-1].append(np.max(trace_data))
      # --- Create and Save Overlaid Plots ---
      print("\n--- Generating Overlaid Histogram Plots for All Filters ---")
      sns.set_theme(style="whitegrid")
      
      # Plot for Copper Filter (Channel 1)
      plt.figure(figsize=(10, 7))
      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, bins='auto', label=metric, histtype='step', linewidth=1.5)
      plt.title('Metric Comparison for Copper (Cu) Filter')
      plt.xlabel('Peak Voltage (V)'); plt.ylabel('Number of Shots'); plt.legend()
      filename_cu = os.path.join(SAVE_DIRECTORY, "Copper_Filter_Metric_Comparison.png")
      plt.savefig(filename_cu); plt.close()
      print(f"Saved plot: {filename_cu}")
      # Plot for Aluminum Filter (Channel 2)
      plt.figure(figsize=(10, 7))
      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, bins='auto', label=metric, histtype='step', linewidth=1.5)
      plt.title('Metric Comparison for Aluminum (Al) Filter')
      plt.xlabel('Peak Voltage (V)'); plt.ylabel('Number of Shots'); plt.legend()
      filename_al = os.path.join(SAVE_DIRECTORY, "Aluminum_Filter_Metric_Comparison.png")
      plt.savefig(filename_al); plt.close()
      print(f"Saved plot: {filename_al}")
      # NEW: Plot for Iron Filter (Channel 3)
      plt.figure(figsize=(10, 7))
      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, bins='auto', label=metric, histtype='step', linewidth=1.5)
      plt.title('Metric Comparison for Iron (Fe) Filter')
      plt.xlabel('Peak Voltage (V)'); plt.ylabel('Number of Shots'); plt.legend()
      filename_fe = os.path.join(SAVE_DIRECTORY, "Iron_Filter_Metric_Comparison.png")
      plt.savefig(filename_fe); plt.close()
      print(f"Saved plot: {filename_fe}")
      # NEW: Plot for Nickel Filter (Channel 4)
      plt.figure(figsize=(10, 7))
      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, bins='auto', label=metric, histtype='step', linewidth=1.5)
      plt.title('Metric Comparison for Nickel (Ni) Filter')
      plt.xlabel('Peak Voltage (V)'); plt.ylabel('Number of Shots'); plt.legend()
      filename_ni = os.path.join(SAVE_DIRECTORY, "Nickel_Filter_Metric_Comparison.png")
      plt.savefig(filename_ni); plt.close()
      print(f"Saved plot: {filename_ni}")

if name == “main”:

  opt = rasterrunner()
  opt.plot_all_filter_histograms()
namespace/getting_data.txt · Last modified: by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki