def maxkurtseries(rc, it=0., ft=.1, stept=1, bl=0.2, fl=5., stepl=1): import numpy as np import AnalysisFunctions as af rc.vars2load(['bx', 'by']) rc.loadenergies() bst = np.int(rc.t[np.argmin(np.abs(rc.ta - it))] / rc.dtmovie) fst = np.int(rc.t[np.argmin(np.abs(rc.ta - ft))] / rc.dtmovie) if fl > 0.5 * rc.lx: fl = 0.5 * rc.lx if bl < rc.dx: bl = rc.dx bsl = int(bl / rc.dx) fsl = int(fl / rc.dx) sclmx = np.zeros((fst - bst) / stept) krtmx = np.zeros((fst - bst) / stept) tsris = np.zeros((fst - bst) / stept) for it in range(bst, fst, stept): print(it) #Find the appropriate index for movie idx = (it - bst) / stept #Load the corresponding time slice rc.loadslice(it) #Assign the appropriate nonlinear time to the timeseries tsris[idx] = rc.ta[np.argmin(np.abs(rc.t - rc.time))] #Compute the scale dependent kurtosis between bl,fl rx, sdx = af.sdk(rc.bx, bs=bsl, fs=fsl, step=stepl, dx=rc.dx, ax=0) ry, sdy = af.sdk(rc.by, bs=bsl, fs=fsl, step=stepl, dx=rc.dx, ax=1) #Find the location of maximum value of kurtosis between sdx,sdy # xx=np.argmin(np.abs(np.array([sdx.max(),sdy.max()]))) tsdk = np.array([sdx, sdy]) rr = np.array([rx, ry]) xx = np.unravel_index(tsdk.argmax(), tsdk.shape) sclmx[idx] = rr[xx] krtmx[idx] = tsdk[xx] # if xx[1] ==0: # sclmx[idx] = rx[xx[0]] # krtmx[idx] = sdx.max() # else: # sclmx[idx] = ry[xx[0]] # krtmx[idx] = sdy.max() return tsris, sclmx, krtmx, np.mean(krtmx)
def _derivedv(self, varname): import AnalysisFunctions as af if varname == 'bx': return af.pcurlx(self.ay, self.az) if varname == 'by': return af.pcurly(self.az, self.ax) if varname == 'bz': return af.pcurlz(self.ax, self.ay) if varname == 'ex': return self.vy * self.bz - self.vz * self.by if varname == 'ey': return self.vz * self.bx - self.vx * self.bz if varname == 'ez': return self.vx * self.by - self.vy * self.bx
def kspec(rc): import AnalysisFunctions as af import numpy as np from subs import ask_for_steps rc.vars2load(['bx', 'by', 'bz']) bs, fs, step = ask_for_steps(rc.numslices) ebx = np.zeros(rc.nx / 2 + 1) eby = np.zeros(rc.nx / 2 + 1) ebz = np.zeros(rc.nx / 2 + 1) for it in range(bs, fs, step): print('time slice', it) rc.loadslice(it) kk, ekx, eky, ekz, ekb = af.fperpspecvec(rc.bx, rc.by, rc.bz) ebx = ebx + ekx eby = eby + eky ebz = ebz + ekz kk = kk * 2 * np.pi / rc.lx dk = kk[2] - kk[1] ebz = ebz * float(step) / (float(fs - bs) * dk) eby = eby * float(step) / (float(fs - bs) * dk) ebx = ebx * float(step) / (float(fs - bs) * dk) outf = open('kspec.' + rc.dirname + '.dat', 'w') for i in range(rc.nx / 2): print(kk[i], ebx[i], eby[i], ebz[i], file=outf) outf.close()
def CalculateMetrics(sectionData): keyLine = sectionData.pop(0) if (keyLine.startswith('stresses')): keys = keyLine.split() ELSet_ID = keys[5] maxMises = 0 maxShear = 0 maxBearing = 0 for data in sectionData: splittedLine = data.split() stressMatrix = splittedLine[2:] #stressLevels tmpMise, tmpBear, tmpShear = AnalysisFunctions.FindStressMetrics( stressMatrix) maxMises = max(maxMises, tmpMise) maxShear = max(maxShear, tmpShear) maxBearing = max(maxBearing, tmpBear) # FactorOfSafety if (ComputedMetricsSummary.gComponentList.has_key(ELSet_ID)): tmpComponent = ComputedMetricsSummary.gComponentList[ELSet_ID] #factorOfSafety = min(float(tmpComponent.MaterialProperty['Shear'])/maxShear, # float(tmpComponent.MaterialProperty['Bearing'])/maxBearing, # float(tmpComponent.MaterialProperty['Mises'])/maxMises) factorOfSafety = float( tmpComponent.MaterialProperty['Mises']) / maxMises if (tmpComponent.MetricsInfo.has_key('Shear')): tmpComponent.MetricsOutput[ tmpComponent.MetricsInfo['Shear']] = maxShear if (tmpComponent.MetricsInfo.has_key('Mises')): tmpComponent.MetricsOutput[ tmpComponent.MetricsInfo['Mises']] = maxMises if (tmpComponent.MetricsInfo.has_key('Bearing')): tmpComponent.MetricsOutput[ tmpComponent.MetricsInfo['Bearing']] = maxBearing if (tmpComponent.MetricsInfo.has_key('FactorOfSafety')): tmpComponent.MetricsOutput[tmpComponent.MetricsInfo[ 'FactorOfSafety']] = factorOfSafety ComputedMetricsSummary.gComponentList[ELSet_ID] = tmpComponent #? elif (keyLine.startswith('displacements')): displacementData = dict() for data in sectionData: splittedLine = data.split() displacementData[ splittedLine[0]] = AnalysisFunctions.FindDisplacementMagnitude( float(splittedLine[1]), float(splittedLine[2]), float(splittedLine[3]))
def RunAnalysis(): op.wipe() # Build Model mf.getSections() mf.buildModel() # Prepare Outputs Model = 'test' LoadCase = 'Pushover' element1 = 1 section1 = 1 element2 = 2 section2 = 3 opp.createODB(Model, LoadCase) opp.saveFiberData2D(Model, LoadCase, element1, section1) opp.saveFiberData2D(Model, LoadCase, element2, section2) # Run Analysis af.PushoverLcD(0.001) op.wipe()
#!/usr/bin/env python from pylab import * import AnalysisFunctions as af from subs import create_object, ask_for_steps rc = create_object() rc.vars2load(['jz']) bs, fs, step = ask_for_steps(rc.numslices) nt = (fs - bs) / step + 1 jzt = np.zeros((rc.nx, rc.ny, rc.nz, nt)) print('What weight function to use?') wght = int(input()) for it in range(bs, fs, step): print('time slice', it) rc.loadslice(it) i = (it - bs) / step jzt[:, :, :, i] = rc.jz jzb, jzpdf = af.calc_pdf(jzt, weight=wght) outf = open('jzpdf.' + rc.dirname + '.dat', 'w') for i in range(len(jzb)): print(jzb[i], jzpdf[i], file=outf) outf.close() rc.fin()
# zpx = vcx + rc.bx zpy = vcy + rc.by zpz = vcz + rc.bz # lezp = 0.5 * np.mean(rho * (np.abs(zpx)**2 + np.abs(zpy)**2 + np.abs(zpz)**2)) zmx = vcx - rc.bx zmy = vcy - rc.by zmz = vcz - rc.bz # lezm = 0.5 * np.mean(rho * (np.abs(zmx)**2 + np.abs(zmy)**2 + np.abs(zmz)**2)) ## #Correlation for z+ #kwave,zkx,zky,zkz,zk = af.PerpSpecVec(zpx,zpy,zpz) kwave, zkx, zky, zkz, zk = af.fperpspecvec(zpx, zpy, zpz, 2, rc.nx / 2) llcp = (np.pi / sum(zk[1:])) * sum(zk[1:] / kwave[1:]) ## #Correlation for z- #kwave,zkx,zky,zkz,zk = af.PerpSpecVec(zmx,zmy,zmz) kwave, zkx, zky, zkz, zk = af.fperpspecvec(zmx, zmy, zmz, 2, rc.nx / 2) llcm = (np.pi / sum(zk[1:])) * sum(zk[1:] / kwave[1:]) # ltt = round(it * rc.dtmovie, 4) ## PRINT TO STDOUT FOR RECAPTURE IF THE RUN CRASHES print ltt, ltt * 2 * np.pi / rc.lx, lezp, lezm, llcp, llcm if rank == 0: tt[it] = ltt ezp[it] = lezp ezm[it] = lezm
#!/usr/bin/env python import AnalysisFunctions as af import numpy as np from subs import create_object,ask_for_steps rc=create_object() rc.vars2load(['bx','by','bz']) bs,fs,step=ask_for_steps(rc.numslices) nt=(fs-bs)/step for it in range(bs,fs,step): print 'time slice',it rc.loadslice(it) kx,xkbx,xkby,xkbz,xkb=af.ReducedSpecVec(rc.bx,rc.by,rc.bz,axx=0,lx=rc.lx) ky,ykbx,ykby,ykbz,ykb=af.ReducedSpecVec(rc.bx,rc.by,rc.bz,axx=1,ly=rc.ly) outf=open('spectrum/xspec-'+rc.dirname+'-%03d.dat'%it,'w') for i in range(len(kx)): print >> outf,kx[i],xkbx[i],xkby[i],xkbz[i],xkb[i] outf.close() outf=open('spectrum/yspec-'+rc.dirname+'-%03d.dat'%it,'w') for i in range(len(ky)): print >> outf,ky[i],ykbx[i],ykby[i],ykbz[i],ykb[i] outf.close() rc.fin()
import numpy as np rc = create_object() rc.vars2load( ['bx', 'by', 'bz', 'jix', 'jiy', 'j*z', 'jex', 'jey', 'jez', 'ni', 'ne']) t = rc.dtmovie * np.arange(rc.numslices) tt = rc.dtmovie * np.arange(rc.numslices) * 2 * np.pi / rc.lx bs, fs, step = ask_for_steps(rc.numslices) ii = 0 + 1j kmin = 2 * np.pi / rc.lx kminsq = kmin**2 kx, ky, kz, km = af.create_kgrid(rc.nx, rc.ny, rc.nz, lx=rc.lx, ly=rc.ly, lz=rc.lz) ksq = km**2 ax = np.zeros((rc.nx, rc.ny, rc.nz), dtype=complex) ay = np.zeros((rc.nx, rc.ny, rc.nz), dtype=complex) az = np.zeros((rc.nx, rc.ny, rc.nz), dtype=complex) wx = np.zeros((rc.nx, rc.ny, rc.nz), dtype=complex) wy = np.zeros((rc.nx, rc.ny, rc.nz), dtype=complex) wz = np.zeros((rc.nx, rc.ny, rc.nz), dtype=complex) outf = open('AW2.' + rc.dirname + '.dat', 'w') print >> outf, 't[it],\t tt[it],\t eb,\t az2,\t ev,\t wz2,\t eb+ev-az2-wz2' for it in range(bs, fs, step): print 'time slice', it
mf.getSections() mf.buildModel() # Prepare Outputs Model = 'Cantilever' LoadCase = 'Pushover' element1 = 1 section1 = 1 element2 = 2 section2 = 3 opp.createODB(Model, LoadCase) opp.saveFiberData2D(Model, LoadCase, element1, section1) opp.saveFiberData2D(Model, LoadCase, element2, section2) # # Run Analysis af.PushoverLcD(0.05) op.wipe() # ============================================================================= # Animation outputs # ============================================================================= opp.plot_fiberResponse2D(Model, LoadCase, element2, section2, InputType='stress', tstep=1) opp.plot_fiberResponse2D(Model, LoadCase,
#!/usr/bin/env python import AnalysisFunctions as af import numpy as np from subs import create_object, ask_for_steps rc=create_object() rc.vars2load(['bx','by','bz']) bs,fs,step=ask_for_steps(rc.numslices) nt=(fs-bs)/step for it in range(bs,fs,step): print('time slice',it) rc.loadslice(it) kk,ekbx,ekby,ekbz,ekb=af.fperpspecvec(rc.bx,rc.by,rc.bz) outf=open('perpspec-'+rc.dirname+'-%03d.dat'%it,'w') for i in range(len(kk)): print(kk[i],ekbx[i],ekby[i],ekbz[i],ekb[i], file=outf) outf.close() rc.fin()
#defaultdict to use nested dictionaries from collections import defaultdict import matplotlib.pyplot as plt import statsmodels.api as sm import numpy as np import dill """ ------------------------------------------------------------------------------------------------------------------------------------------------- PRE-PROCESSING: Import data, organize them, set observations subsets, calculate the quantiles: ------------------------------------------------------------------------------------------------------------------------------------------------- """ # Dictionary initialization: df = af.dictionary() list(df.keys()) # Decide simulation starting time: sim_start = '2018-10-26 12:00:00' # Some parameters for the basin: Verzasca_area = 186 * 1000.0**2 #m2 conv_factor = Verzasca_area / (1000.0 * 3600.0) # Runoff observation: open observation dataframe obs_pattern = '/home/ciccuz/hydro/prevah/runoff/2605.dat' obs_columns = ['year', 'month', 'day', 'hour', 'runoff'] obs_df = pd.DataFrame( pd.read_csv(obs_pattern, names=obs_columns,
def computevars(self, v2c, smth=None): if 'tempi' in v2c: self.tix = self.pixx / self.ni self.tiy = self.piyy / self.ni self.tiz = self.pizz / self.ni self.ti = (self.tix + self.tiy + self.tiz) / 3. if 'tempe' in v2c: self.tex = self.pexx / self.ne self.tey = self.peyy / self.ne self.tez = self.pezz / self.ne self.te = (self.tex + self.tey + self.tez) / 3. if 'vi' in v2c or 'omi' in v2c or 'dui' in v2c or 'zpzm' in v2c or 'udgpi' in v2c: self.vix = self.jix / self.ni self.viy = self.jiy / self.ni self.viz = self.j*z / self.ni if 'omi' in v2c: self.omxi,self.omyi,self.omzi = af.pcurl(self.vix,self.viy,\ self.viz,dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 'dui' in v2c: self.dui = af.pdiv(self.vix, self.viy, self.viz, dx=self.dx, dy=self.dy, dz=self.dz, smth=smth) if 'udgpi' in v2c: self.udgpi = self.vix*af.pdiv(self.pixx, self.pixy, self.pixz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.viy*af.pdiv(self.pixy, self.piyy, self.piyz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.viz*af.pdiv(self.pixz, self.piyz, self.pizz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 've' in v2c or 'ome' in v2c or 'due' in v2c or 'zpzm' in v2c or 'udgpe' in v2c: self.vex = -self.jex / self.ne self.vey = -self.jey / self.ne self.vez = -self.jez / self.ne if 'ome' in v2c: self.omxe,self.omye,self.omze = af.pcurl(self.vex,self.vey,\ self.vez,dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 'due' in v2c: self.due = af.pdiv(self.vex, self.vey, self.vez, dx=self.dx, dy=self.dy, dz=self.dz, smth=smth) if 'udgpe' in v2c: self.udgpe = self.vex*af.pdiv(self.pexx, self.pexy, self.pexz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.vey*af.pdiv(self.pexy, self.peyy, self.peyz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.vez*af.pdiv(self.pexz, self.peyz, self.pezz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 'zpzm' in v2c: cmx = (self.vix + self.m_e * self.vex) / (1 + self.m_e) cmy = (self.viy + self.m_e * self.vey) / (1 + self.m_e) cmz = (self.viz + self.m_e * self.vez) / (1 + self.m_e) den = self.ni + self.m_e * self.ne self.zpx = self.bx / np.sqrt(den) + cmx self.zpy = self.by / np.sqrt(den) + cmy self.zpz = self.bz / np.sqrt(den) + cmz self.zmx = self.bx / np.sqrt(den) - cmx self.zmy = self.by / np.sqrt(den) - cmy self.zmz = self.bz / np.sqrt(den) - cmz
#!/usr/bin/env python import AnalysisFunctions as af import numpy as np from subs import create_object, ask_for_steps print(" NEED TO SIT DOWN AND FIX IT SUCH THAT ") print(" IT CALCULATES THE INCREMENT ARRAY AND ") print(" KURTOSIS ACCORDING TO THE DIRECTION ") print(" THAT YOU PROVIDE. ") rc = create_object() rc.vars2load(['bx', 'by', 'bz']) bs, fs, step = ask_for_steps(rc.numslices) nt = (fs - bs) / step bxk = np.zeros(rc.nx / 2) byk = np.zeros(rc.nx / 2) bzk = np.zeros(rc.nx / 2) xk = np.arange(max([rc.nx, rc.ny, rc.nz]) / 2) * rc.dx for it in range(bs, fs, step): print('time slice', it) rc.loadslice(it) bxk[:rc.ny / 2] = af.sdk(rc.bx, ax=1)[1] byk[:rc.nx / 2] = af.sdk(rc.by, ax=0)[1] bzk[:rc.nx / 2] = af.sdk(rc.bz, ax=0)[1] outf = open('sdk-' + rc.dirname + '-%03d.dat' % it, 'w') for i in range(rc.nx / 2): print(xk[i], bxk[i], byk[i], bzk[i], file=outf) outf.close() rc.fin()
def _derivedv(self, varname): if varname == 'tix': self.tix = self.pixx / self.ni if varname == 'tiy': self.tiy = self.piyy / self.ni if varname == 'tiz': self.tiz = self.pizz / self.ni if varname == 'ti': self.ti = (self.tix + self.tiy + self.tiz) / 3. if varname == 'tex': self.tex = self.pexx / self.ne if varname == 'tey': self.tey = self.peyy / self.ne if varname == 'tez': self.tez = self.pezz / self.ne if varname == 'te': self.te = (self.tex + self.tey + self.tez) / 3. if varname == 'vix': self.vix = self.jix / self.ni if varname == 'viy': self.viy = self.jiy / self.ni if varname == 'viz': self.viz = self.j*z / self.ni if varname == 'omix': self.omix = af.pcurlx(self.viy, self.viz, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omiy': self.omiy = af.pcurly(self.viz, self.vix, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omiz': self.omiz = af.pcurlz(self.vix, self.viy, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omi': pass if varname == 'ensti': self.ensti = self.omix**2 + self.omiy**2 + self.omiz**2 if varname == 'dui': self.dui = af.pdiv(self.vix, self.viy, self.viz, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'vex': self.vex = -self.jex / self.ne if varname == 'vey': self.vey = -self.jey / self.ne if varname == 'vez': self.vez = -self.jez / self.ne if varname == 'omex': self.omex = af.pcurlx(self.vey, self.vez, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omey': self.omey = af.pcurly(self.vez, self.vex, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omez': self.omez = af.pcurlz(self.vex, self.vey, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'ome': pass if varname == 'enste': self.enste = self.omex**2 + self.omey**2 + self.omez**2 if varname == 'due': self.due = af.pdiv(self.vex, self.vey, self.vez, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'cmx': self.cmx = (self.vix + self.m_e * self.vex) / (1 + self.m_e) if varname == 'cmy': self.cmy = (self.viy + self.m_e * self.vey) / (1 + self.m_e) if varname == 'cmz': self.cmz = (self.viz + self.m_e * self.vez) / (1 + self.m_e) if varname == 'omx': self.omx = af.pcurlx(self.cmy, self.cmz, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omy': self.omy = af.pcurly(self.cmz, self.cmx, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'omz': self.omz = af.pcurlz(self.cmx, self.cmy, dx=self.dx, dy=self.dy, dz=self.dz) if varname == 'om': pass if varname == 'enst': self.enst = self.omx**2 + self.omy**2 + self.omz**2 if varname == 'den': self.den = self.ni + self.m_e * self.ne if varname == 'zpx': self.zpx = self.bx / np.sqrt(self.den) + self.cmx if varname == 'zpy': self.zpy = self.by / np.sqrt(self.den) + self.cmy if varname == 'zpz': self.zpz = self.bz / np.sqrt(self.den) + self.cmz if varname == 'zmx': self.zmx = self.bx / np.sqrt(self.den) - self.cmx if varname == 'zmy': self.zmy = self.by / np.sqrt(self.den) - self.cmy if varname == 'zmz': self.zmz = self.bz / np.sqrt(self.den) - self.cmz if varname == 'zpzm': pass if varname == 'pali': tmp = af.pcurl(self.omix, self.omiy, self.omiz, dx=self.dx, dy=self.dy, dz=self.dz) self.pali = 0.5 * (tmp[0]**2 + tmp[1]**2 + tmp[2]**2) tmp = None if varname == 'pale': tmp = af.pcurl(self.omex, self.omey, self.omez, dx=self.dx, dy=self.dy, dz=self.dz) self.pale = 0.5 * (tmp[0]**2 + tmp[1]**2 + tmp[2]**2) tmp = None if varname == 'pal': tmp = af.pcurl(self.omx, self.omy, self.omz, dx=self.dx, dy=self.dy, dz=self.dz) self.pal = 0.5 * (tmp[0]**2 + tmp[1]**2 + tmp[2]**2) tmp = None
import AnalysisFunctions as af lddata=input('Load Data again? ') if lddata == 'y': from subs import create_object rc=create_object() rc.vars2load(['all']) rcd=rc.__dict__ rc.loadenergies() nltime=np.float(input("What nonlinear time? ")) slc=np.int(rc.t[np.argmin(np.abs(rc.ta-nltime))]/rc.dtmovie) smt=float(input("How smooth? ")) rc.loadslice(slc,smth=smt) rc.computevars(['tempi','omi','tempe','ome']) rc.addattr(['Ap','dti','tite','dte'],[0.5*(rc.tix+rc.tiy)/rc.tiz,rc.ti-np.mean(rc.ti),rc.ti*rc.T_e/(rc.te*rc.T_i),rc.te-np.mean(rc.te)]) rc.addattr(['dAp','dtite'],[rc.Ap-1.,rc.tite-1.0]) gj=af.pgrad(rc.jz,rc.dx,rc.dy,rc.dz,smth=1) bdgj = rc.bx*gj[0]+rc.by*gj[1]+rc.bz*gj[2] def correlation(ar1,ar2,ax=0,dx=1.): nlen=np.shape(ar1)[ax]/2 r=np.zeros(nlen);corr=np.zeros(nlen) ar1=ar1-np.mean(ar1) ar2=ar2-np.mean(ar2) mamb=np.mean(ar1)*np.mean(ar2) meanab=np.mean(ar1*ar2) rmsab =np.sqrt(np.mean(ar1**2)*np.mean(ar2**2)) for i in range(nlen): ars=np.roll(ar2,i,axis=ax) corr[i]=np.mean(ar1*ars)#-mamb r[i]=i*dx corr = corr/rmsab
def computevars(self, v2c, smth=None): if 'tempi' in v2c: self.tix = self.pixx / self.ni self.tiy = self.piyy / self.ni self.tiz = self.pizz / self.ni self.ti = (self.tix + self.tiy + self.tiz) / 3. if 'tempe' in v2c: if self.code_type == 'h': self.te = self.pe / self.ni else: self.tex = self.pexx / self.ne self.tey = self.peyy / self.ne self.tez = self.pezz / self.ne self.te = (self.tex + self.tey + self.tez) / 3. if any([ 1 for i in ['vi', 've', 'omi', 'dui', 'zpzm', 'udgpi', 'udgpe', 'ome', 'due'] if i in v2c ]): # if 'vi' in v2c or 've' in v2c or 'omi' in v2c or 'dui' in v2c or 'zpzm' in v2c or 'udgpi' in v2c\ # or 'udgpe' in v2c or 'ome' in v2c or 'due' in v2c: self.vix = self.jix / self.ni self.viy = self.jiy / self.ni self.viz = self.j*z / self.ni if 'omi' in v2c: self.omxi,self.omyi,self.omzi = af.pcurl(self.vix,self.viy,\ self.viz,dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 'dui' in v2c: self.dui = af.pdiv(self.vix, self.viy, self.viz, dx=self.dx, dy=self.dy, dz=self.dz, smth=smth) if 'udgpi' in v2c: self.udgpi = self.vix*af.pdiv(self.pixx, self.pixy, self.pixz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.viy*af.pdiv(self.pixy, self.piyy, self.piyz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.viz*af.pdiv(self.pixz, self.piyz, self.pizz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if any( [1 for i in ['ve', 'ome', 'due', 'zpzm', 'udgpe'] if i in v2c]): # if 've' in v2c or 'ome' in v2c or 'due' in v2c or 'zpzm' in v2c or 'udgpe' in v2c: if self.code_type == 'h': self.vex = self.vix - self.jx / self.ni self.vey = self.viy - self.jy / self.ni self.vez = self.viz - self.jz / self.ni if 'udgpe' in v2c: gp = af.pgrad(self.pe, dx=self.dx, dy=self.dy, dz=self.dz, smth=smth) self.udgpe = self.vex * gp[0] + self.vey * gp[ 1] + self.vez * gp[2] else: self.vex = -self.jex / self.ne self.vey = -self.jey / self.ne self.vez = -self.jez / self.ne if 'udgpe' in v2c: self.udgpe = self.vex*af.pdiv(self.pexx, self.pexy, self.pexz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.vey*af.pdiv(self.pexy, self.peyy, self.peyz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) +\ self.vez*af.pdiv(self.pexz, self.peyz, self.pezz, dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 'ome' in v2c: self.omxe,self.omye,self.omze = af.pcurl(self.vex,self.vey,\ self.vez,dx=self.dx,dy=self.dy,dz=self.dz,smth=smth) if 'due' in v2c: self.due = af.pdiv(self.vex, self.vey, self.vez, dx=self.dx, dy=self.dy, dz=self.dz, smth=smth) if 'zpzm' in v2c: cmx = (self.vix + self.m_e * self.vex) / (1 + self.m_e) cmy = (self.viy + self.m_e * self.vey) / (1 + self.m_e) cmz = (self.viz + self.m_e * self.vez) / (1 + self.m_e) den = self.ni + self.m_e * self.ne self.zpx = self.bx / np.sqrt(den) + cmx self.zpy = self.by / np.sqrt(den) + cmy self.zpz = self.bz / np.sqrt(den) + cmz self.zmx = self.bx / np.sqrt(den) - cmx self.zmy = self.by / np.sqrt(den) - cmy self.zmz = self.bz / np.sqrt(den) - cmz
#!/usr/bin/env python from pylab import * import AnalysisFunctions as af from subs import create_object,ask_for_steps rc = create_object() rc.vars2load(['jz']) bs,fs,step=ask_for_steps(rc.numslices) nt=(fs-bs)/step + 1 jzt=np.zeros((rc.nx,rc.ny,rc.nz,nt)) jzb=0; jzpdf=0 for it in range(bs,fs,step): print 'time slice',it rc.loadslice(it) tmp1,tmp2 = af.normhist(rc.jz,min=-20.,max=20.) jzb=jzb+tmp1 jzpdf=jzpdf+tmp2 jzb=jzb/nt; jzpdf=jzpdf/nt outf=open('jznh.'+rc.dirname+'.dat','w') for i in range(len(jzb)): print >> outf,jzb[i],jzpdf[i] outf.close() rc.fin()
# ============================================================================= # Load control with force # ============================================================================= op.wipe() if runAnalysisLcF == True: # Build Model mf.getSections() mf.buildModel() # opp.plot_model() # Run Analysis rf.getPushoverRecorders(pushoverLcForceName, pushoverLcForceName) af.PushoverLcF(int(NAnalysisSteps[0])) op.wipe() # Plot Analysis pf.plotPushover(pushoverLcForceName, pushoverLcForceName) # ============================================================================= # Load control with Disp # ============================================================================= op.wipe() if runAnalysisLcD == True: # Build Model mf.getSections()
from pylab import * import AnalysisFunctions as af from subs import create_object, ask_for_steps rc = create_object() rc.vars2load(['bx','by','bz']) bs,fs,step=ask_for_steps(rc.numslices) nt=(fs-bs)/step bxk=np.zeros(rc.nx/2)#;xk=np.zeros(rc.nx/2) byk=np.zeros(rc.nx/2) bzk=np.zeros(rc.nx/2) xk = np.arange(rc.nx/2)*rc.dx for it in range(bs,fs,step): print 'time slice',it rc.loadslice(it) bxk = bxk + af.fsdk(rc.bx)[1] byk = byk + af.fsdk(rc.by)[1] bzk = bzk + af.fsdk(rc.bz)[1] bxk=bxk/nt; byk=byk/nt; bzk=bzk/nt outf=open('sdkurtosis.'+rc.dirname+'.dat','w') for i in range(rc.nx/2): print >> outf,xk[i],bxk[i],byk[i],bzk[i] outf.close() rc.fin()
ShortCall_WithHedge_Fees_Annualized_Risk = np.std(ShortCall_WithHedge_Fees['PF_RETURNS'])*math.sqrt(252) print('54% - Strategies done successfully') ### VI - Strategy analysis print('60% - Starting analysis') import AnalysisFunctions as af #Fichier des fonctions AnalysisFunctions.py Metrics = pd.DataFrame(columns = ['Sharpe Ratio','VaR','BREACH_VAR','TE','MaxDrawdown',], index = ['Value']) # fill df Metrics['Sharpe Ratio'] = af.SP(ShortCall_WithHedge_Fees_Annualized_Return,ShortCall_WithHedge_Fees_Annualized_Risk,RiskFreeRate) Metrics['VaR'] = af.VaR(ShortCall_WithHedge_Fees['PF_RETURNS'], 0.99) # value at risk Metrics['BREACH_VAR'] = sum(1 for item in ShortCall_WithHedge_Fees['PF_RETURNS'] if item <= Metrics['VaR'][0])/len(ShortCall_WithHedge_Fees['PF_RETURNS']) # value at risk Metrics['MaxDrawdown'] = af.maxDrawDown(ShortCall_WithHedge_Fees['PF_COMPOUNDED_RETURNS']) # max dd Metrics['TE'] = af.TE(ShortCall_WithHedge_Fees['PF_RETURNS'],IndexData['LEGATREH Index']['Return']) # bench = Bloomberg Barclays Global-Aggregate Total Return Index #Sauvegarder les métriques en image grâce à un HEATPLOT mp.pyplot.clf() mp.pyplot.figure(facecolor='w', edgecolor='k')
def zpzmlclm(rc): import AnalysisFunctions as af import numpy as np from subs import ask_for_steps rc.vars2load(['bx','by','bz','jix','jiy','j*z','ni','jex','jey','jez','ne']) bs,fs,step=ask_for_steps(rc.numslices) #bs=0; fs=rc.numslices; step=1 nt=(fs-bs)/step+1 ie=1/np.e ezp=np.zeros(nt); ezm=np.zeros(nt) tt=np.zeros(nt); tnldi=np.zeros(nt) lcp=np.zeros(nt); lcm=np.zeros(nt) #time_series_output=raw_input("Output zp, zm etc as a time series? ") time_series_output = '' if time_series_output == 'y': zpkxt = np.zeros((rc.nx/2,nt)) zpkyt = np.zeros((rc.nx/2,nt)) zpkzt = np.zeros((rc.nx/2,nt)) zmkxt = np.zeros((rc.nx/2,nt)) zmkyt = np.zeros((rc.nx/2,nt)) zmkzt = np.zeros((rc.nx/2,nt)) for it in range(bs,fs,step): print('time slice',it) rc.loadslice(it) idx=(it-bs)/step rho=rc.ni+rc.ne*rc.m_e rc.jix=rc.jix/rc.ni; rc.jiy=rc.jiy/rc.ni;rc.j*z=rc.j*z/rc.ni rc.jex=rc.jex/rc.ne; rc.jey=rc.jey/rc.ne;rc.jez=rc.jez/rc.ne # vcx = (rc.jix+rc.jex*rc.m_e)/(1+rc.m_e) vcy = (rc.jiy+rc.jey*rc.m_e)/(1+rc.m_e) vcz = (rc.j*z+rc.jez*rc.m_e)/(1+rc.m_e) rc.bx=(rc.bx-np.mean(rc.bx))/np.sqrt(rho) rc.by=(rc.by-np.mean(rc.by))/np.sqrt(rho) rc.bz=(rc.bz-np.mean(rc.bz))/np.sqrt(rho) # vcx=vcx-np.mean(vcx);vcy=vcy-np.mean(vcy);vcz=vcz-np.mean(vcz) # zpx=vcx+rc.bx; zpy=vcy+rc.by; zpz=vcz+rc.bz # ezp[idx]=0.5*np.mean(rho*(np.abs(zpx)**2+np.abs(zpy)**2+np.abs(zpz)**2)) zmx=vcx-rc.bx; zmy=vcy-rc.by; zmz=vcz-rc.bz # ezm[idx]=0.5*np.mean(rho*(np.abs(zmx)**2+np.abs(zmy)**2+np.abs(zmz)**2)) ## #Correlation for z+ #kwave,zkx,zky,zkz,zk = af.PerpSpecVec(zpx,zpy,zpz) kwave,zkx,zky,zkz,zk = af.fperpspecvec(zpx,zpy,zpz) if time_series_output == 'y': zpkt[:,idx]=zk lcp[idx] = (2*np.pi/sum(zk[1:]))*sum(zk[1:]/kwave[1:]) ## #Correlation for z- #kwave,zkx,zky,zkz,zk = af.PerpSpecVec(zmx,zmy,zmz) kwave,zkx,zky,zkz,zk = af.fperpspecvec(zmx,zmy,zmz) if time_series_output == 'y': zmkt[:,idx]=zk lcm[idx] = (2*np.pi/sum(zk[1:]))*sum(zk[1:]/kwave[1:]) # tt[idx]=round(it*rc.dtmovie,4) # wci*tnl(di) = Va/Z (L/di)^(1/3) # Matthaeus EA, ApJ 2014 tnldi[idx]=(rc.B0*((lcp[idx]+lcm[idx])/2.)**(1./3.))/(2*np.sqrt(ezp[idx]+ezm[idx])) outf=open('zpzmlc.'+rc.dirname+'.dat','w') print('#','t','tt','ezp','ezm','lcp','lcm','tnldi', file=outf) for i in range(nt): print(tt[i],tt[i]*2*np.pi/rc.lx,ezp[i],ezm[i],lcp[i],lcm[i],tnldi[i], file=outf) outf.close() rc.fin() if time_series_output == 'y': zpkxt.tofile('zpkxt.'+rc.dirname+'.dat') zpkyt.tofile('zpkyt.'+rc.dirname+'.dat') zpkzt.tofile('zpkzt.'+rc.dirname+'.dat') zmkxt.tofile('zmkxt.'+rc.dirname+'.dat') zmkyt.tofile('zmkyt.'+rc.dirname+'.dat') zmkzt.tofile('zmkzt.'+rc.dirname+'.dat')
rc.vars2load(['bx','by','bz','jix','jiy','j*z','ni']) rcd=rc.__dict__ bs,fs,step=ask_for_steps(rc.numslices) nt=(fs-bs)/step cut=input(" What part of domain? Enter nothing for whole domain") if cut=='': cut=None else: cut=cut.split() cut[0]=float(cut[0]); cut[1]=float(cut[1]) cut[2]=float(cut[2]); cut[3]=float(cut[3]) for it in range(bs,fs,step): print('time slice',it) rc.loadslice(it) rc.computevars(['vi']) k1,k2,ekx,eky,ekz,ekb=af.SpecVec2D(rc.bx,rc.by,rc.bz,axx=2,lx=rc.lx,ly=rc.ly,lz=rc.lz) k1,k2,ekx,eky,ekz,ekv=af.SpecVec2D(rc.vix,rc.viy,rc.viz,axx=2,lx=rc.lx,ly=rc.ly,lz=rc.lz) if it == bs: kcd={'xx':k1,'yy':k2} vmax=np.log10(ekb+ekv).max(); vmin=vmax-6 plt.clf();ax=plt.gca(); imss(kcd,np.log10(ekb+ekv),cmap=plt.cm.pink_r,\ ax=ax,cut=cut,cbar=1,interpolation='none', vmin=vmin, vmax=vmax) ax.set_title('$t\omega_{ci}$ = '+str(round(rc.time,3))) ax.set_xlabel('$k_x d_i$') ax.set_ylabel('$k_y d_i$') plt.savefig('2dspec-'+rc.dirname+'-%04d.png'%it,dpi=300,bbox_inches='tight') rc.fin()
bs, fs, step = ask_for_steps(rc.numslices) xbx = np.zeros(rc.nx / 2) xby = np.zeros(rc.nx / 2) xbz = np.zeros(rc.nx / 2) ybx = np.zeros(rc.ny / 2) yby = np.zeros(rc.ny / 2) ybz = np.zeros(rc.ny / 2) for it in range(bs, fs, step): print 'time slice', it rc.loadslice(it) kx, xkx, xky, xkz, xkb = af.ReducedSpecVec(rc.bx, rc.by, rc.bz, lenx=rc.lx, ax=0) xbx = xbx + xkx xby = xby + xky xbz = xbz + xkz ky, ykx, yky, ykz, ykb = af.ReducedSpecVec(rc.bx, rc.by, rc.bz, leny=rc.ly, ax=1) ybx = ybx + ykx yby = yby + yky ybz = ybz + ykz
fsl = int(fl / rc.dx) if rank == 0: t_start = MPI.Wtime() comm.Barrier() for i in range(bs, fs): rc.loadslice(i) idx = (bs - i) #Assign the appropriate nonlinear time to the timeseries if rank == 0: tsris[i] = rc.ta[np.argmin(np.abs(rc.t - rc.time))] else: snddata[0, idx] = rc.ta[np.argmin(np.abs(rc.t - rc.time))] #Compute the scale dependent kurtosis between bl,fl rx, sdx = af.sdk(rc.bx, bs=bsl, fs=fsl, step=stepl, dx=rc.dx, ax=0) ry, sdy = af.sdk(rc.by, bs=bsl, fs=fsl, step=stepl, dx=rc.dx, ax=1) #Find the location of maximum value of kurtosis between sdx,sdy tsdk = np.array([sdx, sdy]) rr = np.array([rx, ry]) xx = np.unravel_index(tsdk.argmax(), tsdk.shape) if rank == 0: sclmx[i] = rr[xx] krtmx[i] = tsdk[xx] print 'rank,t,sclmx,mxkurt\t', rank, tsris[i], sclmx[i], krtmx[i] else: snddata[1, idx] = rr[xx] snddata[2, idx] = tsdk[xx] print 'rank,t,sclmx,mxkurt\t', rank, snddata[0, idx], snddata[