forked from ecjoliver/eddyTracking
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eddytrackwrap.py
132 lines (107 loc) · 7.46 KB
/
eddytrackwrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Author: Christopher Bull.
# Affiliation: Climate Change Research Centre and ARC Centre of Excellence for Climate System Science.
# Level 4, Mathews Building
# University of New South Wales
# Sydney, NSW, Australia, 2052
# Contact: [email protected]
# www: christopherbull.com.au
# Date created: Tue, 08 Dec 2015 11:53:37
# Machine created on: ccrc165
#
"""
Main function to automate NEMO eddy tracking for the following files:
./eddy_detection.py
./eddy_tracking.py
Interface is by command line.
Usage:
eddytrackwrap.py -h
eddytrackwrap.py RUN RES DT PATHROOT DATA_DIR PLOT_DIR [--mc MCORE --track]
Options:
-h,--help : show this help message
RUN : Run Name
RES : run horizontal resolution of SSH field [degrees]
DT : Sample rate of detected eddies [days]
PATHROOT : path to data
DATA_DIR : path to put all our working data in
PLOT_DIR : path to put all our plots in
--mc MCORE : str with 'corenumber'+'_'+'number-of-cores' (corenumber starts at zero)
--track : track eddies (having completed detection) in multi-core mode
Notes:
Will determine the number of time steps (T) automatically!
Example:
python eddytrackwrap.py 'cb_NEMO' 0.25 1 '/srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24_ERAI01/' ./ ./
python eddytrackwrap.py 'cb_NEMO' 0.25 1 /home/chris/codescratch/mkmov/ ./ ./
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24_ERAI01/plots/
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24_ERAI01b/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24_ERAI01b/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24_ERAI01b/plots/
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24REALNONZ500_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24REALNONZ500_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24REALNONZ500_ERAI01/plots/
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24REALNONZ80_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24REALNONZ80_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24REALNONZ80_ERAI01/plots/
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24FBCTRL_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24FBCTRL_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24FBCTRL_ERAI01/plots/
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24FBNONZ4000_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24FBNONZ4000_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24FBNONZ4000_ERAI01/plots/
python /home/z3457920/hdrive/repos/nemo_analysis/diagnostics/eddytracking/eddytrackwrap.py 'cb_NEMO' 0.25 1 /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/nemo_cordex24SLGEOV1_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24SLGEOV1_ERAI01/ /srv/ccrc/data42/z3457920/20151012_eac_sep_dynamics/analysis/eddy_tracking/nemo_cordex24SLGEOV1_ERAI01/plots/
"""
#see: https://github.com/docopt/docopt
#round brackets mean required square are optional
#download docopt from...
#https://raw.githubusercontent.com/docopt/docopt/master/docopt.py
from docopt import docopt
# import tempfile
# workingfol=tempfile.mkdtemp()+'/'
import subprocess
import pickle
#just so we can find the number of time steps our NEMO experiment has
from eddy_functions import raw_nemo_globber_specifytpe
#is this needed?
import pandas as pd
import os
def mkdir(p):
"""make directory of path that is passed"""
import os
try:
os.makedirs(p)
print "output folder: "+p+ " does not exist, we will make one."
except OSError as exc: # Python >2.5
import errno
if exc.errno == errno.EEXIST and os.path.isdir(p):
pass
else: raise
def find_T(path_to_experiment):
"""function to find the number of time steps for a NEMO experiment, as files contain different numbers of time steps.
:path_to_experiment: path to experiment that was passed into this file
:returns: number of time steps (int dtype)
"""
return len(raw_nemo_globber_specifytpe(path_to_experiment,return_dates=True))
pass
arguments = docopt(__doc__)
if __name__ == "__main__":
print "Running Eddy Tracker in arg passing mode!"
#read in/process arguments
print arguments
# import pdb; pdb.set_trace()
workingfolder=arguments['DATA_DIR']
print "Creating/checking we have output dirs."
mkdir(arguments['DATA_DIR'])
mkdir(arguments['PLOT_DIR'])
#change dtype from string
arguments['DT']=float(arguments['DT'])
arguments['RES']=float(arguments['RES'])
#grab the number of time steps we'll be cycling through
arguments['T']=find_T(arguments['PATHROOT'])
#Save a dictionary into a pickle file.
pickle.dump( arguments, open( workingfolder+'pickleargs.p', "wb" ) )
print "dumping arguments into pickle here: "+workingfolder+'pickleargs.p'
if arguments['--mc'] is not None:
print "Running Eddy Tracker in multi_core mode!"
# corenum=arguments['--mc'].split('_')[0]
# coretotal=arguments['--mc'].split('_')[1]
# print corenum, coretotal
subprocess.call('python '+os.path.dirname(os.path.realpath(__file__))+ '/eddy_detection.py --cli '+workingfolder+'pickleargs.p'+\
' --mc ' + arguments['--mc']\
,shell=True)
elif arguments['--track']:
print "Running Eddy Tracker in multi_core mode! We are tracking... (already done detection)"
subprocess.call('python '+os.path.dirname(os.path.realpath(__file__))+ '/eddy_tracking.py --cli '+workingfolder+'pickleargs.p --track',shell=True)
else:
print "executing: "+'python '+os.path.dirname(os.path.realpath(__file__))+ '/eddy_detection.py --cli '+workingfolder+'pickleargs.p'
subprocess.call('python '+os.path.dirname(os.path.realpath(__file__))+ '/eddy_detection.py --cli '+workingfolder+'pickleargs.p',shell=True)
print "executing: "+'python '+os.path.dirname(os.path.realpath(__file__))+ '/eddy_tracking.py --cli '+workingfolder+'pickleargs.p'
subprocess.call('python '+os.path.dirname(os.path.realpath(__file__))+ '/eddy_tracking.py --cli '+workingfolder+'pickleargs.p',shell=True)