def histogram_src(unit, CPUs, sim_dir, sim_phy, sim_name, lc_dir, HQ_dir): # Run through simulations for sim in range(len(sim_dir)): # File for lens & source properties lc_file = lc_dir[sim] + 'LC_SN_' + sim_name[sim] + '_rndseed.h5' # Simulation Snapshots snapfile = sim_dir[sim] + 'snapdir_%03d/snap_%03d' # LensMaps filenames lm_dir = HQ_dir + '/LensingMap/' + sim_phy[sim] + sim_name[sim] + '/' # Units of Simulation scale = rf.simulation_units(sim_dir[sim]) # Load LightCone Contents LC = rf.LightCone_with_SN_lens(lc_file, 'dictionary') SrcUnit = [] # Run through LensingMap output files for cpu in range(CPUs): lm_file = lm_dir + 'LM_Proc_' + str(cpu) + '_0.pickle' # Load LensingMap Contents filed = open(lm_file, 'rb') LM = pickle.load(filed) for ll in range(len(LM['Halo_ID'])): for ss in range(len(LM['Sources']['Src_ID'][ll])): if unit == 'delta_t': t = LM['Sources']['delta_t'][ll][ss] indx_max = np.argmax(t) t -= t[indx_max] t = np.absolute(t[t != 0]) for ii in range(len(t)): SrcUnit.append(t[ii]) sim_label = la.define_sim_label(sim_name[sim], sim_dir[sim]) if unit == 'mu': plt.hist(SrcUnit, 20, alpha=0.75, label=sim_label + ': ' + str(len(SrcUnit))) elif unit == 'delta_t': plt.hist(SrcUnit, 20, alpha=0.75, label=sim_label + ': ' + str(len(SrcUnit))) if unit == 'mu': plt.xlabel(r'$log(M_{\odot}/h)$') plt.legend(loc=1) plt.savefig('./images/Hsts_mu.png', bbox_inches='tight') elif unit == 'delta_t': plt.xlabel(r'$\Delta t$') plt.legend(loc=1) plt.savefig('./images/Hsts_delta_t.png', bbox_inches='tight') plt.clf()
def histogram_lens(unit, CPUs, sim_dir, sim_phy, sim_name, hfname, lc_dir, HQ_dir): # Run through simulations for sim in range(len(sim_dir)): # File for lens & source properties lc_file = lc_dir[sim] + 'LC_SN_' + sim_name[sim] + '_rndseed.h5' # Simulation Snapshots snapfile = sim_dir[sim] + 'snapdir_%03d/snap_%03d' # LensMaps filenames lm_dir = HQ_dir + '/LensingMap/' + sim_phy[ sim] + hfname + '/' + sim_name[sim] + '/' # Units of Simulation scale = rf.simulation_units(sim_dir[sim]) # Load LightCone Contents LC = rf.LightCone_with_SN_lens(lc_file, 'dictionary') HaloUnit = [] # Run through LensingMap output files for cpu in range(CPUs): lm_file = lm_dir + 'LM_Proc_' + str(cpu) + '_0.pickle' # Load LensingMap Contents filed = open(lm_file, 'rb', encoding='utf8') LM = pickle.load(open(lm_file, 'rb')) indx = np.nonzero(np.in1d(LC['Halo_ID'], LM['Halo_ID']))[0] HaloUnit.append(LC[unit][indx]) HaloUnit = np.concatenate(HaloUnit, axis=0) sim_label = la.define_sim_label(sim_name[sim], sim_dir[sim]) if unit == 'M200': plt.hist(np.log10(HaloUnit), 20, alpha=0.75, label=sim_label + ': ' + str(len(HaloUnit))) elif unit == 'Halo_z': plt.hist(HaloUnit, 20, alpha=0.75, label=sim_label + ': ' + str(len(HaloUnit))) if unit == 'M200': plt.xlabel(r'$log(M_{\odot}/h)$') plt.legend(loc=1) plt.savefig('./images/Hstl_M200.png', bbox_inches='tight') elif unit == 'Halo_z': plt.xlabel(r'$z$') plt.legend(loc=1) plt.savefig('./images/Hstl_redshift.png', bbox_inches='tight') plt.clf()
def dyn_vs_lensing_mass(CPUs, sim_dir, sim_phy, sim_name, hfname, lc_dir, HQ_dir): # protect the 'entry point' for Windows OS # if __name__ == '__main__': # after importing numpy, reset the CPU affinity of the parent process so # that it will use all cores os.system("taskset -p 0xff %d" % os.getpid()) # Run through simulations for sim in range(len(sim_dir)): # File for lens & source properties lc_file = lc_dir[sim] + hfname + '/LC_SN_' + sim_name[ sim] + '_rndseed1.h5' # File for lensing-maps lm_dir = HQ_dir + '/LensingMap/' + sim_phy[ sim] + hfname + '/' + sim_name[sim] + '/' # Simulation Snapshots snapfile = sim_dir[sim] # Units of Simulation scale = rf.simulation_units(sim_dir[sim]) # Cosmological Parameters s = read_hdf5.snapshot(45, snapfile) cosmo = LambdaCDM(H0=s.header.hubble * 100, Om0=s.header.omega_m, Ode0=s.header.omega_l) h = s.header.hubble a = 1 / (1 + s.header.redshift) # Load LightCone Contents LC = rf.LightCone_with_SN_lens(lc_file, hfname) # Sort Lenses according to Snapshot Number (snapnum) indx = np.argsort(LC['snapnum']) Halo_ID = LC['Halo_ID'][indx] # Prepatre Processes to be run in parallel jobs = [] manager = multiprocessing.Manager() results_per_cpu = manager.dict() snapfile = sim_dir[sim] + 'snapdir_%03d/snap_%03d' for cpu in range(CPUs): # Load LensingMaps Contents lm_file = lm_dir + 'LM_Proc_' + str(cpu) + '_0.pickle' p = Process(target=la.dyn_vs_lensing_mass, name='Proc_%d' % cpu, args=(cpu, LC, lm_file, snapfile, h, scale, HQ_dir, sim, sim_phy, sim_name, hfname, cosmo, results_per_cpu)) p.start() jobs.append(p) # Run Processes in parallel # Wait until every job is completed for p in jobs: p.join() # Save Data Halo_ID = [] Src_ID = [] Mdyn = [] Mlens = [] for cpu in range(CPUs): results = results_per_cpu.values()[cpu] for src in range(len(results)): Halo_ID.append(results[src][0]) Src_ID.append(results[src][1]) Mdyn.append(results[src][2]) Mlens.append(results[src][3]) la_dir = HQ_dir + '/LensingAnalysis/' + sim_phy[sim] print('save data', la_dir, sim_name[sim]) sim_label = la.define_sim_label(sim_name[sim], sim_dir[sim]) hf = h5py.File(la_dir + 'DLMass_pa_shmr_svrms' + sim_label + '.h5', 'w') hf.create_dataset('Halo_ID', data=Halo_ID) hf.create_dataset('Src_ID', data=Src_ID) hf.create_dataset('Mdyn', data=Mdyn) hf.create_dataset('Mlens', data=Mlens) hf.close()
def lensing_signal(): # Get command line arguments args = {} args["snapnum"] = int(sys.argv[1]) args["simdir"] = sys.argv[2] args["ladir"] = sys.argv[3] args["hfname"] = sys.argv[4] args["hfdir"] = sys.argv[5] args["outbase"] = sys.argv[6] args["radius"] = sys.argv[7] args["lenses"] = int(sys.argv[8]) snapfile = args["simdir"] + 'snapdir_%03d/snap_%03d' label = args["simdir"].split('/')[-2].split('_')[-2] # Units of Simulation scale = rf.simulation_units(args["simdir"]) # Cosmological Parameters s = read_hdf5.snapshot(args["snapnum"], args["simdir"]) cosmo = LambdaCDM(H0=s.header.hubble * 100, Om0=s.header.omega_m, Ode0=s.header.omega_l) h = s.header.hubble # Stellar Data stars = load.load_stars(args["snapnum"], args["simdir"]) dm = load.load_dm(args["snapnum"], args["simdir"]) gas = load.load_gas(args["snapnum"], args["simdir"]) indxdrop = [] # collect indices of subhalos falling through criterias if args["lenses"] == 1: lafile = glob.glob(args["ladir"] + "*" + "_lens_" + "*" + "409.pickle")[0] lenses = load.load_subhalos(args["snapnum"], args["simdir"], lafile, strong_lensing=1) # Run through lenses for ll in range(len(lenses.index.values)): print('Lenses: %f' % (ll / len(lenses.index.values))) lens = lenses.iloc[ll] if isinstance(lens, (pd.core.series.Series)): indx = load.select_particles(stars['Pos'], lens['Pos'], lens['Rstellarhalfmass'] * 1.5, 'sphere') halo_stars = { 'Pos': stars['Pos'][indx, :], 'Vel': stars['Vel'][indx, :], 'Mass': stars['Mass'][indx] } halo_stars['Pos'] -= lens['Pos'] indx = load.select_particles(dm['Pos'], lens['Pos'], lens['Rein'], 'sphere') halo_dm = {'Pos': dm['Pos'][indx, :], 'Mass': dm['Mass'][indx]} halo_dm['Pos'] -= lens['Pos'] indx = load.select_particles(gas['Pos'], lens['Pos'], lens['Rein'], 'sphere') halo_gas = { 'Pos': gas['Pos'][indx, :], 'Mass': gas['Mass'][indx] } halo_gas['Pos'] -= lens['Pos'] lenses, indxdrop = load.add_properties(halo_stars, halo_dm, halo_gas, lens, lenses, cosmo, s, indxdrop, ll, args["lenses"]) else: print('!!!!!!! SOS !!!!!!!!!') lenses = lenses.drop(indxdrop) print('Saving %d lenses to .hdf5' % (len(lenses.index.values))) zllabel = str(lens['ZL']).replace('.', '')[:3].zfill(3) zslabel = '{:<03d}'.format( int(str(lenses['ZS'].values[0]).replace('.', ''))) fname = (args["outbase"]+'LPPBox_%s_%s_zl%szs%s.h5' % \ (label, 'lens', zllabel, zslabel)) lenses.to_hdf(fname, key='lenses', mode='w') if args["lenses"] == 0: print(args["ladir"] + "*" + "_nonlens_" + "*" + "409.h5") print(glob.glob(args["ladir"] + "*" + "_nonlens_" + "*" + "409.h5")) lafile = glob.glob(args["ladir"] + "*" + "_nonlens_" + "*" + "409.h5")[0] subhalos = load.load_subhalos(args["snapnum"], args["simdir"], lafile, strong_lensing=0) # Run through subhalos for ll in range(len(subhalos.index.values)): print('Non-Lenses: %f' % (ll / len(subhalos.index.values))) subhalo = subhalos.iloc[ll] if isinstance(subhalo, (pd.core.series.Series)): indx = load.select_particles(stars['Pos'], subhalo['Pos'], subhalo['Rstellarhalfmass'] * 1.5, 'sphere') halo_stars = { 'Pos': stars['Pos'][indx, :], 'Vel': stars['Vel'][indx, :], 'Mass': stars['Mass'][indx] } halo_stars['Pos'] -= subhalo['Pos'] #indx = load.select_particles( # dm['Pos'], subhalo['Pos'], # subhalo['Rstellarhalfmass']*1.5, # 'sphere') #halo_dm = {'Pos' : dm['Pos'][indx, :], # 'Vel' : dm['Vel'][indx, :], # 'Mass' : dm['Mass'][indx]} #halo_dm['Pos'] -= subhalo['Pos'] subhalos, indxdrop = load.add_properties( halo_stars, subhalo, subhalos, cosmo, s, indxdrop, ll, args["lenses"]) else: print('!!!!!!! SOS !!!!!!!!!') subhalos = subhalos.drop(indxdrop) print('Saving %d Subhalos to .hdf5' % (len(subhalos.index.values))) zllabel = str(zl).replace('.', '')[:3].zfill(3) zslabel = '{:<03d}'.format( int(str(subhalos['ZS'].values[0]).replace('.', ''))) fname = (args["outbase"]+'LPPBox_%s_%s_zl%szs%s.h5' % \ (label, 'nonlens', zllabel, zslabel)) subhalos.to_hdf(fname, key='subhalos', mode='w')
def lensing_signal(): # Get command line arguments args = {} #args["snapnum"] = int(sys.argv[1]) args["simdir"] = sys.argv[1] args["ladir"] = sys.argv[2] args["rksdir"] = sys.argv[3] args["outbase"] = sys.argv[4] args["radius"] = sys.argv[5] snapfile = args["simdir"] + 'snapdir_%03d/snap_%03d' # Units of Simulation scale = rf.simulation_units(args["simdir"]) # Cosmological Parameters s = read_hdf5.snapshot(45, args["simdir"]) cosmo = LambdaCDM(H0=s.header.hubble * 100, Om0=s.header.omega_m, Ode0=s.header.omega_l) h = s.header.hubble Lens = { "HF_ID": [], "LC_ID": [], "SrcID": [], "n_imgs": [], "M200": [], "zl": [], "zs": [], "Mdyn_rks": [], "Mdyn_stellar": [], "Mlens": [], "Vrms_stellar": [], "Vrms_rks": [], "Rein": [] } label = args["simdir"].split('/')[-2].split('_')[-2] # Run through LensingMap output files for lm_file in glob.glob(args["ladir"] + 'LM_' + label + ".pickle"): # Load LensingMap Contents LM = pickle.load(open(lm_file, 'rb')) print('Processing the following file: \n %s' % (lm_file)) print('which contains %d lenses' % len(LM['HF_ID'][:])) print('with redshifts from %f to %f' % \ (np.min(LM['zl'][:]), np.max(LM['zl'][:]))) if False not in (np.diff(LM['snapnum'][:]) <= 0): pass else: order = np.asarray(np.argsort(LM['snapnum'][:])) LM['HF_ID'] = [LM['HF_ID'][oo] for oo in order] LM['zl'] = [LM['zl'][oo] for oo in order] LM['Sources']['Src_ID'] = [ LM['Sources']['Src_ID'][oo] for oo in order ] LM['Sources']['zs'] = [LM['Sources']['zs'][oo] for oo in order] LM['Sources']['mu'] = [LM['Sources']['mu'][oo] for oo in order] LM['Sources']['Rein'] = [LM['Sources']['Rein'][oo] for oo in order] LM['snapnum'] = [LM['snapnum'][oo] for oo in order] assert False not in (np.diff(LM['snapnum'][:]) >= 0) #TODO: sanity check remove after it works #lcsndir = '/cosma5/data/dp004/dc-beck3/StrongLensing/LightCone/full_physics/Rockstar/LC_SN_L62_N512_GR_kpc_1.h5' #lcsnf = h5py.File(lcsndir, 'r') #lcsndf1 = pd.DataFrame({'HF_ID' : lcsnf['Halo_Rockstar_ID'], # 'LC_ID' : lcsnf['Halo_ID'], # 'snapnum' : lcsnf['snapnum'], # 'zl' : lcsnf['Halo_z'], # 'Rvir' : lcsnf['Rvir']}) #lcsndir = '/cosma5/data/dp004/dc-beck3/StrongLensing/LightCone/full_physics/Rockstar/LC_SN_L62_N512_GR_kpc_2.h5' #lcsnf = h5py.File(lcsndir, 'r') #lcsndf2 = pd.DataFrame({'HF_ID' : lcsnf['Halo_Rockstar_ID'], # 'LC_ID' : lcsnf['Halo_ID'], # 'snapnum' : lcsnf['snapnum'], # 'zl' : lcsnf['Halo_z'], # 'Rvir' : lcsnf['Rvir']}) #lcsndf = pd.concat([lcsndf1, lcsndf2]) previous_snapnum = -1 # Run through lenses for ll in range(len(LM['HF_ID'])): # Load Lens properties HFID = int(LM['HF_ID'][ll]) #int(LM['Rockstar_ID'][ll]) snapnum = int(LM['snapnum'][ll]) zl = LM['zl'][ll] # Only load new particle data if lens is at another snapshot if (previous_snapnum != snapnum): print('::::: Load snapshot: %s' % \ (args["rksdir"]+'halos_%d.dat' % snapnum)) hdata = pd.read_csv(args["rksdir"] + 'halos_%d.dat' % snapnum, sep='\s+', skiprows=np.arange(1, 16)) # Load Particle Properties snap = snapfile % (snapnum, snapnum) s = read_hdf5.snapshot(snapnum, args["simdir"]) s.read([ "Coordinates", "Masses", "Velocities", "GFM_StellarFormationTime" ], parttype=[4]) age = (s.data['GFM_StellarFormationTime']['stars'] ).astype('float64') star_pos = s.data['Coordinates']['stars'][age >= 0, :] * scale star_mass = s.data['Masses']['stars'][age >= 0] star_vel = s.data['Velocities']['stars'][age >= 0, :] previous_snapnum = snapnum # Load Halo Properties try: subhalo = hdata.loc[hdata['#ID'] == HFID] except: continue HPos = subhalo[['X', 'Y', 'Z']].values[0] Vrms = subhalo['Vrms'].values[0] #[km/s] M200 = subhalo['Mvir'].values[0] #[km/s] hvel = subhalo[['VX', 'VY', 'VZ']].values[0] epva = subhalo[['A[x]', 'A[y]', 'A[z]']].values[0] epvb = subhalo[['B[x]', 'B[y]', 'B[z]']].values[0] epvc = subhalo[['C[x]', 'C[y]', 'C[z]']].values[0] ####----> Add keys <----#### if args["radius"] == 'Rshm': #Rhalfmass = hdata['Halfmass_Radius'][indx]*u.kpc # Stellar Half Mass Radius Rad_dyn = cf.call_stellar_halfmass( star_pos[:, 0], star_pos[:, 1], star_pos[:, 2], HPos[0], HPos[1], HPos[2], star_mass, Rvir.to_value('Mpc')) * u.Mpc if Rshm == 0.0: continue ## Stellar Half Light Radius ### https://arxiv.org/pdf/1804.04492.pdf $3.3 else: Rad_dyn = subhalo['Rvir'].values[0] * u.kpc ## Dynamical Mass star_indx = lppf.check_in_sphere(HPos, star_pos, Rad_dyn.to_value('kpc')) if len(star_indx[0]) > 100: slices = np.vstack( (epva / np.linalg.norm(epva), epvb / np.linalg.norm(epvb), epvc / np.linalg.norm(epvc))) mdyn_s, mdyn_r, vrms_s = lppf.mass_dynamical( Rad_dyn, star_vel[star_indx], HPos, hvel, slices, Vrms) else: print('!!! Not enough particles for Mdyn') continue if np.isnan(mdyn_s): print('!!! Mdyn = NaN') continue ## Lensing Mass # Run through sources for ss in range(len(LM['Sources']['Src_ID'][ll])): n_imgs = len(LM['Sources']['mu'][ll][ss]) if n_imgs == 1: # print('!!! numer of lensing images = 1, ', n_imgs) continue zs = LM['Sources']['zs'][ll][ss] Rein_arc = LM['Sources']['Rein'][ll][ss] * u.arcsec Rein = Rein_arc.to_value('rad') * \ cosmo.angular_diameter_distance(zl).to('kpc') Lens['n_imgs'].append(n_imgs) Lens['M200'].append(M200) Lens['Mlens'].append(lppf.mass_lensing(Rein, zl, zs, cosmo)) Lens['Mdyn_rks'].append(mdyn_r) Lens['Mdyn_stellar'].append(mdyn_s) Lens["Vrms_stellar"].append(vrms_s.to_value('km/s')) Lens["Vrms_rks"].append(Vrms) Lens['Rein'].append(LM['Sources']['Rein'][ll][ss]) Lens['HF_ID'].append(HFID) Lens['LC_ID'].append(LM['LC_ID'][ll]) Lens['SrcID'].append(LM['Sources']['Src_ID'][ll][ss]) Lens['zl'].append(zl) Lens['zs'].append(zs) print('Saved data of lens %d' % (ll)) df = pd.DataFrame.from_dict(Lens) print('Saving %d lenses to .hdf5' % (len(df.index))) label = args["simdir"].split('/')[-2].split('_')[-2] fname = (args["outbase"] + 'LPP_%s_2.h5' % label) df.to_hdf(fname, key='df', mode='w')
# Load Simulation Specifications LCSettings = '/cosma5/data/dp004/dc-beck3/StrongLensing/shell_script/LCSettings.txt' sim_dir, sim_phy, sim_name, sim_col, hf_dir, hfname, lc_dir, dd, HQ_dir = rf.Simulation_Specs( LCSettings) ################################################################################ # Run through simulations for sim in range(len(sim_dir)): # File for lensing-maps lm_dir = HQ_dir + '/LensingMap/' + sim_phy[sim] + hfname + '/' + sim_name[ sim] + '/' # Simulation Snapshots snapfile = sim_dir[sim] + 'snapdir_%03d/snap_%03d' # Units of Simulation scale = rf.simulation_units(sim_dir[sim]) # Cosmological Parameters s = read_hdf5.snapshot(45, sim_dir[sim]) cosmo = LambdaCDM(H0=s.header.hubble * 100, Om0=s.header.omega_m, Ode0=s.header.omega_l) h = s.header.hubble HF_ID = [] HaloLCID = [] SrcID = [] Mdyn = [] Mlens = [] # Run through LensingMap output files #for lm_file in glob.glob(lm_dir+'LM_1_Proc_*_0.pickle'):
def lensing_signal(): # Get command line arguments args = {} args["simdir"] = sys.argv[1] args["snapnum"] = int(sys.argv[2]) args["ladir"] = sys.argv[3] args["rksdir"] = sys.argv[4] args["outbase"] = sys.argv[5] args["radius"] = sys.argv[6] #args["zs"] = sys.argv[7] snapfile = args["simdir"] + 'snapdir_%03d/snap_%03d' # Units of Simulation scale = rf.simulation_units(args["simdir"]) # Cosmological Parameters s = read_hdf5.snapshot(args["snapnum"], args["simdir"]) cosmo = LambdaCDM(H0=s.header.hubble * 100, Om0=s.header.omega_m, Ode0=s.header.omega_l) h = s.header.hubble zl = s.header.redshift print('Analyse sub-&halo at z=%f' % zl) Lens = {"HFID": [], "Vrms": [], "FOV": [], "ELIP": [], "PA": []} # Run through LensingMap output files for lm_file in glob.glob(args["ladir"] + "*" + "409.pickle"): # Load LensingMap Contents LM = pickle.load(open(lm_file, 'rb')) print('Processing the following file: \n %s' % (lm_file)) print('which contains %d lenses' % len(LM['HF_ID'][:])) print('with max. einst. radius: %f', np.max(LM['Sources']['Rein'][:])) label = args["simdir"].split('/')[-2].split('_')[-2] snapnum = LM['snapnum'] dfh = pd.read_csv(args["rksdir"] + 'halos_%d.dat' % snapnum, sep='\s+', skiprows=np.arange(1, 16)) print(LM['FOV']) # Run through lenses for ll in range(len(LM['HF_ID'])): HFID = int(LM['HF_ID'][ll]) FOV = int(LM['FOV'][ll]) #[arcsec] # Load Halo Properties indx = dfh['#ID'][dfh['#ID'] == HFID].index[0] HPos = [dfh['X'][indx], dfh['Y'][indx], dfh['Z'][indx]] Vrms = dfh['Vrms'][indx] #[km/s] hvel = pd.concat([dfh['VX'], dfh['VY'], dfh['VZ']], axis=1).loc[[indx]].values epveca = pd.concat([dfh['A[x]'], dfh['A[y]'], dfh['A[z]']], axis=1).loc[[indx]].values epvecb = pd.concat([dfh['B[x]'], dfh['B[y]'], dfh['B[z]']], axis=1).loc[[indx]].values epvecc = pd.concat([dfh['C[x]'], dfh['C[y]'], dfh['C[z]']], axis=1).loc[[indx]].values # Ellipticity (should be between 0.0-0.8) epval = [ np.linalg.norm(vec) for vec in np.vstack((epveca, epvecb, epvecc)) ] print('epval', epval) indx = np.argsort(epval) a = epval[indx[2]] # major b = epval[indx[1]] # intermediate c = epval[indx[0]] # minor ellipticity = (a - b) / (2 * (a + b + c)) print(a, b, c) print('ellipticity', ellipticity) # Position-Angle [rad] # Based on Stark 1977; Binggeli 1980 """ [vu, phi] = Euler_angles(sub_av, sub_bv, sub_cv) j = e1**2*e2**2*np.sin(vu)**2 + \ e1**2*np.cos(vu)*np.cos(phi)**2 + \ e2**2*np.cos(vu)**2*np.sin(phi)**2 l = e1**2*np.sin(phi)**2 + e2**2*np.cos(phi)**2 k = (e1**2 - e2**2)*np.sin(phi)*np.cos(phi)*np.cos(vu) ep = np.sqrt((j + l + np.sqrt((j - l)**2 + 4*k**2)) / (j + l - np.sqtr((j - l)**2 + 4*k**2))) # Observed ellipticity e = 1 - 1/ep f = e1**2*np.sin(vu)**2*np.sin(phi)**2 + e2**2*np.sin(vu)**2*np.cos(phi)**2 + np.cos(vu)**2 """ PA = 0. Lens['HFID'].append(HFID) Lens['FOV'].append(FOV) Lens['Vrms'].append(Vrms) Lens['ELIP'].append(ellipticity) Lens['PA'].append(PA) df = pd.DataFrame.from_dict(Lens) zllabel = str(zl).replace('.', '')[:3].zfill(3) fname = (args["outbase"]+'LPPBox_%s_zl%s.txt' % \ (label, zllabel)) df.to_csv(fname, header=True, index=None, sep=' ', mode='w')