def performJob(runs, string, dirName, fileName, results, i): lagComp = runningJavelin(runs) lagComp.uLag = 1000. lagComp.computeLag(string, dirName, fileName, results, i) # Print update to screen print "\n", "=" * 40 print "\tLoop", i+1, "out of", runs print "\t", float(runs-i-1)/float(runs)*100, "% left" print "=" * 40, "\n"
def runJavelinOnFakeData(dataFile, limits, maxNum, dirName, string, emLine='MgII'): # Check that we have a valid emission line if (emLine != 'Hb' and emLine != 'MgII' and emLine != 'CIV'): print 'Please give valid emission line (Hb/MgII/CIV)' return -1 # End if-statement # Extract limits zMin = limits[0] zMax = limits[1] MagMin = limits[2] MagMax = limits[3] # Check that the given emission line agrees with redshifts if (emLine == 'Hb' and zMax > 0.74): print 'Emission line does not correspond to z-limits.' print 'Please give valid emission line (Hb/MgII/CIV)' return -1 elif (emLine == 'MgII' and (zMin < 0.69 or zMax > 1.94)): print 'Emission line does not correspond to z-limits.' print 'Please give valid emission line (Hb/MgII/CIV)' return -1 elif (emLine == 'CIV' and zMin < 1.58): print 'Emission line does not correspond to z-limits.' print 'Please give valid emission line (Hb/MgII/CIV)' return -1 # End if-statement # Import data for LightCurve-function data = np.loadtxt(dataFile) if (data.shape == (11,)): # Import each datset as a vector even if only one AGN has been created z = data[0][None] rMag = data[1][None] absMag = data[2][None] lag1 = data[5][None] lag2 = data[6][None] sf1 = data[7][None] sf2 = data[8][None] tau1 = data[9][None] tau2 = data[10][None] else: # Import dataset for all AGN z = data[:, 0] rMag = data[:, 1] absMag = data[:, 2] lag1 = data[:, 5] lag2 = data[:, 6] sf1 = data[:, 7] sf2 = data[:, 8] tau1 = data[:, 9] tau2 = data[:, 10] # End if-statement nFull = np.size(z) # Find number of elements in arrays # Extract relevant data zBin = np.array([]) rMagBin = np.array([]) absMagBin = np.array([]) lagBin = np.array([]) sfBin = np.array([]) tauBin = np.array([]) counter = 0 for i in range(0, nFull): if (z[i] > zMin and z[i] <= zMax and absMag[i] > MagMin and absMag[i] <= MagMax): zBin = np.append(zBin, z[i]) rMagBin = np.append(rMagBin, rMag[i]) absMagBin = np.append(absMagBin, absMag[i]) # Choose the right lags, SF and tau values if (emLine == 'Hb'): lagBin = np.append(lagBin, lag1[i]) sfBin = np.append(sfBin, sf1[i]) tauBin = np.append(tauBin, tau1[i]) elif (emLine == 'MgII'): # Take into account redshift when deciding on lag, SF and tau values if (z[i] > 0.74): lagBin = np.append(lagBin, lag1[i]) sfBin = np.append(sfBin, sf1[i]) tauBin = np.append(tauBin, tau1[i]) else: lagBin = np.append(lagBin, lag2[i]) sfBin = np.append(sfBin, sf2[i]) tauBin = np.append(tauBin, tau2[i]) # End if-statement elif (emLine == 'CIV'): lagBin = np.append(lagBin, lag2[i]) sfBin = np.append(sfBin, sf2[i]) tauBin = np.append(tauBin, tau2[i]) # End if-statement counter += 1 if (counter > maxNum): break # End if-statement # End if-statement # End for-loop nBin = np.size(zBin) length = 4190 # Defining directory where the results will be saved fileName = dirName + string + '.dat' directory = os.path.dirname(dirName) # Turn name into directory if not os.path.exists(directory): # Check whether directory exists os.makedirs(directory) # Create directory if nonexistent # End if-statement # Continue appending to file if it did not complete during the previous run try: results = np.loadtxt(fileName) # Load file if (results[:,0].size < nBin): # Check whether there are zero elements numToAppend = nBin - results[:, 0].size # Find number of missing rows to fill zeros = np.zeros((numToAppend, 4)) # Create array of appropriate size results = np.concatenate((results, zeros)) # Append array to previous results except Exception: results = np.zeros((nBin, 4)) # Create completely new array if needed # Do the loop! for i in range(0, nBin): lagComp = runningJavelin(nBin) # Defining parameters for LightCurve and Javelin lagComp.length = length lagComp.z = zBin[i] lagComp.sf = sfBin[i] lagComp.tau = tauBin[i] lagComp.mag = rMagBin[i] lagComp.tLag = lagBin[i] lagComp.lLag = 0 if (3*lagComp.tLag > 1000.0): lagComp.uLag = 3*lagComp.tLag else: lagComp.uLag = 1000.0 # End if-statement # Run Javelin lagComp.computeLag(string, dirName, fileName, results, i) # Print update to screen print "\n", "=" * 40 print "\tLoop", i+1, "out of", nBin print "\t", float(nBin-i-1)/float(nBin)*100, "% left" print "=" * 40, "\n" # End for-loop print 'Finished running Javelin'