def read_all_bodyfiles(prefix): filenames = ff.find_sorted_local_input_fileset(prefix) # Ignore log files for i in range(len(filenames)): if '.log' in filenames[i]: print('Removing log file ', filenames[i]) filenames.remove(filenames[i]) nbodies = len(filenames) print('Reading data for ', nbodies, ' bodies') data = [] for i in range(nbodies): filename = filenames[i] print('Reading ', filename) data.append(read_body_file(filename)) return filenames, data
def obtain_planet_tracks(prefix): '''Reads all planetary data and creates tracks for each planet''' planetfiles = ff.find_sorted_local_input_fileset(prefix + "*planets*") time, nplanet, nactive, active, mp, ap, tmig = read_planets(planetfiles[1]) time_all = np.zeros(len(planetfiles) - 1) active_all = np.zeros((nplanet, len(planetfiles) - 1)) ap_all = np.zeros((nplanet, len(planetfiles) - 1)) mp_all = np.zeros((nplanet, len(planetfiles) - 1)) tmig_all = np.zeros((nplanet, len(planetfiles) - 1)) for i in range(len(planetfiles) - 1): time_all[i], nplanet, nactive, active, mp, ap, tmig = read_planets( planetfiles[i + 1], verbose=False) active_all[:, i] = active[:] mp_all[:, i] = mp[:] ap_all[:, i] = ap[:] tmig_all[:, i] = tmig[:] return time_all, nplanet, active_all, ap_all, mp_all, tmig_all
import filefinder as ff from os import system # Get list of all directories paramfilelist = ff.find_sorted_local_input_fileset("*.params") nfiles = len(paramfilelist) print "There are ", nfiles, " files" # for blocks of 500, create a folder and move them ifile = 0 inext = 0 current_dir = "" for ifile in range(nfiles): if ifile == inext: inext = inext + 500 current_dir = "run_to_" + str(inext) # Create new directory command = "mkdir " + current_dir print command system(command) # Copy essential executable files command = "cp job-placeholder " + current_dir
import filefinder as ff from numpy import genfromtxt from os import system # Get list of all directories directorylist = genfromtxt('directorylist', dtype='string') print directorylist for directory in directorylist: # Get list of all job script files in directory jobfilelist = ff.find_sorted_local_input_fileset(directory + "/job_*") nfiles = len(jobfilelist) print "There are ", nfiles, " files" # Submit each job using sbatch for jobfile in jobfilelist: command = "sbatch " + jobfile print command system(command)
# Written 26/1/17 by dh4gan # Takes outputs from multiple runs of the grapus model and stitches them together # Primarily, this is ensuring that the 'istar' variable is corrected import numpy as np import filefinder as ff from sys import exit from io_grapus import ninitialcol,nlogcol,nfinalcol,logcoldict,finalcoldict, initialfmt,finalfmt,logfmt # Find three (sorted) file lists containing all initial, final and log files to be built initialfiles = ff.find_sorted_local_input_fileset('*.initial') finalfiles = ff.find_sorted_local_input_fileset('*.final') logfiles = ff.find_sorted_local_input_fileset('*.log') ninitial = len(initialfiles) nfinal = len(finalfiles) nlog = len(logfiles) if ninitial!=nfinal or nfinal!=nlog: print 'Unequal file counts: ' print 'Initial files ',ninitial print 'Final files ',nfinal print 'Log files ',nlog exit() # Define the total file names totalinitialfile = 'total.initial' totalfinalfile = 'total.final'
import filefinder as ff from os import system # Get list of all job script files in directory jobfilelist = ff.find_sorted_local_input_fileset("job_*") nfiles = len(jobfilelist) print "There are ", nfiles, " files" # Submit each job using sbatch #for jobfile in jobfilelist: nmin = 51 nmax = 100 for i in range(nmax): jobfile = jobfilelist[i] command = "sbatch "+jobfile print command system(command)
def plot_profile_multifiles_variable(prefix, add_planets=False): '''Reads multiple profile files and plots a specific variable''' filenames = ff.find_sorted_local_input_fileset(prefix + "*profile*") nfiles = len(filenames) initial = input('Starting filenumber? ') final = input('Final filenumber? ') print 'Now select variable to plot: here are the choices' for i in range(len(profilekeys)): print str(i + 1) + ': ' + profilekeys[i] var = input('Which variable (1-' + str(len(profilekeys)) + ')? ') var = var - 1 if (final > nfiles): print "Limiting count to available files" final = nfiles fig1 = plt.figure() ax = fig1.add_subplot(111) if (add_planets): planetfiles = ff.find_sorted_local_input_fileset(prefix + "*planets*") initial = initial - 1 final = final - 1 for i in range(initial, final): time, profdata = read_profile(filenames[i]) if (add_planets): t, nplanet, nactive, active, mp, ap, tmig = read_planets( planetfiles[i], verbose=False) # Setup planet points for plotting xpoints = np.zeros(nplanet) ypoints = np.zeros(nplanet) if profileymin[var] != profileymax[var]: ypoints[:] = 2.0 * profileymin[var] else: ypoints[:] = 2.0 * np.min(profdata[:, var]) planetsizes, planetcolours = get_planet_size_and_colour( nplanet, mp) if (profileylog[var]): ax.set_xscale('log') ax.set_yscale('log') if (profileymin[var] != profileymax[var]): ax.set_ylim(profileymin[var], profileymax[var]) line1 = ax.plot(profdata[:, 0], profdata[:, var]) ax.set_xlabel(profilexlabel) ax.set_ylabel(profilelabels[var]) ax.text(0.9, 0.9, 't = ' + str(np.round(time, 2)) + ' yr', bbox=dict(edgecolor='black', facecolor='none'), horizontalalignment='center', verticalalignment='center', transform=ax.transAxes) if (add_planets): ax.scatter(ap, ypoints, s=planetsizes, facecolor=planetcolours) outputfile = profilekeys[var] + '_' + filenames[i] + '.png' print 'Saving to ', outputfile plt.savefig(outputfile, format='png') ax.clear()