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

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

deleted jobscripts for tracking and updated Sphinx doc

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