pythonmatplotlibyt-project

Annotation options of yt ProjectionPlot


I am new to yt and I would like to make some major adjustments of the yt ProjectionPlot output that I am getting. So far I have:

import yt
ds = yt.load("/path/to/data")
prj = yt.ProjectionPlot(ds, 'z', 'Tmean', method='integrate', weight_field='rho mean')
prj.save('Tmean_prj.png')

'Tmean_prj.png' is attached. The first question I have is whether the matplotlib commands are fully compatible with yt. Then it would become very easy I guess.

I would like to change the following things in this output:

(1) Use a derived variable for projection, one that is not contained in the data set, but can be derived from variables contained in the data set.

(2) As there is a "jet" coming in to a domain (currently that purple thing), I want to align (0,0) with the center of the purple pipe and the upper edge of it. yt seems to know the domain dimensions as well as resolution.

(3) Cut the domain at (currently) x of about 325 microns.

(4) Change scaling from microns to meters, and scale with a constant

(5) Detach color bar from plot (add some white space) and adjust colors and scaling, also modify the 'Tmean' label to be vertical and on top of the color bar.

enter image description here


Solution

  • In response to question (1), this worksenter image description here:

    import yt
    from yt.units import dimensions
    from yt.units.yt_array import YTArray
    import numpy as np
    
    spNms  = ['H2', 'H', 'O2', 'OH', 'H2O', 'HO2', 'H2O2', 'CH3', 'CH4', 'CO', 'CO2', 'CH2O', 'C2H2', 'C2H4', 'C2H6', 'NH3', 'NO', 'HCN', 'N2']
    
    HfO    = [0.0, 216269222.374, 0.0, 2292826.50902, -13423893.4949, 316904.97153, -4001375.87653, 9689965.02785, -4668373.7711, -3946437.03767, \
             -8941308.52674, -3859845.44206, 8707735.03834, 1870243.41835, -2788439.10336, -2695065.81111, 3009074.80936, 4937073.18373, 0.0]
    
    omgdot = ['H2_reaction_rate mea', 'H_reaction_rate mean', 'O2_reaction_rate mea', 'OH_reaction_rate mea', 'H2O_reaction_rate me', 'HO2_reaction_rate me', \
              'H2O2_reaction_rate m', 'CH3_reaction_rate me', 'CH4_reaction_rate me', 'CO_reaction_rate mea', 'CO2_reaction_rate me', 'CH2O_reaction_rate m', \
              'C2H2_reaction_rate m', 'C2H4_reaction_rate m', 'C2H6_reaction_rate m', 'NH3_reaction_rate me', 'NO_reaction_rate mea', 'HCN_reaction_rate me', \
              'N2_reaction_rate mea']
    
    #print 'HfO[16]',HfO[16]
    #print 'omgdot[16]',omgdot[16]
    
    #print 'HfO.shape',HfO.shape
    #print 'omgdot.shape',omgdot.shape
    
    def _HRR(field, data):
        #data._debug()
        Nx = data['Tmean'].shape
        HRR=YTArray(np.zeros(Nx))
        i=0
        for sp in spNms:
            HRR=HRR+(HfO[i]*data[omgdot[i]])
            i=i+1
        HRR = -HRR
        return HRR
    
    yt.add_field(('gas','HRR'), function=_HRR)
    
    ds = yt.load("/data1/ahoffie/iw-dm-4/HighTempLowNOx/JICF_EXP/Scaled_GT_run_12mmPre_r2/out_jicf/post/merged_stats_00027_00034")
    
    prj = yt.ProjectionPlot(ds, 'z', 'HRR', method='integrate', weight_field='rho mean')
    
    prj.save('HRR_prj.png')