diff --git a/sixdeskdb/davsturns.py b/sixdeskdb/davsturns.py index fcc4a90..cbc0dd8 100644 --- a/sixdeskdb/davsturns.py +++ b/sixdeskdb/davsturns.py @@ -442,6 +442,7 @@ def mk_da_vst(data,seed,tune,turnsl,turnstep,emitx,emity,regemi): ajsimp_s=np.array([55/24.,-1/6.,11/8.])#Simpson rule ajsimp_e=np.array([11/8.,-1/6.,55/24.]) warnsimp=True + for it in np.arange(turnstep,tmax+turnstep,turnstep): mta=get_min_turn_ang(s,t,a,it) mta_angle=mta['angle']*np.pi/180#convert to rad @@ -900,7 +901,7 @@ def RunDaVsTurns(db,force,outfile,outfileold,turnstep,davstfit,fitdat,fitdaterr, import itertools -#import pdb + from . import tables # new DA method for unequal emittances - MT def RunDaVsTurns_ue(db, emittances, turnstep=100, method=1, close=True, diff --git a/sixdeskdb/deskdb.py b/sixdeskdb/deskdb.py index 36239fe..aac2ffc 100644 --- a/sixdeskdb/deskdb.py +++ b/sixdeskdb/deskdb.py @@ -2568,7 +2568,9 @@ def mk_da_vst_ang(self,seed,tune,turnstep): e.g. for angmax=29+1 for divisors [1, 2, 3, 5, 6, 10]""" RunDaVsTurnsAng(self,seed,tune,turnstep) - def get_surv(self, seed, tune=None, verbose=True): + + def get_surv_tmp(self, seed, tune=None, verbose=True): + '''get survival turns from DB calculated from emitI and emitII''' if verbose: @@ -2609,6 +2611,29 @@ def get_surv(self, seed, tune=None, verbose=True): return None + def get_surv(self, seed, tune_pair): + '''get survival turns from DB calculated from emitI and emitII''' + + (tunex, tuney) = tune_pair + emit = float(self.env_var['emit']) + gamma = float(self.env_var['gamma']) + turnsl = self.env_var['turnsl'] + cmd="""SELECT angle, emitx + emity, + CASE WHEN sturns1 < sturns2 THEN sturns1 ELSE sturns2 END + FROM results WHERE seed=%s AND tunex=%s AND tuney=%s AND turn_max=%s + ORDER BY angle, emitx + emity""" + cur = self.conn.cursor().execute(cmd%(seed, tunex, tuney, turnsl)) + ftype = [('angle', float), ('sigma', float), ('sturn', float)] + data = np.fromiter(cur, dtype=ftype) + data['sigma'] = np.sqrt(data['sigma']/(emit/gamma)) + angles = len(set(data['angle'])) + try: + return data.reshape(angles, -1) + except ValueError: + print("Cannot reshape array of size %s into "%(len(data))+ + "shape (%s,newaxis). Skip this seed %s!"%(angles, seed)) + return None + def plot_da_vst(self,seed,tune,ldat,ldaterr,ampmin,ampmax,tmax,slog,sfit,fitndrop): """plot dynamic aperture vs number of turns where ldat,ldaterr is the data and the associated error to be plotted. The data is plotted in blue and the fit in red.