forked from AntSimi/py-eddy-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEddyFinalTracking
More file actions
88 lines (69 loc) · 3.24 KB
/
EddyFinalTracking
File metadata and controls
88 lines (69 loc) · 3.24 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Track eddy with Identification file produce with EddyIdentification
"""
from py_eddy_tracker import EddyParser
from py_eddy_tracker.tracking import Correspondances
from os.path import exists
from os import mkdir
import logging
import datetime as dt
def usage():
"""Usage
"""
# Run using:
parser = EddyParser(
"Tool to use identification step to compute tracking")
parser.add_argument('nc_file',
help='File of correspondances to reload link '
'without tracking computation')
parser.add_argument('--path_out',
default='./',
help='Path, where to write file')
parser.add_argument('--eddies_long_model', default=None)
parser.add_argument('--eddies_short_model', default=None)
parser.add_argument('--eddies_untracked_model', default=None)
parser.add_argument('--nb_obs_min',
type=int,
default=28,
help='Minimal length of tracks')
return parser.parse_args()
if __name__ == '__main__':
CONFIG = usage()
# Create output directory
if not exists(CONFIG.path_out):
mkdir(CONFIG.path_out)
SAVE_DIR = CONFIG.path_out
NB_OBS_MIN = CONFIG.nb_obs_min
START_TIME = dt.datetime.now()
CORRESPONDANCES = Correspondances.load(CONFIG.nc_file)
logging.info('Start merging')
CORRESPONDANCES.prepare_merging()
logging.info('The longest tracks have %d observations', CORRESPONDANCES.nb_obs_by_tracks.max())
logging.info('The mean length is %d observations before filtering', CORRESPONDANCES.nb_obs_by_tracks.mean())
if CONFIG.eddies_untracked_model is None:
CONFIG.eddies_untracked_model = '%(path)s/%(sign_type)s_%(prod_time)s_untracked.nc'
CORRESPONDANCES.get_unused_data().write_netcdf(path=SAVE_DIR, filename=CONFIG.eddies_untracked_model)
SHORT_CORRESPONDANCES = CORRESPONDANCES._copy()
SHORT_CORRESPONDANCES.shorter_than(size_max=NB_OBS_MIN)
CORRESPONDANCES.longer_than(size_min=NB_OBS_MIN)
FINAL_EDDIES = CORRESPONDANCES.merge()
SHORT_TRACK = SHORT_CORRESPONDANCES.merge()
# We flag obs
if CORRESPONDANCES.virtual:
FINAL_EDDIES['virtual'][:] = FINAL_EDDIES['time'] == 0
FINAL_EDDIES.filled_by_interpolation(FINAL_EDDIES['virtual'] == 1)
SHORT_TRACK['virtual'][:] = SHORT_TRACK['time'] == 0
SHORT_TRACK.filled_by_interpolation(SHORT_TRACK['virtual'] == 1)
# Total running time
FULL_TIME = dt.datetime.now() - START_TIME
logging.info('Duration : %s', FULL_TIME)
logging.info('Longer track saved have %d obs', CORRESPONDANCES.nb_obs_by_tracks.max())
logging.info('The mean length is %d observations after filtering', CORRESPONDANCES.nb_obs_by_tracks.mean())
if CONFIG.eddies_long_model is None:
CONFIG.eddies_long_model = '%(path)s/%(sign_type)s_%(prod_time)s.nc'
if CONFIG.eddies_short_model is None:
CONFIG.eddies_short_model = '%(path)s/%(sign_type)s_%(prod_time)s_track_too_short.nc'
FINAL_EDDIES.write_netcdf(filename=CONFIG.eddies_long_model,path=SAVE_DIR)
SHORT_TRACK.write_netcdf(filename=CONFIG.eddies_short_model, path=SAVE_DIR)