pyrats/visualization.py
def plot_snapshots(axis=['x','y','z'], center=None,
                   field=('gas', 'density'),
                   weight_field=('index','ones'), slice=False,
                   contour_field = None,
                   width=[(10, 'kpc')], folder='./',
                   cbarunits=None, cbarbounds=None, cmap='viridis', LogScale=True,
                   hnum=None, timestep=None, Galaxy=False, bhid=None,
                   plothalos=False, masshalomin=1e5,
                   plotsinks=[0], plotparticles=[False,'type'], sinkdynamics=0, text_color='black',
                   snap=[-1], extension='png', method='integrate', old_ramses=False):
    """
    Visualization function, by default it is applied to ALL snapshots

    axis : the projection axis #TODO off axis
    center : center (in code_length units) of the region to show, useless if hnum/bhid

    width : width of the window, default (10, 'kpc'), can be 'Rvir'
        in that case the size is set to the virial radius of each snapshots
    folder : folder to save the images

    field : yt field to show
    weight_field : yt field to use to weight, default ('index', 'ones')
    slice : True/False slice/projection, if True weight_field useless
    contour_field: field to overplot as contour plot (eg. ('gas','density'))

    cbarunits : units for the colorbar, defaut units of field
    cbarbounds : limits for the cbar, in units of cbarunits
    cmap : cmap to use
    LogScale (True) : plot in log

    hnum : ID of the halo, in the last output if timestep is None, you want to center the images
    timestep: timestep to consider the halo
    Galaxy: consider galaxies instead of halos in hnum
    bhid : ID of the sink you want to center the images
    
    plothalos : circles around halos with a mass larger than masshalomin
    masshalomin : in Msun, minimum mass for the halo to show
    plotparticles: overplot the particles as black dots
                    [True,'type'] to overplot and type for the type (cloud, stars...)
    plotsinks : if -1 show sinks and their ID
                if list shows only the asked ones
                if [0] do not show
    sinkdynamics : draw lines to show BH dynamics between [t-sinkdynamics, t+sinkdynamics], in Myr
    text_color : color to show BHs and their ID, halos and colorbar

    snap : list of snapshots you want to show, default ALL (-1)
    """

    mylog.setLevel(40)
    files = utils.find_outputs('./Outputs')
    if ((hnum != None) & (timestep == None)):
        timestep = snap[-1]
    ToPlot, haloid = utils.filter_outputs(snap=snap, hnum=hnum, timestep=timestep, Galaxy=Galaxy, bhid=bhid)
    if sinkdynamics > 0:
        s = sink.Sinks()

    for fn in yt.parallel_objects(files):
        i = files.index(fn)
        if ToPlot[i]:
            print('Images for {} in {}'.format(fn, folder))
            #looking at the larger width to load the largest one
            #instead of loading the snapshot many times
            ds = load_snap.load(fn, verbose=False)
            max_width=np.argmax([ds.arr(_[0],_[1]).to('cm') for _ in width])
            max_width = width[max_width] 
            ds = load_snap.load(fn, haloID=haloid[i], Galaxy=Galaxy, bhID=bhid, radius=max_width, old_ramses=old_ramses, verbose=False)
            if center != None:
                sp = ds.sphere(center, max_width)
            else:
                sp = load_snap.get_sphere(ds, max_width, bhid, haloid[i], Galaxy)
           
            for _w in width:
              for _axis in axis: 
                path = _make_path(folder, hnum, Galaxy, bhid, slice, _w,
                    field, _axis, LogScale, plotsinks, timestep)
                #if hnum !=None:
                #    struct = 'Halo'
                #    if Galaxy: struct= 'Galaxy'
                name_fig = path+'/{}'.format(field[0]+field[1])+\
                        '_output{:03}.{}'.format(ds.ids,extension)

                normal = _get_axis(_axis, ds, haloid[i])
                if slice:
                    #p = yt.OffAxisSlicePlot(ds, data_source=sp, normal=normal, fields=field, width=width)
                    p = yt.SlicePlot(ds, data_source=sp, axis=_axis, fields=field, width=_w)
                else:
                    #p = yt.OffAxisProjectionPlot(ds, data_source=sp, normal=normal, fields=field, weight_field=weight_field,
                    #                      width=_w, method=method)
                    p = yt.ProjectionPlot(ds, data_source=sp, axis=_axis, fields=field, weight_field=weight_field,
                                          center=sp.center, width=_w, method=method)

                if (plotsinks != [0]):
                    p = _add_sink(p, plotsinks, ds, sink, sp, text_color, sinkdynamics, _w)
                
                if plothalos != False:
                    p = _add_halos(ds, plothalos, masshalomin, p, text_color)
            
                if plotparticles[0]:
                    p.annotate_particles(_w, ptype=plotparticles[1])

                p = _cleanup_and_save(cmap, p, field, cbarbounds, cbarunits, LogScale, _w,
                            name_fig, extension, ds, text_color)

                if contour_field is not None:
                    p.annotate_contour(contour_field,ncont=[-24,-23],
                    plot_args = {'color':{'yellow','blue','black'}})
                
                p.save(name_fig, mpl_kwargs={'pad_inches':0, 'transparent':True})
    return

    Visualization function, by default it is applied to ALL snapshots

    axis : the projection axis #TODO off axis
    center : center (in code_length units) of the region to show, useless if hnum/bhid

    width : width of the window, default (10, 'kpc'), can be 'Rvir'
        in that case the size is set to the virial radius of each snapshots
    folder : folder to save the images

    field : yt field to show
    weight_field : yt field to use to weight, default ('index', 'ones')
    slice : True/False slice/projection, if True weight_field useless
    contour_field: field to overplot as contour plot (eg. ('gas','density'))

    cbarunits : units for the colorbar, defaut units of field
    cbarbounds : limits for the cbar, in units of cbarunits
    cmap : cmap to use
    LogScale (True) : plot in log

    hnum : ID of the halo, in the last output if timestep is None, you want to center the images
    timestep: timestep to consider the halo
    Galaxy: consider galaxies instead of halos in hnum
    bhid : ID of the sink you want to center the images
    
    plothalos : circles around halos with a mass larger than masshalomin
    masshalomin : in Msun, minimum mass for the halo to show
    plotparticles: overplot the particles as black dots
                    [True,'type'] to overplot and type for the type (cloud, stars...)
    plotsinks : if -1 show sinks and their ID
                if list shows only the asked ones
                if [0] do not show
    sinkdynamics : draw lines to show BH dynamics between [t-sinkdynamics, t+sinkdynamics], in Myr
    text_color : color to show BHs and their ID, halos and colorbar

    snap : list of snapshots you want to show, default ALL (-1)
    
