Example #1
0
def main(trop_limit=True, res='4x5', debug=False):
    """ 
    Get prod loss output for a family and print this to screen  
    """
    # --- Get family from Command line (and other vars)
    wd = sys.argv[1]
    spec = sys.argv[2]
    # version?
    ver = AC.iGEOSChem_ver(wd)

    # --- Get all tags for this family (through dictionary route)
    # ( e.g. 'PIOx', 'LIOx',  'P_Iy', 'L_Iy' )
    nums, rxns, tags, Coe = AC.prod_loss_4_spec(wd, spec, ver=ver)
    # beatify reaction strings
    rxnstr_l = [''.join(i[4:]) for i in rxns]
    # one consider one tag per reaction and tagged reactions
    try:
        tags = [i[0] for i in tags]  # just consider first tag
    except:
        print 'WARNING! - attempting to process just tagged reactions'
        detail_zip = zip(rxnstr_l, zip(nums, tags))
        untagged = [n for n, i in enumerate(tags) if (len(i) < 1)]
        print 'Untagged reactions: ', [detail_zip[i] for i in untagged]
        tags = [i for n, i in enumerate(tags) if (n not in untagged)]
        tags = [i[0] for i in tags]  # just consider first tag


#        tags.pop( tags.index('LR71') )  # rm tag for ClOO loss...

# --- Extract prod loss for these tracers
# get prod loss IDs
    PDs = [AC.PLO3_to_PD(i, ver=ver, wd=wd, fp=True) for i in tags]
    # extract en mass
    fam_loss = AC.get_GC_output( wd, vars=['PORL_L_S__'+i for i in PDs], \
                trop_limit=trop_limit, r_list=True)
    #    print [ ( i.shape, i.sum() ) for i in fam_loss ]
    # Get reference species for family ( e.g. so output is in X g of Y )
    ref_spec = AC.get_ref_spec(spec)
    # get shared variable arrrays
    s_area = get_surface_area(res=res)[..., 0]  # m2 land map
    # convert to mass terms  ( in g X )
    fam_loss = convert_molec_cm3_s_2_g_X_s( ars=fam_loss, \
            ref_spec=ref_spec, wd=wd, conbine_ars=False,  \
            rm_strat=True, month_eq=True  )
    print[i.shape for i in fam_loss]

    # sum and convert to Gg
    p_l = [i.sum() / 1E9 for i in fam_loss]

    # --- print output as: reaction, magnitude, percent of family
    pcent = [np.sum(i) / np.sum(p_l) * 100 for i in p_l]
    d = dict(zip(tags, zip(rxnstr_l, p_l, pcent)))
    df = pd.DataFrame(d).T
    df.columns = ['rxn', 'Gg X', '% of total']
    # sort
    df = df.sort_values(['% of total'], ascending=False)
    print df
def main( trop_limit=True, res='4x5',  debug=False):
    """ 
    Get prod loss output for a family and print this to screen  
    """
    # --- Get family from Command line (and other vars)
    wd =  sys.argv[1]
    spec =  sys.argv[2]
    # version?
    ver = AC.iGEOSChem_ver( wd)

    # --- Get all tags for this family (through dictionary route)   
    # ( e.g. 'PIOx', 'LIOx',  'P_Iy', 'L_Iy' )
    nums, rxns, tags, Coe = AC.prod_loss_4_spec( wd, spec, ver=ver )
    # beatify reaction strings
    rxnstr_l = [ ''.join( i[4:] ) for i in rxns ]
    # one consider one tag per reaction and tagged reactions
    try:
        tags = [  i[0] for i in tags ] # just consider first tag
    except:
        print 'WARNING! - attempting to process just tagged reactions'
        detail_zip = zip( rxnstr_l, zip( nums, tags) )
        untagged = [n for n,i in enumerate(tags) if (len(i)<1) ]
        print 'Untagged reactions: ', [ detail_zip[i] for i in untagged ]
        tags = [ i for n, i in enumerate( tags ) if (n not in untagged) ]
        tags = [  i[0] for i in tags ] # just consider first tag
#        tags.pop( tags.index('LR71') )  # rm tag for ClOO loss... 

    # --- Extract prod loss for these tracers
    # get prod loss IDs
    PDs = [ AC.PLO3_to_PD(i, ver=ver, wd=wd, fp=True) for i in tags ]    
    # extract en mass
    fam_loss = AC.get_GC_output( wd, vars=['PORL_L_S__'+i for i in PDs], \
                trop_limit=trop_limit, r_list=True)
