o
    Mh&                     @   s@   d dl Z d dlZd dlmZ d dlmZ d dlmZ dd ZdS )    N)Path)gen_surf_emis)gen_elev_emisc            +      C   s>  t jt jd} | jddddd | jddtd	dd
 | jddtddd
 | jdddddd | jdddd d | jddd d | jddd d | jddd d | jddd d | jdd d d | jd!d"d d | jd#d$d%d d& | jd'd(d d | jd)d*d d | jd+dd,d d | jd-dd.d d | jd/dd0d d | jd1dd2d d | jd3dd4d d | jd5dd6d d | jd7dd8d d | jd9dd:d d | jd;dd<d d | jd=dd>d d | jd?dd@d d | jdAddBd d | jdCddDd d | jdEdFd d | jdGdHg dId | jdJdKg dLd | jdMdNd d | jdOdPd%d d& | jdQdRd d | jdSdTdd | jdUdVd d | jdWdXd d | jdYdZd d |  }|j}|j}|j}|j	}|j
}|j}|j}|j}	|j}
|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j}|j }|j!}|j"}|j#}|j$} |j%}!|j&}"|j'}#|j(}$|j)}%t*+ }&t,|t,|ksJ d[|d\kr6t-||D ]`\}'}(t.|||(/ fi d]|'/ d^|d_|d`|	da|
db|dc|dd|de|df|dg|dh|di|dj|dk|dl|dm|dn|do|dp|dq|dr|ds|dt|du|"})|)0  q|dvkr|#d krBdw}#t-||D ]\}'}(t.|||(/ fi d]|'/ d^|d_|d`|	da|
db|dc|dd|de|df|dg|dh|di|dj|dk|dl|dm|dn|do|dp|dq|dr|ds|dt|du|"dx|#})|)1  dy|)jv rt,t2t3|4dz|)j5 d{ |# d|kr|)6d} d~|)jv r|)6d d|)jv r|)6d qG|dkrUt-||D ]i\}'}(t7|||(/ fi d]|'/ d^|d_|d`|	da|
db|dc|dd|de|df|dg|dh|di|dj|dk|dl|dm|dn|dp|dq|dr|ds|dt|du|"d|d|!d|d| })|)0  q|dkr|$d krad}$t-||D ]\}'}(t7|||(/ fi d]|'/ d^|d_|d`|	da|
db|dc|dd|de|df|dg|dh|di|dj|dk|dl|dm|dn|dp|dq|dr|ds|dt|du|"d|d|!d|d| dx|$d|%})|)1  dy|)jv rt,t2t3|4dz|)j5 d{ |$ d|kr|)6d} d~|)jv r|)6d d|)jv r
|)6d qft*+ }*t8dt9|*|& d| d d S )N)Zformatter_classz-oz--output-optionszqS to produce 'Surface emissions data' 
E to produce 'Elevated emissions data'. 
Add P to show the parameter list.T)helprequiredz-syrz--start-yearzStarting year)typer   r   z-eyrz
--end-yearzEnding yearz-fz
--filename+zOriginal emission data filename)nargsr   r   z-vz=Variable names. 
Format: species_mode. ex: bc_a1, so4_a2 etc.)r	   r   defaultz-indirzRInput directory. 
Contains raw emissions, SCRIP, vertical distribution etc. files,)r   r
   z-outdirzOOutput directory. 
All new emissions and intermediate data will be stored here.z-soutzXOutput surface emission file name. 
Ending string including the '.nc' for output NetCDF.z-eoutzYOutput elevated emission file name. 
Ending string including the '.nc' for output NetCDF.z-reszkOutput resolution. 
For SE-grid use 30 for ne30pg2 and so on. 
For lat/lon use 180x360 for 1-deg and so on.z-gridzQOutput grid mesh or SCRIP file. 
These files can be produced using the ggen tool.z-meanz6Produce climatological mean.
The mean from syr to eyr.Z
store_true)r   actionr
   z-myrz5Climatological mean year. 
These are the model dates.z-profilezHProfile data. 
Vertical profile data used to produce vertical emissions.z-sectzList of sectorsz-syrszStarting year listz-eyrszEnding year listz-flistz Original emission filenames listz-plistzVertical profiles listz-diamzList of volume mean diametersz-mwzList of moelcular weightsz-rhozList of densitiesz-fraczList of fractionsz
-sulfactorz~List of sulfactors. 
This is the ratio of sulfate (NH4)HSO4 mw and SO2 mw. 
Default value used for sulfate aerosols is 115/64.z-numstrzList of number stringsz-numfilezList of number filez-ncvarz#List of variable names in raw filesz	-altitudez*Altitudes for the elevated emissions data.z
-fractionsz>Vertical fractional distribution. 
Used in elevated emissions.)g      ?333333?r   皙?r   r   皙?r   r   r   r   r   r   z	-ind_fracz9Vertical fractional distribution for IND and ENE sectors.)gp=
ף?gRQ?g)\(?r   r   r   r   r   r   r   r   r   r   z-paramsz5Parameter filename.
 Contains the default parameters.z-checkerzDVerify estimates. 
Compares original data with newly generated data.z-cgridz)Grid area data used when checker is True.z-sedatazAOutput in model native or SE-grid mesh. 
This is by default True.z-specieszAerosol species name (ex: bc, pom etc.). 
Used for species beyond default in place of -v option 
and in conjunction with -mode optionz-modezAerosol mode (ex: 1, 2, 4 etc.). 
Used for mode beond the default in place of -v option 
and in conjunction with -species optionz-prepzYPre-process data from different sources. 
Ex: 'GFED' for GFED4 biomass burning emissions.z8List of variables and files should have the same length!SPZvariableindiroutdirresgridmeanZmean_yrsectorsZsyr_listZeyr_list	filenamesdiammwrhofrac	sulfactornumstrnumfilencvarZ
param_filecheckercgridZSEdataspeciesmodeSzE3SM_surf_emis.ncoutputZa4znum_a4_*_a4__   Znum_a4Za1Znum_a1Za2Znum_a2ZEPprofileZprofiles	fractionsind_fracEzE3SM_elev_emis.ncprepz
Finished in z
 second(s)):argparseZArgumentParserZRawTextHelpFormatterZadd_argumentintZ
parse_argsZoutput_optionsZ
start_yearZend_yearfilenamevr   r   r   r   r   myrsectZsyrsZeyrsflistr   r   r   r   r   r   r   r   paramsr   r    sedatar!   r'   r(   r)   plistr"   souteoutr+   timeperf_counterlenzipr   stripZ
get_paramsZ	prod_emislistr   globZytagZcombine_numvarsr   printround)+parserargsoutsefilevarr   r   r   r   r   r0   r   ZsyrListZeyrListr2   r   r   r   r   r   r   r   r   r3   r   r    r4   r!   r'   r(   r)   r5   r"   r6   r7   r+   ZtimerOnr/   finitZtimerOff rJ   M/global/cfs/cdirs/e3sm/www/hass877/share/emis_processing/FlexEmis/src/main.pymain   sF  
4

46



4

46


rL   )	r8   r,   pathlibr   Zsrc.surfEmis_driverr   Zsrc.elevEmis_driverr   rL   rJ   rJ   rJ   rK   <module>   s    