# WRF/Chem: Editing NetCDF (wrfchemi files) for own emissions

Does anybody here have any experience with editing wrfchemi outputs from the prep_chem utility so that I overwrite the file with my own emissions?

I am knowledgeable in python, but I am not that well oriented with the manipulation of NetCDF files.

What I want to do, basically, is to use my own emissions inside the WRF/Chem model

1. I have a shapefile of emissions (gridded) with each grid having a value for the emissions.
2. I want to convert this to a readable format for the WRF/Chem; however, I think editing the wrfchemi files by prep_chem would be easier? (Tell me if not)

• How to deal with the speciation (my shapefile has only PM10 and PM2.5). where exactly do I place this in the new emissions file (the edited wrfchemi)I want. There are many pm species there (like pm2.5 nucleation mode, pm, etc). I am not sure what weights to put on these.
• My emissions are not time dependent, and what do I do when I edit the wrfchemi file for this. (the wrfchemi files I have now are also not time dependent)

Hoping someone could help out with this.

Thanks!

• If I understand your question correctly: Do you just want to replace values of some variables in your NetCDF file? Are your emission (the ones in the shape file) already on the same grid as present in the WRF/Chem emission file? The python netCDF4 interface is described here: unidata.github.io/netcdf4-python/netCDF4/index.html . Also a tutorial is present there. In order to get familiar with your NetCDF file you might have a look into it with ncdump (command line tool). ncdump -h FILENAME prints the header of the file containing all variables, dimensions etc. – daniel.heydebreck Sep 25 '19 at 19:59
• If your original gridded emission data are not on the same grid as your WRF/Chem setup you could convert the Shape file into NetCDF with NCL and then interpolate it onto your appropriate grid via cdo. Here you find a hint on how to do it: code.mpimet.mpg.de/boards/2/topics/6693 – daniel.heydebreck Sep 25 '19 at 20:00

You can try the R package eixport, with wrf_put

# example
CO <- wrf_get(file = "Path_to_WRFCHEMI", name = "E_CO")
# Change the values, here you should use your data
CO[] = rnorm(length(CO))
# Inyect your emissions into the wrfchemi
wrf_put(file = "Path_to_WRFCHEMI", name = "E_CO", POL = CO)


How to deal with the speciation (my shapefile has only PM10 and PM2.5). where exactly do I place this in the new emissions file (the edited wrfchemi)I want. There are many pm species there (like pm2.5 nucleation mode, pm, etc). I am not sure what weights to put on these.

You need to know the speciation for your local. At my department at Uni. of São Paulo, we use the following speciation of PM 2.5 (g/h/km^2)

e_so4i = 0.0077, e_so4j = 0.0623, e_no3i = 0.00247, e_no3j = 0.01053, e_pm2.5i = 0.1, e_pm2.5j = 0.3, e_orgi = 0.0304, e_orgj = 0.1296, e_eci = 0.056, e_ecj = 0.024, h2o = 0.277

Check this

My emissions are not time dependent, and what do I do when I edit the wrfchemi file for this. (the wrfchemi files I have now are also not time dependent)

You need to first edit the namelist.wps and namelist.input to the desired length of time. Then, after running ./real.exe you will have the wrfinput_d0x. At this stage you can use wrf_create which creates a wrfchemi file with 0. Read the manual to see if you want two 0-12z 12-0z files or one file with the length for all hours. Then you can use wrf_put. Just follow the example and read the manual.

You might also try the R package EmissV

References:

1. Ibarra-Espinosa et al., (2018). eixport: An R package to export emissions to atmospheric models. Journal of Open Source Software, 3(24), 607, https://doi.org/10.21105/joss.00607 Schuch et al., (2018).
2. EmissV: an R package to create vehicular and other emissions for air quality models. Journal of Open Source Software, 3(30), 662, https://doi.org/10.21105/joss.00662
• Hi, @Sergio, thank you for this. I have a question regarding the input units needed. My emissions are in a shapefile format in a grid. What units should the user emissions be in? Also, what should be in the "variables" argument for wrf_create? is this automatically read in with emiss_opt in the namelist? Thank you! – alberto_gar Apr 20 at 13:34

As far as working with netCDF files is concerned, you can use this example. What I've done in the past is loop through the dimensions, variables, and file attributes, with if statements to make changes to the parts of the file that I want to edit.

In your case, you can do what you think is best. Perhaps you can just take an average of the emissions to smooth over the subgrid variability between the wrfchemi grid and the shapefile. Just make sure that the units are consistent. Concerning temporal variability, you can do what you think is appropriate, just specify what you do when communicating your methods. So if it is easier for you to just input constant hourly emissions from a daily average emissions, then do that. If you think it is easier to keep the hour-by-hour pattern, then you can do that.

As far as the speciation is concerned (see pages 14-15), you can put PM10 in the e_pm10 variable. The PM2.5 emissions is up to you, though keep in mind what the difference between these two are (see this and this).