def plotDensity2dHist(filename, phi, theta, show='y', save='n', outFilename="figure", cbar=[0,60], xylims=[-25,25,-25,25]): """ Produces an animation using pngs created and placed in a given folder. INPUT VARIABLES --------------- inDirs (list of strings) - directories where the QGDISK and IPDISK files reside. utime, orbitPeriod (floats) - unit of time and orbit period for simulation. OUTPUT VARIABLES ---------------- An animation of the respective files. """ diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES(filename, diskname, IPname) Becoords *= udist / (7 * 6.96e10) NScoords *= udist / (7 * 6.96e10) partcoords *= udist / (7 * 6.96e10) BINS = 200 h, xedges, yedges = np.histogram2d(partcoords[:,0], partcoords[:,1], bins=BINS) # print xedges - xedges2 # print yedges - yedges2 plt.pcolor(xedges, yedges, h, cmap='RdBu') plt.xlim(xylims[0], xylims[1]) plt.ylim(xylims[2], xylims[3]) # plt.clim(cbar[0], cbar[1]) # plt.ylabel("EW") # plt.xlabel("Time / days") plt.colorbar() if(show == 'y'): plt.show() if(save == 'y'): plt.savefig(outFilename)#, figsize=(18, 16), dpi=100) if(show == 'n'): plt.close()
def plotDensityProfileFromPartNumbers(filenames, Rlims, Rsteps, pltargs=[0], colour='b'): """ Produces a plot of the density profile for the Be star disk in Z and rho space. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- partcoords ((npart, 3) float array) - x,y,z coordinates of the disk particles. rhos (npart float array) - density values of the disk particles. udist, umass (floats) - units used in simulation Rsteps (int) - number of steps from minimum to maximum radius of be star. ylim (2 element float) - defines limits of y axis. tol (float) - tolerance either side of x=0 that the function will use particles for plotting. OUTPUT VARIABLES ---------------- A plot of the disk profile. """ for filename in filenames: #diskname = filename[:-26] + "disk001" #IPname = filename[:-11] + "IPDISK" + filename[-5:-2] diskname = '../../Desktop/40d_0.0e_eqTest/disk001' IPname = '../../Desktop/40d_0.0e_eqTest/IPDISK' + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rhos, u, num_parts, time, umass, udist, utime = readFILES(filename, diskname, IPname) " Initialise arrays " Rs = np.sqrt(partcoords[:,0]**2 + partcoords[:,1]**2) """ Conversion of units """ Rs *= udist / (7 * 695700e3 * 100) Z = partcoords[:,2] * udist / (7 * 695700e3 * 100) R = np.array([]) numpartsDens = np.array([]) for j in np.delete(np.linspace(Rlims[0], Rlims[1], Rsteps), -1): j2 = j + ( max(Rs) - min(Rs) ) / Rsteps R = np.append(R, j + 0.5 * (j2 - j)) num = 0 Zs = np.array([]) for i in range(len(Rs)): if(Rs[i] >= j and Rs[i] < j2): Zs = np.append(Zs, Z[i]) num += 1 if(num == 0): numpartsDens = np.append(numpartsDens, 0) else: volume = 2 * np.pi * (j2**2 - j**2) * max(Zs) numpartsDens = np.append(numpartsDens, num / volume) numpartsDens *= max(rhos) * umass/(udist**3) / max(numpartsDens) if(pltargs[0] == 0): plt.plot(R, np.log10(numpartsDens), label='Density per volume')#, color=colour) else: plt.plot(np.log10(R), np.log10(numpartsDens), label=pltargs[0]+' Density per volume')#, color=colour) plt.xlabel("Radius of disk particle in Be radii") plt.ylabel("Density in g per cube cm") #plt.xlim(0, 25) # plt.title("Density and Number counted density") # plt.legend() return
def plotDensityProfile(filenames, ylims=[-1e-6, 1e-6], tol=1e-3, colours = ['b', 'g', 'r', 'turquoise']): """ Produces a plot of the density profile for the Be star disk. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- partcoords ((npart, 3) float array) - x,y,z coordinates of the disk particles. rhos (npart float array) - density values of the disk particles. udist, umass (floats) - units used in simulation ylim (2 element float) - defines limits of y axis. tol (float) - tolerance either side of x=0 that the function will use particles for plotting. OUTPUT VARIABLES ---------------- A plot of the disk profile. """ " Initialise arrays " count = 0 for filename in filenames: #diskname = 'INPUT/disk001' #IPname = 'INPUT/IPDISK411' diskname = '../../Desktop/40d_0.0e_eqTest/disk001' IPname = '../../Desktop/40d_0.0e_eqTest/IPDISK' + filename[-5:-2] #diskname = filename[:-26] + "disk001" #IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES(filename, diskname, IPname) R = np.sqrt(partcoords[:,0]**2 + partcoords[:,1]**2) Rs = np.array([]) rhos = np.array([]) for i in range(len(R)): if(R[i] > 1.0 * 0.0844): Rs = np.append(Rs, R[i]) rhos = np.append(rhos, rho[i]) """ Conversion of units """ rhos *= umass/(udist**3) Rs *= udist / (7 * 695700e3 * 100) """ Density Scatter """ #p = np.polyfit(np.log10(Rs), np.log10(rhos), 1) # print p plt.scatter(Rs, np.log10(rhos), s=0.75, color=colours[count]) #label=ylims[1] +"gradient = {:.3}".format(p[0])) #plt.plot(np.log10(Rs), p[0] * np.log10(Rs) + p[1], color='r') # plt.xlim(0, 1.5) # plt.ylim(ylims[0], ylims[1]) plt.xlabel("Distance from centre of Be star in Be radii") plt.ylabel("log of g/cm^3") plt.legend() # plt.title("Plot showing density profile and power law fit (gradient of {:.3})".format(p[0])) # plt.title("Plot showing density profile for {}".format(ylims[1])) #plt.show() count += 1 return
def plotRingDensity(filename, colour='b'): """ Produces a plot of the density profile for the Be star disk in Z and rho space. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- partcoords ((npart, 3) float array) - x,y,z coordinates of the disk particles. rhos (npart float array) - density values of the disk particles. udist, umass (floats) - units used in simulation Rsteps (int) - number of steps from minimum to maximum radius of be star. ylim (2 element float) - defines limits of y axis. tol (float) - tolerance either side of x=0 that the function will use particles for plotting. OUTPUT VARIABLES ---------------- A plot of the disk profile. """ diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES(filename, diskname, IPname) Becoords *= udist / (7 * 6.96e10) NScoords *= udist / (7 * 6.96e10) partcoords *= udist / (7 * 6.96e10) " Initialise arrays " R = np.sqrt(partcoords[:,0]**2 + partcoords[:,1]**2) Rs = np.array([]) phi = np.array([]) x = np.array([]) y = np.array([]) rhos = np.array([]) Rmax = 1.05 Rmin = 1.0 zFac = 0.03 for i in range(len(R)): if(R[i] > Rmin and R[i] < Rmax and partcoords[i,2] > -zFac*(Rmax-Rmin) and partcoords[i,2] < zFac*(Rmax-Rmin)): Rs = np.append(Rs, R[i]) rhos = np.append(rhos, rho[i]) phi = np.append(phi, np.arctan2(partcoords[i,0], partcoords[i,1])) x = np.append(x, partcoords[i,0]) y = np.append(y, partcoords[i,1]) """ Conversion of units """ Z = partcoords[:,2] rhos *= umass/(udist**3) sortOrder = np.argsort(phi) phi = phi[sortOrder] rhos = rhos[sortOrder] print phi """ SINE CURVE FIT """ # N = 1000 # number of data points # t = np.linspace(0, 4*np.pi, N) # data = 3.0*np.sin(t+0.001) + 0.5 + np.random.randn(N) # create artificial data with noise N = len(rhos) data = rhos t = phi guess_mean = np.mean(data) guess_std = 3*np.std(data)/(2**0.5) guess_phase = 0 # we'll use this to plot our first estimate. This might already be good enough for you data_first_guess = guess_std*np.sin(t+guess_phase) + guess_mean # Define the function to optimize, in this case, we want to minimize the difference # between the actual data and our "guessed" parameters optimize_func = lambda x: x[0]*np.sin(t+x[1]) + x[2] - data est_std, est_phase, est_mean = leastsq(optimize_func, [guess_std, guess_phase, guess_mean])[0] # recreate the fitted curve using the optimized parameters data_fit = est_std*np.sin(t+est_phase) + est_mean plt.plot(data, '.') plt.plot(data_fit, label='after fitting') plt.plot(data_first_guess, label='first guess') plt.legend() plt.show() # print FFIT # plt.scatter(phi, rhos) # plt.plot(phi, FFIT) # plt.plot(x,y) # plt.xlabel("Radius of disk particle in Be radii") # plt.ylabel("Density in g per cube cm") # plt.ylim(1e-10, 1e-14) # plt.title("Density and Number counted density") # plt.legend() return
def plotPowerLawWindowWithR(filename, Rlims, Rsteps, tol=10.0): """ Produces a plot of the variation of the power law index, n, with radius included in the calculation. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- Rlims (2 float array) - max and min R to perform calculation between in stellar radii. Rsteps (int) - number of steps from 1 stellar radii to Rmax. OUTPUT VARIABLES ---------------- A plot of the disk profile. """ diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rhos, u, num_parts, time, umass, udist, utime = readFILES(filename, diskname, IPname) Rsteparray = np.linspace(Rlims[0] * (7 * 695700e3 * 100) / udist, Rlims[1] * (7 * 695700e3 * 100) / udist, Rsteps) n = np.array([]) Rs = np.sqrt(partcoords[:,0]**2 + partcoords[:,1]**2) ndiff = np.array([]) for i in range(1, len(Rsteparray)): Rtemp = np.array([]) Ztemp = np.array([]) utemp = np.array([]) rhotemp = np.array([]) for j in range(len(Rs)): if(Rs[j] <= Rsteparray[i]): Rtemp = np.append(Rtemp, Rs[j]) rhotemp = np.append(rhotemp, rhos[j]) if(len(Rtemp) < 2): break p = np.polyfit(np.log10(Rtemp * udist), np.log10(rhotemp * umass/(udist**3)), 1) n = np.append(n, p[0]) print n[-1] print Rsteparray[i] * udist / (7 * 695700e3 * 100) if(len(n) > 2): if(np.abs(n[-1]) / np.abs(n[-2]) > tol): # print Rtemp[-1] * udist / (7 * 695700e3 * 100) print "YES" # deltaY = np.log10(rhotemp * umass/(udist**3))[-1] - np.log10(rhotemp * umass/(udist**3))[-2] # deltaX = np.log10(Rtemp * udist)[-1] - np.log10(Rtemp * udist)[-2] # n = np.append(n, deltaY / deltaX) for i in range(2, len(n)): ndiff = np.append(ndiff, n[i] - n[i-2]) # print Rsteparray[np.argmin(ndiff)] * udist / (7 * 695700e3 * 100) # print Rsteparray[np.argmax(ndiff)] * udist / (7 * 695700e3 * 100) plt.plot(Rsteparray[:len(ndiff)] * udist / (7 * 695700e3 * 100), ndiff) # plt.plot(range(12, 26), [4 for i in range(12, 26)]) # plt.plot(range(12, 26), [3.5 for i in range(12, 26)]) # plt.plot(range(12, 26), [2 for i in range(12, 26)]) plt.xlabel("Start of window for fitting") plt.ylabel("Power law index n given by fit")
def plot_System_NSacc_Obscuration_DiscArea(baseName, pngdirectory, DISKstart, DISKend, DISKsteps, orientation=[0, 0], obscTol=1.0, areaSteps=10): maxRhos = np.array([]) minRhos = np.array([]) times = np.array([]) NSacc = np.array([]) rhoObsc = np.array([]) discAreaArray = np.array([]) theta = np.deg2rad(-orientation[0]) phi = np.deg2rad(-orientation[1]) "Assemble full arrays of quantities to plot of each time step" for DISKnum in range(DISKstart, DISKend): for DISKstep in range(1, DISKsteps): filename = '/data/rob1g10/SPH/DATA/DISKS/{}/processedDISKs/QGDISK{:03}{:02}'.format( baseName, DISKnum, DISKstep) diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filename, diskname, IPname) Becoords *= udist / (7 * 6.96e10) NScoords *= udist / (7 * 6.96e10) partcoords *= udist / (7 * 6.96e10) rho *= umass / (udist**3) xcoords = np.array(partcoords[:, 0]) ycoords = np.array(partcoords[:, 1]) zcoords = np.array(partcoords[:, 2]) NScoords = np.array(NScoords) times = np.append(times, time * utime / (24 * 3600)) maxRhos = np.append(maxRhos, np.max(rho)) minRhos = np.append(minRhos, np.min(rho)) "Particle Rotation------------------------------------------------" rotSolution = np.dot(rotation_matrix([0, 0, 1], phi), [xcoords, ycoords, zcoords]) xrot1, yrot1, zrot1 = rotSolution[0], rotSolution[1], rotSolution[ 2] rotSolution = np.dot(rotation_matrix([1, 0, 0], theta), [xrot1, yrot1, zrot1]) xSol, ySol, zSol = rotSolution[0], rotSolution[1], rotSolution[2] "Now NS-----------------------------------------------------------" rotSolution = np.dot(rotation_matrix([0, 0, 1], phi), [NScoords[0], NScoords[1], NScoords[2]]) NSxrot1, NSyrot1, NSzrot1 = rotSolution[0], rotSolution[ 1], rotSolution[2] rotSolution = np.dot(rotation_matrix([1, 0, 0], theta), [NSxrot1, NSyrot1, NSzrot1]) NSxSol, NSySol, NSzSol = rotSolution[0], rotSolution[ 1], rotSolution[2] "Obscuration------------------------------------------------------" rhoSum = np.sum( rho[(xSol <= NSxSol + obscTol) * (xSol >= NSxSol - obscTol) * (ySol <= NSySol + obscTol) * (ySol >= NSySol - obscTol) * (zSol >= NSzSol)]) if (rhoSum < 0): rhoSum = 0 rhoObsc = np.append(rhoObsc, rhoSum) "Disc Area--------------------------------------------------------" "Step through bands of y coordinates and find max and min x coords to find area" discArea = 0 stepSize = (np.max(ySol) - np.min(ySol)) / areaSteps for ybands in np.linspace(np.min(ySol), np.max(ySol), areaSteps): xband = xSol[(ySol >= ybands) * (ySol < ybands + stepSize)] if (len(xband) > 0): discArea += stepSize * (np.max(xband) - np.min(xband)) discAreaArray = np.append(discAreaArray, discArea) times -= times[0] "Alternate colors" rhomax = np.max(maxRhos) rhomin = np.min(minRhos) cm = plt.cm.get_cmap('rainbow') # cm = plt.cm.get_cmap('hot') # colours = np.zeros(len(rho)) # for i in range(len(rho)): # rgrad = round(1 - rho[i]/rhomax, 1) # if(rgrad > 1): # rgrad = 1 # colours[i] = rgrad count = -1 for DISKnum in range(DISKstart + 1, DISKend - 1): for DISKstep in range(1, DISKsteps): count += 1 if (count + 10 >= len(times)): break print "Making image", count + 1, "of", len(times) filename = '/data/rob1g10/SPH/DATA/DISKS/{}/processedDISKs/QGDISK{:03}{:02}'.format( baseName, DISKnum, DISKstep) diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filename, diskname, IPname) Becoords *= udist / (7 * 6.96e10) NScoords *= udist / (7 * 6.96e10) partcoords *= udist / (7 * 6.96e10) rho *= umass / (udist**3) """3D Plot of System""" fig = plt.figure(figsize=(15, 15)) ax3D = fig.add_subplot(2, 2, 1, projection='3d') # print len(rho), len(xcoords) sc = ax3D.scatter(partcoords[:, 0], partcoords[:, 1], partcoords[:, 2], s=0.5, c=rho, vmin=rhomin, vmax=rhomax, cmap=cm, edgecolor='') ax3D.scatter(NScoords[0], NScoords[1], NScoords[2], color='b') ax3D.set_xlim(-11, 11) ax3D.set_ylim(-11, 11) ax3D.set_zlim(-11, 11) ax3D.set_xlabel('x') ax3D.set_ylabel('y') ax3D.set_zlabel('z') ax3D.view_init(elev=orientation[0] + 90, azim=orientation[1] + 90) " NS Accretion " # os.system("ls /data/rob1g10/SPH/DATA/DISKS/{}/disk* > lsdisks.txt".format(filename)) # # f = open("lsdisks.txt", 'r') # lines = f.readlines() # # numdisks = int(lines[-1][-3:]) # # f.close() # # disks = np.array([]) # # for ND in range(1, numdisks+1): # disks = np.append(disks, '/data/rob1g10/SPH/DATA/DISKS/{}/disk{:03}'.format(baseNames[BN], ND)) # accTimes, accArray = createAccretionArray(disks,"NScapture", None, 'day', tol=0.01) # accArray *= 1e-14 * umass / (24*3600) # accTimes = accTimes.astype(float) axAccr = fig.add_subplot(2, 2, 2) # axAccr.plot axDisc.set_xlabel('Time (days)') axDisc.set_ylabel('NS accretion') " Obscuration " axObsc = fig.add_subplot(2, 2, 3) axObsc.scatter(times[count + 5], rhoObsc[count + 5], color='r') axObsc.plot(times[count:count + 10], rhoObsc[count:count + 10]) axObsc.set_ylim(np.min(rhoObsc), np.max(rhoObsc)) axDisc.set_xlabel('Time (days)') axDisc.set_ylabel('Obscuration') " Disc Size " axDisc = fig.add_subplot(2, 2, 4) axDisc.scatter(times[count + 5], discAreaArray[count + 5], color='r') axDisc.plot(times[count:count + 10], discAreaArray[count:count + 10]) axDisc.set_ylim(np.min(discAreaArray), np.max(discAreaArray)) axDisc.set_xlabel('Time (days)') axDisc.set_ylabel('Disc Area') " Save file " outFilename = "{}AniPart{:04}".format(pngdirectory, count + 1) plt.savefig(outFilename, figsize=(18, 16), dpi=100) os.system("convert -delay 20 -loop 0 {}*.png {}.gif".format( pngdirectory, baseName)) return
def plotNSObscuration(baseName, DISKstart, DISKend, DISKsteps, orientation=[0, 0], obscTol=1.0): times = np.array([]) rhoObsc = np.array([]) theta = np.deg2rad(-orientation[0]) phi = np.deg2rad(-orientation[1]) "Assemble full arrays of quantities to plot of each time step" for DISKnum in range(DISKstart, DISKend): for DISKstep in range(1, DISKsteps): filename = '/data/rob1g10/SPH/DATA/DISKS/{}/processedDISKs/QGDISK{:03}{:02}'.format( baseName, DISKnum, DISKstep) diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filename, diskname, IPname) Becoords *= udist / (7 * 6.96e10) NScoords *= udist / (7 * 6.96e10) partcoords *= udist / (7 * 6.96e10) rho *= umass / (udist**3) xcoords = np.array(partcoords[:, 0]) ycoords = np.array(partcoords[:, 1]) zcoords = np.array(partcoords[:, 2]) NScoords = np.array(NScoords) times = np.append(times, time * utime / (24 * 3600)) "Particle Rotation------------------------------------------------" rotSolution = np.dot(rotation_matrix([0, 0, 1], phi), [xcoords, ycoords, zcoords]) xrot1, yrot1, zrot1 = rotSolution[0], rotSolution[1], rotSolution[ 2] rotSolution = np.dot(rotation_matrix([1, 0, 0], theta), [xrot1, yrot1, zrot1]) xSol, ySol, zSol = rotSolution[0], rotSolution[1], rotSolution[2] "Now NS-----------------------------------------------------------" rotSolution = np.dot(rotation_matrix([0, 0, 1], phi), [NScoords[0], NScoords[1], NScoords[2]]) NSxrot1, NSyrot1, NSzrot1 = rotSolution[0], rotSolution[ 1], rotSolution[2] rotSolution = np.dot(rotation_matrix([1, 0, 0], theta), [NSxrot1, NSyrot1, NSzrot1]) NSxSol, NSySol, NSzSol = rotSolution[0], rotSolution[ 1], rotSolution[2] "Obscuration------------------------------------------------------" rhoSum = np.sum( rho[(xSol <= NSxSol + obscTol) * (xSol >= NSxSol - obscTol) * (ySol <= NSySol + obscTol) * (ySol >= NSySol - obscTol) * (zSol >= NSzSol)]) if (rhoSum < 0): rhoSum = 0 rhoObsc = np.append(rhoObsc, rhoSum) plt.plot(times, rhoObsc) return
def plotVisibleDiscArea(baseName, DISKstart, DISKend, DISKsteps, orientation=[0, 0], areaSteps=10): times = np.array([]) discAreaArray = np.array([]) theta = np.deg2rad(-orientation[0]) phi = np.deg2rad(-orientation[1]) "Assemble full arrays of quantities to plot of each time step" for DISKnum in range(DISKstart, DISKend): for DISKstep in range(1, DISKsteps): filename = '/data/rob1g10/SPH/DATA/DISKS/{}/processedDISKs/QGDISK{:03}{:02}'.format( baseName, DISKnum, DISKstep) diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filename, diskname, IPname) Becoords *= udist / (7 * 6.96e10) NScoords *= udist / (7 * 6.96e10) partcoords *= udist / (7 * 6.96e10) rho *= umass / (udist**3) xcoords = np.array(partcoords[:, 0]) ycoords = np.array(partcoords[:, 1]) zcoords = np.array(partcoords[:, 2]) NScoords = np.array(NScoords) times = np.append(times, time * utime / (24 * 3600)) "Particle Rotation------------------------------------------------" rotSolution = np.dot(rotation_matrix([0, 0, 1], phi), [xcoords, ycoords, zcoords]) xrot1, yrot1, zrot1 = rotSolution[0], rotSolution[1], rotSolution[ 2] rotSolution = np.dot(rotation_matrix([1, 0, 0], theta), [xrot1, yrot1, zrot1]) xSol, ySol, zSol = rotSolution[0], rotSolution[1], rotSolution[2] "Disc Area--------------------------------------------------------" "Step through bands of y coordinates and find max and min x coords to find area" discArea = 0 stepSize = (np.max(ySol) - np.min(ySol)) / areaSteps for ybands in np.linspace(np.min(ySol), np.max(ySol), areaSteps): xband = xSol[(ySol >= ybands) * (ySol < ybands + stepSize)] if (len(xband) > 0): discArea += stepSize * (np.max(xband) - np.min(xband)) discAreaArray = np.append(discAreaArray, discArea) plt.plot(times, discAreaArray) return
def plotRotatingOptDepthFigs(CcodeName, filenames, pngdirectory, baseName, thetaRange, phiRange, obsAngles, zoom): """ Produces a scatter plots of varying viewing angles of a system in 2D of the particles and stars. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- filename (list of 3 strings) - name of the filename with the particle data on it and name of disk file for units and also IP disk file name. pngdirectory (string) - directory where png files are found. baseName (string) - base of the name of the file that the plot will be saved as. OUTPUT VARIABLES ---------------- Various plots of the particles. """ for theta in range(thetaRange[0], thetaRange[1], thetaRange[2]): for phi in range(phiRange[0], phiRange[1], phiRange[2]): for zoom in [zoom]: #, 10, 5]: Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filenames[0], filenames[1], filenames[2]) name = "{}{}_theta{}_phi{}_zoom{}_obsAngle{}_time{:0.1f}.png".format( pngdirectory, baseName, theta, phi, zoom, obsAngles[0], time * utime / (24 * 3600)) OD = readOptDepthData4py( "/data/rob1g10/SPH/DATA/DISKS/{}/optDepthData{}{}_theta{}_phi{}_time{:0.1f}.txt" .format(baseName, CcodeName, baseName, obsAngles[0], obsAngles[1], time * utime / (24 * 3600))) plotAndSaveFig([filenames[0], filenames[1]], time * utime / (24 * 3600), name, 'OptDepth', orientation=[0 + phi, 0 + theta], show='n', save='y', xylims=[-zoom, zoom, -zoom, zoom], T=np.exp(-OD)) print(theta, phi) Tsum = 0 xcoords = partcoords[:, 0] * udist / (7 * 6.96e10) ycoords = partcoords[:, 1] * udist / (7 * 6.96e10) R = np.sqrt(xcoords**2 + ycoords**2) for i in range(len(OD)): if (R[i] < 10): Tsum += np.exp(-OD[i]) return Tsum, partcoords
def plotRotatingOptDepthSpectraFigs(CcodeName, filenames, pngdirectory, baseName, thetaRange, phiRange): """ Produces a scatter plots of varying viewing angles of a system in 2D of the particles and stars. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- c filename (list of 3 strings) - name of the filename with the particle data on it and name of disk file for units and also IP disk file name. pngdirectory (string) - directory where png files are found. baseName (string) - base of the name of the file that the plot will be saved as. OUTPUT VARIABLES ---------------- Various plots of the particles. """ # for theta in range(0, 181, 15): # for phi in range(0, 181, 15): for theta in range(thetaRange[0], thetaRange[1], thetaRange[2]): for phi in range(phiRange[0], phiRange[1], phiRange[2]): Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filenames[0], filenames[1], filenames[2]) nameZoom = "{}{}_theta{}_phi{}_time{:0.1f}_zoomY.png".format( pngdirectory, baseName, theta, phi, time * utime / (24 * 3600)) name = "{}{}_theta{}_phi{}_time{:0.1f}_zoomN.png".format( pngdirectory, baseName, theta, phi, time * utime / (24 * 3600)) oD = readOptDepthData4py( "/data/rob1g10/SPH/DATA/DISKS/{}/optDepthData{}{}_theta{}_phi{}_time{:0.1f}.txt" .format(baseName, CcodeName, baseName, theta, phi, time * utime / (24 * 3600))) T = np.exp(-oD) / 1e-3 print(theta, phi) print(len(T)) plotAndSaveSpectralLine(partvels, T, [phi, theta], 200, udist, utime, "uniform", nameZoom, save='y') plotAndSaveSpectralLine(partvels, T, [phi, theta], 200, udist, utime, "uniform", name, save='y', xlims="y") return
def calcOptDepthsOverTime(CcodeName, dataCreationName, baseName, inputdirectory, startDISKs, numDISKs, phi, theta, SubQDISK, dropbox='n'): """ Produces an animation using pngs created and placed in a given folder. INPUT VARIABLES --------------- inDirs (list of strings) - directories where the QGDISK and IPDISK files reside. utime, orbitPeriod (floats) - unit of time and orbit period for simulation. OUTPUT VARIABLES ---------------- An animation of the respective files. """ os.system("rm lsQG.txt lsIP.txt") QGfilenames = np.array([]) f = open("lsQG.txt", "w") for j in range(startDISKs, startDISKs + numDISKs): for k in range(SubQDISK[0], SubQDISK[1]): NAME = "{}QGDISK{:03}{:02}\n".format(inputdirectory, j, k) if (os.system("ls {}".format(NAME)) == 0): f.write(NAME) else: break f.close() f = open("lsIP.txt", "w") for j in range(startDISKs, startDISKs + numDISKs): NAME = "{}IPDISK{:03}\n".format(inputdirectory, j) f.write(NAME) f.close() """ QGDISKs """ f = open("lsQG.txt", "r") lines = f.readlines() for line in lines: f2 = open("{}".format(line[0:-1])) temp = f2.readlines() f2.close() if (len(temp) != 0): QGfilenames = np.append(QGfilenames, line[0:-1]) f.close() for i in range(len(QGfilenames)): filename = QGfilenames[i] diskname = filename[:-26] + "disk001" IPname = filename[:-11] + "IPDISK" + filename[-5:-2] Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filename, diskname, IPname) createOptDepthData4c( dataCreationName, #CcodeName, partcoords * udist, partvels * udist / utime, u * udist**2 / utime**2, rho * umass / udist**3, num_parts, 1e-15 * umass / 2e30, (7 * 6.96e10), 18 * 2e33, 2.5, max(rho) * umass / udist**3, theta, phi) os.system("./opticalDepth{}".format(CcodeName)) name = "{}_theta{}_phi{}_time{:0.1f}".format( baseName, theta, phi, time * utime / (24 * 3600)) if (dropbox == 'y'): os.system( "cp optDepthData4py{}.txt /data/rob1g10/SPH/DATA/DISKS/{}/optDepthData{}{}.txt" .format(CcodeName, baseName, CcodeName, name)) os.system( "mv optDepthData4py{}.txt DATA/optDepthData{}{}.txt".format( CcodeName, CcodeName, name)) else: os.system( "mv optDepthData4py{}.txt /data/rob1g10/SPH/DATA/DISKS/{}/optDepthData{}{}.txt" .format(CcodeName, baseName, CcodeName, name)) # print time * utime / (24 *3600) print name, "done" os.system("rm lsQG.txt lsIP.txt") return
def calcRotatingOptDepths(filenames, baseName, thetaRange, phiRange): """ Produces a scatter plots of varying viewing angles of a system in 2D of the particles and stars. GEOMETRY -------- z axis is height of disk, y axis is width and x axis is depth. INPUT VARIABLES --------------- filename (list of 3 strings) - name of the filename with the particle data on it and name of disk file for units and also IP disk file name. pngdirectory (string) - directory where png files are found. baseName (string) - base of the name of the file that the plot will be saved as. OUTPUT VARIABLES ---------------- Optical Depth values for all particles in given file from all angles.. """ # for theta in range(0, 181, 15): # for phi in range(0, 181, 15): for theta in range(thetaRange[0], thetaRange[1], thetaRange[2]): for phi in range(phiRange[0], phiRange[1], phiRange[2]): Becoords, NScoords, partcoords, partvels, rho, u, num_parts, time, umass, udist, utime = readFILES( filenames[0], filenames[1], filenames[2]) createOptDepthData4c(partcoords * (udist * 0.01), partvels * (udist * 0.01) / utime, u * (udist * 0.01)**2 / utime**2, num_parts, 1e-15 * 0.001 * umass / 2e30, (7 * 6.96e10), 2.5, max(rho) * umass * 1e6 / udist**3, theta, phi) print max(rho) * umass * 1e6 / udist**3 os.system("./opticalDepth") name = "{}_theta{}_phi{}_time{:0.1f}".format( baseName, theta, phi, time * utime / (24 * 3600)) # os.system("cp optDepthData4py.txt /home/rob1g10/Dropbox/PhD/DISKs/optDepthData{}.txt".format(name)) os.system( "mv optDepthData4py.txt /data/rob1g10/SPH/DATA/DISKS/{}/optDepthData{}.txt" .format(baseName, name)) print(theta, phi) return