source: flex_extract.git/documentation/Sphinx/build/html/_modules/EcFlexpart.html @ 2625ca8

dev
Last change on this file since 2625ca8 was 2625ca8, checked in by Anne Philipp <anne.philipp@…>, 9 months ago

new build of sphinx for updated api

  • Property mode set to 100644
File size: 247.5 KB
Line 
1
2
3<!DOCTYPE html>
4<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
5<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
6<head>
7  <meta charset="utf-8">
8 
9  <meta name="viewport" content="width=device-width, initial-scale=1.0">
10 
11  <title>EcFlexpart &mdash; flex_extract 7.1 alpha documentation</title>
12 
13
14 
15 
16 
17 
18
19 
20
21 
22 
23   
24
25 
26
27  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
28  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
29    <link rel="index" title="Index" href="../genindex.html" />
30    <link rel="search" title="Search" href="../search.html" /> 
31
32 
33  <script src="../_static/js/modernizr.min.js"></script>
34
35</head>
36
37<body class="wy-body-for-nav">
38
39   
40  <div class="wy-grid-for-nav">
41
42   
43    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
44      <div class="wy-side-scroll">
45        <div class="wy-side-nav-search">
46         
47
48         
49            <a href="../index.html" class="icon icon-home"> flex_extract
50         
51
52         
53          </a>
54
55         
56           
57           
58              <div class="version">
59                7.1
60              </div>
61           
62         
63
64         
65<div role="search">
66  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
67    <input type="text" name="q" placeholder="Search docs" />
68    <input type="hidden" name="check_keywords" value="yes" />
69    <input type="hidden" name="area" value="default" />
70  </form>
71</div>
72
73         
74        </div>
75
76        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
77         
78           
79           
80             
81           
82           
83              <p class="caption"><span class="caption-text">Table of Contents:</span></p>
84<ul>
85<li class="toctree-l1"><a class="reference internal" href="../downloads.html">Downloads</a></li>
86<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
87<li class="toctree-l1"><a class="reference internal" href="../program_structure.html">Program Structure</a></li>
88<li class="toctree-l1"><a class="reference internal" href="../user_guide.html">User Guide</a></li>
89<li class="toctree-l1"><a class="reference internal" href="../api.html">Auto Generated Documentation</a></li>
90<li class="toctree-l1"><a class="reference internal" href="../support.html">Support</a></li>
91</ul>
92
93           
94         
95        </div>
96      </div>
97    </nav>
98
99    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
100
101     
102      <nav class="wy-nav-top" aria-label="top navigation">
103       
104          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
105          <a href="../index.html">flex_extract</a>
106       
107      </nav>
108
109
110      <div class="wy-nav-content">
111       
112        <div class="rst-content">
113       
114         
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130<div role="navigation" aria-label="breadcrumbs navigation">
131
132  <ul class="wy-breadcrumbs">
133   
134      <li><a href="../index.html">Docs</a> &raquo;</li>
135       
136          <li><a href="index.html">Module code</a> &raquo;</li>
137       
138      <li>EcFlexpart</li>
139   
140   
141      <li class="wy-breadcrumbs-aside">
142       
143      </li>
144   
145  </ul>
146
147 
148  <hr/>
149</div>
150          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
151           <div itemprop="articleBody">
152           
153  <h1>Source code for EcFlexpart</h1><div class="highlight"><pre>
154<span></span><span class="ch">#!/usr/bin/env python</span>
155<span class="c1"># -*- coding: utf-8 -*-</span>
156<span class="c1">#*******************************************************************************</span>
157<span class="c1"># @Author: Anne Fouilloux (University of Oslo)</span>
158<span class="c1">#</span>
159<span class="c1"># @Date: October 2014</span>
160<span class="c1">#</span>
161<span class="c1"># @Change History:</span>
162<span class="c1">#</span>
163<span class="c1">#    November 2015 - Leopold Haimberger (University of Vienna):</span>
164<span class="c1">#        - extended with class Control</span>
165<span class="c1">#        - removed functions mkdir_p, daterange, years_between, months_between</span>
166<span class="c1">#        - added functions darain, dapoly, to_param_id, init128, normal_exit,</span>
167<span class="c1">#          my_error, clean_up, install_args_and_control,</span>
168<span class="c1">#          interpret_args_and_control,</span>
169<span class="c1">#        - removed function __del__ in class EIFLexpart</span>
170<span class="c1">#        - added the following functions in EIFlexpart:</span>
171<span class="c1">#            - create_namelist</span>
172<span class="c1">#            - process_output</span>
173<span class="c1">#            - deacc_fluxes</span>
174<span class="c1">#        - modified existing EIFlexpart - functions for the use in</span>
175<span class="c1">#          flex_extract</span>
176<span class="c1">#        - retrieve also longer term forecasts, not only analyses and</span>
177<span class="c1">#          short term forecast data</span>
178<span class="c1">#        - added conversion into GRIB2</span>
179<span class="c1">#        - added conversion into .fp format for faster execution of FLEXPART</span>
180<span class="c1">#          (see https://www.flexpart.eu/wiki/FpCtbtoWo4FpFormat)</span>
181<span class="c1">#</span>
182<span class="c1">#    February 2018 - Anne Philipp (University of Vienna):</span>
183<span class="c1">#        - applied PEP8 style guide</span>
184<span class="c1">#        - added documentation</span>
185<span class="c1">#        - removed function getFlexpartTime in class EcFlexpart</span>
186<span class="c1">#        - outsourced class ControlFile</span>
187<span class="c1">#        - outsourced class MarsRetrieval</span>
188<span class="c1">#        - changed class name from EIFlexpart to EcFlexpart</span>
189<span class="c1">#        - applied minor code changes (style)</span>
190<span class="c1">#        - removed &quot;dead code&quot; , e.g. retrieval of Q since it is not needed</span>
191<span class="c1">#        - removed &quot;times&quot; parameter from retrieve-method since it is not used</span>
192<span class="c1">#        - seperated function &quot;retrieve&quot; into smaller functions (less code</span>
193<span class="c1">#          duplication, easier testing)</span>
194<span class="c1">#</span>
195<span class="c1"># @License:</span>
196<span class="c1">#    (C) Copyright 2014-2019.</span>
197<span class="c1">#    Anne Philipp, Leopold Haimberger</span>
198<span class="c1">#</span>
199<span class="c1">#    This work is licensed under the Creative Commons Attribution 4.0</span>
200<span class="c1">#    International License. To view a copy of this license, visit</span>
201<span class="c1">#    http://creativecommons.org/licenses/by/4.0/ or send a letter to</span>
202<span class="c1">#    Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.</span>
203<span class="c1">#*******************************************************************************</span>
204<span class="c1">#pylint: disable=unsupported-assignment-operation</span>
205<span class="c1"># this is disabled because for this specific case its an error in pylint</span>
206<span class="c1">#pylint: disable=consider-using-enumerate</span>
207<span class="c1"># this is not useful in this case</span>
208<span class="c1"># ------------------------------------------------------------------------------</span>
209<span class="c1"># MODULES</span>
210<span class="c1"># ------------------------------------------------------------------------------</span>
211<span class="kn">import</span> <span class="nn">os</span>
212<span class="kn">import</span> <span class="nn">sys</span>
213<span class="kn">import</span> <span class="nn">glob</span>
214<span class="kn">import</span> <span class="nn">shutil</span>
215<span class="kn">import</span> <span class="nn">subprocess</span>
216<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
217<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
218
219<span class="kn">from</span> <span class="nn">eccodes</span> <span class="k">import</span> <span class="p">(</span><span class="n">codes_index_select</span><span class="p">,</span> <span class="n">codes_new_from_index</span><span class="p">,</span> <span class="n">codes_get</span><span class="p">,</span>
220                     <span class="n">codes_get_values</span><span class="p">,</span> <span class="n">codes_set_values</span><span class="p">,</span> <span class="n">codes_set</span><span class="p">,</span>
221                     <span class="n">codes_write</span><span class="p">,</span> <span class="n">codes_release</span><span class="p">,</span> <span class="n">codes_new_from_index</span><span class="p">,</span>
222                     <span class="n">codes_index_release</span><span class="p">,</span> <span class="n">codes_index_get</span><span class="p">)</span>
223
224<span class="c1"># software specific classes and modules from flex_extract</span>
225<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../&#39;</span><span class="p">)</span>
226<span class="kn">import</span> <span class="nn">_config</span>
227<span class="kn">from</span> <span class="nn">GribUtil</span> <span class="k">import</span> <span class="n">GribUtil</span>
228<span class="kn">from</span> <span class="nn">mods.tools</span> <span class="k">import</span> <span class="p">(</span><span class="n">init128</span><span class="p">,</span> <span class="n">to_param_id</span><span class="p">,</span> <span class="n">silent_remove</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span>
229                        <span class="n">my_error</span><span class="p">,</span> <span class="n">make_dir</span><span class="p">,</span> <span class="n">get_informations</span><span class="p">,</span> <span class="n">get_dimensions</span><span class="p">,</span>
230                        <span class="n">execute_subprocess</span><span class="p">)</span>
231<span class="kn">from</span> <span class="nn">MarsRetrieval</span> <span class="k">import</span> <span class="n">MarsRetrieval</span>
232<span class="kn">import</span> <span class="nn">mods.disaggregation</span> <span class="k">as</span> <span class="nn">disaggregation</span>
233
234<span class="c1"># ------------------------------------------------------------------------------</span>
235<span class="c1"># CLASS</span>
236<span class="c1"># ------------------------------------------------------------------------------</span>
237<div class="viewcode-block" id="EcFlexpart"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart">[docs]</a><span class="k">class</span> <span class="nc">EcFlexpart</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
238    <span class="sd">&#39;&#39;&#39;</span>
239<span class="sd">    Class to represent FLEXPART specific ECMWF data.</span>
240
241<span class="sd">    FLEXPART needs grib files in a specifc format. All necessary data fields</span>
242<span class="sd">    for one time step are stored in a single file. The class represents an</span>
243<span class="sd">    instance with all the parameter and settings necessary for retrieving</span>
244<span class="sd">    MARS data and modifing them so they are fitting FLEXPART needs. The class</span>
245<span class="sd">    is able to disaggregate the fluxes and convert grid types to the one needed</span>
246<span class="sd">    by FLEXPART, therefore using the FORTRAN program.</span>
247
248<span class="sd">    Attributes</span>
249<span class="sd">    ----------</span>
250<span class="sd">    mreq_count : int</span>
251<span class="sd">        Counter for the number of generated mars requests.</span>
252
253<span class="sd">    inputdir : str</span>
254<span class="sd">        Path to the directory where the retrieved data is stored.</span>
255
256<span class="sd">    dataset : str</span>
257<span class="sd">        For public datasets there is the specific naming and parameter</span>
258<span class="sd">        dataset which has to be used to characterize the type of</span>
259<span class="sd">        data.</span>
260
261<span class="sd">    basetime : str</span>
262<span class="sd">        The time for a half day retrieval. The 12 hours upfront are to be</span>
263<span class="sd">        retrieved.</span>
264
265<span class="sd">    dtime : str</span>
266<span class="sd">        Time step in hours.</span>
267
268<span class="sd">    acctype : str</span>
269<span class="sd">        The field type for the accumulated forecast fields.</span>
270
271<span class="sd">    acctime : str</span>
272<span class="sd">        The starting time from the accumulated forecasts.</span>
273
274<span class="sd">    accmaxstep : str</span>
275<span class="sd">        The maximum forecast step for the accumulated forecast fields.</span>
276
277<span class="sd">    marsclass : str</span>
278<span class="sd">        Characterisation of dataset.</span>
279
280<span class="sd">    stream : str</span>
281<span class="sd">        Identifies the forecasting system used to generate the data.</span>
282
283<span class="sd">    number : str</span>
284<span class="sd">        Selects the member in ensemble forecast run.</span>
285
286<span class="sd">    resol : str</span>
287<span class="sd">        Specifies the desired triangular truncation of retrieved data,</span>
288<span class="sd">        before carrying out any other selected post-processing.</span>
289
290<span class="sd">    accuracy : str</span>
291<span class="sd">        Specifies the number of bits per value to be used in the</span>
292<span class="sd">        generated GRIB coded fields.</span>
293
294<span class="sd">    addpar : str</span>
295<span class="sd">        List of additional parameters to be retrieved.</span>
296
297<span class="sd">    level : str</span>
298<span class="sd">        Specifies the maximum level.</span>
299
300<span class="sd">    expver : str</span>
301<span class="sd">        The version of the dataset.</span>
302
303<span class="sd">    levelist : str</span>
304<span class="sd">        Specifies the required levels.</span>
305
306<span class="sd">    glevelist : str</span>
307<span class="sd">        Specifies the required levels for gaussian grids.</span>
308
309<span class="sd">    gaussian : str</span>
310<span class="sd">        This parameter is deprecated and should no longer be used.</span>
311<span class="sd">        Specifies the desired type of Gaussian grid for the output.</span>
312
313<span class="sd">    grid : str</span>
314<span class="sd">        Specifies the output grid which can be either a Gaussian grid</span>
315<span class="sd">        or a Latitude/Longitude grid.</span>
316
317<span class="sd">    area : str</span>
318<span class="sd">        Specifies the desired sub-area of data to be extracted.</span>
319
320<span class="sd">    purefc : int</span>
321<span class="sd">        Switch for definition of pure forecast mode or not.</span>
322
323<span class="sd">    outputfilelist : list of str</span>
324<span class="sd">        The final list of FLEXPART ready input files.</span>
325
326<span class="sd">    types : dictionary</span>
327<span class="sd">        Determines the combination of type of fields, time and forecast step</span>
328<span class="sd">        to be retrieved.</span>
329
330<span class="sd">    params : dictionary</span>
331<span class="sd">        Collection of grid types and their corresponding parameters,</span>
332<span class="sd">        levels, level types and the grid definition.</span>
333
334<span class="sd">    server : ECMWFService or ECMWFDataServer</span>
335<span class="sd">        This is the connection to the ECMWF data servers.</span>
336
337<span class="sd">    public : int</span>
338<span class="sd">        Decides which Web API Server version is used.</span>
339
340<span class="sd">    dates : str</span>
341<span class="sd">        Contains start and end date of the retrieval in the format</span>
342<span class="sd">        &quot;YYYYMMDD/to/YYYYMMDD&quot;</span>
343<span class="sd">    &#39;&#39;&#39;</span>
344
345    <span class="c1"># --------------------------------------------------------------------------</span>
346    <span class="c1"># CLASS FUNCTIONS</span>
347    <span class="c1"># --------------------------------------------------------------------------</span>
348    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">fluxes</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
349        <span class="sd">&#39;&#39;&#39;Creates an object/instance of EcFlexpart with the associated</span>
350<span class="sd">        settings of its attributes for the retrieval.</span>
351
352<span class="sd">        Parameters:</span>
353<span class="sd">        -----------</span>
354<span class="sd">        c : ControlFile</span>
355<span class="sd">            Contains all the parameters of CONTROL file and</span>
356<span class="sd">            command line.</span>
357
358<span class="sd">        fluxes : boolean, optional</span>
359<span class="sd">            Decides if the flux parameter settings are stored or</span>
360<span class="sd">            the rest of the parameter list.</span>
361<span class="sd">            Default value is False.</span>
362
363<span class="sd">        Return</span>
364<span class="sd">        ------</span>
365
366<span class="sd">        &#39;&#39;&#39;</span>
367        <span class="c1"># set a counter for the number of generated mars requests</span>
368        <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span> <span class="o">=</span> <span class="mi">0</span>
369
370        <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span>
371        <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">dataset</span>
372        <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span>
373        <span class="bp">self</span><span class="o">.</span><span class="n">dtime</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">dtime</span>
374        <span class="bp">self</span><span class="o">.</span><span class="n">acctype</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">acctype</span>
375        <span class="bp">self</span><span class="o">.</span><span class="n">acctime</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">acctime</span>
376        <span class="bp">self</span><span class="o">.</span><span class="n">accmaxstep</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">accmaxstep</span>
377        <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">marsclass</span>
378        <span class="bp">self</span><span class="o">.</span><span class="n">stream</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">stream</span>
379        <span class="bp">self</span><span class="o">.</span><span class="n">number</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">number</span>
380        <span class="bp">self</span><span class="o">.</span><span class="n">resol</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">resol</span>
381        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">accuracy</span>
382        <span class="bp">self</span><span class="o">.</span><span class="n">addpar</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">addpar</span>
383        <span class="bp">self</span><span class="o">.</span><span class="n">level</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">level</span>
384        <span class="bp">self</span><span class="o">.</span><span class="n">expver</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">expver</span>
385        <span class="bp">self</span><span class="o">.</span><span class="n">levelist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">levelist</span>
386        <span class="bp">self</span><span class="o">.</span><span class="n">glevelist</span> <span class="o">=</span> <span class="s1">&#39;1/to/&#39;</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">level</span> <span class="c1"># in case of gaussian grid</span>
387        <span class="bp">self</span><span class="o">.</span><span class="n">gaussian</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">gaussian</span>
388        <span class="bp">self</span><span class="o">.</span><span class="n">grid</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">grid</span>
389        <span class="bp">self</span><span class="o">.</span><span class="n">area</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">area</span>
390        <span class="bp">self</span><span class="o">.</span><span class="n">purefc</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span>
391        <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span> <span class="o">=</span> <span class="p">[]</span>
392
393        <span class="c1"># Define the different types of field combinations (type, time, step)</span>
394        <span class="bp">self</span><span class="o">.</span><span class="n">types</span> <span class="o">=</span> <span class="p">{}</span>
395        <span class="c1"># Define the parameters and their level types, level list and</span>
396        <span class="c1"># grid resolution for the retrieval job</span>
397        <span class="bp">self</span><span class="o">.</span><span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
398
399        <span class="k">if</span> <span class="n">fluxes</span><span class="p">:</span>
400            <span class="bp">self</span><span class="o">.</span><span class="n">_create_params_fluxes</span><span class="p">()</span>
401        <span class="k">else</span><span class="p">:</span>
402            <span class="bp">self</span><span class="o">.</span><span class="n">_create_params</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">gauss</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">omega</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">cwc</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">)</span>
403
404        <span class="k">if</span> <span class="n">fluxes</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
405            <span class="bp">self</span><span class="o">.</span><span class="n">_create_field_types_fluxes</span><span class="p">()</span>
406        <span class="k">else</span><span class="p">:</span>
407            <span class="bp">self</span><span class="o">.</span><span class="n">_create_field_types</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">step</span><span class="p">)</span>
408        <span class="k">return</span>
409
410    <span class="k">def</span> <span class="nf">_create_field_types</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ftype</span><span class="p">,</span> <span class="n">ftime</span><span class="p">,</span> <span class="n">fstep</span><span class="p">):</span>
411        <span class="sd">&#39;&#39;&#39;Create the combination of field type, time and forecast step.</span>
412
413<span class="sd">        Parameters:</span>
414<span class="sd">        -----------</span>
415<span class="sd">        ftype : list of str</span>
416<span class="sd">            List of field types.</span>
417
418<span class="sd">        ftime : list of str</span>
419<span class="sd">            The time in hours of the field.</span>
420
421<span class="sd">        fstep : str</span>
422<span class="sd">            Specifies the forecast time step from forecast base time.</span>
423<span class="sd">            Valid values are hours (HH) from forecast base time.</span>
424
425<span class="sd">        Return</span>
426<span class="sd">        ------</span>
427
428<span class="sd">        &#39;&#39;&#39;</span>
429        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
430        <span class="k">for</span> <span class="n">ty</span><span class="p">,</span> <span class="n">st</span><span class="p">,</span> <span class="n">ti</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span> <span class="n">fstep</span><span class="p">,</span> <span class="n">ftime</span><span class="p">):</span>
431            <span class="n">btlist</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">24</span><span class="p">)</span>
432            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="s1">&#39;12&#39;</span><span class="p">:</span>
433                <span class="n">btlist</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">12</span><span class="p">]</span>
434            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="s1">&#39;00&#39;</span><span class="p">:</span>
435                <span class="n">btlist</span> <span class="o">=</span> <span class="p">[</span><span class="mi">13</span><span class="p">,</span> <span class="mi">14</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">17</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">19</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">23</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
436
437            <span class="c1"># if ((ty.upper() == &#39;AN&#39; and (int(c.time[i]) % int(c.dtime)) == 0) or</span>
438                <span class="c1"># (ty.upper() != &#39;AN&#39; and (int(c.step[i]) % int(c.dtime)) == 0 and</span>
439                 <span class="c1"># (int(c.step[i]) % int(c.dtime) == 0)) ) and \</span>
440                 <span class="c1"># (int(c.time[i]) in btlist or c.purefc):</span>
441
442            <span class="k">if</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">ti</span><span class="p">)</span> <span class="ow">in</span> <span class="n">btlist</span><span class="p">)</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
443
444                <span class="k">if</span> <span class="p">((</span><span class="n">ty</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;AN&#39;</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">ti</span><span class="p">)</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span>
445                    <span class="p">(</span><span class="n">ty</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;AN&#39;</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">st</span><span class="p">)</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)):</span>
446
447                    <span class="k">if</span> <span class="n">ty</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
448                        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;times&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">}</span>
449
450                    <span class="k">if</span> <span class="n">ti</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]:</span>
451                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]:</span>
452                            <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span>
453                        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">ti</span>
454
455                    <span class="k">if</span> <span class="n">st</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]:</span>
456                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]:</span>
457                            <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span>
458                        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">st</span>
459            <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
460        <span class="k">return</span>
461
462    <span class="k">def</span> <span class="nf">_create_field_types_fluxes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
463        <span class="sd">&#39;&#39;&#39;Create the combination of field type, time and forecast step</span>
464<span class="sd">        for the flux data.</span>
465
466<span class="sd">        Parameters:</span>
467<span class="sd">        -----------</span>
468
469<span class="sd">        Return</span>
470<span class="sd">        ------</span>
471
472<span class="sd">        &#39;&#39;&#39;</span>
473        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">acctype</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;times&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">acctime</span><span class="p">),</span>
474                                         <span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/to/</span><span class="si">{}</span><span class="s1">/by/</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
475                                             <span class="bp">self</span><span class="o">.</span><span class="n">dtime</span><span class="p">,</span>
476                                             <span class="bp">self</span><span class="o">.</span><span class="n">accmaxstep</span><span class="p">,</span>
477                                             <span class="bp">self</span><span class="o">.</span><span class="n">dtime</span><span class="p">)}</span>
478        <span class="k">return</span>
479
480    <span class="k">def</span> <span class="nf">_create_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gauss</span><span class="p">,</span> <span class="n">eta</span><span class="p">,</span> <span class="n">omega</span><span class="p">,</span> <span class="n">cwc</span><span class="p">,</span> <span class="n">wrf</span><span class="p">):</span>
481        <span class="sd">&#39;&#39;&#39;Define the specific parameter settings for retrievment.</span>
482
483<span class="sd">        The different parameters need specific grid types and level types</span>
484<span class="sd">        for retrievement. We might get following combination of types</span>
485<span class="sd">        (depending on selection and availability):</span>
486<span class="sd">        (These are short cuts for the grib file names (leading sequence)</span>
487<span class="sd">        SH__ML, OG__ML, GG__ML, SH__SL, OG__SL, GG__SL, OG_OROLSM_SL</span>
488<span class="sd">        where:</span>
489<span class="sd">            SH = Spherical Harmonics, GG = Gaussian Grid, OG = Output Grid,</span>
490<span class="sd">            ML = Model Level, SL = Surface Level</span>
491
492<span class="sd">        For each of this combination there is a list of parameter names,</span>
493<span class="sd">        the level type, the level list and the grid resolution.</span>
494
495<span class="sd">        There are different scenarios for data extraction from MARS:</span>
496<span class="sd">        1) Retrieval of etadot</span>
497<span class="sd">           eta=1, gauss=0, omega=0</span>
498<span class="sd">        2) Calculation of etadot from divergence</span>
499<span class="sd">           eta=0, gauss=1, omega=0</span>
500<span class="sd">        3) Calculation of etadot from omega (for makes sense for debugging)</span>
501<span class="sd">           eta=0, gauss=0, omega=1</span>
502<span class="sd">        4) Retrieval and Calculation of etadot (only for debugging)</span>
503<span class="sd">           eta=1, gauss=1, omega=0</span>
504<span class="sd">        5) Download also specific model and surface level data for FLEXPART-WRF</span>
505
506<span class="sd">        Parameters:</span>
507<span class="sd">        -----------</span>
508<span class="sd">        gauss : int</span>
509<span class="sd">            Gaussian grid is retrieved.</span>
510
511<span class="sd">        eta : int</span>
512<span class="sd">            Etadot parameter will be directly retrieved.</span>
513
514<span class="sd">        omega : int</span>
515<span class="sd">            The omega paramterwill be retrieved.</span>
516
517<span class="sd">        cwc : int</span>
518<span class="sd">            The cloud liquid and ice water content will be retrieved.</span>
519
520<span class="sd">        wrf : int</span>
521<span class="sd">            Additional model level and surface level data will be retrieved for</span>
522<span class="sd">            WRF/FLEXPART-WRF simulations.</span>
523
524<span class="sd">        Return</span>
525<span class="sd">        ------</span>
526
527<span class="sd">        &#39;&#39;&#39;</span>
528        <span class="c1"># SURFACE FIELDS</span>
529        <span class="c1">#-----------------------------------------------------------------------</span>
530        <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;SH__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;LNSP&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="s1">&#39;OFF&#39;</span><span class="p">]</span>
531        <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;SD/MSL/TCC/10U/10V/2T/2D/Z/LSM&#39;</span><span class="p">,</span> \
532                                 <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
533        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">addpar</span><span class="p">:</span>
534            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">addpar</span>
535
536        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;EA&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;EP&#39;</span><span class="p">:</span>
537            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_OROLSM__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;SDOR/CVL/CVH/FSR&quot;</span><span class="p">,</span>
538                                            <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
539        <span class="k">else</span><span class="p">:</span>
540            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_OROLSM__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;SDOR/CVL/CVH/SR&quot;</span><span class="p">,</span> \
541                                            <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
542
543        <span class="c1"># MODEL LEVEL FIELDS</span>
544        <span class="c1">#-----------------------------------------------------------------------</span>
545        <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;T/Q&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">levelist</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
546
547        <span class="k">if</span> <span class="ow">not</span> <span class="n">gauss</span> <span class="ow">and</span> <span class="n">eta</span><span class="p">:</span>
548            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/U/V/ETADOT&#39;</span>
549        <span class="k">elif</span> <span class="n">gauss</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">eta</span><span class="p">:</span>
550            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;GG__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> \
551                                     <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)]</span>
552            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;SH__ML&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;U/V/D&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">glevelist</span><span class="p">,</span> <span class="s1">&#39;OFF&#39;</span><span class="p">]</span>
553        <span class="k">elif</span> <span class="ow">not</span> <span class="n">gauss</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">eta</span><span class="p">:</span>
554            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/U/V&#39;</span>
555        <span class="k">else</span><span class="p">:</span>
556            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Warning: Collecting etadot and parameters for gaussian grid </span><span class="se">\</span>
557<span class="s1">                            is a very costly parameter combination, </span><span class="se">\</span>
558<span class="s1">                            use this combination only for debugging!&#39;</span><span class="p">)</span>
559            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;GG__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> \
560                                     <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)]</span>
561            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;GG__ML&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;U/V/D/77&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">glevelist</span><span class="p">,</span> \
562                                     <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)]</span>
563
564        <span class="k">if</span> <span class="n">omega</span><span class="p">:</span>
565            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/W&#39;</span>
566
567        <span class="k">if</span> <span class="n">cwc</span><span class="p">:</span>
568            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/CLWC/CIWC&#39;</span>
569
570        <span class="c1"># ADDITIONAL FIELDS FOR FLEXPART-WRF MODEL (IF QUESTIONED)</span>
571        <span class="c1">#-----------------------------------------------------------------------</span>
572        <span class="k">if</span> <span class="n">wrf</span><span class="p">:</span>
573            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/Z/VO&#39;</span>
574            <span class="k">if</span> <span class="s1">&#39;/D&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>
575                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/D&#39;</span>
576            <span class="n">wrf_sfc</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;SP&#39;</span><span class="p">,</span><span class="s1">&#39;SKT&#39;</span><span class="p">,</span><span class="s1">&#39;SST&#39;</span><span class="p">,</span><span class="s1">&#39;CI&#39;</span><span class="p">,</span><span class="s1">&#39;STL1&#39;</span><span class="p">,</span><span class="s1">&#39;STL2&#39;</span><span class="p">,</span> <span class="s1">&#39;STL3&#39;</span><span class="p">,</span><span class="s1">&#39;STL4&#39;</span><span class="p">,</span>
577                       <span class="s1">&#39;SWVL1&#39;</span><span class="p">,</span><span class="s1">&#39;SWVL2&#39;</span><span class="p">,</span><span class="s1">&#39;SWVL3&#39;</span><span class="p">,</span><span class="s1">&#39;SWVL4&#39;</span><span class="p">]</span>
578            <span class="k">for</span> <span class="n">par</span> <span class="ow">in</span> <span class="n">wrf_sfc</span><span class="p">:</span>
579                <span class="k">if</span> <span class="n">par</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>
580                    <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="n">par</span>
581
582        <span class="k">return</span>
583
584
585    <span class="k">def</span> <span class="nf">_create_params_fluxes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
586        <span class="sd">&#39;&#39;&#39;Define the parameter setting for flux data.</span>
587
588<span class="sd">        Flux data are accumulated fields in time and are stored on the</span>
589<span class="sd">        surface level. The leading short cut name for the grib files is:</span>
590<span class="sd">        &quot;OG_acc_SL&quot; with OG for Regular Output Grid, SL for Surface Level, and</span>
591<span class="sd">        acc for Accumulated Grid.</span>
592<span class="sd">        The params dictionary stores a list of parameter names, the level type,</span>
593<span class="sd">        the level list and the grid resolution.</span>
594
595<span class="sd">        The flux data are: LSP/CP/SSHF/EWSS/NSSS/SSR</span>
596
597<span class="sd">        Parameters:</span>
598<span class="sd">        -----------</span>
599
600<span class="sd">        Return</span>
601<span class="sd">        ------</span>
602
603<span class="sd">        &#39;&#39;&#39;</span>
604        <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_acc_SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;LSP/CP/SSHF/EWSS/NSSS/SSR&quot;</span><span class="p">,</span> \
605                                    <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
606        <span class="k">return</span>
607
608
609    <span class="k">def</span> <span class="nf">_mk_targetname</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ftype</span><span class="p">,</span> <span class="n">param</span><span class="p">,</span> <span class="n">date</span><span class="p">):</span>
610        <span class="sd">&#39;&#39;&#39;Creates the filename for the requested grib data to be stored in.</span>
611<span class="sd">        This name is passed as the &quot;target&quot; parameter in the request.</span>
612
613<span class="sd">        Parameters</span>
614<span class="sd">        ----------</span>
615<span class="sd">        ftype : str</span>
616<span class="sd">            Shortcut name of the type of the field. E.g. AN, FC, PF, ...</span>
617
618<span class="sd">        param : str</span>
619<span class="sd">            Shortcut of the grid type. E.g. SH__ML, SH__SL, GG__ML,</span>
620<span class="sd">            GG__SL, OG__ML, OG__SL, OG_OROLSM_SL, OG_acc_SL</span>
621
622<span class="sd">        date : str</span>
623<span class="sd">            The date period of the grib data to be stored in this file.</span>
624
625<span class="sd">        Return</span>
626<span class="sd">        ------</span>
627<span class="sd">        targetname : str</span>
628<span class="sd">            The target filename for the grib data.</span>
629<span class="sd">        &#39;&#39;&#39;</span>
630        <span class="n">targetname</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="n">ftype</span> <span class="o">+</span> <span class="n">param</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span>
631                      <span class="nb">str</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getppid</span><span class="p">())</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getpid</span><span class="p">())</span> <span class="o">+</span> <span class="s1">&#39;.grb&#39;</span><span class="p">)</span>
632
633        <span class="k">return</span> <span class="n">targetname</span>
634
635
636    <span class="k">def</span> <span class="nf">_start_retrievement</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">par_dict</span><span class="p">):</span>
637        <span class="sd">&#39;&#39;&#39;Creates the Mars Retrieval and prints or submits the request</span>
638<span class="sd">        depending on the status of the request variable.</span>
639
640<span class="sd">        Parameters</span>
641<span class="sd">        ----------</span>
642<span class="sd">        request : int</span>
643<span class="sd">            Selects the mode of retrieval.</span>
644<span class="sd">            0: Retrieves the data from ECMWF.</span>
645<span class="sd">            1: Prints the mars requests to an output file.</span>
646<span class="sd">            2: Retrieves the data and prints the mars request.</span>
647
648<span class="sd">        par_dict : dictionary</span>
649<span class="sd">            Contains all parameter which have to be set for creating the</span>
650<span class="sd">            Mars Retrievals. The parameter are:</span>
651<span class="sd">            marsclass, dataset, stream, type, levtype, levelist, resol,</span>
652<span class="sd">            gaussian, accuracy, grid, target, area, date, time, number,</span>
653<span class="sd">            step, expver, param</span>
654
655<span class="sd">        Return</span>
656<span class="sd">        ------</span>
657
658<span class="sd">        &#39;&#39;&#39;</span>
659        <span class="c1"># increase number of mars requests</span>
660        <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span> <span class="o">+=</span> <span class="mi">1</span>
661
662        <span class="n">MR</span> <span class="o">=</span> <span class="n">MarsRetrieval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
663                           <span class="bp">self</span><span class="o">.</span><span class="n">public</span><span class="p">,</span>
664                           <span class="n">marsclass</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;marsclass&#39;</span><span class="p">],</span>
665                           <span class="n">dataset</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;dataset&#39;</span><span class="p">],</span>
666                           <span class="n">stream</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;stream&#39;</span><span class="p">],</span>
667                           <span class="nb">type</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">],</span>
668                           <span class="n">levtype</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;levtype&#39;</span><span class="p">],</span>
669                           <span class="n">levelist</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;levelist&#39;</span><span class="p">],</span>
670                           <span class="n">resol</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;resol&#39;</span><span class="p">],</span>
671                           <span class="n">gaussian</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;gaussian&#39;</span><span class="p">],</span>
672                           <span class="n">accuracy</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;accuracy&#39;</span><span class="p">],</span>
673                           <span class="n">grid</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;grid&#39;</span><span class="p">],</span>
674                           <span class="n">target</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">],</span>
675                           <span class="n">area</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">],</span>
676                           <span class="n">date</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">],</span>
677                           <span class="n">time</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">],</span>
678                           <span class="n">number</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;number&#39;</span><span class="p">],</span>
679                           <span class="n">step</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">],</span>
680                           <span class="n">expver</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;expver&#39;</span><span class="p">],</span>
681                           <span class="n">param</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;param&#39;</span><span class="p">])</span>
682
683        <span class="k">if</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
684            <span class="n">MR</span><span class="o">.</span><span class="n">display_info</span><span class="p">()</span>
685            <span class="n">MR</span><span class="o">.</span><span class="n">data_retrieve</span><span class="p">()</span>
686        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
687            <span class="n">MR</span><span class="o">.</span><span class="n">print_infodata_csv</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span><span class="p">)</span>
688        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
689            <span class="n">MR</span><span class="o">.</span><span class="n">print_infodata_csv</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span><span class="p">)</span>
690            <span class="n">MR</span><span class="o">.</span><span class="n">display_info</span><span class="p">()</span>
691            <span class="n">MR</span><span class="o">.</span><span class="n">data_retrieve</span><span class="p">()</span>
692        <span class="k">else</span><span class="p">:</span>
693            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Failure&#39;</span><span class="p">)</span>
694
695        <span class="k">return</span>
696
697
698    <span class="k">def</span> <span class="nf">_mk_index_values</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inputdir</span><span class="p">,</span> <span class="n">inputfiles</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
699        <span class="sd">&#39;&#39;&#39;Creates an index file for a set of grib parameter keys.</span>
700<span class="sd">        The values from the index keys are returned in a list.</span>
701
702<span class="sd">        Parameters</span>
703<span class="sd">        ----------</span>
704<span class="sd">        keys : dictionary</span>
705<span class="sd">            List of parameter names which serves as index.</span>
706
707<span class="sd">        inputfiles : UioFiles</span>
708<span class="sd">            Contains a list of files.</span>
709
710<span class="sd">        Return</span>
711<span class="sd">        ------</span>
712<span class="sd">        iid : codes_index</span>
713<span class="sd">            This is a grib specific index structure to access</span>
714<span class="sd">            messages in a file.</span>
715
716<span class="sd">        index_vals : list of list  of str</span>
717<span class="sd">            Contains the values from the keys used for a distinct selection</span>
718<span class="sd">            of grib messages in processing  the grib files.</span>
719<span class="sd">            Content looks like e.g.:</span>
720<span class="sd">            index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
721<span class="sd">            index_vals[1]: (&#39;0&#39;, &#39;1200&#39;, &#39;1800&#39;, &#39;600&#39;) ; time</span>
722<span class="sd">            index_vals[2]: (&#39;0&#39;, &#39;12&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;) ; stepRange</span>
723<span class="sd">        &#39;&#39;&#39;</span>
724        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
725        <span class="n">index_keys</span> <span class="o">=</span> <span class="n">keys</span>
726
727        <span class="n">indexfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">_config</span><span class="o">.</span><span class="n">FILE_GRIB_INDEX</span><span class="p">)</span>
728        <span class="n">silent_remove</span><span class="p">(</span><span class="n">indexfile</span><span class="p">)</span>
729        <span class="n">grib</span> <span class="o">=</span> <span class="n">GribUtil</span><span class="p">(</span><span class="n">inputfiles</span><span class="o">.</span><span class="n">files</span><span class="p">)</span>
730        <span class="c1"># creates new index file</span>
731        <span class="n">iid</span> <span class="o">=</span> <span class="n">grib</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">index_keys</span><span class="o">=</span><span class="n">index_keys</span><span class="p">,</span> <span class="n">index_file</span><span class="o">=</span><span class="n">indexfile</span><span class="p">)</span>
732
733        <span class="c1"># read the values of index keys</span>
734        <span class="n">index_vals</span> <span class="o">=</span> <span class="p">[]</span>
735        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">index_keys</span><span class="p">:</span>
736            <span class="n">key_vals</span> <span class="o">=</span> <span class="n">codes_index_get</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span>
737            <span class="c1"># have to sort the key values for correct disaggregation,</span>
738            <span class="c1"># therefore convert to int first</span>
739            <span class="n">key_vals</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">key_vals</span><span class="p">]</span>
740            <span class="n">key_vals</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
741            <span class="n">key_vals</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">key_vals</span><span class="p">]</span>
742            <span class="n">index_vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key_vals</span><span class="p">)</span>
743            <span class="c1"># index_vals looks for example like:</span>
744            <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
745            <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;1200&#39;) ; time</span>
746            <span class="c1"># index_vals[2]: (3&#39;, &#39;6&#39;, &#39;9&#39;, &#39;12&#39;) ; stepRange</span>
747
748        <span class="k">return</span> <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span>
749
750
751<div class="viewcode-block" id="EcFlexpart.retrieve"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.retrieve">[docs]</a>    <span class="k">def</span> <span class="nf">retrieve</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">server</span><span class="p">,</span> <span class="n">dates</span><span class="p">,</span> <span class="n">public</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">inputdir</span><span class="o">=</span><span class="s1">&#39;.&#39;</span><span class="p">):</span>
752        <span class="sd">&#39;&#39;&#39;Finalizing the retrieval information by setting final details</span>
753<span class="sd">        depending on grid type.</span>
754<span class="sd">        Prepares MARS retrievals per grid type and submits them.</span>
755
756<span class="sd">        Parameters</span>
757<span class="sd">        ----------</span>
758<span class="sd">        server : ECMWFService or ECMWFDataServer</span>
759<span class="sd">            The connection to the ECMWF server. This is different</span>
760<span class="sd">            for member state users which have full access and non</span>
761<span class="sd">            member state users which have only access to the public</span>
762<span class="sd">            data sets. The decision is made from command line argument</span>
763<span class="sd">            &quot;public&quot;; for public access its True (ECMWFDataServer)</span>
764<span class="sd">            for member state users its False (ECMWFService)</span>
765
766<span class="sd">        dates : str</span>
767<span class="sd">            Contains start and end date of the retrieval in the format</span>
768<span class="sd">            &quot;YYYYMMDD/to/YYYYMMDD&quot;</span>
769
770<span class="sd">        request : int</span>
771<span class="sd">            Selects the mode of retrieval.</span>
772<span class="sd">            0: Retrieves the data from ECMWF.</span>
773<span class="sd">            1: Prints the mars requests to an output file.</span>
774<span class="sd">            2: Retrieves the data and prints the mars request.</span>
775
776<span class="sd">        inputdir : str, optional</span>
777<span class="sd">            Path to the directory where the retrieved data is about</span>
778<span class="sd">            to be stored. The default is the current directory (&#39;.&#39;).</span>
779
780<span class="sd">        Return</span>
781<span class="sd">        ------</span>
782
783<span class="sd">        &#39;&#39;&#39;</span>
784        <span class="bp">self</span><span class="o">.</span><span class="n">dates</span> <span class="o">=</span> <span class="n">dates</span>
785        <span class="bp">self</span><span class="o">.</span><span class="n">server</span> <span class="o">=</span> <span class="n">server</span>
786        <span class="bp">self</span><span class="o">.</span><span class="n">public</span> <span class="o">=</span> <span class="n">public</span>
787        <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">inputdir</span>
788        <span class="n">oro</span> <span class="o">=</span> <span class="kc">False</span>
789
790        <span class="c1"># define times with datetime module</span>
791        <span class="n">t12h</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
792        <span class="n">t24h</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">24</span><span class="p">)</span>
793
794        <span class="c1"># dictionary which contains all parameter for the mars request,</span>
795        <span class="c1"># entries with a &quot;None&quot; will change in different requests and will</span>
796        <span class="c1"># therefore be set in each request seperately</span>
797        <span class="n">retr_param_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;marsclass&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span><span class="p">,</span>
798                           <span class="s1">&#39;dataset&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset</span><span class="p">,</span>
799                           <span class="s1">&#39;stream&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
800                           <span class="s1">&#39;type&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
801                           <span class="s1">&#39;levtype&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
802                           <span class="s1">&#39;levelist&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
803                           <span class="s1">&#39;resol&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">,</span>
804                           <span class="s1">&#39;gaussian&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
805                           <span class="s1">&#39;accuracy&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span><span class="p">,</span>
806                           <span class="s1">&#39;grid&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
807                           <span class="s1">&#39;target&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
808                           <span class="s1">&#39;area&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
809                           <span class="s1">&#39;date&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
810                           <span class="s1">&#39;time&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
811                           <span class="s1">&#39;number&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">number</span><span class="p">,</span>
812                           <span class="s1">&#39;step&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
813                           <span class="s1">&#39;expver&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">expver</span><span class="p">,</span>
814                           <span class="s1">&#39;param&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">}</span>
815
816        <span class="k">for</span> <span class="n">ftype</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">:</span>
817            <span class="c1"># fk contains field types such as</span>
818            <span class="c1">#     [AN, FC, PF, CV]</span>
819            <span class="c1"># fv contains all of the items of the belonging key</span>
820            <span class="c1">#     [times, steps]</span>
821            <span class="k">for</span> <span class="n">pk</span><span class="p">,</span> <span class="n">pv</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
822                <span class="c1"># pk contains one of these keys of params</span>
823                <span class="c1">#     [SH__ML, SH__SL, GG__ML, GG__SL, OG__ML, OG__SL,</span>
824                <span class="c1">#      OG_OROLSM_SL, OG_acc_SL]</span>
825                <span class="c1"># pv contains all of the items of the belonging key</span>
826                <span class="c1">#     [param, levtype, levelist, grid]</span>
827                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">pv</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
828                    <span class="k">continue</span>
829                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ftype</span>
830                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ftype</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]</span>
831                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ftype</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span>
832                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dates</span>
833                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;stream&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stream</span>
834                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> \
835                    <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span>
836                                        <span class="n">pk</span><span class="p">,</span>
837                                        <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
838                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;param&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
839                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;levtype&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
840                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;levelist&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
841                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;grid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
842                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">area</span>
843                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;gaussian&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gaussian</span>
844
845                <span class="k">if</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">oro</span><span class="p">:</span>
846                    <span class="n">oro</span> <span class="o">=</span> <span class="kc">True</span>
847                    <span class="c1"># in CERA20C (class EP) there is no stream &quot;OPER&quot;!</span>
848                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;EP&#39;</span><span class="p">:</span>
849                        <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;stream&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;OPER&#39;</span>
850                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;AN&#39;</span>
851                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;00&#39;</span>
852                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;000&#39;</span>
853                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dates</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
854                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
855                                            <span class="n">pk</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
856                <span class="k">elif</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span> <span class="n">oro</span><span class="p">:</span>
857                    <span class="k">continue</span>
858                <span class="k">if</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;GG__SL&#39;</span> <span class="ow">and</span> <span class="n">pv</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Q&#39;</span><span class="p">:</span>
859                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
860                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;gaussian&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;reduced&#39;</span>
861
862    <span class="c1"># ------  on demand path  --------------------------------------------------</span>
863                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span><span class="p">:</span>
864                    <span class="c1"># ******* start retrievement</span>
865                    <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
866    <span class="c1"># ------  operational path  ------------------------------------------------</span>
867                <span class="k">else</span><span class="p">:</span>
868                    <span class="c1"># check if mars job requests fields beyond basetime.</span>
869                    <span class="c1"># if yes eliminate those fields since they may not</span>
870                    <span class="c1"># be accessible with user&#39;s credentials</span>
871
872                    <span class="n">enddate</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
873                    <span class="n">elimit</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">enddate</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span><span class="p">,</span>
874                                               <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
875
876                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="s1">&#39;12&#39;</span><span class="p">:</span>
877                        <span class="c1"># --------------  flux data ----------------------------</span>
878                        <span class="k">if</span> <span class="s1">&#39;acc&#39;</span> <span class="ow">in</span> <span class="n">pk</span><span class="p">:</span>
879
880                        <span class="c1"># Strategy:</span>
881                        <span class="c1"># if maxtime-elimit &gt;= 24h reduce date by 1,</span>
882                        <span class="c1"># if 12h &lt;= maxtime-elimit&lt;12h reduce time for last date</span>
883                        <span class="c1"># if maxtime-elimit&lt;12h reduce step for last time</span>
884                        <span class="c1"># A split of the MARS job into 2 is likely necessary.</span>
885
886
887                            <span class="n">startdate</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
888                            <span class="n">enddate</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span> <span class="o">-</span> <span class="n">t24h</span><span class="p">,</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
889                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;/&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">startdate</span><span class="p">,</span>
890                                                                <span class="s1">&#39;to&#39;</span><span class="p">,</span>
891                                                                <span class="n">enddate</span><span class="p">])</span>
892
893                            <span class="c1"># ******* start retrievement</span>
894                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
895
896                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> \
897                                <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span> <span class="o">-</span> <span class="n">t12h</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
898                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;00&#39;</span>
899                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> \
900                                <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span> <span class="n">pk</span><span class="p">,</span>
901                                                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
902
903                            <span class="c1"># ******* start retrievement</span>
904                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
905
906                        <span class="c1"># --------------  non flux data ------------------------</span>
907                        <span class="k">else</span><span class="p">:</span>
908                            <span class="c1"># ******* start retrievement</span>
909                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
910
911                    <span class="k">else</span><span class="p">:</span> <span class="c1"># basetime = 0</span>
912                        <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> \
913                            <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span> <span class="o">-</span> <span class="n">t24h</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
914
915                        <span class="n">timesave</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">])</span>
916
917                        <span class="k">if</span> <span class="s1">&#39;/&#39;</span> <span class="ow">in</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]:</span>
918                            <span class="n">times</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
919                            <span class="n">steps</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
920                            <span class="k">while</span> <span class="p">(</span><span class="n">pk</span> <span class="o">!=</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span>
921                                   <span class="s1">&#39;acc&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pk</span> <span class="ow">and</span>
922                                   <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">times</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="nb">int</span><span class="p">(</span><span class="n">steps</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="o">&lt;=</span> <span class="mi">12</span><span class="p">):</span>
923                                <span class="n">times</span> <span class="o">=</span> <span class="n">times</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
924
925                            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">times</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
926                                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;/&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">times</span><span class="p">)</span>
927                            <span class="k">else</span><span class="p">:</span>
928                                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">times</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
929
930                        <span class="c1"># ******* start retrievement</span>
931                        <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
932
933                        <span class="k">if</span> <span class="p">(</span><span class="n">pk</span> <span class="o">!=</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span>
934                            <span class="nb">int</span><span class="p">(</span><span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span>
935                            <span class="nb">int</span><span class="p">(</span><span class="n">timesave</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">):</span>
936
937                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> \
938                                <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
939                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;00&#39;</span>
940                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;000&#39;</span>
941                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> \
942                                <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span> <span class="n">pk</span><span class="p">,</span>
943                                                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
944
945                            <span class="c1"># ******* start retrievement</span>
946                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
947
948        <span class="k">if</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
949            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS retrieve done ... &#39;</span><span class="p">)</span>
950        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
951            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS request printed ...&#39;</span><span class="p">)</span>
952
953        <span class="k">return</span></div>
954
955
956<div class="viewcode-block" id="EcFlexpart.write_namelist"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.write_namelist">[docs]</a>    <span class="k">def</span> <span class="nf">write_namelist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
957        <span class="sd">&#39;&#39;&#39;Creates a namelist file in the temporary directory and writes</span>
958<span class="sd">        the following values to it: maxl, maxb, mlevel,</span>
959<span class="sd">        mlevelist, mnauf, metapar, rlo0, rlo1, rla0, rla1,</span>
960<span class="sd">        momega, momegadiff, mgauss, msmooth, meta, metadiff, mdpdeta</span>
961
962<span class="sd">        Parameters</span>
963<span class="sd">        ----------</span>
964<span class="sd">        c : ControlFile</span>
965<span class="sd">            Contains all the parameters of CONTROL file and</span>
966<span class="sd">            command line.</span>
967
968<span class="sd">        filename : str</span>
969<span class="sd">                Name of the namelist file.</span>
970
971<span class="sd">        Return</span>
972<span class="sd">        ------</span>
973
974<span class="sd">        &#39;&#39;&#39;</span>
975
976        <span class="kn">from</span> <span class="nn">genshi.template.text</span> <span class="k">import</span> <span class="n">NewTextTemplate</span>
977        <span class="kn">from</span> <span class="nn">genshi.template</span> <span class="k">import</span>  <span class="n">TemplateLoader</span>
978        <span class="kn">from</span> <span class="nn">genshi.template.eval</span> <span class="k">import</span>  <span class="n">UndefinedError</span>
979
980        <span class="k">try</span><span class="p">:</span>
981            <span class="n">loader</span> <span class="o">=</span> <span class="n">TemplateLoader</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_TEMPLATES</span><span class="p">,</span> <span class="n">auto_reload</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
982            <span class="n">namelist_template</span> <span class="o">=</span> <span class="n">loader</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">TEMPFILE_NAMELIST</span><span class="p">,</span>
983                                            <span class="bp">cls</span><span class="o">=</span><span class="n">NewTextTemplate</span><span class="p">)</span>
984
985            <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span>
986            <span class="n">area</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">area</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
987            <span class="n">grid</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
988
989            <span class="k">if</span> <span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">area</span><span class="p">[</span><span class="mi">3</span><span class="p">]:</span>
990                <span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">360</span>
991            <span class="n">maxl</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">area</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">-</span> <span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="n">grid</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span>
992            <span class="n">maxb</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">area</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">area</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">/</span> <span class="n">grid</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span>
993
994            <span class="n">stream</span> <span class="o">=</span> <span class="n">namelist_template</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span>
995                <span class="n">maxl</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">maxl</span><span class="p">),</span>
996                <span class="n">maxb</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">maxb</span><span class="p">),</span>
997                <span class="n">mlevel</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">level</span><span class="p">),</span>
998                <span class="n">mlevelist</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">levelist</span><span class="p">),</span>
999                <span class="n">mnauf</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">),</span>
1000                <span class="n">metapar</span> <span class="o">=</span> <span class="s1">&#39;77&#39;</span><span class="p">,</span>
1001                <span class="n">rlo0</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
1002                <span class="n">rlo1</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
1003                <span class="n">rla0</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
1004                <span class="n">rla1</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
1005                <span class="n">momega</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">omega</span><span class="p">),</span>
1006                <span class="n">momegadiff</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">omegadiff</span><span class="p">),</span>
1007                <span class="n">mgauss</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">gauss</span><span class="p">),</span>
1008                <span class="n">msmooth</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">smooth</span><span class="p">),</span>
1009                <span class="n">meta</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">),</span>
1010                <span class="n">metadiff</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">etadiff</span><span class="p">),</span>
1011                <span class="n">mdpdeta</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dpdeta</span><span class="p">)</span>
1012            <span class="p">)</span>
1013        <span class="k">except</span> <span class="n">UndefinedError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1014            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
1015
1016            <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to generate namelist &#39;</span> <span class="o">+</span>
1017                     <span class="n">_config</span><span class="o">.</span><span class="n">TEMPFILE_NAMELIST</span><span class="p">)</span>
1018        <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1019            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR CODE: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="p">))</span>
1020            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR MESSAGE:</span><span class="se">\n</span><span class="s1"> </span><span class="se">\t</span><span class="s1"> &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">))</span>
1021
1022            <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to generate template &#39;</span> <span class="o">+</span>
1023                     <span class="n">_config</span><span class="o">.</span><span class="n">TEMPFILE_NAMELIST</span><span class="p">)</span>
1024
1025        <span class="k">try</span><span class="p">:</span>
1026            <span class="n">namelistfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">_config</span><span class="o">.</span><span class="n">FILE_NAMELIST</span><span class="p">)</span>
1027
1028            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">namelistfile</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
1029                <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">stream</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s1">&#39;text&#39;</span><span class="p">))</span>
1030        <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1031            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR CODE: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="p">))</span>
1032            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR MESSAGE:</span><span class="se">\n</span><span class="s1"> </span><span class="se">\t</span><span class="s1"> &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">))</span>
1033
1034            <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to write &#39;</span> <span class="o">+</span>
1035                     <span class="n">namelistfile</span><span class="p">)</span>
1036
1037        <span class="k">return</span></div>
1038
1039
1040<div class="viewcode-block" id="EcFlexpart.deacc_fluxes"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.deacc_fluxes">[docs]</a>    <span class="k">def</span> <span class="nf">deacc_fluxes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inputfiles</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
1041        <span class="sd">&#39;&#39;&#39;De-accumulate and disaggregate flux data.</span>
1042
1043<span class="sd">        Goes through all flux fields in ordered time and de-accumulate</span>
1044<span class="sd">        the fields. Afterwards the fields are disaggregated in time.</span>
1045<span class="sd">        Different versions of disaggregation is provided for rainfall</span>
1046<span class="sd">        data (darain, modified linear) and the surface fluxes and</span>
1047<span class="sd">        stress data (dapoly, cubic polynomial).</span>
1048
1049<span class="sd">        Parameters</span>
1050<span class="sd">        ----------</span>
1051<span class="sd">        inputfiles : UioFiles</span>
1052<span class="sd">            Contains the list of files that contain flux data.</span>
1053
1054<span class="sd">        c : ControlFile</span>
1055<span class="sd">            Contains all the parameters of CONTROL file and</span>
1056<span class="sd">            command line.</span>
1057
1058<span class="sd">        Return</span>
1059<span class="sd">        ------</span>
1060
1061<span class="sd">        &#39;&#39;&#39;</span>
1062
1063        <span class="n">table128</span> <span class="o">=</span> <span class="n">init128</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_GRIBTABLE</span><span class="p">)</span>
1064        <span class="n">pars</span> <span class="o">=</span> <span class="n">to_param_id</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_acc_SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">table128</span><span class="p">)</span>
1065
1066        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
1067        <span class="n">index_vals</span> <span class="o">=</span> <span class="kc">None</span>
1068
1069        <span class="c1"># get the values of the keys which are used for distinct access</span>
1070        <span class="c1"># of grib messages via product</span>
1071        <span class="n">index_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="s2">&quot;step&quot;</span><span class="p">]</span>
1072        <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mk_index_values</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span>
1073                                                <span class="n">inputfiles</span><span class="p">,</span>
1074                                                <span class="n">index_keys</span><span class="p">)</span>
1075        <span class="c1"># index_vals looks like e.g.:</span>
1076        <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
1077        <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;600&#39;, &#39;1200&#39;, &#39;1800&#39;) ; time</span>
1078        <span class="c1"># index_vals[2]: (&#39;0&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;, &#39;12&#39;) ; stepRange</span>
1079
1080        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span><span class="p">:</span>
1081            <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1082                <span class="n">start_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">start_date</span> <span class="o">+</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1083                <span class="n">end_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">+</span> <span class="s1">&#39;23&#39;</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1084            <span class="k">else</span><span class="p">:</span>
1085                <span class="n">sdate_str</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">start_date</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="si">{:0&gt;2}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">index_vals</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
1086                <span class="n">start_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">sdate_str</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1087                <span class="n">edate_str</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="si">{:0&gt;2}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">index_vals</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
1088                <span class="n">end_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">edate_str</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1089                <span class="n">end_date</span> <span class="o">=</span> <span class="n">end_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">maxstep</span><span class="p">)</span>
1090
1091            <span class="n">info</span> <span class="o">=</span> <span class="n">get_informations</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span>
1092                                                 <span class="n">inputfiles</span><span class="o">.</span><span class="n">files</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
1093            <span class="n">dims</span> <span class="o">=</span> <span class="n">get_dimensions</span><span class="p">(</span><span class="n">info</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">,</span> <span class="n">index_vals</span><span class="p">,</span>
1094                                  <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">)</span>
1095            <span class="c1"># create numpy array</span>
1096            <span class="n">lsp_np</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">dims</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">dims</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dims</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>
1097            <span class="n">cp_np</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">dims</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">dims</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dims</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>
1098            <span class="n">it_lsp</span> <span class="o">=</span> <span class="mi">0</span>
1099            <span class="n">it_cp</span> <span class="o">=</span> <span class="mi">0</span>
1100            <span class="n">date_list</span> <span class="o">=</span> <span class="p">[]</span>
1101            <span class="n">step_list</span> <span class="o">=</span> <span class="p">[]</span>
1102
1103        <span class="c1"># initialize dictionaries to store values</span>
1104        <span class="n">orig_vals</span> <span class="o">=</span> <span class="p">{}</span>
1105        <span class="n">deac_vals</span> <span class="o">=</span> <span class="p">{}</span>
1106        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pars</span><span class="p">:</span>
1107            <span class="n">orig_vals</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
1108            <span class="n">deac_vals</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
1109
1110        <span class="c1"># &quot;product&quot; genereates each possible combination between the</span>
1111        <span class="c1"># values of the index keys</span>
1112        <span class="k">for</span> <span class="n">prod</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">index_vals</span><span class="p">):</span>
1113            <span class="c1"># e.g. prod = (&#39;20170505&#39;, &#39;0&#39;, &#39;12&#39;)</span>
1114            <span class="c1">#             (  date    ,time, step)</span>
1115
1116            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;CURRENT PRODUCT: &#39;</span><span class="p">,</span> <span class="n">prod</span><span class="p">)</span>
1117
1118            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">index_keys</span><span class="p">)):</span>
1119                <span class="n">codes_index_select</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">index_keys</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">prod</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
1120
1121            <span class="c1"># get first id from current product</span>
1122            <span class="n">gid</span> <span class="o">=</span> <span class="n">codes_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
1123
1124            <span class="c1"># if there is no data for this specific time combination / product</span>
1125            <span class="c1"># skip the rest of the for loop and start with next timestep/product</span>
1126            <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
1127                <span class="k">continue</span>
1128
1129            <span class="c1"># create correct timestamp from the three time informations</span>
1130            <span class="n">cdate</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">))</span>
1131            <span class="n">time</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">)</span><span class="o">/</span><span class="mi">100</span> <span class="c1"># integer</span>
1132            <span class="n">step</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">)</span> <span class="c1"># integer</span>
1133            <span class="n">ctime</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;2}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time</span><span class="p">)</span>
1134            <span class="n">cstep</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">)</span>
1135
1136            <span class="n">t_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">cdate</span> <span class="o">+</span> <span class="n">ctime</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1137            <span class="n">t_dt</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="n">step</span><span class="p">)</span>
1138            <span class="n">t_m1dt</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="n">step</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1139            <span class="n">t_m2dt</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="n">step</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1140            <span class="n">t_enddate</span> <span class="o">=</span> <span class="kc">None</span>
1141
1142            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1143                <span class="n">fnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
1144                                     <span class="n">t_date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span>
1145                                     <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)))</span>
1146                <span class="n">gnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
1147                                     <span class="n">t_date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span>
1148                                     <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)))</span>
1149                <span class="n">hnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
1150                                     <span class="n">t_date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span>
1151                                     <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">))</span>
1152            <span class="k">else</span><span class="p">:</span>
1153                <span class="n">fnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
1154                                     <span class="n">t_m2dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">))</span>
1155                <span class="n">gnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
1156                                     <span class="n">t_m1dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">))</span>
1157                <span class="n">hnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
1158                                     <span class="n">t_dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">))</span>
1159
1160            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;outputfile = &quot;</span> <span class="o">+</span> <span class="n">fnout</span><span class="p">)</span>
1161            <span class="n">f_handle</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">fnout</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
1162            <span class="n">h_handle</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">hnout</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
1163            <span class="n">g_handle</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">gnout</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
1164
1165            <span class="c1"># read message for message and store relevant data fields, where</span>
1166            <span class="c1"># data keywords are stored in pars</span>
1167            <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
1168                <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
1169                    <span class="k">break</span>
1170                <span class="n">parId</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;paramId&#39;</span><span class="p">)</span> <span class="c1"># integer</span>
1171                <span class="n">step</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">)</span> <span class="c1"># integer</span>
1172                <span class="n">time</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">)</span> <span class="c1"># integer</span>
1173                <span class="n">ni</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;Ni&#39;</span><span class="p">)</span> <span class="c1"># integer</span>
1174                <span class="n">nj</span> <span class="o">=</span> <span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;Nj&#39;</span><span class="p">)</span> <span class="c1"># integer</span>
1175                <span class="k">if</span> <span class="n">parId</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">orig_vals</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
1176                    <span class="c1"># parameter is not a flux, find next one</span>
1177                    <span class="k">continue</span>
1178
1179                <span class="c1"># define conversion factor</span>
1180                <span class="k">if</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">142</span> <span class="ow">or</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">143</span><span class="p">:</span>
1181                    <span class="n">fak</span> <span class="o">=</span> <span class="mf">1.</span> <span class="o">/</span> <span class="mf">1000.</span>
1182                <span class="k">else</span><span class="p">:</span>
1183                    <span class="n">fak</span> <span class="o">=</span> <span class="mf">3600.</span>
1184
1185                <span class="c1"># get parameter values and reshape</span>
1186                <span class="n">values</span> <span class="o">=</span> <span class="n">codes_get_values</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
1187                <span class="n">values</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="p">(</span><span class="n">nj</span><span class="p">,</span> <span class="n">ni</span><span class="p">)))</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span> <span class="o">/</span> <span class="n">fak</span>
1188
1189                <span class="c1"># save the original and accumulated values</span>
1190                <span class="n">orig_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">values</span><span class="p">[:])</span>
1191
1192                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;EA&#39;</span> <span class="ow">or</span> <span class="n">step</span> <span class="o">&lt;=</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">):</span>
1193                    <span class="c1"># no de-accumulation needed</span>
1194                    <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">values</span><span class="p">[:]</span> <span class="o">/</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1195                <span class="k">else</span><span class="p">:</span>
1196                    <span class="c1"># do de-accumulation</span>
1197                    <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
1198                        <span class="p">(</span><span class="n">orig_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">orig_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="o">-</span><span class="mi">2</span><span class="p">])</span> <span class="o">/</span>
1199                         <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1200
1201                <span class="c1"># store precipitation if new disaggregation method is selected</span>
1202                <span class="c1"># only the exact days are needed</span>
1203                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span><span class="p">:</span>
1204                    <span class="k">if</span> <span class="n">start_date</span> <span class="o">&lt;=</span> <span class="n">t_dt</span> <span class="o">&lt;=</span> <span class="n">end_date</span><span class="p">:</span>
1205                        <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1206                            <span class="k">if</span> <span class="n">t_dt</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">date_list</span><span class="p">:</span>
1207                                <span class="n">date_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t_dt</span><span class="p">)</span>
1208                                <span class="n">step_list</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span>
1209                        <span class="k">else</span><span class="p">:</span>
1210                            <span class="k">if</span> <span class="n">t_date</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">date_list</span><span class="p">:</span>
1211                                <span class="n">date_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t_date</span><span class="p">)</span>
1212                            <span class="k">if</span> <span class="n">step</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">step_list</span><span class="p">:</span>
1213                                <span class="n">step_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">step</span><span class="p">)</span>
1214                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span> <span class="ow">and</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">142</span><span class="p">:</span>
1215                            <span class="n">lsp_np</span><span class="p">[:,</span><span class="n">it_lsp</span><span class="p">]</span> <span class="o">=</span> <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">][:]</span>
1216                            <span class="n">it_lsp</span> <span class="o">+=</span> <span class="mi">1</span>
1217                        <span class="k">elif</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span> <span class="ow">and</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">143</span><span class="p">:</span>
1218                            <span class="n">cp_np</span><span class="p">[:,</span><span class="n">it_cp</span><span class="p">]</span> <span class="o">=</span> <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">][:]</span>
1219                            <span class="n">it_cp</span> <span class="o">+=</span> <span class="mi">1</span>
1220
1221                <span class="c1"># information printout</span>
1222                <span class="nb">print</span><span class="p">(</span><span class="n">parId</span><span class="p">,</span> <span class="n">time</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">values</span><span class="p">),</span> <span class="n">values</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">values</span><span class="p">))</span>
1223
1224                <span class="c1"># length of deac_vals[parId] corresponds to the</span>
1225                <span class="c1"># number of time steps, max. 4 are needed for disaggegration</span>
1226                <span class="c1"># with the old and original method</span>
1227                <span class="c1"># run over all grib messages and perform</span>
1228                <span class="c1"># shifting in time</span>
1229                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">])</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">:</span>
1230                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
1231                        <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span> <span class="ow">and</span> <span class="p">(</span><span class="n">parId</span> <span class="o">==</span> <span class="mi">142</span> <span class="ow">or</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">143</span><span class="p">):</span>
1232                            <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">darain</span><span class="p">(</span><span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">])</span>
1233                        <span class="k">else</span><span class="p">:</span>
1234                            <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">dapoly</span><span class="p">(</span><span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">])</span>
1235
1236                        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">step</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span> \
1237                                <span class="ow">or</span> <span class="n">t_dt</span> <span class="o">==</span> <span class="n">t_enddate</span><span class="p">):</span>
1238                            <span class="c1"># remove first time step in list to shift</span>
1239                            <span class="c1"># time line</span>
1240                            <span class="n">orig_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">]</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
1241                            <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">]</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
1242                    <span class="k">else</span><span class="p">:</span>
1243                        <span class="c1"># if the third time step is read (per parId),</span>
1244                        <span class="c1"># write out the first one as a boundary value</span>
1245                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1246                            <span class="n">values</span> <span class="o">=</span> <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
1247                        <span class="k">else</span><span class="p">:</span>
1248                            <span class="n">values</span> <span class="o">=</span> <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
1249
1250                    <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">rrint</span> <span class="ow">and</span> <span class="p">(</span><span class="n">parId</span> <span class="o">==</span> <span class="mi">142</span> <span class="ow">or</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">143</span><span class="p">)):</span>
1251                        <span class="n">codes_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
1252
1253                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1254                            <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;stepRange&#39;</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">step</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)))</span>
1255                        <span class="k">else</span><span class="p">:</span>
1256                            <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;stepRange&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
1257                            <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="n">t_m2dt</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">)</span>
1258                            <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">t_m2dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)))</span>
1259
1260                        <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">f_handle</span><span class="p">)</span>
1261
1262                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">:</span>
1263                            <span class="n">t_enddate</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">,</span>
1264                                                          <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1265                        <span class="k">else</span><span class="p">:</span>
1266                            <span class="n">t_enddate</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1267
1268                            <span class="c1"># squeeze out information of last two steps</span>
1269                            <span class="c1"># contained in deac_vals[parId]</span>
1270                            <span class="c1"># Note that deac_vals[parId][0] has not been popped</span>
1271                            <span class="c1"># in this case</span>
1272
1273                            <span class="k">if</span> <span class="n">step</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span> <span class="ow">or</span> \
1274                               <span class="n">t_dt</span> <span class="o">==</span> <span class="n">t_enddate</span><span class="p">:</span>
1275                                <span class="c1"># last step</span>
1276                                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1277                                    <span class="n">values</span> <span class="o">=</span> <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span>
1278                                    <span class="n">codes_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
1279                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;stepRange&#39;</span><span class="p">,</span> <span class="n">step</span><span class="p">)</span>
1280                                    <span class="c1">#truedatetime = t_m2dt + timedelta(hours=2*int(c.dtime))</span>
1281                                    <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">h_handle</span><span class="p">)</span>
1282                                <span class="k">else</span><span class="p">:</span>
1283                                    <span class="n">values</span> <span class="o">=</span> <span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span>
1284                                    <span class="n">codes_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
1285                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;stepRange&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
1286                                    <span class="n">truedatetime</span> <span class="o">=</span> <span class="n">t_m2dt</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1287                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="n">truedatetime</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span>
1288                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">truedatetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)))</span>
1289                                    <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">h_handle</span><span class="p">)</span>
1290
1291                                <span class="k">if</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">142</span> <span class="ow">or</span> <span class="n">parId</span> <span class="o">==</span> <span class="mi">143</span><span class="p">:</span>
1292                                    <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">darain</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">])))</span>
1293                                <span class="k">else</span><span class="p">:</span>
1294                                    <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">dapoly</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">deac_vals</span><span class="p">[</span><span class="n">parId</span><span class="p">])))</span>
1295
1296                                <span class="c1"># step before last step</span>
1297                                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1298                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;stepRange&#39;</span><span class="p">,</span> <span class="n">step</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1299                                    <span class="c1">#truedatetime = t_m2dt + timedelta(hours=int(c.dtime))</span>
1300                                    <span class="n">codes_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
1301                                    <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">g_handle</span><span class="p">)</span>
1302                                <span class="k">else</span><span class="p">:</span>
1303                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;stepRange&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
1304                                    <span class="n">truedatetime</span> <span class="o">=</span> <span class="n">t_m2dt</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
1305                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="n">truedatetime</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span>
1306                                    <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">truedatetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)))</span>
1307                                    <span class="n">codes_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
1308                                    <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">g_handle</span><span class="p">)</span>
1309
1310                <span class="n">codes_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
1311
1312                <span class="n">gid</span> <span class="o">=</span> <span class="n">codes_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
1313
1314            <span class="n">f_handle</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
1315            <span class="n">g_handle</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
1316            <span class="n">h_handle</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
1317
1318        <span class="n">codes_index_release</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
1319
1320        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span><span class="p">:</span>
1321            <span class="bp">self</span><span class="o">.</span><span class="n">_create_rr_grib_dummy</span><span class="p">(</span><span class="n">inputfiles</span><span class="o">.</span><span class="n">files</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">)</span>
1322
1323            <span class="bp">self</span><span class="o">.</span><span class="n">_prep_new_rrint</span><span class="p">(</span><span class="n">ni</span><span class="p">,</span> <span class="n">nj</span><span class="p">,</span> <span class="n">lsp_np</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">lsp_np</span><span class="p">,</span>
1324                                 <span class="n">cp_np</span><span class="p">,</span> <span class="n">date_list</span><span class="p">,</span> <span class="n">step_list</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
1325
1326        <span class="k">return</span></div>
1327
1328    <span class="k">def</span> <span class="nf">_prep_new_rrint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ni</span><span class="p">,</span> <span class="n">nj</span><span class="p">,</span> <span class="n">nt</span><span class="p">,</span> <span class="n">lsp_np</span><span class="p">,</span> <span class="n">cp_np</span><span class="p">,</span> <span class="n">date_list</span><span class="p">,</span> <span class="n">step_list</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
1329        <span class="sd">&#39;&#39;&#39;Calculates and writes out the disaggregated precipitation fields.</span>
1330
1331<span class="sd">        Disaggregation is done in time and original times are written to the</span>
1332<span class="sd">        flux files, while the additional subgrid times are written to</span>
1333<span class="sd">        extra files.</span>
1334
1335<span class="sd">        Parameters</span>
1336<span class="sd">        ----------</span>
1337<span class="sd">        ni : int</span>
1338<span class="sd">            Amount of zonal grid points.</span>
1339
1340<span class="sd">        nj : int</span>
1341<span class="sd">            Amount of meridional grid points.</span>
1342
1343<span class="sd">        nt : int</span>
1344<span class="sd">            Number of time steps.</span>
1345
1346<span class="sd">        lsp_np : numpy array of float</span>
1347<span class="sd">            The large scale precipitation fields for each time step.</span>
1348<span class="sd">            Shape (ni * nj, nt).</span>
1349
1350<span class="sd">        cp_np : numpy array of float</span>
1351<span class="sd">            The convective precipitation fields for each time step.</span>
1352<span class="sd">            Shape (ni * nj, nt).</span>
1353
1354<span class="sd">        date_list : list of datetime</span>
1355<span class="sd">            The list of dates for which the disaggregation is to be done.</span>
1356
1357<span class="sd">        step_list : list of int</span>
1358<span class="sd">            The list of steps for a single forecast time.</span>
1359<span class="sd">            Only necessary for pure forecasts.</span>
1360
1361<span class="sd">        c : ControlFile</span>
1362<span class="sd">            Contains all the parameters of CONTROL file and</span>
1363<span class="sd">            command line.</span>
1364
1365<span class="sd">        Return</span>
1366<span class="sd">        ------</span>
1367
1368<span class="sd">        &#39;&#39;&#39;</span>
1369        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... disaggregation or precipitation with new method.&#39;</span><span class="p">)</span>
1370        <span class="n">lsp_new_np</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">ni</span> <span class="o">*</span> <span class="n">nj</span><span class="p">,</span> <span class="n">nt</span> <span class="o">*</span> <span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>
1371        <span class="n">cp_new_np</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">ni</span> <span class="o">*</span> <span class="n">nj</span><span class="p">,</span> <span class="n">nt</span> <span class="o">*</span> <span class="mi">3</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>
1372
1373        <span class="c1"># do the disaggregation, but neglect the last value of the</span>
1374        <span class="c1"># time series. This one corresponds for example to 24 hour,</span>
1375        <span class="c1"># which we don&#39;t need.</span>
1376        <span class="k">for</span> <span class="n">ix</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ni</span><span class="o">*</span><span class="n">nj</span><span class="p">):</span>
1377            <span class="n">lsp_new_np</span><span class="p">[</span><span class="n">ix</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">IA3</span><span class="p">(</span><span class="n">lsp_np</span><span class="p">[</span><span class="n">ix</span><span class="p">,:])[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
1378            <span class="n">cp_new_np</span><span class="p">[</span><span class="n">ix</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">IA3</span><span class="p">(</span><span class="n">cp_np</span><span class="p">[</span><span class="n">ix</span><span class="p">,:])[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
1379
1380        <span class="c1"># write to grib files (full/orig times to flux file and inbetween</span>
1381        <span class="c1"># times into seperate end files)</span>
1382        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... write disaggregated precipitation to files.&#39;</span><span class="p">)</span>
1383        <span class="n">it</span> <span class="o">=</span> <span class="mi">0</span>
1384        <span class="k">for</span> <span class="n">date</span> <span class="ow">in</span> <span class="n">date_list</span><span class="p">:</span>
1385            <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="n">step_list</span><span class="p">:</span>
1386                <span class="n">tmpfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;rr_grib_dummy.grb&#39;</span><span class="p">)</span>
1387
1388                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1389                    <span class="n">fluxfilename</span> <span class="o">=</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span> \
1390                                   <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">)</span>
1391                    <span class="n">filename1</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span> \
1392                                <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;_1&#39;</span>
1393                    <span class="n">filename2</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span> \
1394                                <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;_2&#39;</span>
1395                <span class="k">else</span><span class="p">:</span>
1396                    <span class="n">fluxfilename</span> <span class="o">=</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1397                    <span class="n">filename1</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;_1&#39;</span>
1398                    <span class="n">filename2</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;_2&#39;</span>
1399
1400                <span class="c1"># collect for final processing</span>
1401                <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">fluxfilename</span><span class="p">))</span>
1402                <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">filename1</span><span class="p">))</span>
1403                <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">filename2</span><span class="p">))</span>
1404
1405                <span class="c1"># write original time step to flux file as usual</span>
1406                <span class="n">fluxfile</span> <span class="o">=</span> <span class="n">GribUtil</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">fluxfilename</span><span class="p">))</span>
1407                <span class="n">fluxfile</span><span class="o">.</span><span class="n">set_keys</span><span class="p">(</span><span class="n">tmpfile</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
1408                                  <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">142</span><span class="p">],</span>
1409                                  <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="s1">&#39;stepRange&#39;</span><span class="p">,</span><span class="s1">&#39;values&#39;</span><span class="p">],</span>
1410                                  <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)),</span>
1411                                             <span class="n">date</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">lsp_new_np</span><span class="p">[:,</span><span class="n">it</span><span class="p">]],</span>
1412                                 <span class="p">)</span>
1413                <span class="n">fluxfile</span><span class="o">.</span><span class="n">set_keys</span><span class="p">(</span><span class="n">tmpfile</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
1414                                  <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">143</span><span class="p">],</span>
1415                                  <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="s1">&#39;stepRange&#39;</span><span class="p">,</span><span class="s1">&#39;values&#39;</span><span class="p">],</span>
1416                                  <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)),</span>
1417                                             <span class="n">date</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">cp_new_np</span><span class="p">[:,</span><span class="n">it</span><span class="p">]]</span>
1418                                 <span class="p">)</span>
1419
1420                <span class="c1"># write first subgrid time step</span>
1421                <span class="n">endfile1</span> <span class="o">=</span> <span class="n">GribUtil</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">filename1</span><span class="p">))</span>
1422                <span class="n">endfile1</span><span class="o">.</span><span class="n">set_keys</span><span class="p">(</span><span class="n">tmpfile</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
1423                                  <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">142</span><span class="p">],</span>
1424                                  <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="s1">&#39;stepRange&#39;</span><span class="p">,</span><span class="s1">&#39;values&#39;</span><span class="p">],</span>
1425                                  <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)),</span>
1426                                             <span class="n">date</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">lsp_new_np</span><span class="p">[:,</span><span class="n">it</span><span class="o">+</span><span class="mi">1</span><span class="p">]]</span>
1427                                  <span class="p">)</span>
1428                <span class="n">endfile1</span><span class="o">.</span><span class="n">set_keys</span><span class="p">(</span><span class="n">tmpfile</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
1429                                  <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">143</span><span class="p">],</span>
1430                                  <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="s1">&#39;stepRange&#39;</span><span class="p">,</span><span class="s1">&#39;values&#39;</span><span class="p">],</span>
1431                                  <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)),</span>
1432                                             <span class="n">date</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">cp_new_np</span><span class="p">[:,</span><span class="n">it</span><span class="o">+</span><span class="mi">1</span><span class="p">]]</span>
1433                                 <span class="p">)</span>
1434
1435                <span class="c1"># write second subgrid time step</span>
1436                <span class="n">endfile2</span> <span class="o">=</span> <span class="n">GribUtil</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">filename2</span><span class="p">))</span>
1437                <span class="n">endfile2</span><span class="o">.</span><span class="n">set_keys</span><span class="p">(</span><span class="n">tmpfile</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
1438                                  <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">142</span><span class="p">],</span>
1439                                  <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="s1">&#39;stepRange&#39;</span><span class="p">,</span><span class="s1">&#39;values&#39;</span><span class="p">],</span>
1440                                  <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)),</span>
1441                                             <span class="n">date</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">lsp_new_np</span><span class="p">[:,</span><span class="n">it</span><span class="o">+</span><span class="mi">2</span><span class="p">]]</span>
1442                                 <span class="p">)</span>
1443                <span class="n">endfile2</span><span class="o">.</span><span class="n">set_keys</span><span class="p">(</span><span class="n">tmpfile</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
1444                                  <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">143</span><span class="p">],</span>
1445                                  <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="s1">&#39;stepRange&#39;</span><span class="p">,</span><span class="s1">&#39;values&#39;</span><span class="p">],</span>
1446                                  <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)),</span>
1447                                             <span class="n">date</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="n">cp_new_np</span><span class="p">[:,</span><span class="n">it</span><span class="o">+</span><span class="mi">2</span><span class="p">]]</span>
1448                                 <span class="p">)</span>
1449                <span class="n">it</span> <span class="o">=</span> <span class="n">it</span> <span class="o">+</span> <span class="mi">3</span> <span class="c1"># jump to next original time step</span>
1450        <span class="k">return</span>
1451
1452    <span class="k">def</span> <span class="nf">_create_rr_grib_dummy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ifile</span><span class="p">,</span> <span class="n">inputdir</span><span class="p">):</span>
1453        <span class="sd">&#39;&#39;&#39;Creates a grib file with a dummy message for the two precipitation</span>
1454<span class="sd">        types lsp and cp each.</span>
1455
1456<span class="sd">        Parameters</span>
1457<span class="sd">        ----------</span>
1458<span class="sd">        ifile : str</span>
1459<span class="sd">            Filename of the input file to read the grib messages from.</span>
1460
1461<span class="sd">        inputdir : str, optional</span>
1462<span class="sd">            Path to the directory where the retrieved data is stored.</span>
1463
1464<span class="sd">        Return</span>
1465<span class="sd">        ------</span>
1466
1467<span class="sd">        &#39;&#39;&#39;</span>
1468
1469        <span class="n">gribfile</span> <span class="o">=</span> <span class="n">GribUtil</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">inputdir</span><span class="p">,</span><span class="s1">&#39;rr_grib_dummy.grb&#39;</span><span class="p">))</span>
1470
1471        <span class="n">gribfile</span><span class="o">.</span><span class="n">copy_dummy_msg</span><span class="p">(</span><span class="n">ifile</span><span class="p">,</span> <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span>
1472                      <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">142</span><span class="p">],</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">)</span>
1473
1474        <span class="n">gribfile</span><span class="o">.</span><span class="n">copy_dummy_msg</span><span class="p">(</span><span class="n">ifile</span><span class="p">,</span> <span class="n">keynames</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;paramId&#39;</span><span class="p">],</span>
1475                      <span class="n">keyvalues</span><span class="o">=</span><span class="p">[</span><span class="mi">143</span><span class="p">],</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">)</span>
1476
1477        <span class="k">return</span>
1478
1479<div class="viewcode-block" id="EcFlexpart.create"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.create">[docs]</a>    <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inputfiles</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
1480        <span class="sd">&#39;&#39;&#39;An index file will be created which depends on the combination</span>
1481<span class="sd">        of &quot;date&quot;, &quot;time&quot; and &quot;stepRange&quot; values. This is used to iterate</span>
1482<span class="sd">        over all messages in each grib file which were passed through the</span>
1483<span class="sd">        parameter &quot;inputfiles&quot; to seperate specific parameters into fort.*</span>
1484<span class="sd">        files. Afterwards the FORTRAN program is called to convert</span>
1485<span class="sd">        the data fields all to the same grid and put them in one file</span>
1486<span class="sd">        per unique time step (combination of &quot;date&quot;, &quot;time&quot; and</span>
1487<span class="sd">        &quot;stepRange&quot;).</span>
1488
1489<span class="sd">        Note</span>
1490<span class="sd">        ----</span>
1491<span class="sd">        This method is based on the ECMWF example index.py</span>
1492<span class="sd">        https://software.ecmwf.int/wiki/display/GRIB/index.py</span>
1493
1494<span class="sd">        Parameters</span>
1495<span class="sd">        ----------</span>
1496<span class="sd">        inputfiles : UioFiles</span>
1497<span class="sd">            Contains a list of files.</span>
1498
1499<span class="sd">        c : ControlFile</span>
1500<span class="sd">            Contains all the parameters of CONTROL file and</span>
1501<span class="sd">            command line.</span>
1502
1503<span class="sd">        Return</span>
1504<span class="sd">        ------</span>
1505
1506<span class="sd">        &#39;&#39;&#39;</span>
1507
1508        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
1509            <span class="n">table128</span> <span class="o">=</span> <span class="n">init128</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_GRIBTABLE</span><span class="p">)</span>
1510            <span class="n">wrfpars</span> <span class="o">=</span> <span class="n">to_param_id</span><span class="p">(</span><span class="s1">&#39;sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/</span><span class="se">\</span>
1511<span class="s1">                                   stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4&#39;</span><span class="p">,</span>
1512                                  <span class="n">table128</span><span class="p">)</span>
1513
1514        <span class="c1"># these numbers are indices for the temporary files &quot;fort.xx&quot;</span>
1515        <span class="c1"># which are used to seperate the grib fields to,</span>
1516        <span class="c1"># for the Fortran program input</span>
1517        <span class="c1"># 10: U,V | 11: T | 12: lnsp | 13: D | 16: sfc fields</span>
1518        <span class="c1"># 17: Q | 18: Q , gaussian| 19: w | 21: etadot | 22: clwc+ciwc</span>
1519        <span class="n">fdict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;10&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;11&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;12&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;13&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;16&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
1520                 <span class="s1">&#39;17&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;18&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;19&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;21&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;22&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">}</span>
1521
1522        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
1523        <span class="n">index_vals</span> <span class="o">=</span> <span class="kc">None</span>
1524
1525        <span class="c1"># get the values of the keys which are used for distinct access</span>
1526        <span class="c1"># of grib messages via product</span>
1527        <span class="n">index_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="s2">&quot;step&quot;</span><span class="p">]</span>
1528        <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mk_index_values</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span>
1529                                                <span class="n">inputfiles</span><span class="p">,</span>
1530                                                <span class="n">index_keys</span><span class="p">)</span>
1531        <span class="c1"># index_vals looks like e.g.:</span>
1532        <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
1533        <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;600&#39;, &#39;1200&#39;, &#39;1800&#39;) ; time</span>
1534        <span class="c1"># index_vals[2]: (&#39;0&#39;, &#39;12&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;) ; stepRange</span>
1535
1536        <span class="c1"># &quot;product&quot; genereates each possible combination between the</span>
1537        <span class="c1"># values of the index keys</span>
1538        <span class="k">for</span> <span class="n">prod</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">index_vals</span><span class="p">):</span>
1539            <span class="c1"># e.g. prod = (&#39;20170505&#39;, &#39;0&#39;, &#39;12&#39;)</span>
1540            <span class="c1">#             (  date    ,time, step)</span>
1541
1542            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;current product: &#39;</span><span class="p">,</span> <span class="n">prod</span><span class="p">)</span>
1543
1544            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">index_keys</span><span class="p">)):</span>
1545                <span class="n">codes_index_select</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">index_keys</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">prod</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
1546
1547            <span class="c1"># get first id from current product</span>
1548            <span class="n">gid</span> <span class="o">=</span> <span class="n">codes_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
1549
1550            <span class="c1"># if there is no data for this specific time combination / product</span>
1551            <span class="c1"># skip the rest of the for loop and start with next timestep/product</span>
1552            <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
1553                <span class="k">continue</span>
1554<span class="c1">#============================================================================================</span>
1555            <span class="c1"># remove old fort.* files and open new ones</span>
1556            <span class="c1"># they are just valid for a single product</span>
1557            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">fdict</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
1558                <span class="n">fortfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;fort.&#39;</span> <span class="o">+</span> <span class="n">k</span><span class="p">)</span>
1559                <span class="n">silent_remove</span><span class="p">(</span><span class="n">fortfile</span><span class="p">)</span>
1560                <span class="n">fdict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">fortfile</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
1561<span class="c1">#============================================================================================</span>
1562            <span class="c1"># create correct timestamp from the three time informations</span>
1563            <span class="n">cdate</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">))</span>
1564            <span class="n">ctime</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;2}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">)</span><span class="o">/</span><span class="mi">100</span><span class="p">)</span>
1565            <span class="n">cstep</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">))</span>
1566            <span class="n">timestamp</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">cdate</span> <span class="o">+</span> <span class="n">ctime</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1567            <span class="n">timestamp</span> <span class="o">+=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">cstep</span><span class="p">))</span>
1568            <span class="n">cdate_hour</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">timestamp</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1569
1570            <span class="c1"&