Visualization function, by default it is applied to ALL snapshots
axis : the projection axis #TODO off axis
center : center (in code_length units) of the region to show, useless if hnum/bhid

width : width of the window, default (10, 'kpc'), can be 'Rvir'
in that case the size is set to the virial radius of each snapshots
folder : folder to save the images

field : yt field to show
weight_field : yt field to use to weight, default ('index', 'ones')
slice : True/False slice/projection, if True weight_field useless
contour_field: field to overplot as contour plot )

cbarunits : units for the colorbar, defaut units of field
cbarbounds : limits for the cbar, in units of cbarunits
cmap : cmap to use
LogScale (True) : plot in log

hnum : ID of the halo, in the last output if timestep is None, you want to center the images
timestep: timestep to consider the halo
Galaxy: consider galaxies instead of halos in hnum
bhid : ID of the sink you want to center the images



snap : list of snapshots you want to show, default ALL (-1)
Visualization function by default it is applied to ALL snapshots axis : the projection axis #TODO off axis center : center ( in code_length units ) of the region to show useless if hnum / bhid width : width of the window default ( 10 ' kpc ' ) can be ' Rvir ' in that case the size is set to the virial radius of each snapshots folder : folder to save the images field : yt field to show weight_field : yt field to use to weight default ( ' index ' ' ones ' ) slice : True / False slice / projection if True weight_field useless contour_field : field to overplot as contour plot ) cbarunits : units for the colorbar defaut units of field cbarbounds : limits for the cbar in units of cbarunits cmap : cmap to use LogScale ( True ) : plot in log hnum : ID of the halo in the last output if timestep is None you want to center the images timestep : timestep to consider the halo Galaxy : consider galaxies instead of halos in hnum bhid : ID of the sink you want to center the images snap : list of snapshots you want to show default ALL ( - 1 )
def plot_snapshots(axis=['x','y','z'], center=None,
                   field=('gas', 'density'),
                   weight_field=('index','ones'), slice=False,
                   contour_field = None,
                   width=[(10, 'kpc')], folder='./',
                   cbarunits=None, cbarbounds=None, cmap='viridis', LogScale=True,
                   hnum=None, timestep=None, Galaxy=False, bhid=None,
                   plothalos=False, masshalomin=1e5,
                   plotsinks=[0], plotparticles=[False,'type'], sinkdynamics=0, text_color='black',
                   snap=[-1], extension='png', method='integrate', old_ramses=False):
    mylog.setLevel(40)
    files = utils.find_outputs('./Outputs')
    if ((hnum != None) & (timestep == None)):
        timestep = snap[-1]
    ToPlot, haloid = utils.filter_outputs(snap=snap, hnum=hnum, timestep=timestep, Galaxy=Galaxy, bhid=bhid)
    if sinkdynamics > 0:
        s = sink.Sinks()
    for fn in yt.parallel_objects(files):
        i = files.index(fn)
        if ToPlot[i]:
            print('Images for {} in {}'.format(fn, folder))
            ds = load_snap.load(fn, verbose=False)
            max_width=np.argmax([ds.arr(_[0],_[1]).to('cm') for _ in width])
            max_width = width[max_width] 
            ds = load_snap.load(fn, haloID=haloid[i], Galaxy=Galaxy, bhID=bhid, radius=max_width, old_ramses=old_ramses, verbose=False)
            if center != None:
                sp = ds.sphere(center, max_width)
            else:
                sp = load_snap.get_sphere(ds, max_width, bhid, haloid[i], Galaxy)
            for _w in width:
              for _axis in axis: 
                path = _make_path(folder, hnum, Galaxy, bhid, slice, _w,
                    field, _axis, LogScale, plotsinks, timestep)
                name_fig = path+'/{}'.format(field[0]+field[1])+\
                        '_output{:03}.{}'.format(ds.ids,extension)
                normal = _get_axis(_axis, ds, haloid[i])
                if slice:
                    p = yt.SlicePlot(ds, data_source=sp, axis=_axis, fields=field, width=_w)
                else:
                    p = yt.ProjectionPlot(ds, data_source=sp, axis=_axis, fields=field, weight_field=weight_field,
                                          center=sp.center, width=_w, method=method)
                if (plotsinks != [0]):
                    p = _add_sink(p, plotsinks, ds, sink, sp, text_color, sinkdynamics, _w)
                if plothalos != False:
                    p = _add_halos(ds, plothalos, masshalomin, p, text_color)
                if plotparticles[0]:
                    p.annotate_particles(_w, ptype=plotparticles[1])
                p = _cleanup_and_save(cmap, p, field, cbarbounds, cbarunits, LogScale, _w,
                            name_fig, extension, ds, text_color)
                if contour_field is not None:
                    p.annotate_contour(contour_field,ncont=[-24,-23],
                    plot_args = {'color':{'yellow','blue','black'}})
                p.save(name_fig, mpl_kwargs={'pad_inches':0, 'transparent':True})
    return
