diff --git a/pyrelacs/repros/calbi.py b/pyrelacs/repros/calbi.py index 114472d..2b6c9f9 100644 --- a/pyrelacs/repros/calbi.py +++ b/pyrelacs/repros/calbi.py @@ -3,6 +3,7 @@ import sys import faulthandler import time +import nixio as nix import uldaq from IPython import embed import numpy as np @@ -26,9 +27,9 @@ class Calibration(MccDac): self.SINFREQ = 750 @staticmethod - def run(): + def run(nix_file: nix.File): calb = Calibration() - calb.check_beat() + calb.check_beat(nix_file) def check_amplitude(self): db_values = [0.0, -5.0, -10.0, -20.0, -50.0] @@ -84,7 +85,7 @@ class Calibration(MccDac): self.disconnect_dac() - def check_beat(self): + def check_beat(self, nix_file: nix.File): self.set_attenuation_level(db_channel1=-10.0, db_channel2=0.0) t = np.arange(0, self.DURATION, 1 / self.SAMPLERATE) data = self.AMPLITUDE * np.sin(2 * np.pi * self.SINFREQ * t) @@ -92,7 +93,8 @@ class Calibration(MccDac): db_values = [0.0, -5.0, -8.5, -10.0] colors = ["red", "blue", "black", "green"] colors_in = ["lightcoral", "lightblue", "grey", "lightgreen"] - fig, axes = plt.subplots(2, 2, sharex="col") + block = nix_file.create_block("Calibration", "data") + # fig, axes = plt.subplots(2, 2, sharex="col") for i, db_value in enumerate(db_values): self.set_attenuation_level(db_channel1=db_value) stim = self.write_analog( @@ -127,8 +129,27 @@ class Calibration(MccDac): log.debug( f"Status Analog_output {ao_status}\n, Status Analog_input {ai_status}" ) + channel1 = np.array(readout[::2]) channel2 = np.array(readout[1::2]) + + block.create_data_array( + f"stimulus_{db_value}", + "Array", + shape=data.shape, + data=channel1, + label="Voltage", + unit="V", + ) + block.create_data_array( + f"fish_{db_value}", + "Array", + shape=data.shape, + data=channel2, + label="Voltage", + unit="V", + ) + beat = channel1 + channel2 beat_square = beat**2 @@ -145,69 +166,69 @@ class Calibration(MccDac): f_in, powerspec_in = welch(channel2, fs=self.SAMPLERATE) powerspec_in = decibel(powerspec_in) - axes[0, 0].plot( - t, - channel1, - label=f"{db_value} Readout Channel0", - color=colors[i], - ) - axes[0, 0].plot( - t, - channel2, - label=f"{db_value} Readout Channel1", - color=colors_in[i], - ) - - axes[0, 1].plot( - f_stim, - powerspec_stim, - label=f"{db_value} powerspec Channel0", - color=colors[i], - ) - axes[0, 1].plot( - f_in, - powerspec_in, - label=f"{db_value} powerspec Channel2", - color=colors_in[i], - ) - axes[0, 1].set_xlabel("Freq [HZ]") - axes[0, 1].set_ylabel("dB") - - axes[1, 0].plot( - t, - beat, - label="Beat", - color=colors[i], - ) - axes[1, 0].plot( - t, - beat**2, - label="Beat squared", - color=colors_in[i], - ) - axes[1, 0].legend() - - axes[1, 1].plot( - f, - powerspec, - color=colors[i], - ) - axes[1, 1].plot( - f_sq, - powerspec_sq, - color=colors_in[i], - label=f"dB {db_value}, first peak {np.min(f_sq[peaks])}", - ) - axes[1, 1].scatter( - f_sq[peaks], - powerspec_sq[peaks], - color="maroon", - ) - axes[1, 1].set_xlabel("Freq [HZ]") - axes[1, 1].set_ylabel("dB") - axes[0, 0].legend() - axes[1, 1].legend() - plt.show() + # axes[0, 0].plot( + # t, + # channel1, + # label=f"{db_value} Readout Channel0", + # color=colors[i], + # ) + # axes[0, 0].plot( + # t, + # channel2, + # label=f"{db_value} Readout Channel1", + # color=colors_in[i], + # ) + # + # axes[0, 1].plot( + # f_stim, + # powerspec_stim, + # label=f"{db_value} powerspec Channel0", + # color=colors[i], + # ) + # axes[0, 1].plot( + # f_in, + # powerspec_in, + # label=f"{db_value} powerspec Channel2", + # color=colors_in[i], + # ) + # axes[0, 1].set_xlabel("Freq [HZ]") + # axes[0, 1].set_ylabel("dB") + # + # axes[1, 0].plot( + # t, + # beat, + # label="Beat", + # color=colors[i], + # ) + # axes[1, 0].plot( + # t, + # beat**2, + # label="Beat squared", + # color=colors_in[i], + # ) + # axes[1, 0].legend() + # + # axes[1, 1].plot( + # f, + # powerspec, + # color=colors[i], + # ) + # axes[1, 1].plot( + # f_sq, + # powerspec_sq, + # color=colors_in[i], + # label=f"dB {db_value}, first peak {np.min(f_sq[peaks])}", + # ) + # axes[1, 1].scatter( + # f_sq[peaks], + # powerspec_sq[peaks], + # color="maroon", + # ) + # axes[1, 1].set_xlabel("Freq [HZ]") + # axes[1, 1].set_ylabel("dB") + # axes[0, 0].legend() + # axes[1, 1].legend() + # plt.show() self.set_analog_to_zero() self.disconnect_dac()