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

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

deleted jobscripts for tracking and updated Sphinx doc

  • Property mode set to 100644
File size: 268.1 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> <span class="n">codes_get_array</span><span class="p">,</span>
223                     <span class="n">codes_set_array</span><span class="p">,</span> <span class="n">codes_grib_new_from_file</span><span class="p">)</span>
224
225<span class="c1"># software specific classes and modules from flex_extract</span>
226<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>
227<span class="kn">import</span> <span class="nn">_config</span>
228<span class="kn">from</span> <span class="nn">GribUtil</span> <span class="k">import</span> <span class="n">GribUtil</span>
229<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>
230                        <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>
231                        <span class="n">execute_subprocess</span><span class="p">,</span> <span class="n">to_param_id_with_tablenumber</span><span class="p">)</span>
232<span class="kn">from</span> <span class="nn">MarsRetrieval</span> <span class="k">import</span> <span class="n">MarsRetrieval</span>
233<span class="kn">from</span> <span class="nn">UioFiles</span> <span class="k">import</span> <span class="n">UioFiles</span>
234<span class="kn">import</span> <span class="nn">mods.disaggregation</span> <span class="k">as</span> <span class="nn">disaggregation</span>
235
236<span class="c1"># ------------------------------------------------------------------------------</span>
237<span class="c1"># CLASS</span>
238<span class="c1"># ------------------------------------------------------------------------------</span>
239<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>
240    <span class="sd">&#39;&#39;&#39;</span>
241<span class="sd">    Class to represent FLEXPART specific ECMWF data.</span>
242
243<span class="sd">    FLEXPART needs grib files in a specifc format. All necessary data fields</span>
244<span class="sd">    for one time step are stored in a single file. The class represents an</span>
245<span class="sd">    instance with all the parameter and settings necessary for retrieving</span>
246<span class="sd">    MARS data and modifing them so they are fitting FLEXPART needs. The class</span>
247<span class="sd">    is able to disaggregate the fluxes and convert grid types to the one needed</span>
248<span class="sd">    by FLEXPART, therefore using the FORTRAN program.</span>
249
250<span class="sd">    Attributes</span>
251<span class="sd">    ----------</span>
252<span class="sd">    mreq_count : int</span>
253<span class="sd">        Counter for the number of generated mars requests.</span>
254
255<span class="sd">    inputdir : str</span>
256<span class="sd">        Path to the directory where the retrieved data is stored.</span>
257
258<span class="sd">    dataset : str</span>
259<span class="sd">        For public datasets there is the specific naming and parameter</span>
260<span class="sd">        dataset which has to be used to characterize the type of</span>
261<span class="sd">        data.</span>
262
263<span class="sd">    basetime : int</span>
264<span class="sd">        The time for a half day retrieval. The 12 hours upfront are to be</span>
265<span class="sd">        retrieved.</span>
266
267<span class="sd">    dtime : str</span>
268<span class="sd">        Time step in hours.</span>
269
270<span class="sd">    acctype : str</span>
271<span class="sd">        The field type for the accumulated forecast fields.</span>
272
273<span class="sd">    acctime : str</span>
274<span class="sd">        The starting time from the accumulated forecasts.</span>
275
276<span class="sd">    accmaxstep : str</span>
277<span class="sd">        The maximum forecast step for the accumulated forecast fields.</span>
278
279<span class="sd">    marsclass : str</span>
280<span class="sd">        Characterisation of dataset.</span>
281
282<span class="sd">    stream : str</span>
283<span class="sd">        Identifies the forecasting system used to generate the data.</span>
284
285<span class="sd">    number : str</span>
286<span class="sd">        Selects the member in ensemble forecast run.</span>
287
288<span class="sd">    resol : str</span>
289<span class="sd">        Specifies the desired triangular truncation of retrieved data,</span>
290<span class="sd">        before carrying out any other selected post-processing.</span>
291
292<span class="sd">    accuracy : str</span>
293<span class="sd">        Specifies the number of bits per value to be used in the</span>
294<span class="sd">        generated GRIB coded fields.</span>
295
296<span class="sd">    addpar : str</span>
297<span class="sd">        List of additional parameters to be retrieved.</span>
298
299<span class="sd">    level : str</span>
300<span class="sd">        Specifies the maximum level.</span>
301
302<span class="sd">    expver : str</span>
303<span class="sd">        The version of the dataset.</span>
304
305<span class="sd">    levelist : str</span>
306<span class="sd">        Specifies the required levels.</span>
307
308<span class="sd">    glevelist : str</span>
309<span class="sd">        Specifies the required levels for gaussian grids.</span>
310
311<span class="sd">    gaussian : str</span>
312<span class="sd">        This parameter is deprecated and should no longer be used.</span>
313<span class="sd">        Specifies the desired type of Gaussian grid for the output.</span>
314
315<span class="sd">    grid : str</span>
316<span class="sd">        Specifies the output grid which can be either a Gaussian grid</span>
317<span class="sd">        or a Latitude/Longitude grid.</span>
318
319<span class="sd">    area : str</span>
320<span class="sd">        Specifies the desired sub-area of data to be extracted.</span>
321
322<span class="sd">    purefc : int</span>
323<span class="sd">        Switch for definition of pure forecast mode or not.</span>
324
325<span class="sd">    outputfilelist : list of str</span>
326<span class="sd">        The final list of FLEXPART ready input files.</span>
327
328<span class="sd">    types : dictionary</span>
329<span class="sd">        Determines the combination of type of fields, time and forecast step</span>
330<span class="sd">        to be retrieved.</span>
331
332<span class="sd">    params : dictionary</span>
333<span class="sd">        Collection of grid types and their corresponding parameters,</span>
334<span class="sd">        levels, level types and the grid definition.</span>
335
336<span class="sd">    server : ECMWFService or ECMWFDataServer</span>
337<span class="sd">        This is the connection to the ECMWF data servers.</span>
338
339<span class="sd">    public : int</span>
340<span class="sd">        Decides which Web API Server version is used.</span>
341
342<span class="sd">    dates : str</span>
343<span class="sd">        Contains start and end date of the retrieval in the format</span>
344<span class="sd">        &quot;YYYYMMDD/to/YYYYMMDD&quot;</span>
345<span class="sd">    &#39;&#39;&#39;</span>
346
347    <span class="c1"># --------------------------------------------------------------------------</span>
348    <span class="c1"># CLASS FUNCTIONS</span>
349    <span class="c1"># --------------------------------------------------------------------------</span>
350    <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>
351        <span class="sd">&#39;&#39;&#39;Creates an object/instance of EcFlexpart with the associated</span>
352<span class="sd">        settings of its attributes for the retrieval.</span>
353
354<span class="sd">        Parameters:</span>
355<span class="sd">        -----------</span>
356<span class="sd">        c : ControlFile</span>
357<span class="sd">            Contains all the parameters of CONTROL file and</span>
358<span class="sd">            command line.</span>
359
360<span class="sd">        fluxes : boolean, optional</span>
361<span class="sd">            Decides if the flux parameter settings are stored or</span>
362<span class="sd">            the rest of the parameter list.</span>
363<span class="sd">            Default value is False.</span>
364
365<span class="sd">        Return</span>
366<span class="sd">        ------</span>
367
368<span class="sd">        &#39;&#39;&#39;</span>
369        <span class="c1"># set a counter for the number of generated mars requests</span>
370        <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span> <span class="o">=</span> <span class="mi">0</span>
371
372        <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>
373        <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>
374        <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>
375        <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>
376        <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>
377        <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>
378        <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>
379        <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>
380        <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>
381        <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>
382        <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>
383        <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>
384        <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>
385        <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>
386        <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>
387        <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>
388        <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>
389        <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>
390        <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>
391        <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>
392        <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>
393        <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span> <span class="o">=</span> <span class="p">[]</span>
394
395        <span class="c1"># Define the different types of field combinations (type, time, step)</span>
396        <span class="bp">self</span><span class="o">.</span><span class="n">types</span> <span class="o">=</span> <span class="p">{}</span>
397        <span class="c1"># Define the parameters and their level types, level list and</span>
398        <span class="c1"># grid resolution for the retrieval job</span>
399        <span class="bp">self</span><span class="o">.</span><span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
400
401        <span class="k">if</span> <span class="n">fluxes</span><span class="p">:</span>
402            <span class="bp">self</span><span class="o">.</span><span class="n">_create_params_fluxes</span><span class="p">()</span>
403        <span class="k">else</span><span class="p">:</span>
404            <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>
405
406        <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>
407            <span class="bp">self</span><span class="o">.</span><span class="n">_create_field_types_fluxes</span><span class="p">()</span>
408        <span class="k">else</span><span class="p">:</span>
409            <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>
410        <span class="k">return</span>
411
412    <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>
413        <span class="sd">&#39;&#39;&#39;Create the combination of field type, time and forecast step.</span>
414
415<span class="sd">        Parameters:</span>
416<span class="sd">        -----------</span>
417<span class="sd">        ftype : list of str</span>
418<span class="sd">            List of field types.</span>
419
420<span class="sd">        ftime : list of str</span>
421<span class="sd">            The time in hours of the field.</span>
422
423<span class="sd">        fstep : str</span>
424<span class="sd">            Specifies the forecast time step from forecast base time.</span>
425<span class="sd">            Valid values are hours (HH) from forecast base time.</span>
426
427<span class="sd">        Return</span>
428<span class="sd">        ------</span>
429
430<span class="sd">        &#39;&#39;&#39;</span>
431        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
432        <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>
433            <span class="n">btlist</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ftime</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="mi">12</span><span class="p">:</span>
435                <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>
436            <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="mi">0</span><span class="p">:</span>
437                <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>
438
439            <span class="c1"># if ((ty.upper() == &#39;AN&#39; and (int(c.time[i]) % int(c.dtime)) == 0) or</span>
440                <span class="c1"># (ty.upper() != &#39;AN&#39; and (int(c.step[i]) % int(c.dtime)) == 0 and</span>
441                 <span class="c1"># (int(c.step[i]) % int(c.dtime) == 0)) ) and \</span>
442                 <span class="c1"># (int(c.time[i]) in btlist or c.purefc):</span>
443
444            <span class="k">if</span> <span class="p">(</span><span class="n">i</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>
445
446                <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>
447                    <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>
448
449                    <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>
450                        <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>
451
452                    <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>
453                        <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>
454                            <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>
455                        <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>
456
457                    <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>
458                        <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>
459                            <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>
460                        <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>
461            <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
462
463        <span class="k">return</span>
464
465    <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>
466        <span class="sd">&#39;&#39;&#39;Create the combination of field type, time and forecast step</span>
467<span class="sd">        for the flux data.</span>
468
469<span class="sd">        Parameters:</span>
470<span class="sd">        -----------</span>
471
472<span class="sd">        Return</span>
473<span class="sd">        ------</span>
474
475<span class="sd">        &#39;&#39;&#39;</span>
476        <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>
477                                         <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>
478                                             <span class="bp">self</span><span class="o">.</span><span class="n">dtime</span><span class="p">,</span>
479                                             <span class="bp">self</span><span class="o">.</span><span class="n">accmaxstep</span><span class="p">,</span>
480                                             <span class="bp">self</span><span class="o">.</span><span class="n">dtime</span><span class="p">)}</span>
481        <span class="k">return</span>
482
483    <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>
484        <span class="sd">&#39;&#39;&#39;Define the specific parameter settings for retrievment.</span>
485
486<span class="sd">        The different parameters need specific grid types and level types</span>
487<span class="sd">        for retrievement. We might get following combination of types</span>
488<span class="sd">        (depending on selection and availability):</span>
489<span class="sd">        (These are short cuts for the grib file names (leading sequence)</span>
490<span class="sd">        SH__ML, OG__ML, GG__ML, SH__SL, OG__SL, GG__SL, OG_OROLSM_SL</span>
491<span class="sd">        where:</span>
492<span class="sd">            SH = Spherical Harmonics, GG = Gaussian Grid, OG = Output Grid,</span>
493<span class="sd">            ML = Model Level, SL = Surface Level</span>
494
495<span class="sd">        For each of this combination there is a list of parameter names,</span>
496<span class="sd">        the level type, the level list and the grid resolution.</span>
497
498<span class="sd">        There are different scenarios for data extraction from MARS:</span>
499<span class="sd">        1) Retrieval of etadot</span>
500<span class="sd">           eta=1, gauss=0, omega=0</span>
501<span class="sd">        2) Calculation of etadot from divergence</span>
502<span class="sd">           eta=0, gauss=1, omega=0</span>
503<span class="sd">        3) Calculation of etadot from omega (for makes sense for debugging)</span>
504<span class="sd">           eta=0, gauss=0, omega=1</span>
505<span class="sd">        4) Retrieval and Calculation of etadot (only for debugging)</span>
506<span class="sd">           eta=1, gauss=1, omega=0</span>
507<span class="sd">        5) Download also specific model and surface level data for FLEXPART-WRF</span>
508
509<span class="sd">        Parameters:</span>
510<span class="sd">        -----------</span>
511<span class="sd">        gauss : int</span>
512<span class="sd">            Gaussian grid is retrieved.</span>
513
514<span class="sd">        eta : int</span>
515<span class="sd">            Etadot parameter will be directly retrieved.</span>
516
517<span class="sd">        omega : int</span>
518<span class="sd">            The omega paramterwill be retrieved.</span>
519
520<span class="sd">        cwc : int</span>
521<span class="sd">            The cloud liquid and ice water content will be retrieved.</span>
522
523<span class="sd">        wrf : int</span>
524<span class="sd">            Additional model level and surface level data will be retrieved for</span>
525<span class="sd">            WRF/FLEXPART-WRF simulations.</span>
526
527<span class="sd">        Return</span>
528<span class="sd">        ------</span>
529
530<span class="sd">        &#39;&#39;&#39;</span>
531        <span class="c1"># SURFACE FIELDS</span>
532        <span class="c1">#-----------------------------------------------------------------------</span>
533        <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>
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="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> \
535                                 <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>
536        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">addpar</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__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>
538
539        <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>
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/FSR&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        <span class="k">else</span><span class="p">:</span>
543            <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> \
544                                            <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>
545
546        <span class="c1"># MODEL LEVEL FIELDS</span>
547        <span class="c1">#-----------------------------------------------------------------------</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="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>
549
550        <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>
551            <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>
552        <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>
553            <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> \
554                                     <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>
555            <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>
556        <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>
557            <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>
558        <span class="k">else</span><span class="p">:</span>  <span class="c1"># GAUSS and ETA</span>
559            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Warning: Collecting etadot and parameters for gaussian grid &#39;</span>
560                           <span class="s1">&#39;is a very costly parameter combination, &#39;</span>
561                           <span class="s1">&#39;use this combination only for debugging!&#39;</span><span class="p">)</span>
562            <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>
563                                     <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>
564            <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/ETADOT&#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>
565                                     <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>
566
567        <span class="k">if</span> <span class="n">omega</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;/W&#39;</span>
569
570        <span class="k">if</span> <span class="n">cwc</span><span class="p">:</span>
571            <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>
572
573        <span class="c1"># ADDITIONAL FIELDS FOR FLEXPART-WRF MODEL (IF QUESTIONED)</span>
574        <span class="c1"># -----------------------------------------------------------------------</span>
575        <span class="k">if</span> <span class="n">wrf</span><span class="p">:</span>
576            <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>
577            <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>
578                <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>
579
580            <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>
581                       <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>
582            <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>
583                <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>
584                    <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>
585
586        <span class="k">return</span>
587
588
589    <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>
590        <span class="sd">&#39;&#39;&#39;Define the parameter setting for flux data.</span>
591
592<span class="sd">        Flux data are accumulated fields in time and are stored on the</span>
593<span class="sd">        surface level. The leading short cut name for the grib files is:</span>
594<span class="sd">        &quot;OG_acc_SL&quot; with OG for Regular Output Grid, SL for Surface Level, and</span>
595<span class="sd">        acc for Accumulated Grid.</span>
596<span class="sd">        The params dictionary stores a list of parameter names, the level type,</span>
597<span class="sd">        the level list and the grid resolution.</span>
598
599<span class="sd">        The flux data are: LSP/CP/SSHF/EWSS/NSSS/SSR</span>
600
601<span class="sd">        Parameters:</span>
602<span class="sd">        -----------</span>
603
604<span class="sd">        Return</span>
605<span class="sd">        ------</span>
606
607<span class="sd">        &#39;&#39;&#39;</span>
608        <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>
609                                    <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>
610        <span class="k">return</span>
611
612
613    <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>
614        <span class="sd">&#39;&#39;&#39;Creates the filename for the requested grib data to be stored in.</span>
615<span class="sd">        This name is passed as the &quot;target&quot; parameter in the request.</span>
616
617<span class="sd">        Parameters</span>
618<span class="sd">        ----------</span>
619<span class="sd">        ftype : str</span>
620<span class="sd">            Shortcut name of the type of the field. E.g. AN, FC, PF, ...</span>
621
622<span class="sd">        param : str</span>
623<span class="sd">            Shortcut of the grid type. E.g. SH__ML, SH__SL, GG__ML,</span>
624<span class="sd">            GG__SL, OG__ML, OG__SL, OG_OROLSM_SL, OG_acc_SL</span>
625
626<span class="sd">        date : str</span>
627<span class="sd">            The date period of the grib data to be stored in this file.</span>
628
629<span class="sd">        Return</span>
630<span class="sd">        ------</span>
631<span class="sd">        targetname : str</span>
632<span class="sd">            The target filename for the grib data.</span>
633<span class="sd">        &#39;&#39;&#39;</span>
634        <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>
635                      <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>
636
637        <span class="k">return</span> <span class="n">targetname</span>
638
639
640    <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>
641        <span class="sd">&#39;&#39;&#39;Creates the Mars Retrieval and prints or submits the request</span>
642<span class="sd">        depending on the status of the request variable.</span>
643
644<span class="sd">        Parameters</span>
645<span class="sd">        ----------</span>
646<span class="sd">        request : int</span>
647<span class="sd">            Selects the mode of retrieval.</span>
648<span class="sd">            0: Retrieves the data from ECMWF.</span>
649<span class="sd">            1: Prints the mars requests to an output file.</span>
650<span class="sd">            2: Retrieves the data and prints the mars request.</span>
651
652<span class="sd">        par_dict : dictionary</span>
653<span class="sd">            Contains all parameter which have to be set for creating the</span>
654<span class="sd">            Mars Retrievals. The parameter are:</span>
655<span class="sd">            marsclass, dataset, stream, type, levtype, levelist, resol,</span>
656<span class="sd">            gaussian, accuracy, grid, target, area, date, time, number,</span>
657<span class="sd">            step, expver, param</span>
658
659<span class="sd">        Return</span>
660<span class="sd">        ------</span>
661
662<span class="sd">        &#39;&#39;&#39;</span>
663        <span class="c1"># increase number of mars requests</span>
664        <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span> <span class="o">+=</span> <span class="mi">1</span>
665
666        <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>
667                           <span class="bp">self</span><span class="o">.</span><span class="n">public</span><span class="p">,</span>
668                           <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>
669                           <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>
670                           <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>
671                           <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>
672                           <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>
673                           <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>
674                           <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>
675                           <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>
676                           <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>
677                           <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>
678                           <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>
679                           <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>
680                           <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>
681                           <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>
682                           <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>
683                           <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>
684                           <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>
685                           <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>
686
687        <span class="k">if</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
688            <span class="n">MR</span><span class="o">.</span><span class="n">display_info</span><span class="p">()</span>
689            <span class="n">MR</span><span class="o">.</span><span class="n">data_retrieve</span><span class="p">()</span>
690        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
691            <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>
692        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
693            <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>
694            <span class="n">MR</span><span class="o">.</span><span class="n">display_info</span><span class="p">()</span>
695            <span class="n">MR</span><span class="o">.</span><span class="n">data_retrieve</span><span class="p">()</span>
696        <span class="k">else</span><span class="p">:</span>
697            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Failure&#39;</span><span class="p">)</span>
698
699        <span class="k">return</span>
700
701
702    <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>
703        <span class="sd">&#39;&#39;&#39;Creates an index file for a set of grib parameter keys.</span>
704<span class="sd">        The values from the index keys are returned in a list.</span>
705
706<span class="sd">        Parameters</span>
707<span class="sd">        ----------</span>
708<span class="sd">        keys : dictionary</span>
709<span class="sd">            List of parameter names which serves as index.</span>
710
711<span class="sd">        inputfiles : UioFiles</span>
712<span class="sd">            Contains a list of files.</span>
713
714<span class="sd">        Return</span>
715<span class="sd">        ------</span>
716<span class="sd">        iid : codes_index</span>
717<span class="sd">            This is a grib specific index structure to access</span>
718<span class="sd">            messages in a file.</span>
719
720<span class="sd">        index_vals : list of list  of str</span>
721<span class="sd">            Contains the values from the keys used for a distinct selection</span>
722<span class="sd">            of grib messages in processing  the grib files.</span>
723<span class="sd">            Content looks like e.g.:</span>
724<span class="sd">            index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
725<span class="sd">            index_vals[1]: (&#39;0&#39;, &#39;1200&#39;, &#39;1800&#39;, &#39;600&#39;) ; time</span>
726<span class="sd">            index_vals[2]: (&#39;0&#39;, &#39;12&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;) ; stepRange</span>
727<span class="sd">        &#39;&#39;&#39;</span>
728        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
729        <span class="n">index_keys</span> <span class="o">=</span> <span class="n">keys</span>
730
731        <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>
732        <span class="n">silent_remove</span><span class="p">(</span><span class="n">indexfile</span><span class="p">)</span>
733        <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>
734        <span class="c1"># creates new index file</span>
735        <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>
736
737        <span class="c1"># read the values of index keys</span>
738        <span class="n">index_vals</span> <span class="o">=</span> <span class="p">[]</span>
739        <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>
740            <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>
741            <span class="c1"># have to sort the key values for correct disaggregation,</span>
742            <span class="c1"># therefore convert to int first</span>
743            <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>
744            <span class="n">key_vals</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
745            <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>
746            <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>
747            <span class="c1"># index_vals looks for example like:</span>
748            <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
749            <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;1200&#39;) ; time</span>
750            <span class="c1"># index_vals[2]: (3&#39;, &#39;6&#39;, &#39;9&#39;, &#39;12&#39;) ; stepRange</span>
751
752        <span class="k">return</span> <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span>
753
754
755<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>
756        <span class="sd">&#39;&#39;&#39;Finalizing the retrieval information by setting final details</span>
757<span class="sd">        depending on grid type.</span>
758<span class="sd">        Prepares MARS retrievals per grid type and submits them.</span>
759
760<span class="sd">        Parameters</span>
761<span class="sd">        ----------</span>
762<span class="sd">        server : ECMWFService or ECMWFDataServer</span>
763<span class="sd">            The connection to the ECMWF server. This is different</span>
764<span class="sd">            for member state users which have full access and non</span>
765<span class="sd">            member state users which have only access to the public</span>
766<span class="sd">            data sets. The decision is made from command line argument</span>
767<span class="sd">            &quot;public&quot;; for public access its True (ECMWFDataServer)</span>
768<span class="sd">            for member state users its False (ECMWFService)</span>
769
770<span class="sd">        dates : str</span>
771<span class="sd">            Contains start and end date of the retrieval in the format</span>
772<span class="sd">            &quot;YYYYMMDD/to/YYYYMMDD&quot;</span>
773
774<span class="sd">        request : int</span>
775<span class="sd">            Selects the mode of retrieval.</span>
776<span class="sd">            0: Retrieves the data from ECMWF.</span>
777<span class="sd">            1: Prints the mars requests to an output file.</span>
778<span class="sd">            2: Retrieves the data and prints the mars request.</span>
779
780<span class="sd">        inputdir : str, optional</span>
781<span class="sd">            Path to the directory where the retrieved data is about</span>
782<span class="sd">            to be stored. The default is the current directory (&#39;.&#39;).</span>
783
784<span class="sd">        Return</span>
785<span class="sd">        ------</span>
786
787<span class="sd">        &#39;&#39;&#39;</span>
788        <span class="bp">self</span><span class="o">.</span><span class="n">dates</span> <span class="o">=</span> <span class="n">dates</span>
789        <span class="bp">self</span><span class="o">.</span><span class="n">server</span> <span class="o">=</span> <span class="n">server</span>
790        <span class="bp">self</span><span class="o">.</span><span class="n">public</span> <span class="o">=</span> <span class="n">public</span>
791        <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">inputdir</span>
792        <span class="n">oro</span> <span class="o">=</span> <span class="kc">False</span>
793
794        <span class="c1"># define times with datetime module</span>
795        <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>
796        <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>
797
798        <span class="c1"># dictionary which contains all parameter for the mars request,</span>
799        <span class="c1"># entries with a &quot;None&quot; will change in different requests and will</span>
800        <span class="c1"># therefore be set in each request seperately</span>
801        <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>
802                           <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>
803                           <span class="s1">&#39;stream&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
804                           <span class="s1">&#39;type&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
805                           <span class="s1">&#39;levtype&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
806                           <span class="s1">&#39;levelist&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
807                           <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>
808                           <span class="s1">&#39;gaussian&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
809                           <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>
810                           <span class="s1">&#39;grid&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
811                           <span class="s1">&#39;target&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
812                           <span class="s1">&#39;area&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
813                           <span class="s1">&#39;date&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
814                           <span class="s1">&#39;time&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
815                           <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>
816                           <span class="s1">&#39;step&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
817                           <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>
818                           <span class="s1">&#39;param&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">}</span>
819
820        <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>
821            <span class="c1"># ftype contains field types such as</span>
822            <span class="c1">#     [AN, FC, PF, CV]</span>
823            <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>
824                <span class="c1"># pk contains one of these keys of params</span>
825                <span class="c1">#     [SH__ML, SH__SL, GG__ML, GG__SL, OG__ML, OG__SL,</span>
826                <span class="c1">#      OG_OROLSM_SL, OG_acc_SL]</span>
827                <span class="c1"># pv contains all of the items of the belonging key</span>
828                <span class="c1">#     [param, levtype, levelist, grid]</span>
829                <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>
830                    <span class="k">continue</span>
831                <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>
832                <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>
833                <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>
834                <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>
835                <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>
836                <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> \
837                    <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>
838                                        <span class="n">pk</span><span class="p">,</span>
839                                        <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>
840                <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>
841                <span class="n">ids</span> <span class="o">=</span> <span class="n">to_param_id_with_tablenumber</span><span class="p">(</span><span class="n">pv</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">table128</span><span class="p">)</span>
842                <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">ids</span>
843                <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>
844                <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>
845                <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>
846                <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>
847                <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>
848
849                <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>
850                    <span class="n">oro</span> <span class="o">=</span> <span class="kc">True</span>
851                    <span class="c1"># in CERA20C (class EP) there is no stream &quot;OPER&quot;!</span>
852                    <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>
853                        <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>
854                    <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>
855                    <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>
856                    <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>
857                    <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>
858                    <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>
859                                            <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>
860                <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>
861                    <span class="k">continue</span>
862                <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>
863                    <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>
864                    <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>
865                <span class="k">if</span> <span class="n">ftype</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;FC&#39;</span> <span class="ow">and</span> \
866                    <span class="s1">&#39;acc&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]:</span>
867                    <span class="k">if</span> <span class="p">(</span><span class="nb">int</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><span class="mi">0</span><span class="p">])</span> <span class="o">+</span>
868                        <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="mi">0</span><span class="p">]))</span> <span class="o">&gt;</span> <span class="mi">23</span><span class="p">:</span>
869                        <span class="n">dates</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>
870                        <span class="n">sdate</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">dates</span><span class="p">[</span><span class="mi">0</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>
871                        <span class="n">sdate</span> <span class="o">=</span> <span class="n">sdate</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
872                        <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>
873                            <span class="p">[</span><span class="n">sdate</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)]</span> <span class="o">+</span>
874                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">:])</span>
875
876                        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;CHANGED FC start date to &#39;</span> <span class="o">+</span>
877                              <span class="n">sdate</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span> <span class="o">+</span>
878                              <span class="s1">&#39; to accomodate TIME=&#39;</span> <span class="o">+</span>
879                              <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span>
880                              <span class="s1">&#39;, STEP=&#39;</span> <span class="o">+</span>
881                              <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
882
883    <span class="c1"># ------  on demand path  --------------------------------------------------</span>
884                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
885                    <span class="c1"># ******* start retrievement</span>
886                    <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>
887    <span class="c1"># ------  operational path  ------------------------------------------------</span>
888                <span class="k">else</span><span class="p">:</span>
889                    <span class="c1"># check if mars job requests fields beyond basetime.</span>
890                    <span class="c1"># if yes eliminate those fields since they may not</span>
891                    <span class="c1"># be accessible with user&#39;s credentials</span>
892
893                    <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>
894                    <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="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">basetime</span><span class="p">),</span>
895                                               <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
896
897                    <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="mi">12</span><span class="p">:</span>
898                        <span class="c1"># --------------  flux data ----------------------------</span>
899                        <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>
900                            <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>
901                            <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>
902                            <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>
903                                                                <span class="s1">&#39;to&#39;</span><span class="p">,</span>
904                                                                <span class="n">enddate</span><span class="p">])</span>
905
906                            <span class="c1"># ******* start retrievement</span>
907                            <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>
908
909                            <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> \
910                                <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>
911                            <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>
912                            <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> \
913                                <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>
914                                                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
915
916                            <span class="c1"># ******* start retrievement</span>
917                            <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>
918
919                        <span class="c1"># --------------  non flux data ------------------------</span>
920                        <span class="k">else</span><span class="p">:</span>
921                            <span class="c1"># ******* start retrievement</span>
922                            <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>
923
924                    <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
925                        <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> \
926                            <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>
927
928                        <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>
929
930                        <span class="k">if</span> <span class="p">(</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> <span class="ow">and</span>
931                            <span class="n">pk</span> <span class="o">!=</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span>
932                            <span class="s1">&#39;acc&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pk</span> <span class="p">)</span> <span class="p">:</span>
933                            <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>
934                            <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>
935
936                            <span class="k">while</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>
937                                <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>
938                                <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>
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;/&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">times</span><span class="p">)</span>
940                                <span class="k">else</span><span class="p">:</span>
941                                    <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>
942
943                        <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>
944                            <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>
945                            <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>
946
947                            <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> \
948                                <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>
949                            <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>
950                            <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>
951                            <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> \
952                                <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>
953                                                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
954
955                        <span class="c1"># ******* start retrievement</span>
956                        <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>
957                    <span class="k">else</span><span class="p">:</span>
958                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;ERROR: Basetime has an invalid value &#39;</span>
959                                                 <span class="s1">&#39;-&gt; </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">str</span><span class="p">(</span><span class="n">basetime</span><span class="p">)))</span>
960
961        <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>
962            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS retrieve done ... &#39;</span><span class="p">)</span>
963        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
964            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS request printed ...&#39;</span><span class="p">)</span>
965
966        <span class="k">return</span></div>
967
968
969<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>
970        <span class="sd">&#39;&#39;&#39;Creates a namelist file in the temporary directory and writes</span>
971<span class="sd">        the following values to it: maxl, maxb, mlevel,</span>
972<span class="sd">        mlevelist, mnauf, metapar, rlo0, rlo1, rla0, rla1,</span>
973<span class="sd">        momega, momegadiff, mgauss, msmooth, meta, metadiff, mdpdeta</span>
974
975<span class="sd">        Parameters</span>
976<span class="sd">        ----------</span>
977<span class="sd">        c : ControlFile</span>
978<span class="sd">            Contains all the parameters of CONTROL file and</span>
979<span class="sd">            command line.</span>
980
981<span class="sd">        filename : str</span>
982<span class="sd">                Name of the namelist file.</span>
983
984<span class="sd">        Return</span>
985<span class="sd">        ------</span>
986
987<span class="sd">        &#39;&#39;&#39;</span>
988
989        <span class="kn">from</span> <span class="nn">genshi.template.text</span> <span class="k">import</span> <span class="n">NewTextTemplate</span>
990        <span class="kn">from</span> <span class="nn">genshi.template</span> <span class="k">import</span>  <span class="n">TemplateLoader</span>
991        <span class="kn">from</span> <span class="nn">genshi.template.eval</span> <span class="k">import</span>  <span class="n">UndefinedError</span>
992
993        <span class="k">try</span><span class="p">:</span>
994            <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>
995            <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>
996                                            <span class="bp">cls</span><span class="o">=</span><span class="n">NewTextTemplate</span><span class="p">)</span>
997
998            <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>
999            <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>
1000            <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>
1001
1002            <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>
1003                <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>
1004            <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>
1005            <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>
1006
1007            <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>
1008                <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>
1009                <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>
1010                <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>
1011                <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>
1012                <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>
1013                <span class="n">metapar</span> <span class="o">=</span> <span class="s1">&#39;77&#39;</span><span class="p">,</span>
1014                <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>
1015                <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>
1016                <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>
1017                <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>
1018                <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>
1019                <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>
1020                <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>
1021                <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>
1022                <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>
1023                <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>
1024                <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>
1025            <span class="p">)</span>
1026        <span class="k">except</span> <span class="n">UndefinedError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1027            <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>
1028
1029            <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>
1030                     <span class="n">_config</span><span class="o">.</span><span class="n">TEMPFILE_NAMELIST</span><span class="p">)</span>
1031        <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1032            <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>
1033            <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>
1034
1035            <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>
1036                     <span class="n">_config</span><span class="o">.</span><span class="n">TEMPFILE_NAMELIST</span><span class="p">)</span>
1037
1038        <span class="k">try</span><span class="p">:</span>
1039            <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>
1040
1041            <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>
1042                <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>
1043        <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
1044            <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>
1045            <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>
1046
1047            <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>
1048                     <span class="n">namelistfile</span><span class="p">)</span>
1049
1050        <span class="k">return</span></div>
1051
1052
1053<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>
1054        <span class="sd">&#39;&#39;&#39;De-accumulate and disaggregate flux data.</span>
1055
1056<span class="sd">        Goes through all flux fields in ordered time and de-accumulate</span>
1057<span class="sd">        the fields. Afterwards the fields are disaggregated in time.</span>
1058<span class="sd">        Different versions of disaggregation is provided for rainfall</span>
1059<span class="sd">        data (darain, modified linear) and the surface fluxes and</span>
1060<span class="sd">        stress data (dapoly, cubic polynomial).</span>
1061
1062<span class="sd">        Parameters</span>
1063<span class="sd">        ----------</span>
1064<span class="sd">        inputfiles : UioFiles</span>
1065<span class="sd">            Contains the list of files that contain flux data.</span>
1066
1067<span class="sd">        c : ControlFile</span>
1068<span class="sd">            Contains all the parameters of CONTROL file and</span>
1069<span class="sd">            command line.</span>
1070
1071<span class="sd">        Return</span>
1072<span class="sd">        ------</span>
1073
1074<span class="sd">        &#39;&#39;&#39;</span>
1075
1076        <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>
1077        <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>
1078
1079        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
1080        <span class="n">index_vals</span> <span class="o">=</span> <span class="kc">None</span>
1081
1082        <span class="c1"># get the values of the keys which are used for distinct access</span>
1083        <span class="c1"># of grib messages via product</span>
1084        <span class="k">if</span> <span class="s1">&#39;/&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">number</span><span class="p">:</span>
1085            <span class="c1"># more than one ensemble member is selected</span>
1086            <span class="n">index_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;number&quot;</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>
1087        <span class="k">else</span><span class="p">:</span>
1088            <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>
1089        <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>
1090                                                <span class="n">inputfiles</span><span class="p">,</span>
1091                                                <span class="n">index_keys</span><span class="p">)</span>
1092        <span class="c1"># index_vals looks like e.g.:</span>
1093        <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
1094        <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;600&#39;, &#39;1200&#39;, &#39;1800&#39;) ; time</span>
1095        <span class="c1"># index_vals[2]: (&#39;0&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;, &#39;12&#39;) ; stepRange</span>
1096
1097        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span><span class="p">:</span>
1098            <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>
1099                <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>
1100                <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>
1101            <span class="k">else</span><span class="p">:</span>
1102                <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>
1103                <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>
1104                <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>
1105                <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>
1106                <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>
1107
1108            <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>
1109                                                 <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>
1110            <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>
1111                                  <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">)</span>
1112            <span class="c1"># create numpy array</span>
1113            <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>
1114            <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>
1115            <span class="n">it_lsp</span> <span class="o">=</span> <span class="mi">0</span>
1116            <span class="n">it_cp</span> <span class="o">=</span> <span class="mi">0</span>
1117            <span class="n">date_list</span> <span class="o">=</span> <span class="p">[]</span>
1118            <span class="n">step_list</span> <span class="o">=</span> <span class="p">[]</span>
1119
1120        <span class="c1"># initialize dictionaries to store values</span>
1121        <span class="n">orig_vals</span> <span class="o">=</span> <span class="p">{}</span>
1122        <span class="n">deac_vals</span> <span class="o">=</span> <span class="p">{}</span>
1123        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pars</span><span class="p">:</span>
1124            <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>
1125            <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>
1126
1127        <span class="c1"># &quot;product&quot; genereates each possible combination between the</span>
1128        <span class="c1"># values of the index keys</span>
1129        <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>
1130            <span class="c1"># e.g. prod = (&#39;20170505&#39;, &#39;0&#39;, &#39;12&#39;)</span>
1131            <span class="c1">#             (  date    ,time, step)</span>
1132
1133            <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>
1134
1135            <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>
1136                <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>
1137
1138            <span class="c1"># get first id from current product</span>
1139            <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>
1140
1141            <span class="c1"># if there is no data for this specific time combination / product</span>
1142            <span class="c1"># skip the rest of the for loop and start with next timestep/product</span>
1143            <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
1144                <span class="k">continue</span>
1145
1146            <span class="c1"># create correct timestamp from the three time informations</span>
1147            <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>
1148            <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>
1149            <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>
1150            <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>
1151            <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>
1152
1153            <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>
1154            <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>
1155            <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>
1156            <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>
1157            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
1158                <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="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">),</span>
1159                                              <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
1160            <span class="k">else</span><span class="p">:</span>
1161                <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>
1162
1163            <span class="c1"># if necessary, add ensemble member number to filename suffix</span>
1164            <span class="c1"># otherwise, add empty string</span>
1165            <span class="k">if</span> <span class="s1">&#39;number&#39;</span> <span class="ow">in</span> <span class="n">index_keys</span><span class="p">:</span>
1166                <span class="n">index_number</span> <span class="o">=</span> <span class="n">index_keys</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;number&#39;</span><span class="p">)</span>
1167                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">index_vals</span><span class="p">[</span><span class="n">index_number</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
1168                    <span class="n">numbersuffix</span> <span class="o">=</span> <span class="s1">&#39;.N</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="nb">int</span><span class="p">(</span><span class="n">prod</span><span class="p">[</span><span class="n">index_number</span><span class="p">]))</span>
1169            <span class="k">else</span><span class="p">:</span>
1170                <span class="n">numbersuffix</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
1171
1172            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1173                <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>
1174                                     <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>
1175                                     <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> <span class="o">+</span>
1176                                     <span class="n">numbersuffix</span><span class="p">)</span>
1177                <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>
1178                                     <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>
1179                                     <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> <span class="o">+</span>
1180                                     <span class="n">numbersuffix</span><span class="p">)</span>
1181                <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>
1182                                     <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>
1183                                     <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>
1184                                     <span class="n">numbersuffix</span><span class="p">)</span>
1185            <span class="k">else</span><span class="p">:</span>
1186                <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>
1187                                     <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> <span class="o">+</span> <span class="n">numbersuffix</span><span class="p">)</span>
1188                <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>
1189                                     <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> <span class="o">+</span> <span class="n">numbersuffix</span><span class="p">)</span>
1190                <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>
1191                                     <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> <span class="o">+</span> <span class="n">numbersuffix</span><span class="p">)</span>
1192
1193            <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>
1194            <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>
1195            <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>
1196            <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>
1197
1198            <span class="c1"># read message for message and store relevant data fields, where</span>
1199            <span class="c1"># data keywords are stored in pars</span>
1200            <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
1201                <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
1202                    <span class="k">break</span>
1203                <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>
1204                <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>
1205                <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>
1206                <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>
1207                <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>
1208                <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>
1209                    <span class="c1"># parameter is not a flux, find next one</span>
1210                    <span class="k">continue</span>
1211
1212                <span class="c1"># define conversion factor</span>
1213                <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>
1214                    <span class="n">fak</span> <span class="o">=</span> <span class="mf">1.</span> <span class="o">/</span> <span class="mf">1000.</span>
1215                <span class="k">else</span><span class="p">:</span>
1216                    <span class="n">fak</span> <span class="o">=</span> <span class="mf">3600.</span>
1217
1218                <span class="c1"># get parameter values and reshape</span>
1219                <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>
1220                <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>
1221
1222                <span class="c1"># save the original and accumulated values</span>
1223                <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>
1224
1225                <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>
1226                    <span class="c1"># no de-accumulation needed</span>
1227                    <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>
1228                <span class="k">else</span><span class="p">:</span>
1229                    <span class="c1"># do de-accumulation</span>
1230                    <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>
1231                        <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>
1232                         <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>
1233
1234                <span class="c1"># store precipitation if new disaggregation method is selected</span>
1235                <span class="c1"># only the exact days are needed</span>
1236                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span><span class="p">:</span>
1237                    <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>
1238                        <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>
1239                            <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>
1240                                <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>
1241                                <span class="n">step_list</span> <span class="o">=</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="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>
1244                                <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>
1245                            <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>
1246                                <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>
1247                        <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>
1248                            <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>
1249                            <span class="n">it_lsp</span> <span class="o">+=</span> <span class="mi">1</span>
1250                        <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>
1251                            <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>
1252                            <span class="n">it_cp</span> <span class="o">+=</span> <span class="mi">1</span>
1253
1254                <span class="c1"># information printout</span>
1255                <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>
1256
1257                <span class="c1"># length of deac_vals[parId] corresponds to the</span>
1258                <span class="c1"># number of time steps, max. 4 are needed for disaggegration</span>
1259                <span class="c1"># with the old and original method</span>
1260                <span class="c1"># run over all grib messages and perform</span>
1261                <span class="c1"># shifting in time</span>
1262                <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>
1263                    <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>
1264                        <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>
1265                            <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>
1266                        <span class="k">else</span><span class="p">:</span>
1267                            <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>
1268
1269                        <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> \
1270                                <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>
1271                            <span class="c1"># remove first time step in list to shift</span>
1272                            <span class="c1"># time line</span>
1273                            <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>
1274                            <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>
1275                    <span class="k">else</span><span class="p">:</span>
1276                        <span class="c1"># if the third time step is read (per parId),</span>
1277                        <span class="c1"># write out the first one as a boundary value</span>
1278                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1279                            <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>
1280                        <span class="k">else</span><span class="p">:</span>
1281                            <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>
1282
1283                    <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>
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
1286                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</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;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>
1288                        <span class="k">else</span><span class="p">:</span>
1289                            <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>
1290                            <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>
1291                            <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>
1292
1293                        <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>
1294
1295                        <span class="c1"># squeeze out information of last two steps</span>
1296                        <span class="c1"># contained in deac_vals[parId]</span>
1297                        <span class="c1"># Note that deac_vals[parId][0] has not been popped</span>
1298                        <span class="c1"># in this case</span>
1299
1300                        <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> \
1301                           <span class="n">t_dt</span> <span class="o">==</span> <span class="n">t_enddate</span><span class="p">:</span>
1302                            <span class="c1"># last step</span>
1303                            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1304                                <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>
1305                                <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>
1306                                <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>
1307                                <span class="c1">#truedatetime = t_m2dt + timedelta(hours=2*int(c.dtime))</span>
1308                                <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>
1309                            <span class="k">else</span><span class="p">:</span>
1310                                <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>
1311                                <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>
1312                                <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>
1313                                <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>
1314                                <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>
1315                                <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>
1316                                <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>
1317
1318                            <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>
1319                                <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>
1320                            <span class="k">else</span><span class="p">:</span>
1321                                <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>
1322
1323                            <span class="c1"># step before last step</span>
1324                            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1325                                <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>
1326                                <span class="c1">#truedatetime = t_m2dt + timedelta(hours=int(c.dtime))</span>
1327                                <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>
1328                                <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>
1329                            <span class="k">else</span><span class="p">:</span>
1330                                <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>
1331                                <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>
1332                                <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>
1333                                <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>
1334                                <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>
1335                                <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>
1336
1337                <span class="n">codes_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
1338
1339                <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>
1340
1341            <span class="n">f_handle</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
1342            <span class="n">g_handle</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
1343            <span class="n">h_handle</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
1344
1345        <span class="n">codes_index_release</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
1346
1347        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">rrint</span><span class="p">:</span>
1348            <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>
1349
1350            <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>
1351                                 <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>
1352
1353        <span class="k">return</span></div>
1354
1355    <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>
1356        <span class="sd">&#39;&#39;&#39;Calculates and writes out the disaggregated precipitation fields.</span>
1357
1358<span class="sd">        Disaggregation is done in time and original times are written to the</span>
1359<span class="sd">        flux files, while the additional subgrid times are written to</span>
1360<span class="sd">        extra files.</span>
1361
1362<span class="sd">        Parameters</span>
1363<span class="sd">        ----------</span>
1364<span class="sd">        ni : int</span>
1365<span class="sd">            Amount of zonal grid points.</span>
1366
1367<span class="sd">        nj : int</span>
1368<span class="sd">            Amount of meridional grid points.</span>
1369
1370<span class="sd">        nt : int</span>
1371<span class="sd">            Number of time steps.</span>
1372
1373<span class="sd">        lsp_np : numpy array of float</span>
1374<span class="sd">            The large scale precipitation fields for each time step.</span>
1375<span class="sd">            Shape (ni * nj, nt).</span>
1376
1377<span class="sd">        cp_np : numpy array of float</span>
1378<span class="sd">            The convective precipitation fields for each time step.</span>
1379<span class="sd">            Shape (ni * nj, nt).</span>
1380
1381<span class="sd">        date_list : list of datetime</span>
1382<span class="sd">            The list of dates for which the disaggregation is to be done.</span>
1383
1384<span class="sd">        step_list : list of int</span>
1385<span class="sd">            The list of steps for a single forecast time.</span>
1386<span class="sd">            Only necessary for pure forecasts.</span>
1387
1388<span class="sd">        c : ControlFile</span>
1389<span class="sd">            Contains all the parameters of CONTROL file and</span>
1390<span class="sd">            command line.</span>
1391
1392<span class="sd">        Return</span>
1393<span class="sd">        ------</span>
1394
1395<span class="sd">        &#39;&#39;&#39;</span>
1396        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... disaggregation of precipitation with new method.&#39;</span><span class="p">)</span>
1397        <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>
1398        <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>
1399
1400        <span class="c1"># do the disaggregation, but neglect the last value of the</span>
1401        <span class="c1"># time series. This one corresponds for example to 24 hour,</span>
1402        <span class="c1"># which we don&#39;t need.</span>
1403        <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>
1404            <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>
1405            <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>
1406
1407        <span class="c1"># write to grib files (full/orig times to flux file and inbetween</span>
1408        <span class="c1"># times into seperate end files)</span>
1409        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... write disaggregated precipitation to files.&#39;</span><span class="p">)</span>
1410        <span class="n">it</span> <span class="o">=</span> <span class="mi">0</span>
1411        <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>
1412            <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>
1413                <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>
1414
1415                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
1416                    <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> \
1417                                   <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>
1418                    <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> \
1419                                <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>
1420                    <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> \
1421                                <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>
1422                <span class="k">else</span><span class="p">:</span>
1423                    <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>
1424                    <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>
1425                    <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>
1426
1427                <span class="c1"># write original time step to flux file as usual</span>
1428                <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>
1429                <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>
1430                                  <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>
1431                                  <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>
1432                                  <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>
1433                                             <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>
1434                                 <span class="p">)</span>
1435                <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>
1436                                  <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>
1437                                  <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>
1438                                  <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>
1439                                             <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>
1440                                 <span class="p">)</span>
1441
1442                <span class="c1"># write first subgrid time step</span>
1443                <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>
1444                <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>
1445                                  <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>
1446                                  <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>
1447                                  <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>
1448                                             <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>
1449                                  <span class="p">)</span>
1450                <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>
1451                                  <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>
1452                                  <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>
1453                                  <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>
1454                                             <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>
1455                                 <span class="p">)</span>
1456
1457                <span class="c1"># write second subgrid time step</span>
1458                <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>
1459                <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>
1460                                  <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>
1461                                  <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>
1462                                  <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>
1463                                             <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>
1464                                 <span class="p">)</span>
1465                <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>
1466                                  <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>
1467                                  <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>
1468                                  <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>
1469                                             <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>
1470                                 <span class="p">)</span>
1471                <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>
1472        <span class="k">return</span>
1473
1474    <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>
1475        <span class="sd">&#39;&#39;&#39;Creates a grib file with a dummy message for the two precipitation</span>
1476<span class="sd">        types lsp and cp each.</span>
1477
1478<span class="sd">        Parameters</span>
1479<span class="sd">        ----------</span>
1480<span class="sd">        ifile : str</span>
1481<span class="sd">            Filename of the input file to read the grib messages from.</span>
1482
1483<span class="sd">        inputdir : str, optional</span>
1484<span class="sd">            Path to the directory where the retrieved data is stored.</span>
1485
1486<span class="sd">        Return</span>
1487<span class="sd">        ------</span>
1488
1489<span class="sd">        &#39;&#39;&#39;</span>
1490
1491        <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>
1492
1493        <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>
1494                      <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>
1495
1496        <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>
1497                      <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>
1498
1499        <span class="k">return</span>
1500
1501<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>
1502        <span class="sd">&#39;&#39;&#39;An index file will be created which depends on the combination</span>
1503<span class="sd">        of &quot;date&quot;, &quot;time&quot; and &quot;stepRange&quot; values. This is used to iterate</span>
1504<span class="sd">        over all messages in each grib file which were passed through the</span>
1505<span class="sd">        parameter &quot;inputfiles&quot; to seperate specific parameters into fort.*</span>
1506<span class="sd">        files. Afterwards the FORTRAN program is called to convert</span>
1507<span class="sd">        the data fields all to the same grid and put them in one file</span>
1508<span class="sd">        per unique time step (combination of &quot;date&quot;, &quot;time&quot; and</span>
1509<span class="sd">        &quot;stepRange&quot;).</span>
1510
1511<span class="sd">        Note</span>
1512<span class="sd">        ----</span>
1513<span class="sd">        This method is based on the ECMWF example index.py</span>
1514<span class="sd">        https://software.ecmwf.int/wiki/display/GRIB/index.py</span>
1515
1516<span class="sd">        Parameters</span>
1517<span class="sd">        ----------</span>
1518<span class="sd">        inputfiles : UioFiles</span>
1519<span class="sd">            Contains a list of files.</span>
1520
1521<span class="sd">        c : ControlFile</span>
1522<span class="sd">            Contains all the parameters of CONTROL file and</span>
1523<span class="sd">            command line.</span>
1524
1525<span class="sd">        Return</span>
1526<span class="sd">        ------</span>
1527
1528<span class="sd">        &#39;&#39;&#39;</span>
1529
1530        <span class="c1"># generate start and end timestamp of the retrieval period</span>
1531        <span class="n">start_period</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="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">[</span><span class="mi">0</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>
1532        <span class="n">start_period</span> <span class="o">=</span> <span class="n">start_period</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">step</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
1533        <span class="n">end_period</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">time</span><span class="p">[</span><span class="o">-</span><span class="mi">1</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>
1534        <span class="n">end_period</span> <span class="o">=</span> <span class="n">end_period</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">step</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
1535
1536        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
1537            <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>
1538            <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>
1539<span class="s1">                                   stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4&#39;</span><span class="p">,</span>
1540                                  <span class="n">table128</span><span class="p">)</span>
1541
1542        <span class="c1"># these numbers are indices for the temporary files &quot;fort.xx&quot;</span>
1543        <span class="c1"># which are used to seperate the grib fields to,</span>
1544        <span class="c1"># for the Fortran program input</span>
1545        <span class="c1"># 10: U,V | 11: T | 12: lnsp | 13: D | 16: sfc fields</span>
1546        <span class="c1"># 17: Q | 18: Q , gaussian| 19: w | 21: etadot | 22: clwc+ciwc</span>