def plot_snapshots ( axis = [ 'x' , 'y' , 'z' ] , center = None , field = ( 'gas' , 'density' ) , weight_field = ( 'index' , 'ones' ) , slice = False , contour_field = None , width = [ ( 10 , 'kpc' ) ] , folder = './' , cbarunits = None , cbarbounds = None , cmap = 'viridis' , LogScale = True , hnum = None , timestep = None , Galaxy = False , bhid = None , plothalos = False , masshalomin = 1e5 , plotsinks = [ 0 ] , plotparticles = [ False , 'type' ] , sinkdynamics = 0 , text_color = 'black' , snap = [ - 1 ] , extension = 'png' , method = 'integrate' , old_ramses = False ) : mylog . setLevel ( 40 ) files = utils . find_outputs ( './Outputs' ) if ( ( hnum != None ) & ( timestep == None ) ) : timestep = snap [ - 1 ] ToPlot , haloid = utils . filter_outputs ( snap = snap , hnum = hnum , timestep = timestep , Galaxy = Galaxy , bhid = bhid ) if sinkdynamics > 0 : s = sink . Sinks ( ) for fn in yt . parallel_objects ( files ) : i = files . index ( fn ) if ToPlot [ i ] : print ( 'Images for {} in {}' . format ( fn , folder ) ) ds = load_snap . load ( fn , verbose = False ) max_width = np . argmax ( [ ds . arr ( _ [ 0 ] , _ [ 1 ] ) . to ( 'cm' ) for _ in width ] ) max_width = width [ max_width ] ds = load_snap . load ( fn , haloID = haloid [ i ] , Galaxy = Galaxy , bhID = bhid , radius = max_width , old_ramses = old_ramses , verbose = False ) if center != None : sp = ds . sphere ( center , max_width ) else : sp = load_snap . get_sphere ( ds , max_width , bhid , haloid [ i ] , Galaxy ) for _w in width : for _axis in axis : path = _make_path ( folder , hnum , Galaxy , bhid , slice , _w , field , _axis , LogScale , plotsinks , timestep ) name_fig = path + '/{}' . format ( field [ 0 ] + field [ 1 ] ) + '_output{:03}.{}' . format ( ds . ids , extension ) normal = _get_axis ( _axis , ds , haloid [ i ] ) if slice : p = yt . SlicePlot ( ds , data_source = sp , axis = _axis , fields = field , width = _w ) else : p = yt . ProjectionPlot ( ds , data_source = sp , axis = _axis , fields = field , weight_field = weight_field , center = sp . center , width = _w , method = method ) if ( plotsinks != [ 0 ] ) : p = _add_sink ( p , plotsinks , ds , sink , sp , text_color , sinkdynamics , _w ) if plothalos != False : p = _add_halos ( ds , plothalos , masshalomin , p , text_color ) if plotparticles [ 0 ] : p . annotate_particles ( _w , ptype = plotparticles [ 1 ] ) p = _cleanup_and_save ( cmap , p , field , cbarbounds , cbarunits , LogScale , _w , name_fig , extension , ds , text_color ) if contour_field is not None : p . annotate_contour ( contour_field , ncont = [ - 24 , - 23 ] , plot_args = { 'color' : { 'yellow' , 'blue' , 'black' } } ) p . save ( name_fig , mpl_kwargs = { 'pad_inches' : 0 , 'transparent' : True } ) return
Visualization function, by default it is applied to ALL snapshots
axis : the projection axis #TODO off axis
center : center (in code_length units) of the region to show, useless if hnum/bhid
Visualization function by default it is applied to ALL snapshots axis : the projection axis #TODO off axis center : center ( in code_length units ) of the region to show useless if hnum / bhid
"""
    Visualization function, by default it is applied to ALL snapshots

    axis : the projection axis #TODO off axis
    center : center (in code_length units) of the region to show, useless if hnum/bhid

    width : width of the window, default (10, 'kpc'), can be 'Rvir'
        in that case the size is set to the virial radius of each snapshots
    folder : folder to save the images

    field : yt field to show
    weight_field : yt field to use to weight, default ('index', 'ones')
    slice : True/False slice/projection, if True weight_field useless
    contour_field: field to overplot as contour plot (eg. ('gas','density'))

    cbarunits : units for the colorbar, defaut units of field
    cbarbounds : limits for the cbar, in units of cbarunits
    cmap : cmap to use
    LogScale (True) : plot in log

    hnum : ID of the halo, in the last output if timestep is None, you want to center the images
    timestep: timestep to consider the halo
    Galaxy: consider galaxies instead of halos in hnum
    bhid : ID of the sink you want to center the images
    
    plothalos : circles around halos with a mass larger than masshalomin
    masshalomin : in Msun, minimum mass for the halo to show
    plotparticles: overplot the particles as black dots
                    [True,'type'] to overplot and type for the type (cloud, stars...)
    plotsinks : if -1 show sinks and their ID
                if list shows only the asked ones
                if [0] do not show
    sinkdynamics : draw lines to show BH dynamics between [t-sinkdynamics, t+sinkdynamics], in Myr
    text_color : color to show BHs and their ID, halos and colorbar

    snap : list of snapshots you want to show, default ALL (-1)
    """ #looking at the larger width to load the largest one #instead of loading the snapshot many times #if hnum !=None: #    struct = 'Halo' #    if Galaxy: struct= 'Galaxy' #p = yt.OffAxisSlicePlot(ds, data_source=sp, normal=normal, fields=field, width=width) #p = yt.OffAxisProjectionPlot(ds, data_source=sp, normal=normal, fields=field, weight_field=weight_field, #                      width=_w, method=method)
axis
center
field
weight_field
slice
contour_field
width
folder
cbarunits
cbarbounds
cmap
LogScale
hnum
timestep
Galaxy
bhid
plothalos
masshalomin
plotsinks
plotparticles
sinkdynamics
text_color
snap
extension
method
old_ramses