def test_singlesim(): # gets current path path = pathlib.Path(__file__).parents[0].absolute() sys.path.insert(1, str(path.parents[0])) # gets the number of cores on the machine cores = mp.cpu_count() if cores == 1: warnings.warn("There is only 1 core on the machine", stacklevel=3) else: # Run vspace if not (path / "BP_Extract").exists(): subprocess.check_output(["vspace", "vspace.in"], cwd=path) # Run multi-planet if not (path / ".BP_Extract").exists(): subprocess.check_output(["multiplanet", "vspace.in"], cwd=path) # Run bigplanet if not (path / "Test.bpf").exists(): subprocess.check_output(["bigplanet", "bpl.in"], cwd=path) file = bp.BPLFile(path / "Test.bpf") earth_Tman_forward = bp.ExtractColumn(file, 'earth:TMan:forward') earth_Tcore_inital = bp.ExtractColumn(file, 'earth:TCore:initial') assert np.isclose(earth_Tman_forward[0][-1], 2257.850930) assert np.isclose(earth_Tcore_inital[0], 6000.00000)
def test_bpextract(): # gets current path path = pathlib.Path(__file__).parents[0].absolute() sys.path.insert(1, str(path.parents[0])) # gets the number of cores on the machine cores = mp.cpu_count() if cores == 1: warnings.warn("There is only 1 core on the machine", stacklevel=3) else: # Run vspace if not (path / "BP_Extract").exists(): subprocess.check_output(["vspace", "vspace.in"], cwd=path) # Run multi-planet if not (path / ".BP_Extract").exists(): subprocess.check_output(["multiplanet", "vspace.in"], cwd=path) # Run bigplanet if not (path / ".BP_Extract_BPL").exists(): subprocess.check_output(["bigplanet", "bpl.in", "-a"], cwd=path) file = bp.BPLFile(path / "BP_Extract.bpa") earth_Instellation_final = bp.ExtractColumn( file, 'earth:Instellation:final') sun_RotPer_initial = bp.ExtractColumn(file, 'sun:RotPer:initial') assert np.isclose(earth_Instellation_final[0], 1367.635318) assert np.isclose(earth_Instellation_final[1], 341.90883) assert np.isclose(sun_RotPer_initial[0], 86400.0)
def test_bpstats(): #gets the number of cores on the machine cores = str(mp.cpu_count()) if cores == 1: warnings.warn("There is only 1 core on the machine", stacklevel=3) else: #removes checkpoint files cp = cwd + '/.BP_Stats' sub.run(['rm', cp], cwd=cwd) cp_hdf5 = cwd + '/.BP_Stats_hdf5' sub.run(['rm', cp_hdf5], cwd=cwd) #removes the folders from when vspace is ran dir = cwd + '/BP_Stats' sub.run(['rm', '-rf', dir], cwd=cwd) sub.run(['rm', '-rf', (dir + '.hdf5')], cwd=cwd) #runs vspace sub.run(['python', '../../vspace/vspace/vspace.py', 'vspace.in'], cwd=cwd) #runs multi-planet sub.run([ 'python', '../../multi-planet/multi-planet.py', 'vspace.in', '-c', cores ], cwd=cwd) #runs bigplanet sub.run([ 'python', '../../bigplanet/bigplanet/bigplanet.py', 'vspace.in', '-c', cores ], cwd=cwd) #reads in the hdf5 file file = h5py.File((dir + '.hdf5'), 'r') earth_RIC_min = bp.ExtractColumn(file, 'earth_RIC_min') earth_235UNumMan_max = bp.ExtractColumn(file, 'earth_235UNumMan_max') earth_TCMB_mean = bp.ExtractColumn(file, 'earth_TCMB_mean') earth_FMeltUMan_geomean = bp.ExtractColumn(file, 'earth_FMeltUMan_geomean') earth_BLUMan_stddev = bp.ExtractColumn(file, 'earth_BLUMan_stddev') for i in range(len(earth_RIC_min)): assert np.isclose(earth_RIC_min[i], 0) for j in range(len(earth_235UNumMan_max)): assert np.isclose(earth_235UNumMan_max[j], 5.074241e+26) for k in range(len(earth_TCMB_mean)): assert np.isclose(earth_TCMB_mean[j], 4359.67230935) for l in range(len(earth_FMeltUMan_geomean)): assert np.isclose(earth_FMeltUMan_geomean[l], 0.20819565) for m in range(len(earth_BLUMan_stddev)): assert np.isclose(earth_BLUMan_stddev[m], 18.26509002)
def test_bpextract(): #gets the number of cores on the machine cores = str(mp.cpu_count()) if cores == 1: warnings.warn("There is only 1 core on the machine", stacklevel=3) else: #removes checkpoint files cp = cwd + '/.BP_Extract' sub.run(['rm', cp], cwd=cwd) cp_hdf5 = cwd + '/.BP_Extract_hdf5' sub.run(['rm', cp_hdf5], cwd=cwd) #removes the folders from when vspace is ran dir = cwd + '/BP_Extract' sub.run(['rm', '-rf', dir], cwd=cwd) sub.run(['rm', '-rf', (dir + '.hdf5')], cwd=cwd) #runs vspace sub.run(['python', '../../vspace/vspace/vspace.py', 'vspace.in'], cwd=cwd) #runs multi-planet sub.run([ 'python', '../../multi-planet/multi-planet.py', 'vspace.in', '-c', cores ], cwd=cwd) #runs bigplanet sub.run([ 'python', '../../bigplanet/bigplanet/bigplanet.py', 'vspace.in', '-c', cores ], cwd=cwd) #reads in the hdf5 file file = h5py.File((dir + '.hdf5'), 'r') earth_Instellation_final = bp.ExtractColumn( file, 'earth_Instellation_final') sun_RotPer_initial = bp.ExtractColumn(file, 'sun_RotPer_initial') for i in range(len(earth_Instellation_final)): assert np.isclose(earth_Instellation_final[0], 1367.635318) assert np.isclose(earth_Instellation_final[1], 341.90883) for j in range(len(sun_RotPer_initial)): assert np.isclose(sun_RotPer_initial[j], 86400.0)
def test_bpextract(): # gets current path path = pathlib.Path(__file__).parents[0].absolute() sys.path.insert(1, str(path.parents[0])) # gets the number of cores on the machine cores = mp.cpu_count() if cores == 1: warnings.warn("There is only 1 core on the machine", stacklevel=3) else: # Run vspace if not (path / "BP_Extract").exists(): subprocess.check_output(["vspace", "vspace.in"], cwd=path) # Run multi-planet if not (path / ".BP_Extract").exists(): subprocess.check_output(["multiplanet", "vspace.in"], cwd=path) # Run bigplanet if not (path / "BP_Extract.bpa").exists(): subprocess.check_output(["bigplanet", "bpl.in", "-a"], cwd=path) # Run bigplanet if not (path / "Test.bpf").exists(): subprocess.check_output(["bigplanet", "bpl.in"], cwd=path) file = bp.BPLFile(path / "Test.bpf") earth_Instellation_final = bp.ExtractColumn( file, 'earth:Instellation:final') sun_Luminosity_option = bp.ExtractColumn(file, 'sun:dLuminosity:option') earth_Mass_option = bp.ExtractColumn(file, 'earth:dMass:option') vpl_stoptime_option = bp.ExtractColumn(file, 'vpl:dStopTime:option') earth_tman_forward = bp.ExtractColumn(file, 'earth:TMan:forward') assert np.isclose(earth_Instellation_final[1], 341.90883) assert np.isclose(sun_Luminosity_option[0], 3.846e26) assert np.isclose(earth_Mass_option[1], -1.5) assert np.isclose(vpl_stoptime_option[0], 4.5e9) assert np.isclose(earth_tman_forward[0][0], 3000.0)
def test_bpstats(): # gets current path path = pathlib.Path(__file__).parents[0].absolute() sys.path.insert(1, str(path.parents[0])) # gets the number of cores on the machine cores = mp.cpu_count() if cores == 1: warnings.warn("There is only 1 core on the machine", stacklevel=3) else: # Run vspace if not (path / "BP_Stats").exists(): subprocess.check_output(["vspace", "vspace.in"], cwd=path) # Run multi-planet if not (path / ".BP_Stats").exists(): subprocess.check_output(["multiplanet", "vspace.in"], cwd=path) # Run bigplanet if not (path / "BP_Stats.bpa").exists(): subprocess.check_output(["bigplanet", "bpl.in", "-a"], cwd=path) file = bp.BPLFile(path / "BP_Stats.bpa") earth_TMan_min = bp.ExtractColumn(file, 'earth:TMan:min') earth_235UNumMan_max = bp.ExtractColumn(file, 'earth:235UNumMan:max') earth_TCMB_mean = bp.ExtractColumn(file, 'earth:TCMB:mean') earth_FMeltUMan_geomean = bp.ExtractColumn(file, 'earth:FMeltUMan:geomean') earth_BLUMan_stddev = bp.ExtractColumn(file, 'earth:BLUMan:stddev') assert np.isclose(earth_TMan_min[0], 2257.85093) assert np.isclose(earth_235UNumMan_max[0], 2.700598e+28) assert np.isclose(earth_TCMB_mean[0], 4359.67230935255) assert np.isclose(earth_FMeltUMan_geomean[0], 0.20819565439935903) assert np.isclose(earth_BLUMan_stddev[0], 18.285373298439122)
def clim_evol(plname, dir='.', xrange=False, orbit=False, show=True): """ Creates plots of insolation, temperature, albedo, ice mass, and bed rock height over the length of the simulation Parameters ---------- plname : string The name of the planet with .Climate data Keyword Arguments ----------------- dir : string Directory of vplanet simulation (default = '.') xrange : float tuple, list, or numpy array Range of x-values (time) to restrict plot (default = False (no restriction)) orbit : bool Plot orbital data (obliquity, eccentricity, COPP) (default = False) show : bool Show plot in Python (default = True) Output ------ PDF format plot with name 'evol_<dir>.pdf' """ # gets current path path = pathlib.Path(__file__).parents[0].absolute() sys.path.insert(1, str(path.parents[0])) fig = plt.figure(figsize=(9, 8)) fig.subplots_adjust(wspace=0.5, hspace=0.5) file = bp.BPLFile(path / "DynamicExample.bpf") ecc = bp.ExtractColumn(file, 'earth:Eccentricity:forward')[0] obl = bp.ExtractColumn(file, 'earth:Obliquity:forward')[0] copp = bp.ExtractColumn(file, 'earth:COPP:forward')[0] lats = bp.ExtractUniqueValues(file, 'earth:Latitude:climate') times = bp.ExtractColumn(file, 'earth:Time:forward')[0] temp = bp.ExtractColumn(file, 'earth:TempLat:climate')[0] alb = bp.ExtractColumn(file, 'earth:AlbedoLat:climate')[0] ice = bp.ExtractColumn(file, 'earth:IceHeight:climate')[0] insol = bp.ExtractColumn(file, 'earth:AnnInsol:climate')[0] brock = bp.ExtractColumn(file, 'earth:BedrockH:climate')[0] nlats = len(lats) ntimes = len(times) # plot temperature temp = bp.CreateMatrix(lats, times, temp) temp_T = np.array(temp).T.tolist() #temp = np.reshape(temp,(ntimes,nlats)) plt.subplot(4, 2, 1) c = plt.contourf(times, lats, temp_T, cmap='plasma') plt.ylabel(r'Latitude [$^\circ$]', fontsize=10) plt.title(r'Surface Temp [$^{\circ}$C]', fontsize=12) plt.ylim(-85, 85) plt.yticks([-60, -30, 0, 30, 60], fontsize=9) plt.xticks(fontsize=9) if xrange: plt.xlim(xrange) cbar = plt.colorbar(c) plt.setp(cbar.ax.yaxis.get_ticklabels(), fontsize=9) # plot albedo #alb = np.reshape(alb,(ntimes,nlats)) alb = bp.CreateMatrix(lats, times, alb) alb_T = np.array(alb).T.tolist() plt.subplot(4, 2, 3) #pos = ax2.figbox.get_points() c = plt.contourf(times, lats, alb_T, cmap='Blues_r') plt.ylabel(r'Latitude [$^\circ$]', fontsize=10) plt.title('Albedo [TOA]', fontsize=12) plt.ylim(-85, 85) plt.yticks([-60, -30, 0, 30, 60], fontsize=9) plt.xticks(fontsize=9) if xrange: plt.xlim(xrange) cbar = plt.colorbar(c) plt.setp(cbar.ax.yaxis.get_ticklabels(), fontsize=9) # plot ice height #ice = np.reshape(ice,(ntimes,nlats)) ice = bp.CreateMatrix(lats, times, ice) ice_T = np.array(ice).T.tolist() plt.subplot(4, 2, 5) #pos = ax3.figbox.get_points() c = plt.contourf(times, lats, ice_T, cmap='Blues_r') plt.ylabel(r'Latitude [$^\circ$]', fontsize=10) plt.title('Ice sheet height [m]', fontsize=12) plt.ylim(-85, 85) plt.yticks([-60, -30, 0, 30, 60], fontsize=9) plt.xticks(fontsize=9) if xrange: plt.xlim(xrange) cbar = plt.colorbar(c) plt.setp(cbar.ax.yaxis.get_ticklabels(), fontsize=9) # plot bedrock brock = bp.CreateMatrix(lats, times, brock) brock_T = np.array(brock).T.tolist() plt.subplot(4, 2, 7) c = plt.contourf(times, lats, brock_T, cmap='Reds_r') plt.ylabel(r'Latitude [$^\circ$]', fontsize=10) plt.title('Bedrock height [m]', fontsize=12) plt.ylim(-85, 85) plt.yticks([-60, -30, 0, 30, 60], fontsize=9) plt.xlabel('Time [years]', fontsize=10) plt.xticks(fontsize=9) if xrange: plt.xlim(xrange) cbar = plt.colorbar(c) plt.setp(cbar.ax.yaxis.get_ticklabels(), fontsize=9) # plot insolation insol = bp.CreateMatrix(lats, times, insol) insol_T = np.array(insol).T.tolist() plt.subplot(4, 2, 2) c = plt.contourf(times, lats, insol_T, cmap='plasma') plt.ylabel(r'Latitude [$^\circ$]', fontsize=10) plt.title(r'Annual average instellation [W/m$^2$]', fontsize=12) plt.ylim(-85, 85) plt.yticks([-60, -30, 0, 30, 60], fontsize=9) plt.xticks(fontsize=9) if xrange: plt.xlim(xrange) cbar = plt.colorbar(c) plt.setp(cbar.ax.yaxis.get_ticklabels(), fontsize=9) #obliquity plt.subplot(4, 2, 4) plt.plot(times, obl, linestyle='solid', marker='None', color='darkblue', linewidth=2) plt.ylabel(r'Obliquity [$^\circ$]', fontsize=10) plt.yticks(fontsize=9) plt.xticks(fontsize=9) plt.xlim(0, 250000) if xrange: plt.xlim(xrange) #eccentricity plt.subplot(4, 2, 6) plt.plot(times, ecc, linestyle='solid', marker='None', color='darkorchid', linewidth=2) plt.ylabel('Eccentricity', fontsize=10) plt.xticks(fontsize=9) plt.yticks(fontsize=9) plt.xlim(0, 250000) if xrange: plt.xlim(xrange) #e sin(obl) sin varpi plt.subplot(4, 2, 8) plt.plot(times, copp, linestyle='solid', marker='None', color='salmon', linewidth=2) plt.ylabel('COPP', fontsize=10) plt.xlabel('Time [years]', fontsize=10) plt.xticks(fontsize=9) plt.yticks(fontsize=9) plt.xlim(0, 250000) if xrange: plt.xlim(xrange) if (sys.argv[1] == 'pdf'): plt.savefig('DynamicExample.pdf') if (sys.argv[1] == 'png'): plt.savefig('DynamicExample.png') if show: plt.show() else: plt.close()
#!/usr/bin/env python import bigplanet as bp import h5py as h5 import matplotlib.pyplot as plt import vplot as vpl import sys import os os.chdir(os.path.dirname(os.path.abspath(__file__))) data = bp.HDF5File('ParameterSweep.hdf5') RIC = bp.ExtractColumn(data,'earth_RIC_final') RIC_units = bp.ExtractUnits(data,'earth_RIC_final') TCore_uniq = bp.ExtractUniqueValues(data,'earth_TCore_initial') TCore_units = bp.ExtractUnits(data,'earth_TCore_initial') K40_uniq = bp.ExtractUniqueValues(data,'earth_40KPowerCore_final') K40_units = bp.ExtractUnits(data,'earth_40KPowerCore_final') RIC_Matrix = bp.CreateMatrix(TCore_uniq,K40_uniq,RIC) #print(RIC_Matrix) contours = [0,500,1000,1500,2000,2500] xlabel = 'Initial Core Temperature ('+TCore_units+')' ylabel = 'Current Potassium-40 Power ('+K40_units+')' title = 'Final Inner Core Radius ('+RIC_units+')'
subprocess.check_output(["vspace", "vspace.in"], cwd=path) # Run multi-planet if not (path / ".ParameterSweep").exists(): subprocess.check_output(["multiplanet", "vspace.in"], cwd=path) # Run bigplanet if not (path / "ParameterSweep.bpf").exists(): subprocess.check_output(["bigplanet", "bpl.in"], cwd=path) data = bp.BPLFile(path / "ParameterSweep.bpf") mpl.rcParams["figure.figsize"] = (10, 8) fig = plt.figure() RIC = bp.ExtractColumn(data, "earth:RIC:final") RIC_units = bp.ExtractUnits(data, "earth:RIC:final") TCore_uniq = bp.ExtractUniqueValues(data, "earth:TCore:initial") TCore_units = bp.ExtractUnits(data, "earth:TCore:initial") K40_uniq = bp.ExtractUniqueValues(data, "earth:40KPowerCore:final") K40_units = bp.ExtractUnits(data, "earth:40KPowerCore:final") RIC_Matrix = np.reshape(RIC, (len(TCore_uniq), len(K40_uniq))) #RIC_Matrix = bp.CreateMatrix(TCore_uniq, K40_uniq, RIC) contours = [0, 500, 1000, 1500, 2000, 2500] xlabel = "Initial Core Temperature (" + TCore_units + ")" ylabel = "Current Potassium-40 Power (" + K40_units + ")"
matplotlib.rc('ytick', labelsize = 12) style = ["solid","dashed", "dotted", "dashdot"] labels = ["e=0","e=0.1","e=0.2","e=0.3"] star = ["K Dwarf", "G Dwarf", "F Dwarf"] fig, axs = plt.subplots(3,1,figsize=(6.5,9)) fig.subplots_adjust(top=0.913,bottom=0.079,left=0.14,right=0.952,hspace=0.35,wspace=0.13) for i in range(len(dest)): for ii in range(len(dest[i])): HDF5_File = h5py.File('Test.bpf', 'r') earth_icebelt_L = bp.ExtractColumn(HDF5_File,'earth:IceBeltLand:final') earth_icebelt_S = bp.ExtractColumn(HDF5_File,'earth:IceBeltSea:final') earth_northcap_L = bp.ExtractColumn(HDF5_File,'earth:IceCapNorthLand:final') earth_northcap_S = bp.ExtractColumn(HDF5_File,'earth:IceCapNorthSea:final') earth_southcap_L = bp.ExtractColumn(HDF5_File,'earth:IceCapSouthLand:final') earth_southcap_S = bp.ExtractColumn(HDF5_File,'earth:IceCapSouthSea:final') earth_icefree = bp.ExtractColumn(HDF5_File,'earth:IceFree:final') earth_snowball_L = bp.ExtractColumn(HDF5_File,'earth:SnowballLand:final') earth_snowball_S = bp.ExtractColumn(HDF5_File,'earth:SnowballSea:final') #gets the x and y axis data earth_Obliq_uniq = bp.ExtractUniqueValues(HDF5_File,'earth:Obliquity:initial') earth_intstel_uniq = bp.ExtractUniqueValues(HDF5_File,'earth:Instellation:final')
bottom=0.098, left=0.085, right=0.98, hspace=0.839, wspace=0.2) for x in range(len(dest)): num = int(num) data = np.zeros(151) avg_count = np.zeros(151) icecount = 0 file = bp.BPLFile(dest + "/" + dest + ".bpa") icebeltL = bp.ExtractColumn(file, 'earth:IceBeltLand:final') icebeltS = bp.ExtractColumn(file, 'earth:IceBeltSea:final') northCapL = bp.ExtractColumn(file, 'earth:IceCapNorthLand:final') northCapS = bp.ExtractColumn(file, 'earth:IceCapNorthSea:final') southCapL = bp.ExtractColumn(file, 'earth:IceCapSouthLand:final') southCapS = bp.ExtractColumn(file, 'earth:IceCapSouthSea:final') earth_icefree = bp.ExtractColumn(file, 'earth:IceFree:final') snowballL = bp.ExtractColumn(file, 'earth:SnowballLand:final') snowballS = bp.ExtractColumn(file, 'earth:SnowballSea:final') if (icebeltL == 1 and icebeltS == 0 and southCapS == 0 and southCapL == 0 and northCapS == 0 and northCapL == 0 and snowballL == 0 and snowballS == 0): if icecount <= 70: lats = bp.ExtractUniqueValues(file, 'earth:Latitude:climate')