11import sys
22import time
3+ import json
34from sliderule import icesat2
45
56#
@@ -17,20 +18,31 @@ def parse_command_line(args, cfg):
1718 for entry in cfg :
1819 if args [i ] == '--' + entry :
1920 if type (cfg [entry ]) is str or cfg [entry ] == None :
20- cfg [entry ] = args [i + 1 ]
21+ if args [i + 1 ] == "None" :
22+ cfg [entry ] = None
23+ else :
24+ cfg [entry ] = args [i + 1 ]
2125 elif type (cfg [entry ]) is list :
22- l = []
23- while (i + 1 ) < len (args ) and '--' not in args [i + 1 ]:
24- if args [i + 1 ].isnumeric ():
25- l .append (int (args [i + 1 ]))
26- else :
27- l .append (args [i + 1 ])
28- i += 1
29- cfg [entry ] = l
26+ if args [i + 1 ] == "None" :
27+ cfg [entry ] = None
28+ else :
29+ l = []
30+ while (i + 1 ) < len (args ) and '--' not in args [i + 1 ]:
31+ if args [i + 1 ].isnumeric ():
32+ l .append (int (args [i + 1 ]))
33+ else :
34+ l .append (args [i + 1 ])
35+ i += 1
36+ cfg [entry ] = l
3037 elif type (cfg [entry ]) is int :
31- cfg [entry ] = int (args [i + 1 ])
38+ if args [i + 1 ] == "None" :
39+ cfg [entry ] = None
40+ else :
41+ cfg [entry ] = int (args [i + 1 ])
3242 elif type (cfg [entry ]) is bool :
33- if args [i + 1 ] == "True" or args [i + 1 ] == "true" :
43+ if args [i + 1 ] == "None" :
44+ cfg [entry ] = None
45+ elif args [i + 1 ] == "True" or args [i + 1 ] == "true" :
3446 cfg [entry ] = True
3547 elif args [i + 1 ] == "False" or args [i + 1 ] == "false" :
3648 cfg [entry ] = False
@@ -61,21 +73,21 @@ def initialize_client(args):
6173 "atl03_geo_fields" : [],
6274 "atl03_ph_fields" : [],
6375 "profile" : True ,
64- "verbose" : True
76+ "verbose" : True ,
77+ "timeout" : 0 ,
78+ "rqst-timeout" : 0 ,
79+ "node-timeout" : 0 ,
80+ "read-timeout" : 0
6581 }
6682
6783 # Parse Configuration Parameters
6884 parse_command_line (args , cfg )
6985
70- # Region of Interest
71- region = icesat2 .toregion (cfg ["region" ])
72-
7386 # Configure SlideRule
7487 icesat2 .init (cfg ["url" ], cfg ["verbose" ], organization = cfg ["organization" ])
7588
7689 # Build Initial Parameters
7790 parms = {
78- "poly" : region ['poly' ],
7991 "srt" : cfg ['srt' ],
8092 "cnf" : cfg ['cnf' ],
8193 "ats" : cfg ['ats' ],
@@ -85,9 +97,12 @@ def initialize_client(args):
8597 "maxi" : cfg ['maxi' ],
8698 }
8799
88- # Add Raster
89- if cfg ["raster" ]:
90- parms ["raster" ] = region ['raster' ]
100+ # Region of Interest
101+ if cfg ["region" ]:
102+ region = icesat2 .toregion (cfg ["region" ])
103+ parms ["poly" ] = region ['poly' ]
104+ if cfg ["raster" ]:
105+ parms ["raster" ] = region ['raster' ]
91106
92107 # Add Ancillary Fields
93108 if len (cfg ['atl03_geo_fields' ]) > 0 :
@@ -99,6 +114,19 @@ def initialize_client(args):
99114 if len (cfg ['atl08_class' ]) > 0 :
100115 parms ['atl08_class' ] = cfg ['atl08_class' ]
101116
117+ # Provide Timeouts
118+ if cfg ["timeout" ] > 0 :
119+ parms ["timeout" ] = cfg ["timeout" ]
120+ parms ["rqst-timeout" ] = cfg ["timeout" ]
121+ parms ["node-timeout" ] = cfg ["timeout" ]
122+ parms ["read-timeout" ] = cfg ["timeout" ]
123+ if cfg ["rqst-timeout" ] > 0 :
124+ parms ["rqst-timeout" ] = cfg ["rqst-timeout" ]
125+ if cfg ["node-timeout" ] > 0 :
126+ parms ["node-timeout" ] = cfg ["node-timeout" ]
127+ if cfg ["read-timeout" ] > 0 :
128+ parms ["read-timeout" ] = cfg ["read-timeout" ]
129+
102130 # Latch Start Time
103131 tstart = time .perf_counter ()
104132
@@ -124,4 +152,10 @@ def display_statistics(gdf, name):
124152
125153 print ("\n Timing Profiles" )
126154 for key in icesat2 .profiles :
127- print ("{:16}: {:.6f} secs" .format (key , icesat2 .profiles [key ]))
155+ print ("{:16}: {:.6f} secs" .format (key , icesat2 .profiles [key ]))
156+
157+ #
158+ # Pretty Print JSON
159+ #
160+ def pprint (obj ):
161+ print (json .dumps (obj , indent = 2 ))
0 commit comments