@@ -11,44 +11,93 @@ logger = logging.getLogger("pet")
11
11
12
12
13
13
def id_parser ():
14
- parser = EddyParser ('Eddy Subsetter' )
15
- parser .add_argument ('filename' )
16
- parser .add_argument ('filename_out' )
17
-
18
- group = parser .add_argument_group ('Extraction options' )
19
- group .add_argument ('-p' , '--period' , nargs = 2 , type = int ,
20
- help = 'Start day and end day, if it s negative value we will add to day min and add to day max, if 0 it s not use' )
21
- group .add_argument ('-l' , '--length' , nargs = 2 , type = int ,
22
- help = 'Minimal and maximal quantity of observation for one track, ones bounds could be negative, it will be not use' )
23
- group .add_argument ('-f' , '--full_path' , action = 'store_true' ,
24
- help = 'Extract path, if one obs or more are selected' )
25
- group .add_argument ('-d' , '--remove_incomplete' , action = 'store_true' ,
26
- help = 'Extract path only if all obs are selected' )
27
- group .add_argument ('--reject_virtual' , action = 'store_true' ,
28
- help = "If there are only virtual observation in selection, we don't select track" )
29
- group .add_argument ('-a' , '--area' , nargs = 4 , type = float ,
30
- metavar = ('llcrnrlon' , 'llcrnrlat' , 'urcrnrlon' , 'urcrnrlat' ),
31
- help = 'Coordinates of bounding to extract'
32
- )
33
- group .add_argument ('--direction' , choices = ['E' , 'W' , 'S' , 'N' ],
34
- help = 'Select only track which have an end point which go in this direction' )
35
- group .add_argument ('--minimal_degrees_displacement_in_direction' , type = float ,
36
- help = 'Minimal displacement in direction specified in --directio options' )
37
- group .add_argument ('--select_first_observation_in_box' , type = float ,
38
- help = 'Select only the first obs in each box for each tracks, value specified must be resolution' )
39
- group .add_argument ('--remove_var' , nargs = '+' , type = str , help = 'remove all listed variable' )
40
- group .add_argument ('--include_var' , nargs = '+' , type = str , help = 'use only listed variable, remove_var will be ignored' )
41
- group .add_argument ('-i' , '--ids' , nargs = '+' , type = int , help = 'List of tracks which will be extract' )
42
-
43
- group = parser .add_argument_group ('General options' )
44
- group .add_argument ('--sort_time' , action = 'store_true' , help = 'sort all observation with time' )
45
-
46
- parser .add_argument ('-n' , '--no_raw_mode' , action = 'store_true' ,
47
- help = 'Uncompress all data, could be create a memory error for huge file, but is safer for extern file of py eddy tracker' )
14
+ parser = EddyParser ("Eddy Subsetter" )
15
+ parser .add_argument ("filename" )
16
+ parser .add_argument ("filename_out" )
17
+
18
+ group = parser .add_argument_group ("Extraction options" )
19
+ group .add_argument (
20
+ "-p" ,
21
+ "--period" ,
22
+ nargs = 2 ,
23
+ type = int ,
24
+ help = "Start day and end day, if it s negative value we will add to day min and add to day max, if 0 it s not use" ,
25
+ )
26
+ group .add_argument (
27
+ "-l" ,
28
+ "--length" ,
29
+ nargs = 2 ,
30
+ type = int ,
31
+ help = "Minimal and maximal quantity of observation for one track, ones bounds could be negative, it will be not use" ,
32
+ )
33
+ group .add_argument (
34
+ "-f" ,
35
+ "--full_path" ,
36
+ action = "store_true" ,
37
+ help = "Extract path, if one obs or more are selected" ,
38
+ )
39
+ group .add_argument (
40
+ "-d" ,
41
+ "--remove_incomplete" ,
42
+ action = "store_true" ,
43
+ help = "Extract path only if all obs are selected" ,
44
+ )
45
+ group .add_argument (
46
+ "--reject_virtual" ,
47
+ action = "store_true" ,
48
+ help = "If there are only virtual observation in selection, we don't select track" ,
49
+ )
50
+ group .add_argument (
51
+ "-a" ,
52
+ "--area" ,
53
+ nargs = 4 ,
54
+ type = float ,
55
+ metavar = ("llcrnrlon" , "llcrnrlat" , "urcrnrlon" , "urcrnrlat" ),
56
+ help = "Coordinates of bounding to extract" ,
57
+ )
58
+ group .add_argument (
59
+ "--direction" ,
60
+ choices = ["E" , "W" , "S" , "N" ],
61
+ help = "Select only track which have an end point which go in this direction" ,
62
+ )
63
+ group .add_argument (
64
+ "--minimal_degrees_displacement_in_direction" ,
65
+ type = float ,
66
+ help = "Minimal displacement in direction specified in --directio options" ,
67
+ )
68
+ group .add_argument (
69
+ "--select_first_observation_in_box" ,
70
+ type = float ,
71
+ help = "Select only the first obs in each box for each tracks, value specified must be resolution" ,
72
+ )
73
+ group .add_argument (
74
+ "--remove_var" , nargs = "+" , type = str , help = "remove all listed variable"
75
+ )
76
+ group .add_argument (
77
+ "--include_var" ,
78
+ nargs = "+" ,
79
+ type = str ,
80
+ help = "use only listed variable, remove_var will be ignored" ,
81
+ )
82
+ group .add_argument (
83
+ "-i" , "--ids" , nargs = "+" , type = int , help = "List of tracks which will be extract"
84
+ )
85
+
86
+ group = parser .add_argument_group ("General options" )
87
+ group .add_argument (
88
+ "--sort_time" , action = "store_true" , help = "sort all observation with time"
89
+ )
90
+
91
+ parser .add_argument (
92
+ "-n" ,
93
+ "--no_raw_mode" ,
94
+ action = "store_true" ,
95
+ help = "Uncompress all data, could be create a memory error for huge file, but is safer for extern file of py eddy tracker" ,
96
+ )
48
97
return parser
49
98
50
99
51
- if __name__ == ' __main__' :
100
+ if __name__ == " __main__" :
52
101
args = id_parser ().parse_args ()
53
102
54
103
# Original dataset
@@ -69,37 +118,46 @@ if __name__ == '__main__':
69
118
70
119
# Select with a start date and end date
71
120
if args .period is not None :
72
- dataset = dataset .extract_with_period (args .period , full_path = args .full_path ,
73
- remove_incomplete = args .remove_incomplete ,
74
- reject_virtual = args .reject_virtual )
121
+ dataset = dataset .extract_with_period (
122
+ args .period ,
123
+ full_path = args .full_path ,
124
+ remove_incomplete = args .remove_incomplete ,
125
+ reject_virtual = args .reject_virtual ,
126
+ )
75
127
76
128
# Select track which go through an area
77
129
if args .area is not None :
78
- area = dict (llcrnrlon = args .area [0 ],
79
- llcrnrlat = args .area [1 ],
80
- urcrnrlon = args .area [2 ],
81
- urcrnrlat = args .area [3 ],
82
- )
83
- dataset = dataset .extract_with_area (area , full_path = args .full_path ,
84
- remove_incomplete = args .remove_incomplete ,
85
- reject_virtual = args .reject_virtual )
130
+ area = dict (
131
+ llcrnrlon = args .area [0 ],
132
+ llcrnrlat = args .area [1 ],
133
+ urcrnrlon = args .area [2 ],
134
+ urcrnrlat = args .area [3 ],
135
+ )
136
+ dataset = dataset .extract_with_area (
137
+ area ,
138
+ full_path = args .full_path ,
139
+ remove_incomplete = args .remove_incomplete ,
140
+ reject_virtual = args .reject_virtual ,
141
+ )
86
142
87
143
# Select only track which go in the direction specified
88
144
if args .direction :
89
145
if args .minimal_degrees_displacement_in_direction :
90
146
dataset = dataset .extract_in_direction (
91
- args .direction ,
92
- value = args . minimal_degrees_displacement_in_direction )
147
+ args .direction , value = args . minimal_degrees_displacement_in_direction
148
+ )
93
149
else :
94
150
dataset = dataset .extract_in_direction (args .direction )
95
151
96
152
if args .select_first_observation_in_box :
97
- dataset = dataset .extract_first_obs_in_box (res = args .select_first_observation_in_box )
153
+ dataset = dataset .extract_first_obs_in_box (
154
+ res = args .select_first_observation_in_box
155
+ )
98
156
99
157
if args .sort_time :
100
- logger .debug (' start sorting ...' )
101
- dataset .obs .sort (order = [' time' , ' lon' , ' lat' ])
102
- logger .debug (' end sorting' )
158
+ logger .debug (" start sorting ..." )
159
+ dataset .obs .sort (order = [" time" , " lon" , " lat" ])
160
+ logger .debug (" end sorting" )
103
161
104
162
# if no data, no output will be written
105
163
if len (dataset ) == 0 :
0 commit comments