moved working copy from RHEL8 to outdated git #2
No files matched your search
Executable
+134
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from time import sleep
|
||||
from collections import deque
|
||||
import numpy as np
|
||||
import scipy.signal
|
||||
|
||||
from zoetrope import aniplot as plt
|
||||
from bstrd import BS, bsstream
|
||||
plt.blit = False
|
||||
|
||||
|
||||
|
||||
# config
|
||||
cam_name = "SARES11-XMI125-C4P1"
|
||||
xmin = 0
|
||||
xmax = 400
|
||||
ymin = 400
|
||||
ymax = 700
|
||||
proj_axis = 0
|
||||
um_per_px = 2.28
|
||||
buffer_length = 100
|
||||
|
||||
|
||||
|
||||
def get_data(cam):
|
||||
img = 0
|
||||
for i in range(1):
|
||||
img += cam.get()
|
||||
next(bsstream)
|
||||
cropped = img[xmin:xmax, ymin:ymax]
|
||||
projx = cropped.mean(axis=proj_axis)
|
||||
projy = cropped.mean(axis=int(not proj_axis))
|
||||
return cropped, projx, projy
|
||||
|
||||
|
||||
def find_spacing(py, extend=5):
|
||||
py -= py.mean()
|
||||
|
||||
if extend > 1:
|
||||
py = np.concatenate((py, np.zeros(len(py) * extend)))
|
||||
|
||||
spectrum = np.abs(np.fft.fft(py))
|
||||
freq = np.fft.fftfreq(len(spectrum))
|
||||
|
||||
which = (freq > 0.005)
|
||||
spectrum = spectrum[which]
|
||||
freq = freq[which]
|
||||
|
||||
index_peaks = scipy.signal.find_peaks(spectrum)[0]
|
||||
peaks_pos = freq[index_peaks]
|
||||
peak_height = spectrum[index_peaks]
|
||||
|
||||
cut_freq = peaks_pos[np.argmax(peak_height)]
|
||||
return freq, spectrum, cut_freq
|
||||
|
||||
|
||||
def make_xs(arr):
|
||||
return np.arange(len(arr))
|
||||
|
||||
|
||||
# create channel
|
||||
cam = BS(cam_name + ".roi_signal_x_profile", modulo=5)
|
||||
cropped, width, proj = get_data(cam)
|
||||
pixel_proj = make_xs(proj)
|
||||
pixel_width = make_xs(width)
|
||||
|
||||
|
||||
plt.fig.set_figheight(12)
|
||||
plt.fig.set_figwidth(9)
|
||||
|
||||
plt.suptitle(cam_name)
|
||||
|
||||
plt.subplot(321)
|
||||
plt.title(f"cropped image\n[{xmin}:{xmax}, {ymin}:{ymax}]")
|
||||
pimg = plt.imshow(cropped, origin="lower")
|
||||
|
||||
plt.subplot(322)
|
||||
plt.title("projection")
|
||||
pln_proj = plt.plot(proj, pixel_proj)
|
||||
|
||||
plt.subplot(323)
|
||||
plt.title("projection")
|
||||
pln_width = plt.plot([0])
|
||||
|
||||
plt.subplot(324)
|
||||
plt.title("FFT")
|
||||
plt.xlabel("frequency in 1/pixel")
|
||||
pln_fft_spec = plt.plot([0])
|
||||
plt.xlim(0,0.2)
|
||||
pln_fft_cut = plt.plot([0])
|
||||
|
||||
plt.subplot(313)
|
||||
plt.title(f"spacing assuming {um_per_px} μm per pixel")
|
||||
pln_spac = plt.plot([0], 'o')
|
||||
plt.ylim(0,250)
|
||||
plt.tight_layout()
|
||||
|
||||
|
||||
spacings = deque(maxlen=buffer_length)
|
||||
|
||||
for counter in plt.show():
|
||||
print(counter)
|
||||
next(bsstream)
|
||||
|
||||
|
||||
cropped, width, proj = get_data(cam)
|
||||
|
||||
pimg.set(cropped)
|
||||
pln_proj.set(proj, pixel_proj)
|
||||
pln_width.set(pixel_width, width)
|
||||
|
||||
freq, spectrum, cut_freq = find_spacing(proj, extend=10)
|
||||
spac = um_per_px / cut_freq
|
||||
spacings.append(spac)
|
||||
|
||||
pln_spac.set(make_xs(spacings), spacings)
|
||||
pln_fft_spec.set(freq, spectrum)
|
||||
pln_fft_cut.set([cut_freq]*2, [spectrum.min(), spectrum.max()])
|
||||
pln_fft_spec.ax.set_title(f"FFT\ncurrent spacing: {spac:.1f} μm")
|
||||
|
||||
|
||||
# this, I need to move into the library
|
||||
ps = [pln_proj, pln_width, pln_spac, pln_fft_spec]
|
||||
for p in ps:
|
||||
p.ax.relim()
|
||||
p.ax.autoscale_view()
|
||||
|
||||
|
||||
|
||||
bsstream.close()
|
||||
|
||||
|
||||
|
||||
File renamed without changes.
File renamed without changes.
+40
-57
@@ -3,35 +3,26 @@
|
||||
from time import sleep
|
||||
from collections import deque
|
||||
import numpy as np
|
||||
import scipy.signal
|
||||
from scipy import signal
|
||||
|
||||
from zoetrope import aniplot as plt
|
||||
from bstrd import BS, bsstream
|
||||
plt.blit = False
|
||||
|
||||
|
||||
|
||||
# config
|
||||
cam_name = "SARES11-XMI125-C4P1"
|
||||
xmin = 0
|
||||
xmax = 400
|
||||
ymin = 400
|
||||
ymax = 700
|
||||
proj_axis = 0
|
||||
um_per_px = 2.28
|
||||
buffer_length = 100
|
||||
|
||||
|
||||
cam_name = "SARES11-SPEC125-M2.jet_projection"
|
||||
um_per_px = 3.33 # calibrated as of feb 6 2024
|
||||
buffer_length = 1000
|
||||
shots = 10
|
||||
fftthresh = 10000
|
||||
|
||||
def get_data(cam):
|
||||
img = 0
|
||||
for i in range(1):
|
||||
img += cam.get()
|
||||
jet = np.empty((shots, 500))
|
||||
for i in range(shots):
|
||||
jet[i] = cam.get()
|
||||
next(bsstream)
|
||||
cropped = img[xmin:xmax, ymin:ymax]
|
||||
projx = cropped.mean(axis=proj_axis)
|
||||
projy = cropped.mean(axis=int(not proj_axis))
|
||||
return cropped, projx, projy
|
||||
proj = jet.max(axis=0)
|
||||
return proj
|
||||
|
||||
|
||||
def find_spacing(py, extend=5):
|
||||
@@ -40,14 +31,14 @@ def find_spacing(py, extend=5):
|
||||
if extend > 1:
|
||||
py = np.concatenate((py, np.zeros(len(py) * extend)))
|
||||
|
||||
spectrum = np.abs(np.fft.fft(py))
|
||||
spectrum = np.abs(np.fft.fft(py))**2
|
||||
freq = np.fft.fftfreq(len(spectrum))
|
||||
|
||||
which = (freq > 0.005)
|
||||
spectrum = spectrum[which]
|
||||
freq = freq[which]
|
||||
|
||||
index_peaks = scipy.signal.find_peaks(spectrum)[0]
|
||||
index_peaks = signal.find_peaks(spectrum)[0]
|
||||
peaks_pos = freq[index_peaks]
|
||||
peak_height = spectrum[index_peaks]
|
||||
|
||||
@@ -60,42 +51,40 @@ def make_xs(arr):
|
||||
|
||||
|
||||
# create channel
|
||||
cam = BS(cam_name + ".roi_signal_x_profile", modulo=5)
|
||||
cropped, width, proj = get_data(cam)
|
||||
cam = BS(cam_name)
|
||||
proj = get_data(cam)
|
||||
pixel_proj = make_xs(proj)
|
||||
pixel_width = make_xs(width)
|
||||
|
||||
plt.fig.set_figheight(8)
|
||||
plt.fig.set_figwidth(8)
|
||||
|
||||
plt.fig.set_figheight(12)
|
||||
plt.fig.set_figwidth(9)
|
||||
|
||||
plt.suptitle(cam_name)
|
||||
|
||||
plt.subplot(321)
|
||||
plt.title(f"cropped image\n[{xmin}:{xmax}, {ymin}:{ymax}]")
|
||||
pimg = plt.imshow(cropped, origin="lower")
|
||||
|
||||
plt.subplot(322)
|
||||
plt.subplot(221)
|
||||
plt.title("projection")
|
||||
pln_proj = plt.plot(proj, pixel_proj)
|
||||
plt.xlim(-45,45)
|
||||
plt.gca().invert_yaxis()
|
||||
plt.grid()
|
||||
|
||||
plt.subplot(323)
|
||||
plt.title("projection")
|
||||
pln_width = plt.plot([0])
|
||||
|
||||
plt.subplot(324)
|
||||
plt.subplot(222)
|
||||
plt.title("FFT")
|
||||
plt.xlabel("frequency in 1/pixel")
|
||||
pln_fft_spec = plt.plot([0])
|
||||
plt.xlim(0,0.2)
|
||||
plt.xlim(0,0.25)
|
||||
plt.grid()
|
||||
#plt.ylim(0,500000)
|
||||
pln_fft_cut = plt.plot([0])
|
||||
|
||||
plt.subplot(313)
|
||||
plt.subplot(212)
|
||||
plt.title(f"spacing assuming {um_per_px} μm per pixel")
|
||||
pln_spac = plt.plot([0], 'o')
|
||||
plt.ylim(0,250)
|
||||
plt.tight_layout()
|
||||
pln_spac.ax.axhline(y=95, color='r') # 95um spacing set for CRY4 expt
|
||||
plt.xlabel('1000 (*10) most recent images')
|
||||
plt.ylabel('ladder spacing in $\mu$m')
|
||||
plt.ylim(0,150)
|
||||
plt.xlim(0,buffer_length)
|
||||
|
||||
plt.grid()
|
||||
plt.tight_layout()
|
||||
|
||||
spacings = deque(maxlen=buffer_length)
|
||||
|
||||
@@ -103,32 +92,26 @@ for counter in plt.show():
|
||||
print(counter)
|
||||
next(bsstream)
|
||||
|
||||
proj = get_data(cam)
|
||||
|
||||
cropped, width, proj = get_data(cam)
|
||||
|
||||
pimg.set(cropped)
|
||||
pln_proj.set(proj, pixel_proj)
|
||||
pln_width.set(pixel_width, width)
|
||||
|
||||
freq, spectrum, cut_freq = find_spacing(proj, extend=10)
|
||||
spac = um_per_px / cut_freq
|
||||
spacings.append(spac)
|
||||
if spectrum.max() > fftthresh:
|
||||
spacings.append(spac)
|
||||
else:
|
||||
spacings.append(np.nan)
|
||||
|
||||
pln_spac.set(make_xs(spacings), spacings)
|
||||
pln_fft_spec.set(freq, spectrum)
|
||||
pln_fft_cut.set([cut_freq]*2, [spectrum.min(), spectrum.max()])
|
||||
pln_fft_spec.ax.set_title(f"FFT\ncurrent spacing: {spac:.1f} μm")
|
||||
|
||||
pln_fft_spec.ax.set_title(f"FFT; current spacing: {spac:.1f} μm")
|
||||
|
||||
# this, I need to move into the library
|
||||
ps = [pln_proj, pln_width, pln_spac, pln_fft_spec]
|
||||
ps = [pln_proj, pln_spac, pln_fft_spec]
|
||||
for p in ps:
|
||||
p.ax.relim()
|
||||
p.ax.autoscale_view()
|
||||
|
||||
|
||||
|
||||
bsstream.close()
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# The following block allows to use the `run` script like this
|
||||
# ```
|
||||
# ln -s run a_script.sh
|
||||
# ./a_script.sh
|
||||
# ```
|
||||
# which then runs `./run a_script.py`
|
||||
|
||||
fn=$(basename $0)
|
||||
if [ "$fn" != "run" ]; then
|
||||
dn=$(dirname "$0")
|
||||
sn=$(basename "$0" .sh)
|
||||
dn="${dn}/run"
|
||||
sn="${sn}.py"
|
||||
echo "Running: $dn $sn"
|
||||
$dn $sn
|
||||
exit
|
||||
fi
|
||||
|
||||
###
|
||||
|
||||
function help() {
|
||||
echo "Load conda env and run a script"
|
||||
@@ -42,8 +23,14 @@ if [[ -z $@ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source /sf/alvra/applications/miniconda3/etc/profile.d/conda.sh
|
||||
conda activate adaq
|
||||
source /sf/eido/source-python
|
||||
#!/usr/bin/env python
|
||||
|
||||
#source /sf/alvra/applications/miniconda3/etc/profile.d/conda.sh
|
||||
#conda activate adaq
|
||||
#source /sf/eido/applications/miniconda3/etc/profile.d/conda.sh
|
||||
#conda activate slic-3.8-update6
|
||||
source /sf/daq/source-conda
|
||||
conda activate slic
|
||||
source /sf/daq/source-python
|
||||
$@
|
||||
|
||||
Reference in new issue
Block a user