Skip to content

Commit

Permalink
#5 Merge pull request from deshima-dev/astropenguin/issue2
Browse files Browse the repository at this point in the history
Do not use deprecated imports and functions
  • Loading branch information
astropenguin authored Jun 17, 2024
2 parents 6314efa + 8f0d4f3 commit 5cb344d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions scripts/libs/bbsweeplib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def get_cache(self, name):
else:
func = getattr(self, name)
orig_func = func.orig_func
argspec = inspect.getargspec(orig_func)
argspec = inspect.getfullargspec(orig_func)
# print argspec
args, varargs, kws, defaults = argspec
args, varargs, kws, defaults, *_ = argspec
# print argspec
if args == ['self'] and varargs is None and kws is None:
return func()
Expand Down
35 changes: 18 additions & 17 deletions scripts/libs/bbsweeplib/kids.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings
import os
from collections import Mapping, OrderedDict
from collections import OrderedDict
from collections.abc import Mapping

import numpy as np
from astropy.io import fits as pyfits
Expand Down Expand Up @@ -47,7 +48,7 @@ def open(self):
self._read_bins = {}

self.offset = -100 # remove last part of data (sometimes they behave bad)

def close(self):
self.hud.close()

Expand Down Expand Up @@ -110,24 +111,24 @@ def __init__(self, infile, Readout, Channel):
self.R = Readout
self.Ch = Channel
self.header = dict()

self.open()

def read_header(self):
#sysinfo = dict( self.hud.attrs )
#chinfo = dict( self.hud['rack_%02d' %self.R]['channel_%02d' %self.Ch].attrs )
datainfo = dict( self.hud['rack_%02d' %self.R]['channel_%02d' %self.Ch]['data'].attrs )

self.header['lofreq'] = datainfo['lo_frequency']*1e+6 # MHz to Hz
self.header['npoints'] = datainfo['frame_length']
self.header['fftgain'] = datainfo['fft_gain']
self.header['nbins'] = datainfo['num_bins']
self.header['framert'] = datainfo['frame_rate']

def open(self):
self.hud = h5py.File(self.infile, 'r')
self.read_header()

self.fftgain = self.header['fftgain']
self.framert = self.header['framert']
self.nbins = self.header['nbins']
Expand All @@ -136,7 +137,7 @@ def open(self):
lbins = self.hud['rack_%02d' %self.R]['channel_%02d' %self.Ch]['bins']
assert( len(lbins)==self.nbins )
for i in range(self.nbins):
self.header['BIN%d' %i] = lbins[i]
self.header['BIN%d' %i] = lbins[i]
self.bins = [_to_nbit_signed(self.header['BIN%d' %i], self.npoints)
for i in range(self.nbins)]
self.if_freq = self.kSampleRate * np.array(self.bins) / 2**self.npoints
Expand All @@ -150,7 +151,7 @@ def open(self):
self._read_bins = {}

self.offset = -100 # remove last part of data (sometimes they behave bad)

def close(self):
self.hud.close()

Expand Down Expand Up @@ -249,7 +250,7 @@ def __init__(self, path, kidslist, sweeps_path, tods_path, **kws):
else:
print('There is no local sweep with room chopper closed')
self._sweeps_roomchopper_path = None

def bins_kid(self):
return self._kidslist[1]

Expand Down Expand Up @@ -296,13 +297,13 @@ def find_glitch(self, baseline_thresh = 6.0, glitch_thresh = 5.0, clusterize_thr
bad = k.find_glitch.cache
else:
bad = k.find_glitch(baseline_thresh, glitch_thresh, clusterize_thresh)

if bad_for_any is None:
#bad_for_any = bad
bad_for_any = bad.copy()
else:
bad_for_any |= bad

#if i % 20 == 0:
# self.save(clear_memory=True)

Expand Down Expand Up @@ -519,7 +520,7 @@ def average_slice_tod(self):
#dphases.append( np.std(phase)/np.sqrt( len(phase)-1 ) )
dampls.append( np.std(ampl) )
dphases.append( np.std(phase) )

return np.array([ampls, dampls, phases, dphases])

@do_cache
Expand All @@ -544,7 +545,7 @@ def average_slice_psds(self):
@do_cache
def set_filter_params(self, masterid, kind, F0, dF0, Q, dQ):
return masterid, kind, F0, dF0, Q, dQ

@do_cache
def set_dPdT(self, pval, perr):
return pval, perr
Expand Down Expand Up @@ -624,7 +625,7 @@ def convert_to_fshift(self, phase, opt='phase'):
import scipy.interpolate
tck = scipy.interpolate.splrep(phase_f, swp.x, s=0)
f = scipy.interpolate.splev(phase, tck, der=0)

if opt=='phase':
return phase
elif opt=='fshift':
Expand All @@ -637,15 +638,15 @@ def convert_to_fshift(self, phase, opt='phase'):
else:
print( '>>> KID::convert_to_fshift: Not supported option!!' )
print( '>>> return phase' )
return phase
return phase

def slice_tod(self, opt='phase'):
slices = self._parent.get_cache('set_slice')
d = self.get_cache('deglitch')
ts, ampl, phase = d.unpack()

## linearize phase
fshift = self.convert_to_fshift(phase, opt)
fshift = self.convert_to_fshift(phase, opt)

d = md.FixedFitData(d.frequency*1e+9, ts, ampl, fshift)
return [d[s] for s in slices]
Expand Down
2 changes: 1 addition & 1 deletion scripts/libs/fit/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _fit(function, xs, ys, err=None, via=None, range=None, silent=False,
if type(function) == Expr_with_args:
tmpargs = function.arg_names
else:
argspec = inspect.getargspec(func)
argspec = inspect.getfullargspec(func)
tmpargs = argspec.args[1:]

## prepare params argument
Expand Down

0 comments on commit 5cb344d

Please sign in to comment.