<p>There is an feature of the <code>-d</code> option that makes the call of <code>ncks</code> redundant. However, it is available since NCO version 4.2.1 (Aug. 2012).</p>

<pre><code>ncrcat -d Time,13,,132,120 wrfout* summary.nc
# -d dim,[min][,[max][,[stride][,[subcycle]]]]
</code></pre>

<p>This feature is deeply hidden in the online manual. You find it here: <a href="http://nco.sourceforge.net/nco.html#Subcycle" rel="nofollow">nco.sourceforge.net/nco.html#Subcycle</a> .</p>

<p>Explanation:</p>

<ul>
<li>13: first time step we consider</li>
<li>[empty]: till the end</li>
<li>132: we have a cycle length of 132 steps</li>
<li>120: we take the first 120 values (starting from the 13th) of each cycle</li>
</ul>

<p>If we write <code>-d Time,13,0,132</code>, which equals <code>-d Time,13,0,132,1</code>, we would only get each 132nd value starting with the 13th.</p>

<p>I do not process WRF output but we work with the Chemistry Transport Model CMAQ. We get hourly resolved concentration output files for each day. These files have 25 time steps (0 o'clock of the current and the next day) and we need to remove one of the ) o'clock time steps and append the files. For this purpose, I use <code>ncrcat -d TSTEP,0,,25,24 [infiles] [outfile]</code>.</p>

<p>The straight forward approach would be to write a Fortran program for this purpose. But, I also prefer the NCO's. Maybe you could try the cdo's (<a href="https://code.zmaw.de/projects/cdo" rel="nofollow">code.zmaw.de/projects/cdo</a>) as an alternative. However, my solution with cdo's for this task was more bulky than the NCO solution.</p>

CC BY-SA 3.0
2016-03-27T14:40:25.270Z
Excited to read your answer. I'm think about learning WRF-CMAQ. So, you mean that in one day meteorology simulation, remove the first 1-h data is  reasonable for CTM later? I haven't tried CTM now, just ask for curious.
Han Zhengzu
CC BY-SA 3.0
2016-03-27T15:19:21.477Z
The reason for having 25 instead of 24 hours per output file is only of technical nature: The first time step contains the initial concentrations of that model day. Thus, for each day we have one time step with initial concentrations and 24 time steps with newly modeled concentrations. We have a spin-up period of approximately 4 days - I often take 10 days spin-up just to make sure.
daniel.heydebreck
CC BY-SA 3.0
2016-03-28T00:08:15.217Z
Thanks for your reply. I know CMAQ is an off-line model. So, you output the houly output first, and take 25 hours for one single run in CMAQ. Did I get it?
Han Zhengzu
CC BY-SA 3.0
2016-03-28T00:38:42.340Z
With "So, you output the houly output first," you mean the meteorological data? Yes, we have the meteorological data pre-processed as daily files.
daniel.heydebreck
CC BY-SA 3.0
2016-03-28T00:45:26.243Z
Thanks, I understand. One more question, with " often take 10 days spin-up just to make sure" sentence, you mean run WRF for like 30 days for single run and cut the first 10 days off.
Han Zhengzu
CC BY-SA 3.0
2016-03-28T12:31:21.970Z
Yes, cut the 10 days off - but for CMAQ runs. We don't use WRF for the meteorology. Colleagues in another department produce meteo hindcasts with the model COSMO-CLM. I am not sure how they set up COSMO-CLM with respect to spin-up. We just get their data and pre-process it as input for CMAQ. For CMAQ, the 4 days of spin-up are sufficient - a colleague test it for 2 days spin-up and it also looked quite good. I do 10 days because it is a round numger :-) .
daniel.heydebreck
CC BY-SA 3.0
2016-03-28T12:39:42.583Z
Thanks for your reply! I have also heard some model that developed in Europe like COSMO-ART, REMO, etc. In China, WRF is the most popular one.
Han Zhengzu
CC BY-SA 3.0
2016-03-29T08:45:46.343Z
There is a real model zoo in Europe ;-) .
daniel.heydebreck
CC BY-SA 3.0
2016-03-27T14:33:59.773Z
2016-03-27T14:33:59.773Z
daniel.heydebreck
<p>Here is my  present approach.    </p>

