Skip to content

Commit 78cb8bc

Browse files
committed
Fix age_lookback issues with plotKip3
1 parent cdfbded commit 78cb8bc

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

mesaPlot/plot.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,22 +2082,20 @@ def plotKip3(self,m,plot_type='history',xaxis='model_number',yaxis='mass',zaxis=
20822082
else:
20832083
center=self._getSafeCenter(m,radius)
20842084
data_y=np.linspace(np.min(center),np.max(m.hist.data["star_mass"]),num_zones)
2085+
2086+
#May need to interpolate data:
2087+
lin_x=np.linspace(data_x[modInd][0],data_x[modInd][-1],np.count_nonzero(data_x[modInd]))
20852088

20862089
#Get burn data
20872090
if show_burn:
20882091
data_z=self._getHistBurnData(m,data_x,data_y,modInd,burn_prefix,radius)
2092+
data_z=self._rebinKipDataX(data_z,data_x[modInd],lin_x)
20892093

20902094
#Get mix data
20912095
if show_mix:
2092-
mix_data=self._getHistMixData(m,data_x,data_y,modInd,mix,mix_prefix,radius)
2093-
2094-
#May need to interpolate data:
2095-
lin_x=np.linspace(data_x[modInd][0],data_x[modInd][-1],np.count_nonzero(data_x[modInd]))
2096-
2097-
data_z=self._rebinKipDataX(data_z,data_x[modInd],lin_x)
2098-
if show_mix:
2096+
mix_data=self._getHistMixData(m,data_x,data_y,modInd,mix,mix_prefix,radius)
20992097
mix_data=self._rebinKipDataX(mix_data,data_x[modInd],lin_x,nan=True,nan_value=1)
2100-
2098+
21012099
else:
21022100
show_mix=False
21032101
show_burn=False
@@ -2122,6 +2120,9 @@ def plotKip3(self,m,plot_type='history',xaxis='model_number',yaxis='mass',zaxis=
21222120
count=count+1
21232121

21242122
data_x=np.array(data_x)
2123+
2124+
2125+
21252126
if num_zones is None:
21262127
num_zones=np.max(zones) * 1.0/zone_frac
21272128
data_z,lin_x,data_y=self._rebinKipDataXY(data_z,data_x,data_y,count,num_zones)
@@ -2224,6 +2225,7 @@ def plotKip3(self,m,plot_type='history',xaxis='model_number',yaxis='mass',zaxis=
22242225
ax2.plot(lin_x,f(lin_x),c='k')
22252226
if y2rng is not None:
22262227
ax2.set_ylim(y2rng)
2228+
22272229

22282230
if xlabel is None:
22292231
if xaxis=='model_number':
@@ -2359,14 +2361,13 @@ def _rebinKipqDataWithModInd(self,m,qtype,z,y,modInd,radius):
23592361

23602362
def _getSafeAge(self,m,age_lookback=False,age_zero=None,age_units='sec',age_log=False,age_reverse=False,end_time=None):
23612363

2362-
if 'star_age_sec' in m.hist.data.dtype.names:
2364+
if 'log_dt' in m.hist.data.dtype.names:
2365+
#Age in years does not have enough digits to be able to distingush the final models in pre-sn progenitors
2366+
age=np.cumsum(10**np.longdouble(m.hist.log_dt))*self.secyear
2367+
elif 'star_age_sec' in m.hist.data.dtype.names:
23632368
age=m.hist.star_age_sec
23642369
elif 'star_age' in m.hist.data.dtype.names:
2365-
if age_lookback:
2366-
#Age in years does not have enough digits to be able to distingush the final models in pre-sn progenitors
2367-
age=np.cumsum(10**np.longdouble(m.hist.log_dt))*self.secyear
2368-
else:
2369-
age=m.hist.star_age*self.secyear
2370+
age=m.hist.star_age*self.secyear
23702371

23712372
if age_lookback:
23722373
xx=age[-1]
@@ -2461,6 +2462,7 @@ def _getModInd(self,m,mod_index=None,mod_min=None,mod_max=None,step=1,xaxis='',x
24612462
def _rebinKipDataX(self,data,x,lin_x,nan=False,nan_value=1):
24622463
sorter=np.argsort(x)
24632464
ind=np.searchsorted(x,lin_x,sorter=sorter,side='left')
2465+
24642466
data=data[sorter[ind],:]
24652467
if nan:
24662468
data[data<nan_value]=np.nan

tests/test_mesaplot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ def test_plotKip2(self):
9797

9898
def test_plotKip3(self):
9999
self.p.plotKip3(self.m,show=False)
100+
101+
def test_plotKip3(self):
102+
self.p.plotKip3(self.m,show=False,age_lookback=True,xaxis='star_age')
100103

101104
def test_plotMix(self):
102-
self.p.plotKip3(self.m,show=False)
105+
self.p.plotMix(self.m,show=False)
103106

104107
def test_plotTRho(self):
105108
self.p.plotTRho(self.m,show=False)

0 commit comments

Comments
 (0)