# How to read variables from another conc or aconc file?

**URL:** https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918
**Category:** Post-processing
**Created:** [November 19, 2020, 9:07am UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918 "2020-11-19T09:07:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@Wang](https://forum.cmascenter.org/u/Wang)
#### Post date: [November 19, 2020, 9:07am UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/1 "2020-11-19T09:07:48Z")

</div>

Hi everyone,  
I’m trying to read O3 concentration from another CMAQ outputfile instead of from the last time step of the running file, which has the same gird and time settings. Anyone can give me some advices on how to do this?  
Thanks!

---

<div class="post-metadata">

### Author: ![cgnolte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/cgnolte/32/53_2.png) [@cgnolte](https://forum.cmascenter.org/u/cgnolte)
#### Post date: [November 20, 2020, 1:12am UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/2 "2020-11-20T01:12:19Z")

</div>

The easiest way to do this would be to use a tool like [m3xtract](https://www.cmascenter.org/ioapi/documentation/all_versions/html/M3XTRACT.html) to copy the data you want, overwriting the existing data in your CGRID file. You could also use [COMBINE](https://github.com/USEPA/CMAQ/tree/master/POST/combine) but I would use m3xtract here.

---

<div class="post-metadata">

### Author: ![Wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@Wang](https://forum.cmascenter.org/u/Wang)
#### Post date: [November 20, 2020, 2:40am UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/3 "2020-11-20T02:40:58Z")

</div>

Thank you for your reply, but overwriting CGRID file can only replace the first hour, I want to read each hour from another file, so I need to overwrite the O3 data in my CONC file after each hour’s calculation.

---

<div class="post-metadata">

### Author: ![cgnolte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/cgnolte/32/53_2.png) [@cgnolte](https://forum.cmascenter.org/u/cgnolte)
#### Post date: [November 20, 2020, 1:25pm UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/4 "2020-11-20T13:25:18Z")

</div>

I thought you meant that you wanted to start a CMAQ simulation with a different initial condition. If instead you mean that you want to create an output file that has some variables from one output file and some other variables from a different output file, then that is what the COMBINE program (linked above) allows you to do.

---

<div class="post-metadata">

### Author: ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)
#### Post date: [November 20, 2020, 2:28pm UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/5 "2020-11-20T14:28:06Z")

</div>

Or (more flexibly, because it allows more-general linear combinations, including the “trivial” extract-a-variable ones), I/O API _m3tools_ program _m3combo_: [https://cjcoats.github.io/ioapi/M3COMBO.html](https://cjcoats.github.io/ioapi/M3COMBO.html)

---

<div class="post-metadata">

### Author: ![Wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@Wang](https://forum.cmascenter.org/u/Wang)
#### Post date: [November 23, 2020, 9:00am UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/6 "2020-11-23T09:00:19Z")

</div>

Sorry I didn’t make it clear. Maybe this figure can show my question clearly. 😃

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/1X/2c3da0cf6d960fa2f50a9ad4d171dfb6742b64b3.png)

---

<div class="post-metadata">

### Author: ![cgnolte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/cgnolte/32/53_2.png) [@cgnolte](https://forum.cmascenter.org/u/cgnolte)
#### Post date: [November 23, 2020, 1:09pm UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/7 "2020-11-23T13:09:21Z")

</div>

I don’t know why you would want to do that. At any rate, CMAQ is not set up to handle such an artificial case of continually replacing a value that is being calculated. While it should not be too difficult to modify the code to do what you describe, doing so is not something that is supported.

The answer you obtain would of course depend on when (during or before which science process) you decided to replace the model’s current calculated value for ozone with the value from the previous simulation.

---

<div class="post-metadata">

### Author: ![rpedruzzi](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/rpedruzzi/32/142_2.png) [@rpedruzzi](https://forum.cmascenter.org/u/rpedruzzi)
#### Post date: [November 23, 2020, 2:13pm UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/8 "2020-11-23T14:13:01Z")

</div>

Dear @Wang

you can you python to extract the information you need using netcdf library

first you need to import netcdf library and numpy

```
from netCDF4 import Dataset
import numpy as np

```

# open the CMAQ file using the netcdf Dataset

`aconc = Dataset(path/to/your/file/CONC.nc, mode='r')`

#after you just need to extract the O3 from your file.  
Usually the CMAQ output netcdf file has this configuration:  
(TSTEP, LAY, ROW, COL)

So you just need to select the layer, row and col you want to get the dat, like this:

`O3 = aconc.variables['O3'][:,0,30,30]`

[:,0,30,30] --\> this part of the code means:

: means all time steps  
0 means the first layer  
30 and 30 are the respective row and column.

Regards  
Rizzieri

---

<div class="post-metadata">

### Author: ![Wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@Wang](https://forum.cmascenter.org/u/Wang)
#### Post date: [November 24, 2020, 1:59am UTC](https://forum.cmascenter.org/t/how-to-read-variables-from-another-conc-or-aconc-file/1918/9 "2020-11-24T01:59:09Z")

</div>

Yes, i know i need to modify the original CMAQ code, but i have no idea which codes and how should i modify. Could you give me some tips?
