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

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

new build of sphinx for updated api

  • Property mode set to 100644
File size: 49.0 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>MarsRetrieval &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>MarsRetrieval</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 MarsRetrieval</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">#        - optimized display_info</span>
165<span class="c1">#        - optimized data_retrieve and seperate between python and shell</span>
166<span class="c1">#          script call</span>
167<span class="c1">#</span>
168<span class="c1">#   February 2018 - Anne Philipp (University of Vienna):</span>
169<span class="c1">#        - applied PEP8 style guide</span>
170<span class="c1">#        - added documentation</span>
171<span class="c1">#        - applied some minor modifications in programming style/structure</span>
172<span class="c1">#        - added writing of mars request attributes to a csv file</span>
173<span class="c1">#</span>
174<span class="c1"># @License:</span>
175<span class="c1">#    (C) Copyright 2014-2019.</span>
176<span class="c1">#    Anne Philipp, Leopold Haimberger</span>
177<span class="c1">#</span>
178<span class="c1">#    This work is licensed under the Creative Commons Attribution 4.0</span>
179<span class="c1">#    International License. To view a copy of this license, visit</span>
180<span class="c1">#    http://creativecommons.org/licenses/by/4.0/ or send a letter to</span>
181<span class="c1">#    Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.</span>
182<span class="c1">#*******************************************************************************</span>
183
184<span class="c1"># ------------------------------------------------------------------------------</span>
185<span class="c1"># MODULES</span>
186<span class="c1"># ------------------------------------------------------------------------------</span>
187<span class="kn">import</span> <span class="nn">os</span>
188<span class="kn">import</span> <span class="nn">sys</span>
189<span class="kn">import</span> <span class="nn">subprocess</span>
190
191<span class="c1"># software specific classes and modules from flex_extract</span>
192<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>
193<span class="kn">import</span> <span class="nn">_config</span>
194<span class="c1"># ------------------------------------------------------------------------------</span>
195<span class="c1"># CLASS</span>
196<span class="c1"># ------------------------------------------------------------------------------</span>
197<div class="viewcode-block" id="MarsRetrieval"><a class="viewcode-back" href="../api.html#MarsRetrieval.MarsRetrieval">[docs]</a><span class="k">class</span> <span class="nc">MarsRetrieval</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
198    <span class="sd">&#39;&#39;&#39;Specific syntax and content for submission of MARS retrievals.</span>
199
200<span class="sd">    A MARS revtrieval has a specific syntax with a selection of keywords and</span>
201<span class="sd">    their corresponding values. This class provides the necessary functions</span>
202<span class="sd">    by displaying the selected parameters and their values and the actual</span>
203<span class="sd">    retrievement of the data through a mars request or a Python web api</span>
204<span class="sd">    interface. The initialization already expects all the keyword values.</span>
205
206<span class="sd">    A description of MARS keywords/arguments and examples of their</span>
207<span class="sd">    values can be found here:</span>
208<span class="sd">    https://software.ecmwf.int/wiki/display/UDOC/\</span>
209<span class="sd">                   Identification+keywords#Identificationkeywords-class</span>
210
211<span class="sd">    Attributes</span>
212<span class="sd">    ----------</span>
213<span class="sd">    server : ECMWFService or ECMWFDataServer</span>
214<span class="sd">        This is the connection to the ECMWF data servers.</span>
215
216<span class="sd">    public : int</span>
217<span class="sd">        Decides which Web API Server version is used.</span>
218
219<span class="sd">    marsclass : str, optional</span>
220<span class="sd">        Characterisation of dataset.</span>
221
222<span class="sd">    dataset : str, optional</span>
223<span class="sd">        For public datasets there is the specific naming and parameter</span>
224<span class="sd">        dataset which has to be used to characterize the type of</span>
225<span class="sd">        data.</span>
226
227<span class="sd">    type : str, optional</span>
228<span class="sd">        Determines the type of fields to be retrieved.</span>
229
230<span class="sd">    levtype : str, optional</span>
231<span class="sd">        Denotes type of level.</span>
232
233<span class="sd">    levelist : str, optional</span>
234<span class="sd">        Specifies the required levels.</span>
235
236<span class="sd">    repres : str, optional</span>
237<span class="sd">        Selects the representation of the archived data.</span>
238
239<span class="sd">    date : str, optional</span>
240<span class="sd">        Specifies the Analysis date, the Forecast base date or</span>
241<span class="sd">        Observations date.</span>
242
243<span class="sd">    resol : str, optional</span>
244<span class="sd">        Specifies the desired triangular truncation of retrieved data,</span>
245<span class="sd">        before carrying out any other selected post-processing.</span>
246
247<span class="sd">    stream : str, optional</span>
248<span class="sd">        Identifies the forecasting system used to generate the data.</span>
249
250<span class="sd">    area : str, optional</span>
251<span class="sd">        Specifies the desired sub-area of data to be extracted.</span>
252
253<span class="sd">    time : str, optional</span>
254<span class="sd">        Specifies the time of the data in hours and minutes.</span>
255
256<span class="sd">    step : str, optional</span>
257<span class="sd">        Specifies the forecast time step from forecast base time.</span>
258
259<span class="sd">    expver : str, optional</span>
260<span class="sd">        The version of the dataset.</span>
261
262<span class="sd">    number : str, optional</span>
263<span class="sd">        Selects the member in ensemble forecast run.</span>
264
265<span class="sd">    accuracy : str, optional</span>
266<span class="sd">        Specifies the number of bits per value to be used in the</span>
267<span class="sd">        generated GRIB coded fields.</span>
268
269<span class="sd">    grid : str, optional</span>
270<span class="sd">        Specifies the output grid which can be either a Gaussian grid</span>
271<span class="sd">        or a Latitude/Longitude grid.</span>
272
273<span class="sd">    gaussian : str, optional</span>
274<span class="sd">        This parameter is deprecated and should no longer be used.</span>
275<span class="sd">        Specifies the desired type of Gaussian grid for the output.</span>
276
277<span class="sd">    target : str, optional</span>
278<span class="sd">        Specifies a file into which data is to be written after</span>
279<span class="sd">        retrieval or manipulation.</span>
280
281<span class="sd">    param : str, optional</span>
282<span class="sd">        Specifies the meteorological parameter.</span>
283<span class="sd">    &#39;&#39;&#39;</span>
284
285    <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">server</span><span class="p">,</span> <span class="n">public</span><span class="p">,</span> <span class="n">marsclass</span><span class="o">=</span><span class="s2">&quot;ei&quot;</span><span class="p">,</span> <span class="n">dataset</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
286                 <span class="n">levtype</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">levelist</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">repres</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">date</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">resol</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
287                 <span class="n">stream</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">area</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">time</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">expver</span><span class="o">=</span><span class="s2">&quot;1&quot;</span><span class="p">,</span>
288                 <span class="n">number</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">accuracy</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">grid</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">gaussian</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
289                 <span class="n">param</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
290        <span class="sd">&#39;&#39;&#39;Initialises the instance of the MarsRetrieval class and</span>
291<span class="sd">        defines and assigns a set of the necessary retrieval parameters</span>
292<span class="sd">        for the FLEXPART input data.</span>
293<span class="sd">        A description of MARS keywords/arguments, their dependencies</span>
294<span class="sd">        on each other and examples of their values can be found here:</span>
295
296<span class="sd">        https://software.ecmwf.int/wiki/display/UDOC/MARS+keywords</span>
297
298<span class="sd">        Parameters</span>
299<span class="sd">        ----------</span>
300<span class="sd">        server : ECMWFService or ECMWFDataServer</span>
301<span class="sd">            This is the connection to the ECMWF data servers.</span>
302<span class="sd">            It is needed for the pythonic access of ECMWF data.</span>
303
304<span class="sd">        public : int</span>
305<span class="sd">            Decides which Web API version is used:</span>
306<span class="sd">            0: member-state users and full archive access</span>
307<span class="sd">            1: public access and limited access to the public server and</span>
308<span class="sd">               datasets. Needs the parameter dataset.</span>
309<span class="sd">            Default is &quot;0&quot; and for member-state users.</span>
310
311<span class="sd">        marsclass : str, optional</span>
312<span class="sd">            Characterisation of dataset. E.g. EI (ERA-Interim),</span>
313<span class="sd">            E4 (ERA40), OD (Operational archive), ea (ERA5).</span>
314<span class="sd">            Default is the ERA-Interim dataset &quot;ei&quot;.</span>
315
316<span class="sd">        dataset : str, optional</span>
317<span class="sd">            For public datasets there is the specific naming and parameter</span>
318<span class="sd">            dataset which has to be used to characterize the type of</span>
319<span class="sd">            data. Usually there is less data available, either in times,</span>
320<span class="sd">            domain or parameter.</span>
321<span class="sd">            Default is an empty string.</span>
322
323<span class="sd">        type : str, optional</span>
324<span class="sd">            Determines the type of fields to be retrieved.</span>
325<span class="sd">            Selects between observations, images or fields.</span>
326<span class="sd">            Examples for fields: Analysis (an), Forecast (fc),</span>
327<span class="sd">            Perturbed Forecast (pf), Control Forecast (cf) and so on.</span>
328<span class="sd">            Default is an empty string.</span>
329
330<span class="sd">        levtype : str, optional</span>
331<span class="sd">            Denotes type of level. Has a direct implication on valid</span>
332<span class="sd">            levelist values!</span>
333<span class="sd">            E.g. model level (ml), pressure level (pl), surface (sfc),</span>
334<span class="sd">            potential vorticity (pv), potential temperature (pt)</span>
335<span class="sd">            and depth (dp).</span>
336<span class="sd">            Default is an empty string.</span>
337
338<span class="sd">        levelist : str, optional</span>
339<span class="sd">            Specifies the required levels. It has to have a valid</span>
340<span class="sd">            correspondence to the selected levtype.</span>
341<span class="sd">            Examples: model level: 1/to/137, pressure levels: 500/to/1000</span>
342<span class="sd">            Default is an empty string.</span>
343
344<span class="sd">        repres : str, optional</span>
345<span class="sd">            Selects the representation of the archived data.</span>
346<span class="sd">            E.g. sh - spherical harmonics, gg - Gaussian grid,</span>
347<span class="sd">            ll - latitude/longitude, ...</span>
348<span class="sd">            Default is an empty string.</span>
349
350<span class="sd">        date : str, optional</span>
351<span class="sd">            Specifies the Analysis date, the Forecast base date or</span>
352<span class="sd">            Observations date. Valid formats are:</span>
353<span class="sd">            Absolute as YYYY-MM-DD or YYYYMMDD.</span>
354<span class="sd">            Default is an empty string.</span>
355
356<span class="sd">        resol : str, optional</span>
357<span class="sd">            Specifies the desired triangular truncation of retrieved data,</span>
358<span class="sd">            before carrying out any other selected post-processing.</span>
359<span class="sd">            The default is automatic truncation (auto), by which the lowest</span>
360<span class="sd">            resolution compatible with the value specified in grid is</span>
361<span class="sd">            automatically selected for the retrieval.</span>
362<span class="sd">            Users wanting to perform post-processing from full spectral</span>
363<span class="sd">            resolution should specify Archived Value (av).</span>
364<span class="sd">            The following are examples of existing resolutions found in</span>
365<span class="sd">            the archive: 63, 106, 159, 213, 255, 319, 399, 511, 799 or 1279.</span>
366<span class="sd">            This keyword has no meaning/effect if the archived data is</span>
367<span class="sd">            not in spherical harmonics representation.</span>
368<span class="sd">            The best selection can be found here:</span>
369<span class="sd">            https://software.ecmwf.int/wiki/display/UDOC/\</span>
370<span class="sd">                  Retrieve#Retrieve-Truncationbeforeinterpolation</span>
371<span class="sd">            Default is an empty string.</span>
372
373<span class="sd">        stream : str, optional</span>
374<span class="sd">            Identifies the forecasting system used to generate the data.</span>
375<span class="sd">            E.g. oper (Atmospheric model), enfo (Ensemble forecats), ...</span>
376<span class="sd">            Default is an empty string.</span>
377
378<span class="sd">        area : str, optional</span>
379<span class="sd">            Specifies the desired sub-area of data to be extracted.</span>
380<span class="sd">            Areas can be defined to wrap around the globe.</span>
381
382<span class="sd">            Latitude values must be given as signed numbers, with:</span>
383<span class="sd">                north latitudes (i.e. north of the equator)</span>
384<span class="sd">                    being positive (e.g: 40.5)</span>
385<span class="sd">                south latitutes (i.e. south of the equator)</span>
386<span class="sd">                    being negative (e.g: -50.5)</span>
387<span class="sd">            Longtitude values must be given as signed numbers, with:</span>
388<span class="sd">                east longitudes (i.e. east of the 0 degree meridian)</span>
389<span class="sd">                    being positive (e.g: 35.0)</span>
390<span class="sd">                west longitudes (i.e. west of the 0 degree meridian)</span>
391<span class="sd">                    being negative (e.g: -20.5)</span>
392
393<span class="sd">            E.g.: North/West/South/East</span>
394<span class="sd">            Default is an empty string.</span>
395
396<span class="sd">        time : str, optional</span>
397<span class="sd">            Specifies the time of the data in hours and minutes.</span>
398<span class="sd">            Valid values depend on the type of data: Analysis time,</span>
399<span class="sd">            Forecast base time or First guess verification time</span>
400<span class="sd">            (all usually at synoptic hours: 00, 06, 12 and 18 ).</span>
401<span class="sd">            Observation time (any combination in hours and minutes is valid,</span>
402<span class="sd">            subject to data availability in the archive).</span>
403<span class="sd">            The syntax is HHMM or HH:MM. If MM is omitted it defaults to 00.</span>
404<span class="sd">            Default is an empty string.</span>
405
406<span class="sd">        step : str, optional</span>
407<span class="sd">            Specifies the forecast time step from forecast base time.</span>
408<span class="sd">            Valid values are hours (HH) from forecast base time. It also</span>
409<span class="sd">            specifies the length of the forecast which verifies at</span>
410<span class="sd">            First Guess time.</span>
411<span class="sd">            E.g. 1/3/6-hourly</span>
412<span class="sd">            Default is an empty string.</span>
413
414<span class="sd">        expver : str, optional</span>
415<span class="sd">            The version of the dataset. Each experiment is assigned a</span>
416<span class="sd">            unique code (version). Production data is assigned 1 or 2,</span>
417<span class="sd">            and experimental data in Operations 11, 12 ,...</span>
418<span class="sd">            Research or Member State&#39;s experiments have a four letter</span>
419<span class="sd">            experiment identifier.</span>
420<span class="sd">            Default is &quot;1&quot;.</span>
421
422<span class="sd">        number : str, optional</span>
423<span class="sd">            Selects the member in ensemble forecast run. (Only then it</span>
424<span class="sd">            is necessary.) It has a different meaning depending on</span>
425<span class="sd">            the type of data.</span>
426<span class="sd">            E.g. Perturbed Forecasts: specifies the Ensemble forecast member</span>
427<span class="sd">            Default is an empty string.</span>
428
429<span class="sd">        accuracy : str, optional</span>
430<span class="sd">            Specifies the number of bits per value to be used in the</span>
431<span class="sd">            generated GRIB coded fields.</span>
432<span class="sd">            A positive integer may be given to specify the preferred number</span>
433<span class="sd">            of bits per packed value. This must not be greater than the</span>
434<span class="sd">            number of bits normally used for a Fortran integer on the</span>
435<span class="sd">            processor handling the request (typically 32 or 64 bit).</span>
436<span class="sd">            Within a compute request the accuracy of the original fields</span>
437<span class="sd">            can be passed to the result field by specifying accuracy=av.</span>
438<span class="sd">            Default is an empty string.</span>
439
440<span class="sd">        grid : str, optional</span>
441<span class="sd">            Specifies the output grid which can be either a Gaussian grid</span>
442<span class="sd">            or a Latitude/Longitude grid. MARS requests specifying</span>
443<span class="sd">            grid=av will return the archived model grid.</span>
444
445<span class="sd">            Lat/Lon grid: The grid spacing needs to be an integer</span>
446<span class="sd">            fraction of 90 degrees e.g. grid = 0.5/0.5</span>
447
448<span class="sd">            Gaussian grid: specified by a letter denoting the type of</span>
449<span class="sd">            Gaussian grid followed by an integer (the grid number)</span>
450<span class="sd">            representing the number of lines between the Pole and Equator,</span>
451<span class="sd">            e.g.</span>
452<span class="sd">            grid = F160 - full (or regular) Gaussian grid with</span>
453<span class="sd">                   160 latitude lines between the pole and equator</span>
454<span class="sd">            grid = N320 - ECMWF original reduced Gaussian grid with</span>
455<span class="sd">                   320 latitude lines between the pole and equator,</span>
456<span class="sd">                   see Reduced Gaussian Grids for grid numbers used at ECMWF</span>
457<span class="sd">            grid = O640 - ECMWF octahedral (reduced) Gaussian grid with</span>
458<span class="sd">                   640 latitude lines between the pole and equator</span>
459<span class="sd">            Default is an empty string.</span>
460
461<span class="sd">        gaussian : str, optional</span>
462<span class="sd">            This parameter is deprecated and should no longer be used.</span>
463<span class="sd">            Specifies the desired type of Gaussian grid for the output.</span>
464<span class="sd">            Valid Gaussian grids are quasi-regular (reduced) or regular.</span>
465<span class="sd">            Keyword gaussian can only be specified together with</span>
466<span class="sd">            keyword grid. Gaussian without grid has no effect.</span>
467<span class="sd">            Default is an empty string.</span>
468
469<span class="sd">        target : str, optional</span>
470<span class="sd">            Specifies a file into which data is to be written after</span>
471<span class="sd">            retrieval or manipulation. Path names should always be</span>
472<span class="sd">            enclosed in double quotes. The MARS client supports automatic</span>
473<span class="sd">            generation of multiple target files using MARS keywords</span>
474<span class="sd">            enclosed in square brackets [ ].  If the environment variable</span>
475<span class="sd">            MARS_MULTITARGET_STRICT_FORMAT is set to 1 before calling mars,</span>
476<span class="sd">            the keyword values will be used in the filename as shown by</span>
477<span class="sd">            the ecCodes GRIB tool grib_ls -m, e.g. with</span>
478<span class="sd">            MARS_MULTITARGET_STRICT_FORMAT set to 1 the keywords time,</span>
479<span class="sd">            expver and param will be formatted as 0600, 0001 and 129.128</span>
480<span class="sd">            rather than 600, 1 and 129.</span>
481<span class="sd">            Default is an empty string.</span>
482
483<span class="sd">        param : str, optional</span>
484<span class="sd">            Specifies the meteorological parameter.</span>
485<span class="sd">            The list of meteorological parameters in MARS is extensive.</span>
486<span class="sd">            Their availability is directly related to their meteorological</span>
487<span class="sd">            meaning and, therefore, the rest of directives specified</span>
488<span class="sd">            in the MARS request.</span>
489<span class="sd">            Meteorological parameters can be specified by their</span>
490<span class="sd">            GRIB code (param=130), their mnemonic (param=t) or</span>
491<span class="sd">            full name (param=temperature).</span>
492<span class="sd">            The list of parameter should be seperated by a &quot;/&quot;-sign.</span>
493<span class="sd">            E.g. 130/131/133</span>
494<span class="sd">            Default is an empty string.</span>
495
496<span class="sd">        Return</span>
497<span class="sd">        ------</span>
498
499<span class="sd">        &#39;&#39;&#39;</span>
500
501        <span class="bp">self</span><span class="o">.</span><span class="n">server</span> <span class="o">=</span> <span class="n">server</span>
502        <span class="bp">self</span><span class="o">.</span><span class="n">public</span> <span class="o">=</span> <span class="n">public</span>
503        <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span> <span class="o">=</span> <span class="n">marsclass</span>
504        <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span> <span class="o">=</span> <span class="n">dataset</span>
505        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="nb">type</span>
506        <span class="bp">self</span><span class="o">.</span><span class="n">levtype</span> <span class="o">=</span> <span class="n">levtype</span>
507        <span class="bp">self</span><span class="o">.</span><span class="n">levelist</span> <span class="o">=</span> <span class="n">levelist</span>
508        <span class="bp">self</span><span class="o">.</span><span class="n">repres</span> <span class="o">=</span> <span class="n">repres</span>
509        <span class="bp">self</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="n">date</span>
510        <span class="bp">self</span><span class="o">.</span><span class="n">resol</span> <span class="o">=</span> <span class="n">resol</span>
511        <span class="bp">self</span><span class="o">.</span><span class="n">stream</span> <span class="o">=</span> <span class="n">stream</span>
512        <span class="bp">self</span><span class="o">.</span><span class="n">area</span> <span class="o">=</span> <span class="n">area</span>
513        <span class="bp">self</span><span class="o">.</span><span class="n">time</span> <span class="o">=</span> <span class="n">time</span>
514        <span class="bp">self</span><span class="o">.</span><span class="n">step</span> <span class="o">=</span> <span class="n">step</span>
515        <span class="bp">self</span><span class="o">.</span><span class="n">expver</span> <span class="o">=</span> <span class="n">expver</span>
516        <span class="bp">self</span><span class="o">.</span><span class="n">number</span> <span class="o">=</span> <span class="n">number</span>
517        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span> <span class="o">=</span> <span class="n">accuracy</span>
518        <span class="bp">self</span><span class="o">.</span><span class="n">grid</span> <span class="o">=</span> <span class="n">grid</span>
519        <span class="bp">self</span><span class="o">.</span><span class="n">gaussian</span> <span class="o">=</span> <span class="n">gaussian</span>
520        <span class="bp">self</span><span class="o">.</span><span class="n">target</span> <span class="o">=</span> <span class="n">target</span>
521        <span class="bp">self</span><span class="o">.</span><span class="n">param</span> <span class="o">=</span> <span class="n">param</span>
522
523        <span class="k">return</span>
524
525
526<div class="viewcode-block" id="MarsRetrieval.display_info"><a class="viewcode-back" href="../api.html#MarsRetrieval.MarsRetrieval.display_info">[docs]</a>    <span class="k">def</span> <span class="nf">display_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
527        <span class="sd">&#39;&#39;&#39;Prints all class attributes and their values to the</span>
528<span class="sd">        standard output.</span>
529
530<span class="sd">        Parameters</span>
531<span class="sd">        ----------</span>
532
533<span class="sd">        Return</span>
534<span class="sd">        ------</span>
535
536<span class="sd">        &#39;&#39;&#39;</span>
537        <span class="c1"># Get all class attributes and their values as a dictionary</span>
538        <span class="n">attrs</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
539
540        <span class="c1"># iterate through all attributes and print them</span>
541        <span class="c1"># with their corresponding values</span>
542        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">attrs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
543            <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;server&#39;</span><span class="p">,</span> <span class="s1">&#39;public&#39;</span><span class="p">]:</span>
544                <span class="k">pass</span>
545            <span class="k">else</span><span class="p">:</span>
546                <span class="nb">print</span><span class="p">(</span><span class="n">item</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="nb">str</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
547
548        <span class="k">return</span></div>
549
550
551<div class="viewcode-block" id="MarsRetrieval.print_infodata_csv"><a class="viewcode-back" href="../api.html#MarsRetrieval.MarsRetrieval.print_infodata_csv">[docs]</a>    <span class="k">def</span> <span class="nf">print_infodata_csv</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">request_number</span><span class="p">):</span>
552        <span class="sd">&#39;&#39;&#39;Write all request parameter in alpabetical order into a &quot;csv&quot; file.</span>
553
554<span class="sd">        Parameters</span>
555<span class="sd">        ----------</span>
556<span class="sd">        inputdir : str</span>
557<span class="sd">            The path where all data from the retrievals are stored.</span>
558
559<span class="sd">        request_number : int</span>
560<span class="sd">            Number of mars requests for flux and non-flux data.</span>
561
562<span class="sd">        Return</span>
563<span class="sd">        ------</span>
564
565<span class="sd">        &#39;&#39;&#39;</span>
566
567        <span class="c1"># Get all class attributes and their values as a dictionary</span>
568        <span class="n">attrs</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
569        <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;server&#39;</span><span class="p">]</span>
570        <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;public&#39;</span><span class="p">]</span>
571
572        <span class="c1"># open a file to store all requests to</span>
573        <span class="k">with</span> <span class="nb">open</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>
574                               <span class="n">_config</span><span class="o">.</span><span class="n">FILE_MARS_REQUESTS</span><span class="p">),</span> <span class="s1">&#39;a&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
575            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">request_number</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;, &#39;</span><span class="p">)</span>
576            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">attrs</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
577                              <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">attrs</span><span class="o">.</span><span class="n">iterkeys</span><span class="p">())))</span>
578            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
579
580        <span class="k">return</span></div>
581
582<div class="viewcode-block" id="MarsRetrieval.data_retrieve"><a class="viewcode-back" href="../api.html#MarsRetrieval.MarsRetrieval.data_retrieve">[docs]</a>    <span class="k">def</span> <span class="nf">data_retrieve</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
583        <span class="sd">&#39;&#39;&#39;Submits a MARS retrieval. Depending on the existence of</span>
584<span class="sd">        ECMWF Web-API it is submitted via Python or a</span>
585<span class="sd">        subprocess in the Shell. The parameter for the mars retrieval</span>
586<span class="sd">        are taken from the defined class attributes.</span>
587
588<span class="sd">        Parameters</span>
589<span class="sd">        ----------</span>
590
591<span class="sd">        Return</span>
592<span class="sd">        ------</span>
593
594<span class="sd">        &#39;&#39;&#39;</span>
595        <span class="c1"># Get all class attributes and their values as a dictionary</span>
596        <span class="n">attrs</span> <span class="o">=</span> <span class="nb">vars</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
597
598        <span class="c1"># eliminate unnecessary attributes from the dictionary attrs</span>
599        <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;server&#39;</span><span class="p">]</span>
600        <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;public&#39;</span><span class="p">]</span>
601
602        <span class="c1"># exchange parameter name for marsclass</span>
603        <span class="n">mclass</span> <span class="o">=</span> <span class="n">attrs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;marsclass&#39;</span><span class="p">)</span>
604        <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;marsclass&#39;</span><span class="p">]</span>
605        <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;class&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mclass</span>
606
607        <span class="c1"># prepare target variable as needed for the Web API mode</span>
608        <span class="c1"># within the dictionary for full access</span>
609        <span class="c1"># as a single variable for public access</span>
610        <span class="n">target</span> <span class="o">=</span> <span class="n">attrs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;target&#39;</span><span class="p">)</span>
611        <span class="k">if</span> <span class="ow">not</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">public</span><span class="p">):</span>
612            <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span>
613        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;target: &#39;</span> <span class="o">+</span> <span class="n">target</span><span class="p">)</span>
614
615        <span class="c1"># find all keys without a value and convert all other values to strings</span>
616        <span class="n">empty_keys</span> <span class="o">=</span> <span class="p">[]</span>
617        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">attrs</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
618            <span class="k">if</span> <span class="n">value</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span><span class="p">:</span>
619                <span class="n">empty_keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
620            <span class="k">else</span><span class="p">:</span>
621                <span class="n">attrs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
622
623        <span class="c1"># delete all empty parameter from the dictionary</span>
624        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">empty_keys</span><span class="p">:</span>
625            <span class="k">del</span> <span class="n">attrs</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
626
627        <span class="c1"># MARS request via Python script</span>
628        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="p">:</span>
629            <span class="k">try</span><span class="p">:</span>
630                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">public</span><span class="p">:</span>
631                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;RETRIEVE PUBLIC DATA!&#39;</span><span class="p">)</span>
632                    <span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">retrieve</span><span class="p">(</span><span class="n">attrs</span><span class="p">)</span>
633                <span class="k">else</span><span class="p">:</span>
634                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;EXECUTE NON-PUBLIC RETRIEVAL!&#39;</span><span class="p">)</span>
635                    <span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">attrs</span><span class="p">,</span> <span class="n">target</span><span class="p">)</span>
636            <span class="k">except</span><span class="p">:</span>
637                <span class="n">e</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
638                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;ERROR: &quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
639                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS Request failed!&#39;</span><span class="p">)</span>
640                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">public</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">target</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
641                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS Request returned no data - &#39;</span>
642                          <span class="s1">&#39;please check request&#39;</span><span class="p">)</span>
643                    <span class="k">raise</span> <span class="ne">IOError</span>
644                <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">public</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">target</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
645                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Public MARS Request returned no data - &#39;</span>
646                          <span class="s1">&#39;please check request&#39;</span><span class="p">)</span>
647                    <span class="k">raise</span> <span class="ne">IOError</span>
648                <span class="k">else</span><span class="p">:</span>
649                    <span class="k">raise</span> <span class="ne">IOError</span>
650        <span class="c1"># MARS request via extra process in shell</span>
651        <span class="k">else</span><span class="p">:</span>
652            <span class="n">request_str</span> <span class="o">=</span> <span class="s1">&#39;ret&#39;</span>
653            <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">attrs</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
654                <span class="n">request_str</span> <span class="o">=</span> <span class="n">request_str</span> <span class="o">+</span> <span class="s1">&#39;,&#39;</span> <span class="o">+</span> <span class="n">key</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">value</span><span class="p">)</span>
655            <span class="n">request_str</span> <span class="o">+=</span> <span class="s1">&#39;,target=&quot;&#39;</span> <span class="o">+</span> <span class="n">target</span> <span class="o">+</span> <span class="s1">&#39;&quot;&#39;</span>
656            <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s1">&#39;mars&#39;</span><span class="p">],</span>
657                                 <span class="n">stdin</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
658                                 <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
659                                 <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
660                                 <span class="n">bufsize</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
661            <span class="n">pout</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">communicate</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">request_str</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
662            <span class="nb">print</span><span class="p">(</span><span class="n">pout</span><span class="o">.</span><span class="n">decode</span><span class="p">())</span>
663
664            <span class="k">if</span> <span class="s1">&#39;Some errors reported&#39;</span> <span class="ow">in</span> <span class="n">pout</span><span class="o">.</span><span class="n">decode</span><span class="p">():</span>
665                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS Request failed - please check request&#39;</span><span class="p">)</span>
666                <span class="k">raise</span> <span class="ne">IOError</span>
667            <span class="k">elif</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">target</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
668                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS Request returned no data - please check request&#39;</span><span class="p">)</span>
669                <span class="k">raise</span> <span class="ne">IOError</span>
670
671        <span class="k">return</span></div></div>
672</pre></div>
673
674           </div>
675           
676          </div>
677          <footer>
678 
679
680  <hr/>
681
682  <div role="contentinfo">
683    <p>
684        &copy; Copyright 2018, Anne Philipp and Leopold Haimberger
685
686    </p>
687  </div>
688  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
689
690</footer>
691
692        </div>
693      </div>
694
695    </section>
696
697  </div>
698 
699
700
701 
702
703   
704   
705      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
706        <script type="text/javascript" src="../_static/jquery.js"></script>
707        <script type="text/javascript" src="../_static/underscore.js"></script>
708        <script type="text/javascript" src="../_static/doctools.js"></script>
709   
710
711 
712
713  <script type="text/javascript" src="../_static/js/theme.js"></script>
714
715  <script type="text/javascript">
716      jQuery(function () {
717          SphinxRtdTheme.Navigation.enable(true);
718      });
719  </script> 
720
721</body>
722</html>
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG