Changeset 095dc73 in flex_extract.git for source/python/mods/tools.py
- Timestamp:
- Dec 7, 2018, 3:23:56 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- d2febd4
- Parents:
- b0cf1a6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/mods/tools.py
r97f4f4c r095dc73 55 55 import traceback 56 56 import exceptions 57 from datetime import datetime 57 58 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter 58 59 … … 117 118 formatter_class=ArgumentDefaultsHelpFormatter) 118 119 119 # the most important arguments120 # control parameters that override control file values 120 121 parser.add_argument("--start_date", dest="start_date", 121 122 type=none_or_str, default=None, … … 130 131 type=none_or_str, default='CONTROL.temp', 131 132 help="file with CONTROL parameters") 132 133 # parameter for extra output information 133 parser.add_argument("--basetime", dest="basetime", 134 type=none_or_int, default=None, 135 help="base such as 00 or 12 (for half day retrievals)") 136 parser.add_argument("--step", dest="step", 137 type=none_or_str, default=None, 138 help="steps such as 00/to/48") 139 parser.add_argument("--levelist", dest="levelist", 140 type=none_or_str, default=None, 141 help="Vertical levels to be retrieved, e.g. 30/to/60") 142 parser.add_argument("--area", dest="area", 143 type=none_or_str, default=None, 144 help="area defined as north/west/south/east") 145 146 # some switches 134 147 parser.add_argument("--debug", dest="debug", 135 148 type=none_or_int, default=None, … … 137 150 parser.add_argument("--request", dest="request", 138 151 type=none_or_int, default=None, 139 help="list all mars request in file mars_requests.dat \ 140 and skip submission to mars") 152 help="list all mars requests in file mars_requests.dat") 141 153 parser.add_argument("--public", dest="public", 142 154 type=none_or_int, default=None, 143 155 help="public mode - retrieves the public datasets") 144 145 # some arguments that override the default in the CONTROL file 146 parser.add_argument("--basetime", dest="basetime", 156 parser.add_argument("--rrint", dest="rrint", 147 157 type=none_or_int, default=None, 148 help="base such as 00 or 12 (for half day retrievals)") 149 parser.add_argument("--step", dest="step", 150 type=none_or_str, default=None, 151 help="steps such as 00/to/48") 152 parser.add_argument("--levelist", dest="levelist", 153 type=none_or_str, default=None, 154 help="Vertical levels to be retrieved, e.g. 30/to/60") 155 parser.add_argument("--area", dest="area", 156 type=none_or_str, default=None, 157 help="area defined as north/west/south/east") 158 159 # set the working directories 158 help="select old or new precipitation interpolation \ 159 0 - old method\ 160 1 - new method (additional subgrid points)") 161 162 # set directories 160 163 parser.add_argument("--inputdir", dest="inputdir", 161 164 type=none_or_str, default=None, … … 634 637 635 638 return job_id 639 640 641 def get_informations(filename): 642 '''Gets basic information from an example grib file. 643 644 These information are important for later use and the 645 initialization of numpy arrays for data storing. 646 647 Parameters 648 ---------- 649 filename : :obj:`string` 650 Name of the file which will be opened to extract basic information. 651 652 Return 653 ------ 654 data : :obj:`dictionary` 655 Contains basic informations of the ECMWF grib files, e.g. 656 'Ni', 'Nj', 'latitudeOfFirstGridPointInDegrees', 657 'longitudeOfFirstGridPointInDegrees', 'latitudeOfLastGridPointInDegrees', 658 'longitudeOfLastGridPointInDegrees', 'jDirectionIncrementInDegrees', 659 'iDirectionIncrementInDegrees', 'missingValue' 660 ''' 661 from eccodes import * 662 663 data = {} 664 665 # --- open file --- 666 print("Opening file for getting information data --- %s" % filename) 667 with open(filename) as f: 668 # load first message from file 669 gid = codes_grib_new_from_file(f) 670 671 # information needed from grib message 672 keys = [ 673 'Ni', 674 'Nj', 675 'latitudeOfFirstGridPointInDegrees', 676 'longitudeOfFirstGridPointInDegrees', 677 'latitudeOfLastGridPointInDegrees', 678 'longitudeOfLastGridPointInDegrees', 679 'jDirectionIncrementInDegrees', 680 'iDirectionIncrementInDegrees', 681 'missingValue', 682 ] 683 684 print('\nInformations are: ') 685 for key in keys: 686 # Get the value of the key in a grib message. 687 data[key] = codes_get(gid,key) 688 print("%s = %s" % (key,data[key])) 689 690 # Free the memory for the message referred as gribid. 691 codes_release(gid) 692 693 return data 694 695 696 def get_dimensions(c, info): 697 '''This function specifies the correct dimensions for x, y and t. 698 699 Parameters 700 ---------- 701 c : :obj:`ControlFile` 702 Contains all the parameters of CONTROL file and 703 command line. 704 705 info : :obj:`dictionary` 706 Contains basic informations of the ECMWF grib files, e.g. 707 'Ni', 'Nj', 'latitudeOfFirstGridPointInDegrees', 708 'longitudeOfFirstGridPointInDegrees', 'latitudeOfLastGridPointInDegrees', 709 'longitudeOfLastGridPointInDegrees', 'jDirectionIncrementInDegrees', 710 'iDirectionIncrementInDegrees', 'missingValue' 711 712 Return 713 ------ 714 (ix, jy, it) : :obj:`tuple` of :obj:`integer` 715 Dimension in x-direction, y-direction and in time. 716 ''' 717 718 ix = info['Ni'] 719 720 jy = info['Nj'] 721 722 start = datetime.strptime(c.start_date, '%Y%m%d') 723 end = datetime.strptime(c.end_date, '%Y%m%d') 724 it = ((end - start).days + 1) * 24/int(c.dtime) 725 print 'it', it, (end - start).days, 24/int(c.dtime) 726 727 return (ix, jy, it)
Note: See TracChangeset
for help on using the changeset viewer.