<ol>
<li>All <strong>wrfout-files</strong> are located in the same path.</li>
<li><p>Using <strong>pynco</strong> in python loop to split the spin-up dataframe</p>

<pre><code>import glob
nco = Nco()
for fn in glob.iglob('*.nc'):
    filename, extname = os.path.splitext(fn)
    output_fn = filename[11:22] + str(int(filename[22:24]) + 12) + extname
    nco.ncks(input=fn, output=output_fn, dimension='Time,13,')  
</code></pre></li>
</ol>

<p>The input shows like: <code>2014-04-04_12.nc</code>(120 frame inside)<br>
The output shows like:<code>wrfout_2014-04-04_00:00:00.nc</code>(133 frame inside)</p>

CC BY-SA 3.0
2016-03-25T01:00:47.933Z
2016-03-25T01:00:47.933Z
Han Zhengzu
<p>I'm a user of WRF V3.5 aiming at  meteorological simulation.<br>
Sometimes, I'll run the model <em>for a long period</em>.     </p>

<h3>My attempt</h3>

<p>I split the long period(e.g 1 year) into serval short ones.    </p>

<p>For example:    </p>

<pre><code> ## WPS namelist.wps      
 start_date = '2014-01-01_06:00:00'
 end_date   = '2014-01-31_23:00:00'  

 ## WRF run period setting in .csh file.    
 set year = "2014"
 foreach strtime (010106010512 010500011012 011000011512 011500012012 012000012512 012500013012 013000020100)

 set smon = `echo ${strtime}|cut -c1-2`
 set sday = `echo ${strtime}|cut -c3-4`
 set shr  = `echo ${strtime}|cut -c5-6`
 set emon = `echo ${strtime}|cut -c7-8`
 set eday = `echo ${strtime}|cut -c9-10`
 set ehr  = `echo ${strtime}|cut -c11-12`  

 &amp;time_control
 run_days                            = 0,
 run_hours                           = 132,
 run_minutes                         = 0,
 run_seconds                         = 0,
 start_year                          = ${year},${year},
 start_month                         = ${smon},${smon},
 start_day                           = ${sday},${sday},
 start_hour                          = ${shr},${shr},
 start_minute                        = 00,00,
 start_second                        = 00,00,
 end_year                            = ${year},${year},
 end_month                           = ${emon},${emon},
 end_day                             = ${eday},${eday},
 end_hour                            = ${ehr},${ehr},
 end_minute                          = 00,00,
 end_second                          = 00,00,
 interval_seconds                    = 21600
</code></pre>

<p>In these short period, I set the first 12-h as the spinning period(except the start one.)        </p>

<p>This is the schematics of the temporal  modeling setup which I clipped from the Internet.   </p>

<p><a href="http://i12.tietuku.cn/afd906ddd823ddd6.png" rel="nofollow noreferrer">http://i12.tietuku.cn/afd906ddd823ddd6.png</a>   </p>

<h3>Result</h3>

<p>It generate 8 .nc file which each contain 132 frames of data.<br>
For now, I use the <strong>The netCDF Operators(NCO)</strong> to deal with the output files.     </p>

<ol>
<li><p>Using <code>ncks</code> to delete the first 12-h frames for each file separately.</p></li>
<li><p>Using <code>ncrcat</code>to concat all 8 .nc files together to get one file represent the whole simulation period.   </p></li>
</ol>

<h3>Problem</h3>

<p>I was using this method for a while. But when the amount of files are huge, it really a dump approach.      </p>

<p><strong>Are there someone offering your approaches to dealing with spin-up data deletion?</strong>      </p>

<h3>My target</h3>

<ul>
<li>The model can generate only one file which contain all the simulation period.   </li>
<li>The spin-up time can be covered by last file's frames automatically. </li>
</ul>

<h3>Update: Wish you share your approaches!</h3>

