Changeset 8209738 in flex_extract.git for Source/Python/Mods/get_mars_data.py


Ignore:
Timestamp:
May 7, 2020, 3:32:03 PM (4 years ago)
Author:
anphi <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
b936fd3
Parents:
05e9362
Message:

language corrections in comment sections and print commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Source/Python/Mods/get_mars_data.py

    r0f89116 r8209738  
    1010#    November 2015 - Leopold Haimberger (University of Vienna):
    1111#        - moved the getEIdata program into a function "get_mars_data"
    12 #        - moved the AgurmentParser into a seperate function
    13 #        - adatpted the function for the use in flex_extract
    14 #        - renamed file to get_mars_data
     12#        - moved the AgurmentParser into a separate function
     13#        - adapted the function for use in flex_extract
     14#        - renamed source file to get_mars_data
    1515#
    1616#    February 2018 - Anne Philipp (University of Vienna):
     
    2222#          online documentation)
    2323#        - use of UIFiles class for file selection and deletion
    24 #        - seperated get_mars_data function into several smaller pieces:
     24#        - separated get_mars_data function into several smaller pieces:
    2525#          write_reqheader, mk_server, mk_dates, remove_old, do_retrievment
    2626#
     
    3636#    Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
    3737#*******************************************************************************
    38 '''This script extracts MARS data from ECMWF servers.
     38'''This script extracts MARS data from ECMWF.
    3939
    4040At first, the necessary parameters from command line and CONTROL files are
     
    4444functions:
    4545
    46     * main - the main function of the script
    47     * get_mars_data - overall control of ECMWF data retrievment
     46    * main            - the main function of the script
     47    * get_mars_data   - overall control of ECMWF data retrievment
    4848    * write_reqheader - writes the header into the mars_request file
    49     * mk_server - creates the server connection to ECMWF servers
    50     * mk_dates - defines the start and end date
    51     * remove_old - deletes old retrieved grib files
    52     * do_retrievement - creates individual retrievals
    53 
    54 Type: get_mars_data.py --help
     49    * mk_server       - creates the server connection to ECMWF servers
     50    * mk_dates        - defines the start and end date
     51    * remove_old      - deletes old retrieved grib files
     52    * do_retrieval    - creates individual retrievals
     53
     54Type get_mars_data.py --help
    5555to get information about command line parameters.
    5656Read the documentation for usage instructions.
     
    6666from datetime import datetime, timedelta
    6767
    68 # software specific classes and modules from flex_extract
    69 # add path to local main python path for flex_extract to get full access
     68# software-specific classes and modules from flex_extract
     69# add path to local main Python path for flex_extract to get full access
    7070sys.path.append(os.path.dirname(os.path.abspath(
    7171    inspect.getfile(inspect.currentframe()))) + '/../')
     
    9494# ------------------------------------------------------------------------------
    9595def main():
    96     '''Controls the program to get data out of mars.
    97 
    98     This is done if it is called directly from command line.
    99     Then it also takes program call arguments and control file input.
     96    '''Controls the program to retrieve data from MARS.
     97
     98    This is done if called directly from command line.
     99    Then, arguments and control file are taken as input.
    100100
    101101    Parameters
     
    114114
    115115def get_mars_data(c):
    116     '''Retrieves the EC data needed for a FLEXPART simulation.
    117 
    118     Start and end dates for retrieval period is set. Retrievals
    119     are divided into smaller periods if necessary and datechunk parameter
     116    '''Retrieves the ECMWF data required for a FLEXPART simulation.
     117
     118    Start and end dates for retrieval period are set. Retrievals
     119    are divided into shorter periods if necessary and if datechunk parameter
    120120    is set.
    121121
     
    137137
    138138    if c.request == 0:
    139         print("Retrieving EC data!")
     139        print("Retrieving ECMWF data!")
    140140    else:
    141141        if c.request == 1:
    142             print("Printing mars requests!")
     142            print("Printing MARS requests!")
    143143        elif c.request == 2:
    144             print("Retrieving EC data and printing mars request!")
     144            print("Retrieving ECMWF data and printing MARS request!")
    145145        write_reqheader(os.path.join(c.inputdir, _config.FILE_MARS_REQUESTS))
    146146
     
    165165
    166166def write_reqheader(marsfile):
    167     '''Writes header with column names into mars request file.
     167    '''Writes header with column names into MARS request file.
    168168
    169169    Parameters
    170170    ----------
    171171    marsfile : str
    172         Path to the mars request file.
     172        Path to the MARS request file.
    173173
    174174    Return
     
    188188
    189189def mk_server(c):
    190     '''Creates a server connection with available python API.
    191 
    192     Which API is used depends on availability and the dataset to be retrieved.
    193     The CDS API is used for ERA5 dataset no matter if the user is a member or
    194     a public user. ECMWF WebAPI is used for all other available datasets.
     190    '''Creates a server connection with available Python API.
     191
     192    The API selected depends on availability and the data set to be retrieved.
     193    The CDS API is used for ERA5 data, no matter whether the user is a
     194    member-state or a public user.
     195    ECMWF WebAPI is used for all other available datasets.
    195196
    196197    Parameters
     
    247248
    248249def mk_dates(c, fluxes):
    249     '''Prepares start and end date depending on flux or non flux data.
    250 
    251     If forecast for maximum one day (upto 24h) are to be retrieved, then
     250    '''Prepares start and end date depending on flux or non-flux type of data.
     251
     252    If forecasts for a maximum of one day (24 h) are to be retrieved, then
    252253    collect accumulation data (flux data) with additional days in the
    253     beginning and at the end (used for complete disaggregation of
     254    beginning and at the end (needed for complete disaggregation of
    254255    original period)
    255256
    256     If forecast data longer than 24h are to be retrieved, then
     257    If forecast data for more than +24 h are to be retrieved, then
    257258    collect accumulation data (flux data) with the exact start and end date
    258259    (disaggregation will be done for the exact time period with
     
    314315    ----------
    315316    pattern : str
    316         The sub string pattern which identifies the files to be deleted.
     317        The substring pattern which identifies the files to be deleted.
    317318
    318319    inputdir : str, optional
    319         Path to the directory where the retrieved data is stored.
    320 
    321     Return
    322     ------
    323 
    324     '''
    325     print('... removing old content of ' + inputdir)
     320        Path to the directory where the retrieved data are stored.
     321
     322    Return
     323    ------
     324
     325    '''
     326    print('... removing old files in ' + inputdir)
    326327
    327328    tobecleaned = UioFiles(inputdir, pattern)
     
    332333
    333334def do_retrievement(c, server, start, end, delta_t, fluxes=False):
    334     '''Divides the complete retrieval period in smaller chunks and
     335    '''Divides the total retrieval period into smaller chunks and
    335336    retrieves the data from MARS.
    336337
     
    351352
    352353    delta_t : datetime
    353         Delta_t + 1 is the maximal time period of a single
    354         retrieval.
     354        Delta_t + 1 is the maximum time period of a single retrieval.
    355355
    356356    fluxes : boolean, optional
     
    365365
    366366    # since actual day also counts as one day,
    367     # we only need to add datechunk - 1 days to retrieval
    368     # for a period
     367    # we only need to add datechunk - 1 days to retrieval for a period
    369368    delta_t_m1 = delta_t - timedelta(days=1)
    370369
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG