pynemo_exe.py 1.97 KB
Newer Older
James Harle's avatar
James Harle committed
1 2 3 4 5 6 7
'''
Entry for the project

@author: Mr. Srikanth Nagella
'''

import sys, getopt
James Harle's avatar
2to3  
James Harle committed
8
from . import profile
James Harle's avatar
James Harle committed
9 10 11 12 13
import logging

# Logging set to info
logging.basicConfig(level=logging.INFO)
import time
thopri's avatar
thopri committed
14 15 16
from yaspin import yaspin
from yaspin.spinners import Spinners

James Harle's avatar
James Harle committed
17 18 19 20 21 22 23
def main():
    """ Main function which checks the command line parameters and
        passes them to the profile module for processing """

    setup_file = ''
    mask_gui = False
    try:
24
        opts, dummy_args = getopt.getopt(sys.argv[1:], "hs:d:g", ["help", "setup=", "download_cmems=", "mask_gui"])
James Harle's avatar
James Harle committed
25
    except getopt.GetoptError:
thopri's avatar
thopri committed
26
        print("usage: pynemo -g -s -d <namelist.bdy> ")
James Harle's avatar
James Harle committed
27 28 29 30
        sys.exit(2)

    for opt, arg in opts:
        if opt == "-h":
thopri's avatar
thopri committed
31
            print("usage: pynemo [-g] -s -d <namelist.bdy> ")
James Harle's avatar
2to3  
James Harle committed
32 33
            print("       -g (optional) will open settings editor before extracting the data")
            print("       -s <bdy filename> file to use")
thopri's avatar
thopri committed
34
            print("       -d (optional) will download CMEMS data using provided bdy file")
James Harle's avatar
James Harle committed
35 36 37
            sys.exit()
        elif opt in ("-s", "--setup"):
            setup_file = arg
thopri's avatar
thopri committed
38
        elif opt in ("-g", "--mask_gui"):
James Harle's avatar
James Harle committed
39
            mask_gui = True
thopri's avatar
thopri committed
40 41 42
        elif opt in ("-d", "--download_cmems"):
            setup_file = arg
            t0 = time.time()
43
            with yaspin(Spinners.earth, text='PyNEMO: download CMEMS data is running'):
thopri's avatar
thopri committed
44
                profile.download_cmems(setup_file)
thopri's avatar
thopri committed
45 46 47
            t1 = time.time()
            print("CMEMS download time: %s" % (t1 - t0))
            sys.exit(0)
48

James Harle's avatar
James Harle committed
49
    if setup_file == "":
James Harle's avatar
2to3  
James Harle committed
50
        print("usage: pynemo [-g] -s <namelist.bdy> ")
James Harle's avatar
James Harle committed
51 52 53 54 55
        sys.exit(2)

    #Logger
    #logger = logging.getLogger(__name__)
    t0 = time.time()
56
    with yaspin(Spinners.earth, text='PyNEMO: boundary generation is running'):
thopri's avatar
thopri committed
57
        profile.process_bdy(setup_file, mask_gui)
James Harle's avatar
James Harle committed
58
    t1 = time.time()
James Harle's avatar
2to3  
James Harle committed
59
    print("Execution Time: %s" % (t1-t0))
James Harle's avatar
James Harle committed
60 61 62
    
if __name__ == "__main__":
    main()