Changeset ff99eae in flex_extract.git for python/MarsRetrieval.py


Ignore:
Timestamp:
Jun 1, 2018, 8:34:59 PM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
e1228f3
Parents:
ccab809
Message:

completed application of pep8 style guide and pylint investigations. added documentation almost everywhere

File:
1 moved

Legend:

Unmodified
Added
Removed
  • python/MarsRetrieval.py

    r991df6a rff99eae  
    11#!/usr/bin/env python
    22# -*- coding: utf-8 -*-
    3 #************************************************************************
    4 # TODO AP
    5 # -
    6 #************************************************************************
    73#*******************************************************************************
    84# @Author: Anne Fouilloux (University of Oslo)
     
    139#
    1410#   November 2015 - Leopold Haimberger (University of Vienna):
    15 #        - optimized displayInfo
    16 #        - optimized dataRetrieve and seperate between python and shell
     11#        - optimized display_info
     12#        - optimized data_retrieve and seperate between python and shell
    1713#          script call
    1814#
     
    3733# @Class Content:
    3834#    - __init__
    39 #    - displayInfo
    40 #    - dataRetrieve
     35#    - display_info
     36#    - data_retrieve
     37#
     38# @Class Attributes:
     39#    - server
     40#    - marsclass
     41#    - dtype
     42#    - levtype
     43#    - levelist
     44#    - repres
     45#    - date
     46#    - resol
     47#    - stream
     48#    - area
     49#    - time
     50#    - step
     51#    - expver
     52#    - number
     53#    - accuracy
     54#    - grid
     55#    - gaussian
     56#    - target
     57#    - param
    4158#
    4259#*******************************************************************************
     
    4865import os
    4966
    50 ecapi = True
    51 try:
    52     import ecmwfapi
    53 except ImportError:
    54     ecapi = False
    55 
    5667# ------------------------------------------------------------------------------
    5768# CLASS
    5869# ------------------------------------------------------------------------------
    59 class MARSretrieval:
     70class MarsRetrieval(object):
    6071    '''
    6172    Class for submitting MARS retrievals.
     
    6879    '''
    6980
    70     def __init__(self, server, marsclass = "ei", type = "", levtype = "",
    71                  levelist = "", repres = "", date = "", resol = "", stream = "",
    72                  area = "", time = "", step = "", expver = "1", number = "",
    73                  accuracy = "", grid = "", gaussian = "", target = "",
    74                  param = ""):
     81    def __init__(self, server, marsclass="ei", dtype="", levtype="",
     82                 levelist="", repres="", date="", resol="", stream="",
     83                 area="", time="", step="", expver="1", number="",
     84                 accuracy="", grid="", gaussian="", target="",
     85                 param=""):
    7586        '''
    7687        @Description:
    77             Initialises the instance of the MARSretrieval class and
     88            Initialises the instance of the MarsRetrieval class and
    7889            defines and assigns a set of the necessary retrieval parameters
    7990            for the FLEXPART input data.
     
    8495
    8596        @Input:
    86             self: instance of MARSretrieval
     97            self: instance of MarsRetrieval
    8798                For description see class documentation.
    8899
     
    96107                Default is the ERA-Interim dataset "ei".
    97108
    98             type: string, optional
     109            dtype: string, optional
    99110                Determines the type of fields to be retrieved.
    100111                Selects between observations, images or fields.
     
    275286        self.server = server
    276287        self.marsclass = marsclass
    277         self.type = type
     288        self.dtype = dtype
    278289        self.levtype = levtype
    279290        self.levelist = levelist
     
    296307
    297308
    298     def displayInfo(self):
     309    def display_info(self):
    299310        '''
    300311        @Description:
     
    302313
    303314        @Input:
    304             self: instance of MARSretrieval
     315            self: instance of MarsRetrieval
    305316                For description see class documentation.
    306317
     
    314325        # with their corresponding values
    315326        for item in attrs.items():
    316             if item[0] in ('server'):
     327            if item[0] in 'server':
    317328                pass
    318329            else:
    319                 print(item[0] + ': ' + str(item[1]))
     330                print item[0] + ': ' + str(item[1])
    320331
    321332        return
    322333
    323     def dataRetrieve(self):
     334    def data_retrieve(self):
    324335        '''
    325336        @Description:
     
    330341
    331342        @Input:
    332             self: instance of MARSretrieval
     343            self: instance of MarsRetrieval
    333344                For description see class documentation.
    334345
     
    344355        s = 'ret'
    345356        for k, v in attrs.iteritems():
    346             if k in ('server'):
     357            if k in 'server':
    347358                continue
    348359            if k == 'marsclass':
     
    360371                self.server.execute(s, target)
    361372            except:
    362                 print('MARS Request failed, \
    363                     have you already registered at apps.ecmwf.int?')
     373                print 'MARS Request failed, \
     374                    have you already registered at apps.ecmwf.int?'
    364375                raise IOError
    365376            if os.stat(target).st_size == 0:
    366                 print('MARS Request returned no data - please check request')
     377                print 'MARS Request returned no data - please check request'
    367378                raise IOError
    368379        # MARS request via extra process in shell
     
    373384                                 stderr=subprocess.PIPE, bufsize=1)
    374385            pout = p.communicate(input=s)[0]
    375             print(pout.decode())
     386            print pout.decode()
    376387
    377388            if 'Some errors reported' in pout.decode():
    378                 print('MARS Request failed - please check request')
     389                print 'MARS Request failed - please check request'
    379390                raise IOError
    380391
    381392            if os.stat(target).st_size == 0:
    382                 print('MARS Request returned no data - please check request')
     393                print 'MARS Request returned no data - please check request'
    383394                raise IOError
    384395
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG