1010
1111import argparse
1212import os
13-
13+ import json
1414import numpy as np
1515from pgamit .pyOkada import cosd , sind
1616from tqdm import tqdm
1717
1818from pgamit import dbConnection , pyETM
1919from pgamit .pyLeastSquares import adjust_lsq
2020from pgamit .Utils import (cart2euler , get_stack_stations , process_stnlist ,
21- stationID )
21+ stationID , file_write )
2222
2323
2424def build_design (hdata , vdata ):
@@ -96,7 +96,9 @@ def main():
9696 metavar = '{stack name}' ,
9797 help = '''Stack name to work with. The Euler pole
9898 will be calculated so as to fix the velocities
99- of the selected sites in this stack.''' )
99+ of the selected sites in this stack. To use PPP
100+ solutions, provide any name for this argument and
101+ pass the -ppp switch.''' )
100102
101103 parser .add_argument ('-include' , '--include_stations' , nargs = '+' , type = str ,
102104 metavar = '{net.stnm}' ,
@@ -120,6 +122,16 @@ def main():
120122 If not specified, assumed to be the
121123 production directory.''' )
122124
125+ parser .add_argument ('-ppp' , '--ppp_solutions' , action = 'store_true' ,
126+ default = False ,
127+ help = '''Use PPP solutions instead of GAMIT. The
128+ input stack name will be ignored.''' )
129+
130+ parser .add_argument ('-json' , '--save_json' , action = 'store_true' ,
131+ default = False ,
132+ help = '''Save json files for the plotted ETMs.
133+ Needs -plot to work.''' )
134+
123135 parser .add_argument ('-save' , '--save_stack' , type = str ,
124136 metavar = '{new stack name}' ,
125137 help = '''Save the time series in the plate-fixed
@@ -168,13 +180,24 @@ def main():
168180 station = stn ['StationCode' ]
169181 network = stn ['NetworkCode' ]
170182
171- rs = cnn .query_float (f'''SELECT etms.*, stations.lat, stations.lon
172- FROM etms INNER JOIN stations
173- USING ("NetworkCode", "StationCode")
174- WHERE ("NetworkCode", "StationCode", "stack",
175- "object") =
176- (\' { network } \' , \' { station } \' , \' { stack } \' ,
177- \' polynomial\' )''' , as_dict = True )
183+ if not args .ppp_solutions :
184+ # use a GAMIT stack
185+ rs = cnn .query_float (f'''SELECT etms.*, stations.lat, stations.lon
186+ FROM etms INNER JOIN stations
187+ USING ("NetworkCode", "StationCode")
188+ WHERE ("NetworkCode", "StationCode", "stack",
189+ "object") =
190+ (\' { network } \' , \' { station } \' , \' { stack } \' ,
191+ \' polynomial\' )''' , as_dict = True )
192+ else :
193+ # use PPP solutions
194+ rs = cnn .query_float (f'''SELECT etms.*, stations.lat, stations.lon
195+ FROM etms INNER JOIN stations
196+ USING ("NetworkCode", "StationCode")
197+ WHERE ("NetworkCode", "StationCode", "soln",
198+ "object") =
199+ (\' { network } \' , \' { station } \' , \' ppp\' ,
200+ \' polynomial\' )''' , as_dict = True )
178201
179202 if len (rs ):
180203 params = np .array (rs [0 ]['params' ])
@@ -193,13 +216,24 @@ def main():
193216 station = stn ['StationCode' ]
194217 network = stn ['NetworkCode' ]
195218
196- rs = cnn .query_float (f'''SELECT etms.*, stations.lat, stations.lon
197- FROM etms INNER JOIN stations
198- USING ("NetworkCode", "StationCode")
199- WHERE ("NetworkCode", "StationCode",
200- "stack", "object") =
201- (\' { network } \' , \' { station } \' , \' { stack } \' ,
202- \' polynomial\' )''' , as_dict = True )
219+ if not args .ppp_solutions :
220+ # use a GAMIT stack
221+ rs = cnn .query_float (f'''SELECT etms.*, stations.lat, stations.lon
222+ FROM etms INNER JOIN stations
223+ USING ("NetworkCode", "StationCode")
224+ WHERE ("NetworkCode", "StationCode",
225+ "stack", "object") =
226+ (\' { network } \' , \' { station } \' , \' { stack } \' ,
227+ \' polynomial\' )''' , as_dict = True )
228+ else :
229+ # use PPP solutions
230+ rs = cnn .query_float (f'''SELECT etms.*, stations.lat, stations.lon
231+ FROM etms INNER JOIN stations
232+ USING ("NetworkCode", "StationCode")
233+ WHERE ("NetworkCode", "StationCode",
234+ "soln", "object") =
235+ (\' { network } \' , \' { station } \' , \' ppp\' ,
236+ \' polynomial\' )''' , as_dict = True )
203237
204238 if len (rs ):
205239 params = np .array (rs [0 ]['params' ])
@@ -270,13 +304,11 @@ def main():
270304 tqdm .write (' -- Obs. nok : %i' % index [~ index ].shape [0 ])
271305 tqdm .write (' -- wrms : %.3f mm/yr' % (factor [0 , 0 ] * 1000. ))
272306 tqdm .write (' ==== EULER POLE SUMMARY ====' )
273- tqdm .write (''' -- XYZ (mas/yr mas/yr mas/yr) : %8.4f \xB1 %.3f %9.4f
274- \xB1 %.3f %7.4f \xB1 %.3f'''
307+ tqdm .write (''' -- XYZ (mas/yr mas/yr mas/yr) : %8.4f \xB1 %.3f %9.4f \xB1 %.3f %7.4f \xB1 %.3f'''
275308 % (C [0 , 0 ]* k , sigma [0 , 0 ]* k ,
276309 C [1 , 0 ]* k , sigma [0 , 1 ]* k ,
277310 C [2 , 0 ]* k , sigma [0 , 2 ]* k ))
278- tqdm .write (''' -- llr (deg deg deg/Myr) : %8.4f \xB1 %.3f %9.4f
279- \xB1 %.3f %7.4f \xB1 %.3f'''
311+ tqdm .write (''' -- llr (deg deg deg/Myr) : %8.4f \xB1 %.3f %9.4f \xB1 %.3f %7.4f \xB1 %.3f'''
280312 % (lat , np .rad2deg (np .sqrt (cov_lla [1 , 1 ])),
281313 lon , np .rad2deg (np .sqrt (cov_lla [2 , 2 ])),
282314 rot , np .rad2deg (np .sqrt (cov_lla [0 , 0 ])) * 1e-9 * 1e6 ))
@@ -287,15 +319,24 @@ def main():
287319 v = np .zeros ((3 , 1 ))
288320 v [0 :3 if len (vref ) > 0 else 2 ] = A @ C
289321 model = pyETM .Model (pyETM .Model .VEL , velocity = v , fit = True )
290- etm = pyETM .GamitETM (cnn , stn ['NetworkCode' ], stn ['StationCode' ],
291- stack_name = stack , models = [model ],
292- plot_remove_jumps = True )
322+
323+ if not args .ppp_solutions :
324+ etm = pyETM .GamitETM (cnn , stn ['NetworkCode' ], stn ['StationCode' ],
325+ stack_name = stack , models = [model ],
326+ plot_remove_jumps = True )
327+ else :
328+ etm = pyETM .PPPETM (cnn , stn ['NetworkCode' ], stn ['StationCode' ],
329+ models = [model ], plot_remove_jumps = True )
293330
294331 xfile = os .path .join (args .directory , '%s.%s_%s'
295332 % (etm .NetworkCode ,
296333 etm .StationCode , 'plate-fixed' ))
297334 etm .plot (xfile + '.png' , plot_missing = False )
298335
336+ if args .save_json :
337+ obj = etm .todictionary (time_series = True , model = True )
338+ file_write (xfile + '.json' , json .dumps (obj , indent = 4 , sort_keys = False ))
339+
299340 if save_stack :
300341 stations = get_stack_stations (cnn , args .stack_name [0 ])
301342
@@ -313,12 +354,19 @@ def main():
313354 v [0 :3 if len (vref ) > 0 else 2 ] = A @ C
314355 model = pyETM .Model (pyETM .Model .VEL , velocity = v , fit = True )
315356 try :
316- etm = pyETM .GamitETM (cnn ,
317- stn ['NetworkCode' ],
318- stn ['StationCode' ],
319- stack_name = stack ,
320- models = [model ],
321- plot_remove_jumps = True )
357+ if not args .ppp_solutions :
358+ etm = pyETM .GamitETM (cnn ,
359+ stn ['NetworkCode' ],
360+ stn ['StationCode' ],
361+ stack_name = stack ,
362+ models = [model ],
363+ plot_remove_jumps = True )
364+ else :
365+ etm = pyETM .PPPETM (cnn ,
366+ stn ['NetworkCode' ],
367+ stn ['StationCode' ],
368+ models = [model ],
369+ plot_remove_jumps = True )
322370
323371 tqdm .write (' -- Saving station %s to stack %s (%i/%i)'
324372 % (stationID (stn ), save_stack ,
0 commit comments