forked from AntSimi/py-eddy-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEddyFinalTracking
More file actions
80 lines (62 loc) · 2.35 KB
/
EddyFinalTracking
File metadata and controls
80 lines (62 loc) · 2.35 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
#!/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
from numpy import unique
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('--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)
START_TIME = dt.datetime.now()
CORRESPONDANCES = Correspondances.load(CONFIG.nc_file)
logging.info('Start merging')
CORRESPONDANCES.prepare_merging()
FINAL_EDDIES = CORRESPONDANCES.merge()
# We flag obs
if CORRESPONDANCES.virtual:
FINAL_EDDIES['virtual'][:] = FINAL_EDDIES['time'] == 0
FINAL_EDDIES.filled_by_interpolation(FINAL_EDDIES['virtual'] == 1)
FULL_TIME = dt.datetime.now() - START_TIME
logging.info('Duration : %s', FULL_TIME)
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())
SUBSET_EDDIES = FINAL_EDDIES.extract_longer_eddies(
CONFIG.nb_obs_min,
CORRESPONDANCES.nb_obs_by_tracks.repeat(
CORRESPONDANCES.nb_obs_by_tracks)
)
logging.info('%d tracks will be saved',
len(unique(SUBSET_EDDIES['track'])))
logging.info(
'The mean length is %d observations after filtering',
CORRESPONDANCES.nb_obs_by_tracks[
CORRESPONDANCES.nb_obs_by_tracks > CONFIG.nb_obs_min
].mean())
SUBSET_EDDIES.write_netcdf(path=CONFIG.path_out)