CC BY-SA 3.0
2016-03-17T15:21:41.303Z
I often do the same thing, except for trimming the spin-up period. Do you really need everything in just one file? What I do is have WRF output each time frame in a separate (in my case hourly) file, and I organize separate runs in individual directories. When I need the whole thing concatenated, I just select the files I need from a shell or Python script.
milancurcic
CC BY-SA 3.0
2016-03-17T15:56:27.023Z
Thanks for your reply. So,you mean set per hour as one WRF output file. How to avoid the overlay by the latter frame? For example, `wrfout_2016_03_17_00` was the last frame for  one simulation. The next simulation start with  `wrfout_2016_03_17_00`.Then the file would be rewritten. But　I want to keep the older one.
Han Zhengzu
CC BY-SA 3.0
2016-03-17T21:45:34.193Z
I store the output files from different runs in different directories in order to avoid the older output being overwritten by newer.
milancurcic
<meteorology><atmosphere><models><atmosphere-modelling><wrf>
Technique to delete spin-up frames from WRF
Han Zhengzu
# Technique to delete spin-up frames from WRF

(Asked by: username_0 on 2016-03-17)

I'm a user of WRF V3.5 aiming at meteorological simulation.  
Sometimes, I'll run the model *for a long period*.

### My attempt

I split the long period(e.g 1 year) into serval short ones.

For example:

```
 ## WPS namelist.wps      
 start_date = '2014-01-01_06:00:00'
 end_date   = '2014-01-31_23:00:00'  

 ## WRF run period setting in .csh file.    
 set year = "2014"
 foreach strtime (010106010512 010500011012 011000011512 011500012012 012000012512 012500013012 013000020100)

 set smon = `echo ${strtime}|cut -c1-2`
 set sday = `echo ${strtime}|cut -c3-4`
 set shr  = `echo ${strtime}|cut -c5-6`
 set emon = `echo ${strtime}|cut -c7-8`
 set eday = `echo ${strtime}|cut -c9-10`
 set ehr  = `echo ${strtime}|cut -c11-12`  

 &time_control
 run_days                            = 0,
 run_hours                           = 132,
 run_minutes                         = 0,
 run_seconds                         = 0,
 start_year                          = ${year},${year},
 start_month                         = ${smon},${smon},
 start_day                           = ${sday},${sday},
 start_hour                          = ${shr},${shr},
 start_minute                        = 00,00,
 start_second                        = 00,00,
 end_year                            = ${year},${year},
 end_month                           = ${emon},${emon},
 end_day                             = ${eday},${eday},
 end_hour                            = ${ehr},${ehr},
 end_minute                          = 00,00,
 end_second                          = 00,00,
 interval_seconds                    = 21600

```

In these short period, I set the first 12-h as the spinning period(except the start one.)

This is the schematics of the temporal modeling setup which I clipped from the Internet.

<http://i12.tietuku.cn/afd906ddd823ddd6.png>

### Result

It generate 8 .nc file which each contain 132 frames of data.  
For now, I use the **The netCDF Operators(NCO)** to deal with the output files.

1. Using `ncks` to delete the first 12-h frames for each file separately.
2. Using `ncrcat`to concat all 8 .nc files together to get one file represent the whole simulation period.

### Problem

I was using this method for a while. But when the amount of files are huge, it really a dump approach.

**Are there someone offering your approaches to dealing with spin-up data deletion?**

### My target

* The model can generate only one file which contain all the simulation period.
* The spin-up time can be covered by last file's frames automatically.

### Update: Wish you share your approaches!

**Tags:** meteorology, atmosphere, models, atmosphere-modelling, wrf

> **Comments:**
> **username_1**: I often do the same thing, except for trimming the spin-up period. Do you really need everything in just one file? What I do is have WRF output each time frame in a separate (in my case hourly) file, and I organize separate runs in individual directories. When I need the whole thing concatenated, I just select the files I need from a shell or Python script.  
> **username_0**: Thanks for your reply. So,you mean set per hour as one WRF output file. How to avoid the overlay by the latter frame? For example, `wrfout_2016_03_17_00` was the last frame for  one simulation. The next simulation start with  `wrfout_2016_03_17_00`.Then the file would be rewritten. But　I want to keep the older one.  
> **username_1**: I store the output files from different runs in different directories in order to avoid the older output being overwritten by newer.  

