forked from AntSimi/py-eddy-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetwork.py
More file actions
130 lines (117 loc) · 3.98 KB
/
network.py
File metadata and controls
130 lines (117 loc) · 3.98 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
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
# -*- coding: utf-8 -*-
"""
Entry point to create and manipulate observations network
"""
import logging
from .. import EddyParser
from ..observations.network import Network, NetworkObservations
from ..observations.tracking import TrackEddiesObservations
logger = logging.getLogger("pet")
def build_network():
parser = EddyParser("Merge eddies")
parser.add_argument(
"identification_regex", help="Give an expression which will use with glob"
)
parser.add_argument("out", help="output file")
parser.add_argument(
"--window", "-w", type=int, help="Half time window to search eddy", default=1
)
parser.add_argument(
"--min-overlap",
"-p",
type=float,
help="minimum overlap area to associate observations",
default=0.2,
)
parser.add_argument(
"--minimal-area",
action="store_true",
help="If True, use intersection/little polygon, else intersection/union",
)
parser.contour_intern_arg()
parser.memory_arg()
args = parser.parse_args()
n = Network(
args.identification_regex,
window=args.window,
intern=args.intern,
memory=args.memory,
)
group = n.group_observations(
min_overlap=args.min_overlap, minimal_area=args.minimal_area
)
n.build_dataset(group).write_file(filename=args.out)
def divide_network():
parser = EddyParser("Separate path for a same group (network)")
parser.add_argument("input", help="input network file")
parser.add_argument("out", help="output file")
parser.contour_intern_arg()
parser.add_argument(
"--window", "-w", type=int, help="Half time window to search eddy", default=1
)
parser.add_argument(
"--min-overlap",
"-p",
type=float,
help="minimum overlap area to associate observations",
default=0.2,
)
parser.add_argument(
"--minimal-area",
action="store_true",
help="If True, use intersection/little polygon, else intersection/union",
)
args = parser.parse_args()
contour_name = TrackEddiesObservations.intern(args.intern, public_label=True)
e = TrackEddiesObservations.load_file(
args.input,
include_vars=("time", "track", "latitude", "longitude", *contour_name),
)
n = NetworkObservations.from_split_network(
TrackEddiesObservations.load_file(args.input, raw_data=True),
e.split_network(
intern=args.intern,
window=args.window,
min_overlap=args.min_overlap,
minimal_area=args.minimal_area,
),
)
n.write_file(filename=args.out)
def subset_network():
parser = EddyParser("Subset network")
parser.add_argument("input", help="input network file")
parser.add_argument("out", help="output file")
parser.add_argument(
"-l",
"--length",
nargs=2,
type=int,
help="Nb of days that must be covered by the network, first minimum number of day and last maximum number of day,"
"if value is negative, this bound won't be used",
)
parser.add_argument(
"--remove_dead_end",
nargs=2,
type=int,
help="Remove short dead end, first is for minimal obs number and second for minimal segment time to keep",
)
parser.add_argument(
"--remove_trash", action="store_true", help="Remove trash (network id == 0)",
)
parser.add_argument(
"-p",
"--period",
nargs=2,
type=int,
help="Start day and end day, if it's a negative value we will add to day min and add to day max,"
"if 0 it is not used",
)
args = parser.parse_args()
n = NetworkObservations.load_file(args.input, raw_data=True)
if args.length is not None:
n = n.longer_than(*args.length)
if args.remove_dead_end is not None:
n = n.remove_dead_end(*args.remove_dead_end)
if args.period is not None:
n = n.extract_with_period(args.period)
n.write_file(filename=args.out)