Commit 92c718de authored by Maxime Rey's avatar Maxime Rey
Browse files

Improvements on 'plot_runtime_estimate'.

parent 82a9ca89
......@@ -140,8 +140,8 @@ def get_runstart_time(RamsesDir,year=2020):
return date_first[1:]
def plot_runtime_estimate(genpath,folders,legend,fmt='days',xlim=[],ylim=[],figname=None):
"From Marion."
def plot_runtime_estimate(genpath,folders,legend,fmt='days',xlim=None,ylim=None,figname=None):
"From Marion Farcy, changed by Maxime Rey."
from ratatouille import readNsave as ras
import matplotlib.pyplot as plt
import numpy as np
......@@ -168,12 +168,17 @@ def plot_runtime_estimate(genpath,folders,legend,fmt='days',xlim=[],ylim=[],fign
continue
a=np.loadtxt(myfile, skiprows=0)
time = np.cumsum(a[:,1]) #runtime in sec
time = np.cumsum(a[:,1]) # runtime in sec
time = np.insert(time,0,0)
output_time = a[:,0] #simu time in code units (if not cosmo) or aexp (if cosmo)
output_time = a[:,0] # simu time in cu (if not cosmo) or aexp (if cosmo)
output_time = np.insert(output_time,0,1/(1+50))
output_time = [UC.t_Universe(aexp, omega_matter, h0 )[0]*1000 for aexp in output_time] #simu time in Myr
info = ras.extract_info(1, genpath+folder)
if info['is_cosmo']:
output_time = np.insert(output_time,0,1/(1+50))
output_time = [UC.t_Universe(aexp, omega_matter, h0 )[0] for aexp in output_time] # simu time in Gyr
else:
output_time = output_time*info['unit_t']/1e6/365.25/24/3600/1e3 # simu time in Gyr
output_time = np.insert(output_time,0,0)
if fmt == 'sec':
time = time
......@@ -187,6 +192,12 @@ def plot_runtime_estimate(genpath,folders,legend,fmt='days',xlim=[],ylim=[],fign
time = time / 3600 / 24 / 30
elif fmt == 'years':
time = time / 3600 / 24 / 30 / 12
elif fmt == 'hCPU':
time = time / 3600 * info['ncpu']
elif fmt == 'MhCPU':
time = time / 3600 * info['ncpu'] / 1e6
else:
raise ValueError(f'The format {fmt} is not accepted.')
ax.plot(output_time,time,label=legend[i])
......@@ -194,25 +205,27 @@ def plot_runtime_estimate(genpath,folders,legend,fmt='days',xlim=[],ylim=[],fign
min_t = np.min(output_time)
if max_t < np.max(output_time):
max_t = np.max(output_time)
if legend!=[]:
print(f'{"%.2e"%time[-1]} {fmt} \t t = {"%.2e"%(output_time[-1])} Myr \t {legend[i]}')
#COSMETICS
if showLegend:
ax.legend(frameon=False, fancybox=True)
ax.set_xlabel("Time [Myr]")
ax.set_xlabel("Time [Gyr]")
ax.set_ylabel(f'Runtime [{fmt}]')
# if is_run_cosmo(RamsesDir):
ax2=ax.twiny() # Axis with redshift
ax2.set_xlabel(r'${\rm Redshift}$')
ax2.minorticks_off()
zeds=np.array([15,10,8,7,6,5,4,3,2,1.5,1])
zticks = [UC.t_Universe(1./(1.+z), omega_matter, h0 )[0] for z in zeds]
zticks = np.array(zticks)*1000
ax2.set_xticks(zticks)
ax2.set_xticklabels([f'{z:g}' for z in zeds])
ax2.set_xlim(min_t,max_t)
if info['is_cosmo']:
ax2=ax.twiny() # Axis with redshift
ax2.set_xlabel(r'${\rm Redshift}$')
ax2.minorticks_off()
zeds=np.array([15,10,8,7,6,5,4,3,2,1.5,1])
zticks = [UC.t_Universe(1./(1.+z), omega_matter, h0 )[0] for z in zeds]
zticks = np.array(zticks)
ax2.set_xticks(zticks)
ax2.set_xticklabels([f'{z:g}' for z in zeds])
ax2.set_xlim(min_t,max_t)
if xlim:
ax.set_xlim(xlim)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment