Changeset 54a8a01 in flex_extract.git for python/prepare_flexpart.py


Ignore:
Timestamp:
Aug 31, 2018, 7:50:37 AM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
597d4d1
Parents:
e1228f3
Message:

restructuring, documentations and bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/prepare_flexpart.py

    rff99eae r54a8a01  
    11#!/usr/bin/env python
    22# -*- coding: utf-8 -*-
    3 #************************************************************************
    4 # ToDo AP
    5 # - wieso start=startm1 wenn basetime = 0 ?  wenn die fluxes nicht mehr
    6 #   relevant sind? verstehe ich nicht
    7 #************************************************************************
    83#*******************************************************************************
    94# @Author: Anne Fouilloux (University of Oslo)
     
    6257import sys
    6358import socket
     59import _config
    6460
    6561# software specific classes and modules from flex_extract
    6662from UioFiles import UioFiles
    67 from tools import interpret_args_and_control, clean_up
     63from tools import clean_up, get_cmdline_arguments, read_ecenv
    6864from EcFlexpart import EcFlexpart
    6965
     
    8177    sys.path.append(LOCAL_PYTHON_PATH)
    8278
     79
    8380# ------------------------------------------------------------------------------
    8481# FUNCTION
     
    9794        <nothing>
    9895    '''
    99     args, c = interpret_args_and_control()
    100     prepare_flexpart(args, c)
     96
     97    args = get_cmdline_arguments()
     98
     99    try:
     100        c = ControlFile(args.controlfile)
     101    except IOError:
     102        try:
     103            c = ControlFile(LOCAL_PYTHON_PATH + args.controlfile)
     104        except IOError:
     105            print 'Could not read CONTROL file "' + args.controlfile + '"'
     106            print 'Either it does not exist or its syntax is wrong.'
     107            print 'Try "' + sys.argv[0].split('/')[-1] + \
     108                  ' -h" to print usage information'
     109            sys.exit(1)
     110
     111    env_parameter = read_ecenv(c.ecmwfdatadir + 'python/ECMWF_ENV')
     112    c.assign_args_to_control(args, env_parameter)
     113    c.assign_envs_to_control(env_parameter)
     114    c.check_conditions()
     115    prepare_flexpart(args.ppid, c)
    101116
    102117    return
    103118
    104 def prepare_flexpart(args, c):
     119def prepare_flexpart(ppid, c):
    105120    '''
    106121    @Description:
     
    112127
    113128    @Input:
    114         args: instance of ArgumentParser
    115             Contains the commandline arguments from script/program call.
     129        ppid: int
     130            Contains the ppid number of the current ECMWF job. If it is called
     131            from this script, it is "None".
    116132
    117133        c: instance of class ControlFile
     
    132148    '''
    133149
    134     if not args.ppid:
     150    if not ppid:
    135151        c.ppid = str(os.getppid())
    136152    else:
    137         c.ppid = args.ppid
     153        c.ppid = ppid
    138154
    139155    c.ecapi = ecapi
     
    148164                        day=int(c.end_date[6:]))
    149165
    150     # to deaccumulate the fluxes correctly
    151     # one day ahead of the start date and
    152     # one day after the end date is needed
    153     startm1 = start - datetime.timedelta(days=1)
    154 #    endp1 = end + datetime.timedelta(days=1)
    155 
    156     # get all files with flux data to be deaccumulated
    157     inputfiles = UioFiles('*OG_acc_SL*.' + c.ppid + '.*')
    158     inputfiles.list_files(c.inputdir)
     166    # assign starting date minus 1 day
     167    # since for basetime 00 we need the 12 hours upfront
     168    # (the day before from 12 UTC to current day 00 UTC)
     169    if c.basetime == '00':
     170        start = start - datetime.timedelta(days=1)
     171
     172    print 'Prepare ' + start.strftime("%Y%m%d") + \
     173           "/to/" + end.strftime("%Y%m%d")
    159174
    160175    # create output dir if necessary
    161176    if not os.path.exists(c.outputdir):
    162177        os.makedirs(c.outputdir)
     178
     179    # get all files with flux data to be deaccumulated
     180    inputfiles = UioFiles(c.inputdir, '*OG_acc_SL*.' + c.ppid + '.*')
    163181
    164182    # deaccumulate the flux data
     
    167185    flexpart.deacc_fluxes(inputfiles, c)
    168186
    169     print 'Prepare ' + start.strftime("%Y%m%d") + \
    170           "/to/" + end.strftime("%Y%m%d")
    171 
    172187    # get a list of all files from the root inputdir
    173     inputfiles = UioFiles('????__??.*' + c.ppid + '.*')
    174     inputfiles.list_files(c.inputdir)
    175 
    176     # produce FLEXPART-ready GRIB files and
    177     # process GRIB files -
     188    inputfiles = UioFiles(c.inputdir, '????__??.*' + c.ppid + '.*')
     189
     190    # produce FLEXPART-ready GRIB files and process them -
    178191    # copy/transfer/interpolate them or make them GRIB2
    179     if c.basetime == '00':
    180         start = startm1
    181 
    182192    flexpart = EcFlexpart(c, fluxes=False)
    183193    flexpart.create(inputfiles, c)
     
    187197    # otherwise delete temporary files
    188198    if int(c.debug) != 0:
    189         print 'Temporary files left intact'
     199        print '\nTemporary files left intact'
    190200    else:
    191201        clean_up(c)
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG