Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #18

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified scripts/kid_test.db
Binary file not shown.
5 changes: 3 additions & 2 deletions scripts/terahertzsweep/AnaSpectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import copy

import matplotlib.pyplot as plt
import mkid_data as md
#import mkid_data as md
import numpy as np
from astropy.io import fits

script_dir = os.path.dirname(os.path.abspath(__file__))
libpath = os.path.join(os.path.dirname(script_dir), 'libs')
sys.path.append(libpath)

from common import *
#from common import *
import pandas as pd
import scipy.optimize
import lmfit
Expand Down Expand Up @@ -673,5 +673,6 @@ def Plot(mode, kidid, result_F0, result_fit, pp, opt):
from fit.confidence_band import confidence_band
from matplotlib.backends.backend_pdf import PdfPages

import mkid_data as md
main()

4 changes: 2 additions & 2 deletions scripts/terahertzsweep/Configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def complete(text, state):
measure_id = os.path.basename(os.path.dirname(targetdir))
#print("mkdir -p /home/deshima/data/analysis/%s/%s"%(run_id, measure_id))
#os.system("mkdir -p /home/deshima/data/analysis/%s/%s"%(run_id, measure_id))
print("mkdir -p /Users/sfujita/Desktop/DESHIMA/toptica/analysis/%s/%s"%(run_id, measure_id))
os.system("mkdir -p /Users/sfujita/Desktop/DESHIMA/toptica/analysis/%s/%s"%(run_id, measure_id))
# print("mkdir -p /Users/sfujita/Desktop/DESHIMA/toptica/analysis/%s/%s"%(run_id, measure_id))
# os.system("mkdir -p /Users/sfujita/Desktop/DESHIMA/toptica/analysis/%s/%s"%(run_id, measure_id))
outdir = args.outdir or input('out directory (e.g., out_test):')
confdir = outdir + '/conf'
disabled_kid_file = outdir + '/disabled_kids.dat'
Expand Down
4 changes: 3 additions & 1 deletion scripts/terahertzsweep/FitSweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections import OrderedDict

import matplotlib.pyplot as plt
import mkid_data as md
#import mkid_data as md
import numpy as np

def get_kids_from_db(runid):
Expand Down Expand Up @@ -353,6 +353,8 @@ def Plot(kids, force, test, NCPU):
"""

def plot_multi(params):
import mkid_data as md

i = params["i"]
kid = params["kid"]
plotdir = params["plotdir"]
Expand Down
62 changes: 53 additions & 9 deletions scripts/terahertzsweep/KIDCorresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import sqlite3
import datetime
import numpy as np
dbname = '/Users/sfujita/Desktop/DESHIMA/toptica/kid_test.db'
#dbname = '/Users/sfujita/Desktop/DESHIMA/toptica/kid_test.db'
dbname = '../kid_test.db'
conn = sqlite3.connect(dbname,
detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)

Expand Down Expand Up @@ -106,27 +107,68 @@ def kid_corresp(kids, args):
ax.set_ylabel('F_filter [GHz]')
fig.savefig(os.path.join(plotdir, 'raw.pdf'))
fig.savefig(os.path.join(plotdir, 'raw.png'), dpi = 300)
plt.close()
plt.clf()
plt.cla()

# fig.savefig(os.path.join(plotdir, 'raw.design.pdf'))
# fig.savefig(os.path.join(plotdir, 'raw.design.png'), dpi = 300)

########################## adjust


#### Arend's adjustment
# Split into left and right of LO
measured_idx_sort = np.argsort(f_KID_measured)
design_idx_sort = np.argsort(f_KID_design)

F_filter_measured = F_filter_measured[measured_idx_sort]
F_filter_design = F_filter_design[design_idx_sort]
f_KID_measured = np.sort(f_KID_measured)
f_KID_design = np.sort(f_KID_design)

max_idx_measured = np.argmax(np.diff(f_KID_measured))
max_idx_design = np.argmax(np.diff(f_KID_design))

f_KID_measured_lo = f_KID_measured[:max_idx_measured+1]
f_KID_measured_hi = f_KID_measured[max_idx_measured+1:]
f_KID_design_lo = f_KID_design[:max_idx_design+1]
f_KID_design_hi = f_KID_design[max_idx_design+1:]

def adjust(a, b):
''' supposing a and b are numpy array'''
return a, (a.std()/b.std())*(b - b.mean()) + a.mean()

print( f_KID_design, f_KID_measured )
fKda_lo, fKma_lo = adjust(f_KID_design_lo, f_KID_measured_lo)
fKda_hi, fKma_hi = adjust(f_KID_design_hi, f_KID_measured_hi)

# Also adjust whole arrays, for the Y-axis rectification
fKda, fKma = adjust(f_KID_design, f_KID_measured)

Ffda, Ffma = adjust(F_filter_design, F_filter_measured)

def rectify(a, b, offset):
""" offset parameter to move to left and right of LO gap """
return a - a.mean() - offset, (b - b.mean())*a.std()/b.std()

def rectify(a, b):
return a - a.mean(), (b - b.mean())*a.std()/b.std()
X_design_lo, Y_design_lo = rectify(fKda_lo, Ffda, offset=0.5)
X_design_hi, Y_design_hi = rectify(fKda_hi, Ffda, offset=-0.5)
_, Y_design = rectify(fKda, Ffda, offset=0)
X_design = np.append(X_design_lo, X_design_hi)
#Y_design = np.append(Y_design_lo, Y_design_hi)

X_design, Y_design = rectify(fKda, Ffda)
C_design = X_design + 1j*Y_design
X_measured, Y_measured = rectify(fKma, Ffma)

X_measured_lo, Y_measured_lo = rectify(fKma_lo, Ffma, offset=0.5)
X_measured_hi, Y_measured_hi = rectify(fKma_hi, Ffma, offset=-0.5)
_, Y_measured = rectify(fKma, Ffma, offset=0)
X_measured = np.append(X_measured_lo, X_measured_hi)
#Y_measured = np.append(Y_measured_lo, Y_measured_hi)

C_measured = X_measured + 1j*Y_measured

#### End of Arend's adjustment

############# adj plot
fig, ax = plt.subplots(figsize = (8,8))
ax.scatter(X_measured, Y_measured, label = 'Measured')
Expand Down Expand Up @@ -204,12 +246,14 @@ def collision_handler():
import json
## add wideband KID
ref_list = []
line_count = 0
with open(os.path.join(outdir, "reference.dat")) as f:
for line in f:
if line_count != 0:
if line[0] == '#':
continue
elif len(line[:-1]) == 0:
continue
else:
ref_list.append(int(line.split("\n")[0]))
line_count += 1
print("reference.dat = ", ref_list)
tmpdict = {}
if len(ref_list)>=4:
Expand Down
4 changes: 3 additions & 1 deletion scripts/terahertzsweep/SaveFits.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ def Plot(kids, plot_tod_ratio, force, blindtone, test, NCPU):
else:
os.symlink(plotdir, calibtoddir)

blinddir = outdir + '/figSaveFits.Blindtone'
if blindtone:
blinddir = outdir + '/figSaveFits.Blindtone'
if force:
try:
shutil.rmtree(blinddir)
Expand Down Expand Up @@ -281,6 +281,8 @@ def Plot(kids, plot_tod_ratio, force, blindtone, test, NCPU):
#
# if test and i>10: break
def plot_multi(params):
import mkid_data as md

i = params["i"]
kid = params["kid"]
plotdir = params["plotdir"]
Expand Down