#    print [ ( i.shape, i.sum() ) for i in fam_loss ]
    # Get reference species for family ( e.g. so output is in X g of Y )
    ref_spec = AC.get_ref_spec( spec )
    # get shared variable arrrays
    s_area = get_surface_area(res=res)[...,0] # m2 land map
    # convert to mass terms  ( in g X )
    fam_loss = convert_molec_cm3_s_2_g_X_s( ars=fam_loss, \
            ref_spec=ref_spec, wd=wd, conbine_ars=False,  \
            rm_strat=True, month_eq=True  ) 
    print [ i.shape for i in fam_loss ]
import AC_tools as AC

# Download the example data if it is not already downloaded.
from AC_tools.Scripts import get_data_files

# Specify the working directory
wd = "../data"

# Get the GeosChem species data from the wd
my_data = AC.get_GC_output(wd, species='O3')

# Get a 2d slice from the 3d array
my_data = my_data[:, :, 0, 0]

# Turn from part per part to part per billion
my_data = my_data * 1E9

# Create the plot
AC.map_plot(my_data)

# Save the plot and show it.
AC.save_plot("my_plot")
AC.show_plot()
unit, scale = AC.tra_unit( species, scale=True)

# debug/print verbose output?
debug=True

# Only consider GEOS-Chem chemical troposphere
trop_limit=True
calc_burden=False#True

try:    # chcck if a directory was given ad command line
    wd = sys.argv[1]
except: # Otherwise use path below
    wd = '<insert GEOS-Chem run direcotory path here>'

# get data as 4D array ( lon, lat, alt, time ) 
mixing_ratio  = AC.get_GC_output( wd, species=species, category='IJ-AVG-$', \
    trop_limit=trop_limit ) 
print mixing_ratio.shape

# Get data to calculate burden
if calc_burden:

    # Get air mass as numpy array
    air_mass = AC.get_GC_output( wd, vars=['BXHGHT_S__AD'], \
                                  trop_limit=trop_limit )
    # get time in troposphere as fraction from ctm.bpchh diagnostics
    time_in_trop = AC.get_GC_output( wd, vars=['TIME_TPS__TIMETROP'],
                                  trop_limit=trop_limit )
    # print shapes of array to screen
    print [i.shape for i in mixing_ratio, air_mass, time_in_trop ]

    # calc the total & mean mass of a speices - select data you want to calc & print
unit, scale = AC.tra_unit(species, scale=True)

# debug/print verbose output?
debug = True

# Only consider GEOS-Chem chemical troposphere
trop_limit = True
calc_burden = False  #True

try:  # chcck if a directory was given ad command line
    wd = sys.argv[1]
except:  # Otherwise use path below
    wd = '<insert GEOS-Chem run direcotory path here>'

# get data as 4D array ( lon, lat, alt, time )
mixing_ratio  = AC.get_GC_output( wd, species=species, category='IJ-AVG-$', \
    trop_limit=trop_limit )
print mixing_ratio.shape

# Get data to calculate burden
if calc_burden:

    # Get air mass as numpy array
    air_mass = AC.get_GC_output( wd, vars=['BXHGHT_S__AD'], \
                                  trop_limit=trop_limit )
    # get time in troposphere as fraction from ctm.bpchh diagnostics
    time_in_trop = AC.get_GC_output(wd,
                                    vars=['TIME_TPS__TIMETROP'],
                                    trop_limit=trop_limit)
    # print shapes of array to screen
    print[i.shape for i in mixing_ratio, air_mass, time_in_trop]
Example #6
0
import AC_tools as AC

# Download the example data if it is not already downloaded.
from AC_tools.Scripts import get_data_files

# Specify the working directory
wd = "../data"

# Get the GeosChem species data from the wd
my_data = AC.get_GC_output( wd, species='O3')


# Get a 2d slice from the 3d array
my_data = my_data[:,:,0,0]

# Turn from part per part to part per billion
my_data = my_data*1E9

# Create the plot
AC.map_plot( my_data)

# Save the plot and show it.
AC.save_plot("my_plot")
AC.show_plot()