## Flexible Emission Pre-processor for E3SM (FlexEmis) 

* E3SM emission pre-processing infrastructure.
* Default is CEDS and GFED. 
* For other inventory, preprocess them to mimic CEDS/GFED.

**Primary Developer & Maintainer:** Taufiq Hassan

**For Questions:** [taufiq.hassan@pnnl.gov](taufiq.hassan@pnnl.gov)

Installation
------------

Git clone the repo
```bash
git clone git@github.com:eagles-project/FlexEmis.git
```

General Usage
-------------

```bash
python e4prep -h
```

```bash
usage: e4prep.py [-h] -o OUTPUT_OPTIONS -syr START_YEAR -eyr END_YEAR -f FILENAME [FILENAME ...] [-v V [V ...]]
                 [-indir INDIR] [-outdir OUTDIR] [-sout SOUT] [-eout EOUT] [-res RES] [-grid GRID] [-algo ALGO] [-mean]
                 [-myr MYR] [-profile PROFILE] [-sect SECT [SECT ...]] [-syrs SYRS [SYRS ...]] [-eyrs EYRS [EYRS ...]]
                 [-flist FLIST [FLIST ...]] [-plist PLIST [PLIST ...]] [-diam DIAM [DIAM ...]] [-mw MW [MW ...]]
                 [-rho RHO [RHO ...]] [-frac FRAC [FRAC ...]] [-sulfactor SULFACTOR [SULFACTOR ...]]
                 [-numstr NUMSTR [NUMSTR ...]] [-numfile NUMFILE [NUMFILE ...]] [-ncvar NCVAR [NCVAR ...]]
                 [-altitude ALTITUDE] [-fractions FRACTIONS] [-ind_frac IND_FRAC] [-params PARAMS] [-checker] [-cgrid CGRID]
                 [-sedata SEDATA] [-species SPECIES] [-mode MODE] [-prep PREP]

options:
  -h, --help            show this help message and exit
  -o OUTPUT_OPTIONS, --output-options OUTPUT_OPTIONS
                        S to produce 'Surface emissions data'
                        E to produce 'Elevated emissions data'.
                        Add P to show the parameter list.
  -syr START_YEAR, --start-year START_YEAR
                        Starting year
  -eyr END_YEAR, --end-year END_YEAR
                        Ending year
  -f FILENAME [FILENAME ...], --filename FILENAME [FILENAME ...]
                        Original emission data filename
  -v V [V ...]          Variable names.
                        Format: species_mode. ex: bc_a1, so4_a2 etc.
  -indir INDIR          Input directory.
                        Contains raw emissions, SCRIP, vertical distribution etc. files,
  -outdir OUTDIR        Output directory.
                        All new emissions and intermediate data will be stored here.
  -sout SOUT            Output surface emission file name.
                        Ending string including the '.nc' for output NetCDF.
  -eout EOUT            Output elevated emission file name.
                        Ending string including the '.nc' for output NetCDF.
  -res RES              Output resolution.
                        For SE-grid use 30 for ne30pg2 and so on.
                        For lat/lon use 180x360 for 1-deg and so on.
  -grid GRID            Output grid mesh or SCRIP file.
                        These files can be produced using the ggen tool.
  -algo ALGO            Remapping algorithm
  -mean                 Produce climatological mean.
                        The mean from syr to eyr.
  -myr MYR              Climatological mean year.
                        These are the model dates.
  -profile PROFILE      Profile data.
                        Vertical profile data used to produce vertical emissions.
  -sect SECT [SECT ...]
                        List of sectors
  -syrs SYRS [SYRS ...]
                        Starting year list
  -eyrs EYRS [EYRS ...]
                        Ending year list
  -flist FLIST [FLIST ...]
                        Original emission filenames list
  -plist PLIST [PLIST ...]
                        Vertical profiles list
  -diam DIAM [DIAM ...]
                        List of volume mean diameters
  -mw MW [MW ...]       List of moelcular weights
  -rho RHO [RHO ...]    List of densities
  -frac FRAC [FRAC ...]
                        List of fractions
  -sulfactor SULFACTOR [SULFACTOR ...]
                        List of sulfactors.
                        This is the ratio of sulfate (NH4)HSO4 mw and SO2 mw.
                        Default value used for sulfate aerosols is 115/64.
  -numstr NUMSTR [NUMSTR ...]
                        List of number strings
  -numfile NUMFILE [NUMFILE ...]
                        List of number file
  -ncvar NCVAR [NCVAR ...]
                        List of variable names in raw files
  -altitude ALTITUDE    Altitudes for the elevated emissions data.
  -fractions FRACTIONS  Vertical fractional distribution.
                        Used in elevated emissions.
  -ind_frac IND_FRAC    Vertical fractional distribution for IND and ENE sectors.
  -params PARAMS        Parameter filename.
                         Contains the default parameters.
  -checker              Verify estimates.
                        Compares original data with newly generated data.
  -cgrid CGRID          Grid area data used when checker is True.
  -sedata SEDATA        Output in model native or SE-grid mesh.
                        This is by default True.
  -species SPECIES      Aerosol species name (ex: bc, pom etc.).
                        Used for species beyond default in place of -v option
                        and in conjunction with -mode option
  -mode MODE            Aerosol mode (ex: 1, 2, 4 etc.).
                        Used for mode beond the default in place of -v option
                        and in conjunction with -species option
  -prep PREP            Pre-process data from different sources.
                        Ex: 'GFED' for GFED4 biomass burning emissions.
```

Example
-------
Generate Black Carbon (BC) surface emissions data for the year 2016 -
```bash
python /path/to/e4prep/e4prep.py -o S -syr 2016 -eyr 2016 -v bc_a4 -f OriginalFile.nc -indir /path/to/input/directory -outdir /path/to/output/directory -sout FileNameTailEnd.nc -grid Output_grid_SCRIP_file.nc
```


