Skip to content

Instantly share code, notes, and snippets.

@hersfeldtn
Created June 14, 2022 14:17
Show Gist options
  • Save hersfeldtn/ef995c2012b00124e0064680f69e3896 to your computer and use it in GitHub Desktop.
Save hersfeldtn/ef995c2012b00124e0064680f69e3896 to your computer and use it in GitHub Desktop.
import exoplasim as exo
import configparser
import os
name='earth45ax'
prev='earth30ax15ex'
lastyear=0
if os.path.exists(name+'_crashed'):
while True:
if lastyear < 90:
filename = name+'_crashed/MOST_REST.000' + str(lastyear+10)
elif lastyear < 990:
filename = name+'_crashed/MOST_REST.00' + str(lastyear+10)
else:
filename = name+'_crashed/MOST_REST.0' + str(lastyear+10)
if os.path.exists(filename):
lastyear += 1
else:
break
if lastyear == 0:
filename = prev+'_out/'+prev+'/MOST_REST.00009'
elif lastyear < 100:
filename = name+'_crashed/MOST_REST.000' + str(lastyear)
elif lastyear < 1000:
filename = name+'_crashed/MOST_REST.00' + str(lastyear)
else:
filename = name+'_crashed/MOST_REST.0' + str(lastyear)
else:
filename = prev+'_out/'+prev+'/MOST_REST.00009'
check = configparser.ConfigParser()
check.read('times.ini')
times = check['Time']
step = times.getint('times')
cfg = configparser.ConfigParser()
cfg.read('state.ini')
rpt = cfg['State']
level = rpt.getfloat('level')
if level > 10e-6:
fluxlev = 1367
clev = level
else:
fluxlev = 1357 + (level * 1000000)
clev = 10e-6
model = exo.Model(workdir=name+"_run", modelname=name, ncpus=8, resolution="T42", layers=10, precision=8, outputtype='.nc', inityear=lastyear)
model.configure(timestep=step, runsteps=int(360*24*60/step), fixedorbit=True, landmap='earth64_surf_0172.sra', topomap='earth64_surf_0129.sra',
pN2=0.78, pO2=0.21, pAr=0.01, pCO2=clev, ozone=True,
eccentricity=0, year=360, rotationperiod=1, obliquity=45, flux=fluxlev,
physicsfilter='gp|exp|sp', restartfile=filename,
wetsoil=True, glaciers={'toggle': True, 'mindepth': 2.0, 'initialh': -1.0}, vegetation=2, initgrowth=0.5)
model.runtobalance(baseline=20, maxyears=1000, minyears=20, crashifbroken=True, clean=True)
report = configparser.ConfigParser()
year = str(model.currentyear)
tas = str(model.getbalance(key='tas'))
co2 = str(level)
report['Report'] = {'name' : name,
'outcome' : 'Success',
'year' : year,
'tas' : tas,
'co2' : co2
}
model.finalize(name+'_out', allyears=False, clean=True, keeprestarts=True)
os.chdir('/home/user')
with open('report.ini', 'w') as r:
report.write(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment