22"""
33All entry point to manipulate grid
44"""
5+ from argparse import Action
56from datetime import datetime
67
78from .. import EddyParser
@@ -47,6 +48,17 @@ def grid_filtering():
4748 h .write (args .filename_out )
4849
4950
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+
5062def eddy_id (args = None ):
5163 parser = EddyParser ("Eddy Identification" )
5264 parser .add_argument ("filename" )
@@ -69,8 +81,14 @@ def eddy_id(args=None):
6981 parser .add_argument ("--unregular" , action = "store_true" , help = "if grid is unregular" )
7082 help = "Output will be wrote in zarr"
7183 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+ )
7291 args = parser .parse_args (args ) if args else parser .parse_args ()
73-
7492 date = datetime .strptime (args .datetime , "%Y%m%d" )
7593 kwargs = dict (
7694 step = args .isoline_step ,
@@ -90,7 +108,8 @@ def eddy_id(args=None):
90108 unregular = args .unregular ,
91109 cut_wavelength = args .cut_wavelength ,
92110 filter_order = args .filter_order ,
93- ** kwargs
111+ indexs = args .indexs ,
112+ ** kwargs ,
94113 )
95114 out_name = date .strftime ("%(path)s/%(sign_type)s_%Y%m%d.nc" )
96115 a .write_file (path = args .path_out , filename = out_name , zarr_flag = args .zarr )
@@ -108,10 +127,11 @@ def identification(
108127 unregular = False ,
109128 cut_wavelength = 500 ,
110129 filter_order = 1 ,
130+ indexs = None ,
111131 ** kwargs
112132):
113133 grid_class = UnRegularGridDataset if unregular else RegularGridDataset
114- grid = grid_class (filename , lon , lat )
134+ grid = grid_class (filename , lon , lat , indexs = indexs )
115135 if u == "None" and v == "None" :
116136 grid .add_uv (h )
117137 u , v = "u" , "v"
0 commit comments