2
2
"""
3
3
All entry point to manipulate grid
4
4
"""
5
+ from argparse import Action
5
6
from datetime import datetime
6
7
7
8
from .. import EddyParser
@@ -47,6 +48,17 @@ def grid_filtering():
47
48
h .write (args .filename_out )
48
49
49
50
51
+ class DictAction (Action ):
52
+ def __call__ (self , parser , namespace , values , option_string = None ):
53
+ indexs = None
54
+ if len (values ):
55
+ indexs = dict ()
56
+ for value in values :
57
+ k , v = value .split ("=" )
58
+ indexs [k ] = int (v )
59
+ setattr (namespace , self .dest , indexs )
60
+
61
+
50
62
def eddy_id (args = None ):
51
63
parser = EddyParser ("Eddy Identification" )
52
64
parser .add_argument ("filename" )
@@ -69,8 +81,14 @@ def eddy_id(args=None):
69
81
parser .add_argument ("--unregular" , action = "store_true" , help = "if grid is unregular" )
70
82
help = "Output will be wrote in zarr"
71
83
parser .add_argument ("--zarr" , action = "store_true" , help = help )
84
+ help = "Indexs to select grid : --indexs time=2, will select third step along time dimensions"
85
+ parser .add_argument (
86
+ "--indexs" ,
87
+ nargs = "*" ,
88
+ help = help ,
89
+ action = DictAction ,
90
+ )
72
91
args = parser .parse_args (args ) if args else parser .parse_args ()
73
-
74
92
date = datetime .strptime (args .datetime , "%Y%m%d" )
75
93
kwargs = dict (
76
94
step = args .isoline_step ,
@@ -90,7 +108,8 @@ def eddy_id(args=None):
90
108
unregular = args .unregular ,
91
109
cut_wavelength = args .cut_wavelength ,
92
110
filter_order = args .filter_order ,
93
- ** kwargs
111
+ indexs = args .indexs ,
112
+ ** kwargs ,
94
113
)
95
114
out_name = date .strftime ("%(path)s/%(sign_type)s_%Y%m%d.nc" )
96
115
a .write_file (path = args .path_out , filename = out_name , zarr_flag = args .zarr )
@@ -108,10 +127,11 @@ def identification(
108
127
unregular = False ,
109
128
cut_wavelength = 500 ,
110
129
filter_order = 1 ,
130
+ indexs = None ,
111
131
** kwargs
112
132
):
113
133
grid_class = UnRegularGridDataset if unregular else RegularGridDataset
114
- grid = grid_class (filename , lon , lat )
134
+ grid = grid_class (filename , lon , lat , indexs = indexs )
115
135
if u == "None" and v == "None" :
116
136
grid .add_uv (h )
117
137
u , v = "u" , "v"
0 commit comments