---

## 2 answers

### Answer by username_2 on 2016-03-27. Score: 2 | Accepted answer

There is an feature of the `-d` option that makes the call of `ncks` redundant. However, it is available since NCO version 4.2.1 (Aug. 2012).

```
ncrcat -d Time,13,,132,120 wrfout* summary.nc
# -d dim,[min][,[max][,[stride][,[subcycle]]]]

```

This feature is deeply hidden in the online manual. You find it here: [nco.sourceforge.net/nco.html#Subcycle](http://nco.sourceforge.net/nco.html#Subcycle) .

Explanation:

* 13: first time step we consider
* [empty]: till the end
* 132: we have a cycle length of 132 steps
* 120: we take the first 120 values (starting from the 13th) of each cycle

If we write `-d Time,13,0,132`, which equals `-d Time,13,0,132,1`, we would only get each 132nd value starting with the 13th.

I do not process WRF output but we work with the Chemistry Transport Model CMAQ. We get hourly resolved concentration output files for each day. These files have 25 time steps (0 o'clock of the current and the next day) and we need to remove one of the ) o'clock time steps and append the files. For this purpose, I use `ncrcat -d TSTEP,0,,25,24 [infiles] [outfile]`.

The straight forward approach would be to write a Fortran program for this purpose. But, I also prefer the NCO's. Maybe you could try the cdo's ([code.zmaw.de/projects/cdo](https://code.zmaw.de/projects/cdo)) as an alternative. However, my solution with cdo's for this task was more bulky than the NCO solution.

> **Comments:**
> **username_0**: Excited to read your answer. I'm think about learning WRF-CMAQ. So, you mean that in one day meteorology simulation, remove the first 1-h data is  reasonable for CTM later? I haven't tried CTM now, just ask for curious.  
> **username_2**: The reason for having 25 instead of 24 hours per output file is only of technical nature: The first time step contains the initial concentrations of that model day. Thus, for each day we have one time step with initial concentrations and 24 time steps with newly modeled concentrations. We have a spin-up period of approximately 4 days - I often take 10 days spin-up just to make sure.  
> **username_0**: Thanks for your reply. I know CMAQ is an off-line model. So, you output the houly output first, and take 25 hours for one single run in CMAQ. Did I get it?  
> **username_2**: With "So, you output the houly output first," you mean the meteorological data? Yes, we have the meteorological data pre-processed as daily files.  
> **username_0**: Thanks, I understand. One more question, with " often take 10 days spin-up just to make sure" sentence, you mean run WRF for like 30 days for single run and cut the first 10 days off.  
> **username_2**: Yes, cut the 10 days off - but for CMAQ runs. We don't use WRF for the meteorology. Colleagues in another department produce meteo hindcasts with the model COSMO-CLM. I am not sure how they set up COSMO-CLM with respect to spin-up. We just get their data and pre-process it as input for CMAQ. For CMAQ, the 4 days of spin-up are sufficient - a colleague test it for 2 days spin-up and it also looked quite good. I do 10 days because it is a round numger :-) .  
> **username_0**: Thanks for your reply! I have also heard some model that developed in Europe like COSMO-ART, REMO, etc. In China, WRF is the most popular one.  
> **username_2**: There is a real model zoo in Europe ;-) .  

---

### Answer by username_0 on 2016-03-25. Score: 2

Here is my present approach.

1. All **wrfout-files** are located in the same path.
2. Using **pynco** in python loop to split the spin-up dataframe

   ```
   import glob
   nco = Nco()
   for fn in glob.iglob('*.nc'):
       filename, extname = os.path.splitext(fn)
       output_fn = filename[11:22] + str(int(filename[22:24]) + 12) + extname
       nco.ncks(input=fn, output=output_fn, dimension='Time,13,')  

   ```

The input shows like: `2014-04-04_12.nc`(120 frame inside)  
The output shows like:`wrfout_2014-04-04_00:00:00.nc`(133 frame inside)


---

