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)
Example #2
0
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)
Example #3
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)
Example #5
0
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()
Example #6
0
sys.path.insert(1, str(path.parents[0]))
from get_args import get_args

# Run vspace
if not (path / "ParameterSweep").exists():
    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)))
Example #7
0
fig, axs = plt.subplots(3, 1, figsize=(9, 7))
fig.subplots_adjust(top=0.851,
                    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):