def kip_cont(self, modstart, modstop, dcoeff_thresh=<NUM_LIT>,<EOL>xres=<NUM_LIT:1000>, ylims=[<NUM_LIT:0.>, <NUM_LIT:0.>], xlims=[<NUM_LIT:0.>, <NUM_LIT:0.>], yres=<NUM_LIT>,<EOL>ixaxis='<STR_LIT>', outfile='<STR_LIT>',<EOL>landscape_plot=False, codev='<STR_LIT>', kepswitch=<NUM_LIT>,<EOL>outlines=False, write_preproc=False, hatching=False):
tmp_cycles=self.se.cycles<EOL>original_cyclelist = [int(tmp_cycles[i]) for i in range(len(tmp_cycles))]<EOL>nmodels=len(self.se.cycles[modstart:modstop])<EOL>print('<STR_LIT>', nmodels)<EOL>sparse = int(max(<NUM_LIT:1>,old_div(nmodels,xres)))<EOL>cyclelist = original_cyclelist[modstart:modstop:sparse]<EOL>age_unit=self.get('<STR_LIT>')<EOL>if codev == '<STR_LIT>':<EOL><INDENT>oneyear = <NUM_LIT>*<NUM_LIT>*<NUM_LIT><EOL><DEDENT>elif codev == '<STR_LIT>':<EOL><INDENT>oneyear=self.get('<STR_LIT>')<EOL><DEDENT>elif codev == '<STR_LIT>':<EOL><INDENT>oneyear=<NUM_LIT><EOL><DEDENT>m_min=ylims[<NUM_LIT:0>]<EOL>m_max=ylims[<NUM_LIT:1>]<EOL>if m_min==<NUM_LIT:0.>:<EOL><INDENT>m_min=<NUM_LIT:0.><EOL>ylims[<NUM_LIT:0>] = m_min<EOL><DEDENT>if m_max==<NUM_LIT:0.>:<EOL><INDENT>m_max=float(self.se.get('<STR_LIT>'))<EOL>ylims[<NUM_LIT:1>] = m_max<EOL><DEDENT>dy = old_div((m_max-m_min),float(yres))<EOL>y = np.arange(m_min, m_max, dy)<EOL>Z = np.zeros([len(y),len(cyclelist)],float)<EOL>datatype='<STR_LIT>'<EOL>if '<STR_LIT>' not in self.se.dcols:<EOL><INDENT>datatype='<STR_LIT>'<EOL><DEDENT>def list_to_string(array):<EOL><INDENT>string='<STR_LIT>'<EOL>for el in array:<EOL><INDENT>string+='<STR_LIT:U+0020>'+str(el)+'<STR_LIT:U+0020>'<EOL><DEDENT>string+='<STR_LIT:\n>'<EOL>return string<EOL><DEDENT>if write_preproc==True:<EOL><INDENT>if os.path.exists(self.sedir+'<STR_LIT>'):<EOL><INDENT>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>allcycs=[int(self.se.cycles[i]) for i in range(len(self.se.cycles))]<EOL>mass=self.se.get(allcycs,'<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>if datatype=='<STR_LIT>':<EOL><INDENT>conv=se.f.se.get(allcycs,'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>conv=self.se.get(allcycs,'<STR_LIT>')<EOL><DEDENT>print('<STR_LIT>')<EOL>models=self.se.cycles<EOL>print('<STR_LIT>')<EOL>if codev=='<STR_LIT>':<EOL><INDENT>deltat=self.se.get(allcycs,'<STR_LIT>')<EOL>ages=np.cumsum(deltat)<EOL><DEDENT>else:<EOL><INDENT>ages=self.se.ages<EOL><DEDENT>print('<STR_LIT>')<EOL>f=open(self.sedir+'<STR_LIT>','<STR_LIT:w>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>')<EOL>f.write('<STR_LIT>')<EOL>for i in range(len(models)):<EOL><INDENT>percent = int(i*<NUM_LIT:100>/len(self.se.cycles))<EOL>sys.stdout.flush()<EOL>sys.stdout.write("<STR_LIT>" + "<STR_LIT>" % percent)<EOL>f.write(str(models[i])+'<STR_LIT:\n>')<EOL>f.write(str(ages[i])+'<STR_LIT:\n>')<EOL>f.write(list_to_string(mass[i]))<EOL>f.write(list_to_string(conv[i]))<EOL><DEDENT>f.close()<EOL>print('<STR_LIT>')<EOL>sys.exit()<EOL><DEDENT>def realarray(array):<EOL><INDENT>"""<STR_LIT>"""<EOL>floatarray=np.array([float(el) for el in array])<EOL>return floatarray<EOL><DEDENT>print('<STR_LIT>')<EOL>if os.path.exists(self.sedir+'<STR_LIT>'):<EOL><INDENT>print('<STR_LIT>')<EOL>lines=open(self.sedir+'<STR_LIT>','<STR_LIT:r>').readlines()<EOL>lines=lines[<NUM_LIT:6>:]<EOL>mod=np.array([float(line.split()[<NUM_LIT:0>]) for line in lines[::<NUM_LIT:4>]])<EOL>age=old_div(np.array([float(line.split()[<NUM_LIT:0>]) for line in lines[<NUM_LIT:1>::<NUM_LIT:4>]]),oneyear)<EOL>masses=lines[<NUM_LIT:2>::<NUM_LIT:4>]<EOL>conv=lines[<NUM_LIT:3>::<NUM_LIT:4>]<EOL>tmp=[realarray(massco.split()) for massco in masses]<EOL>masses=tmp<EOL>tmp=[realarray(mixvec.split()) for mixvec in conv]<EOL>conv=tmp<EOL>print(len(age),len(mod),len(masses),len(conv))<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL>masses=self.se.get(cyclelist,'<STR_LIT>')<EOL>mod=cyclelist<EOL>if self.deltat == None:<EOL><INDENT>print('<STR_LIT>')<EOL>self.deltat = self.se.get(self.se.cycles,'<STR_LIT>')<EOL><DEDENT>age=old_div(np.cumsum(self.deltat), (<NUM_LIT>*<NUM_LIT>*<NUM_LIT>))<EOL>if datatype=='<STR_LIT>':<EOL><INDENT>conv=self.se.get(cyclelist,'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>conv=self.se.get(cyclelist,'<STR_LIT>')<EOL><DEDENT><DEDENT>print('<STR_LIT>')<EOL>print(len(masses))<EOL>conv_i_vec_matrix=np.zeros([len(y),len(masses)],float)<EOL>for i in range(len(masses)):<EOL><INDENT>percent = int(i*<NUM_LIT:100>/len(masses))<EOL>sys.stdout.flush()<EOL>sys.stdout.write("<STR_LIT>" + "<STR_LIT>" % percent)<EOL>mass = masses[i]<EOL>mix = conv[i]<EOL><INDENT>print i, len(mass),len(mix)<EOL><DEDENT>if mass[-<NUM_LIT:1>]<mass[<NUM_LIT:0>]:<EOL><INDENT>mass=np.append(mass,[<NUM_LIT:0.>])[::-<NUM_LIT:1>]<EOL>mix=np.append(mix,[<NUM_LIT:0.>])[::-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>mass=np.append(mass[::-<NUM_LIT:1>],[<NUM_LIT:0.>])[::-<NUM_LIT:1>]<EOL>mix=np.append(mix[::-<NUM_LIT:1>],[<NUM_LIT:0.>])[::-<NUM_LIT:1>]<EOL><DEDENT>f = interpolate.interp1d(mass, mix, bounds_error=False, fill_value=<NUM_LIT:0.>)<EOL>mixnew = f(y)<EOL>for j in range(len(mixnew)):<EOL><INDENT>conv_i_vec_matrix[j,i] = mixnew[j]<EOL><DEDENT><DEDENT>print('<STR_LIT>')<EOL>mtot = np.array([np.max(m) for m in masses])<EOL>fsize=<NUM_LIT:20><EOL>params = {'<STR_LIT>':  fsize,<EOL>'<STR_LIT>':   fsize,<EOL>'<STR_LIT>': fsize,<EOL>'<STR_LIT>': fsize*<NUM_LIT>,<EOL>'<STR_LIT>': fsize*<NUM_LIT>,<EOL>'<STR_LIT>': <NUM_LIT:8>,          <EOL>'<STR_LIT>': <NUM_LIT:6>,          <EOL>'<STR_LIT>': False}<EOL>pl.rcParams.update(params)<EOL>fig = pl.figure(<NUM_LIT:1>)<EOL>ax = pl.axes()<EOL>if landscape_plot == True:<EOL><INDENT>fig.set_size_inches(<NUM_LIT:9>,<NUM_LIT:4>)<EOL>fsize=<NUM_LIT:20><EOL>pl.gcf().subplots_adjust(bottom=<NUM_LIT>)<EOL>pl.gcf().subplots_adjust(right=<NUM_LIT>)<EOL><DEDENT>ax.set_ylabel('<STR_LIT>',fontsize=fsize)<EOL>xxx=[]<EOL>age_array = age<EOL>if ixaxis == '<STR_LIT>':<EOL><INDENT>gage= np.array(age_array)<EOL>lage=np.zeros(len(gage))<EOL>agemin = max(old_div(abs(gage[-<NUM_LIT:1>]-gage[-<NUM_LIT:2>]),<NUM_LIT>),<NUM_LIT>)<EOL>for i in np.arange(len(gage)):<EOL><INDENT>if gage[-<NUM_LIT:1>]-gage[i]>agemin:<EOL><INDENT>lage[i]=np.log10(gage[-<NUM_LIT:1>]-gage[i]+agemin)<EOL><DEDENT>else :<EOL><INDENT>lage[i]=np.log10(agemin)<EOL><DEDENT><DEDENT>xxx = np.array([lage[int(i)] for i in cyclelist]) <EOL>print(len(xxx))<EOL>print('<STR_LIT>')<EOL>ax.set_xlabel('<STR_LIT>',fontsize=fsize)<EOL>if xlims == [<NUM_LIT:0.>,<NUM_LIT:0.>]:<EOL><INDENT>xlims = [xxx[<NUM_LIT:0>],xxx[-<NUM_LIT:1>]]<EOL><DEDENT><DEDENT>elif ixaxis =='<STR_LIT>':<EOL><INDENT>cyclelist=mod[modstart:modstop:sparse] <EOL>xxx= cyclelist<EOL>print('<STR_LIT>')<EOL>ax.set_xlabel('<STR_LIT>',fontsize=fsize)<EOL>if xlims == [<NUM_LIT:0.>,<NUM_LIT:0.>]:<EOL><INDENT>xlims = [cyclelist[<NUM_LIT:0>],cyclelist[-<NUM_LIT:1>]]<EOL><DEDENT><DEDENT>elif ixaxis =='<STR_LIT>':<EOL><INDENT>xxx = old_div(np.array([age_array[int(i)] for i in cyclelist]),<NUM_LIT>)<EOL>print('<STR_LIT>')<EOL>ax.set_xlabel('<STR_LIT>',fontsize=fsize)<EOL>if xlims == [<NUM_LIT:0.>,<NUM_LIT:0.>]:<EOL><INDENT>xlims = [xxx[<NUM_LIT:0>],xxx[-<NUM_LIT:1>]]<EOL><DEDENT><DEDENT>cmapMIX = mpl.colors.ListedColormap(['<STR_LIT>']) <EOL>class ListCollection(Collection):<EOL><INDENT>def __init__(self, collections, **kwargs):<EOL><INDENT>Collection.__init__(self, **kwargs)<EOL>self.set_collections(collections)<EOL><DEDENT>def set_collections(self, collections):<EOL><INDENT>self._collections = collections<EOL><DEDENT>def get_collections(self):<EOL><INDENT>return self._collections<EOL><DEDENT>@allow_rasterization<EOL>def draw(self, renderer):<EOL><INDENT>for _c in self._collections:<EOL><INDENT>_c.draw(renderer)<EOL><DEDENT><DEDENT><DEDENT>def insert_rasterized_contour_plot(c):<EOL><INDENT>collections = c.collections<EOL>for _c in collections:<EOL><INDENT>_c.remove()<EOL><DEDENT>cc = ListCollection(collections, rasterized=True)<EOL>ax = pl.gca()<EOL>ax.add_artist(cc)<EOL>return cc<EOL><DEDENT>print('<STR_LIT>')<EOL>ax.autoscale(False)<EOL>low_level = dcoeff_thresh - old_div(dcoeff_thresh,<NUM_LIT:10>)<EOL>high_level= dcoeff_thresh + old_div(dcoeff_thresh,<NUM_LIT:10>)<EOL>if datatype=='<STR_LIT>':<EOL><INDENT>low_level = dcoeff_thresh - old_div(dcoeff_thresh,<NUM_LIT:10>)<EOL>high_level= dcoeff_thresh + old_div(dcoeff_thresh,<NUM_LIT:10>)<EOL>CMIX=ax.contourf(xxx,y,conv_i_vec_matrix, cmap=cmapMIX, alpha=<NUM_LIT:1.0>,levels=[low_level,<NUM_LIT>])<EOL><DEDENT>else:<EOL><INDENT>CMIX=ax.contourf(xxx,y,conv_i_vec_matrix, cmap=cmapMIX, alpha=<NUM_LIT:1.0>,levels=[<NUM_LIT:0.5>,<NUM_LIT>])<EOL><DEDENT>if outlines == True:<EOL><INDENT>if datatype=='<STR_LIT>':<EOL><INDENT>CMIXoutlines=ax.contour(xxx,y,conv_i_vec_matrix, cmap=cmapMIX,levels=[low_level,high_level])<EOL><DEDENT>else:<EOL><INDENT>CMIX_outlines=ax.contour(xxx,y,conv_i_vec_matrix, cmap=cmapMIX,levels=[<NUM_LIT:0.5>,<NUM_LIT>])<EOL><DEDENT><DEDENT>ax.plot(xxx,mtot,color='<STR_LIT:k>')<EOL>ax.axis([xlims[<NUM_LIT:0>],xlims[-<NUM_LIT:1>],ylims[<NUM_LIT:0>],ylims[<NUM_LIT:1>]])<EOL>def contour_to_hatched_patches(cntrset, hatch_colors, hatch_patterns,<EOL>remove_contour=True):<EOL><INDENT>from itertools import cycle<EOL>patches_list = []<EOL>for pathcollection in cntrset.collections:<EOL><INDENT>patches_list.append([PathPatch(p1) for p1 in  pathcollection.get_paths()])<EOL>if remove_contour:<EOL><INDENT>pathcollection.remove()<EOL><DEDENT><DEDENT>for patches, hc, hp  in zip(patches_list,<EOL>cycle(hatch_colors), cycle(hatch_patterns)):<EOL><INDENT>for p in patches:<EOL><INDENT>p.set_fc("<STR_LIT:none>")<EOL>p.set_ec("<STR_LIT:k>")<EOL>p.set_hatch(hp)<EOL>ax.add_patch(p)<EOL><DEDENT><DEDENT><DEDENT>hatch_colors = "<STR_LIT:k>"<EOL>hatch_patterns = "<STR_LIT>"<EOL>if hatching==True:<EOL><INDENT>contour_to_hatched_patches(CMIX, hatch_colors, hatch_patterns,<EOL>remove_contour=True)<EOL><DEDENT>if outfile!='<STR_LIT>':<EOL><INDENT>if outfile[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>fig.savefig(outfile,dpi=<NUM_LIT>)<EOL><DEDENT>elif outfile[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>fig.savefig(outfile,format='<STR_LIT>')<EOL><DEDENT>elif outfile[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>fig.savefig(outfile,format='<STR_LIT>')<EOL><DEDENT>elif outfile[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>fig.savefig(outfile,format='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL>print(outfile+'<STR_LIT>')<EOL>fig.savefig(outfile+'<STR_LIT>',format='<STR_LIT>')<EOL><DEDENT><DEDENT>pl.show()<EOL>
This function creates a Kippenhahn diagram as a contour plot of
the se output using a convection flag or diffusion coefficient
threshold.

Parameters
----------
modstart, modstop : integer
    First and last cycle numbers to plot.
dcoeff_thresh : float, optional
    Diffusion coefficient threshold, above which assume
    convection is present (only for MESA, where
    convection_indicator is not there)).  The default is 1.e12.
xres, yres : integer, optional
    x and y resolution.  The default for xres is 1000, the
    default for yres is 2000.
xlims, ylims : list, optional
    x and y plot limits.  The default is [0., 0.].
ixaxis : string, optional
    Choose one of 'age', 'model_number' or 'log_time_left'.  The
    default is 'log_time_left'.
outfile : string, optional
    Name of output file including extension, which will be saved
    in 300 dpi.  The default is ''.
landscape_plot : boolean, optional
    For a landscape plot.  The default is False.
codev : string, optional
    Coose one of 'KEP', 'MES' or 'GNV'.  The default is 'KEP'.
kepswitch : integer, optional
    The default is 12555.
outlines : boolean, optional
    The default is False.
write_preproc : boolean, optional
    The default is False.
hatching : boolean, optional
    The default if False.

Examples
--------
>>> pt.kip_cont(0, -1, xres=1000, yres=1000, ixaxis='log_time_left')

Notes
-----
Unfortunately, although the implicit do loops are faster, I
cannot implement a % bar, but this example call should not take
more than 1 minute.