meteortools.rmsutils.pickleToKml
1# Copyright (C) 2018-2023 Mark McIntyre 2import numpy as np 3import json 4import os 5import pandas as pd 6import matplotlib.pyplot as plt 7 8from ..fileformats import trackCsvtoKML 9try: 10 from wmpl.Utils.Pickling import loadPickle 11except: 12 print('WMPL not available') 13 14 15def pickleToKml(picklename, outdir=None): 16 """Create a KML file of the trajectory in a solution pickle 17 18 Arguments: 19 picklename: [string] full path to the solution pickle file 20 21 Keyword Args: 22 outdir: [string] where to save the KML. Default same place as pickle. 23 24 Returns: 25 the KML file as a tuple 26 """ 27 pickpath, trajname = os.path.split(picklename) 28 data = loadPickle(pickpath, trajname).toJson() 29 jsd = json.loads(data) 30 lats = [] 31 lons = [] 32 hts = [] 33 times = [] 34 for js in jsd['observations']: 35 k = list(js.keys())[0] 36 thisstat = js[k] 37 lats += thisstat['model_lat'] 38 lons += thisstat['model_lon'] 39 hts += thisstat['model_ht'] 40 times += thisstat['time_data'] 41 df = pd.DataFrame({"lats": np.degrees(lats), "lons": np.degrees(lons), "alts": hts, "times": times}) 42 df = df.sort_values(by=['times', 'lats']) 43 os.makedirs(outdir, exist_ok=True) 44 return trackCsvtoKML(trajname.replace('.pickle', 'csv'), df, saveOutput=True, outdir=outdir) 45 46 47def pickleTo2dTrack(picklename, outdir=None): 48 """Create a 2d graph of the trajectory in a solution pickle 49 50 Arguments: 51 picklename: [string] full path to the solution pickle file 52 53 Keyword Args: 54 outdir: [string] where to save the plot. Default same place as pickle. 55 56 Returns: 57 none 58 """ 59 pickpath, trajname = os.path.split(picklename) 60 data = loadPickle(pickpath, trajname).toJson() 61 jsd = json.loads(data) 62 alts = [] 63 times = [] 64 rngs = [] 65 for js in jsd['observations']: 66 k = list(js.keys())[0] 67 thisstat = js[k] 68 alts += thisstat['model_ht'] 69 times += thisstat['time_data'] 70 rngs += thisstat['model_range'] 71 72 plt.clf() 73 fig = plt.gcf() 74 fig.set_size_inches(11.6, 8.26) 75 76 plt.plot(times, alts, linewidth=2) 77 ax = plt.gca() 78 ax.set(xlabel="Time(s)", ylabel="Altitude (m)") 79 #print(min(alts), max(alts)) 80 ax.set_ylim(bottom = min(min(alts), 25000), top=max(max(alts), 120000)) 81 orig, fname = os.path.split(picklename) 82 if outdir is None: 83 outdir = orig 84 fname = fname.replace('.pickle', '_2dtrack.png') 85 f3dname = os.path.join(outdir, fname) 86 87 plt.title('Trajectory of {}'.format(fname[:15])) 88 plt.tight_layout() 89 plt.savefig(f3dname, dpi=200) 90 plt.close() 91 92 plt.clf() 93 fig = plt.gcf() 94 fig.set_size_inches(11.6, 8.26) 95 96 plt.plot(rngs, alts, linewidth=2) 97 ax = plt.gca() 98 ax.set(xlabel="Range (m)", ylabel="Altitude (m)") 99 #print(min(alts), max(alts)) 100 ax.set_ylim(bottom = min(min(alts), 25000), top=max(max(alts), 120000)) 101 orig, fname = os.path.split(picklename) 102 if outdir is None: 103 outdir = orig 104 fname = fname.replace('.pickle', '_2drange.png') 105 f3dname = os.path.join(outdir, fname) 106 107 plt.title('Trajectory of {}'.format(fname[:15])) 108 plt.tight_layout() 109 plt.savefig(f3dname, dpi=200) 110 plt.close() 111 return
def
pickleToKml(picklename, outdir=None):
16def pickleToKml(picklename, outdir=None): 17 """Create a KML file of the trajectory in a solution pickle 18 19 Arguments: 20 picklename: [string] full path to the solution pickle file 21 22 Keyword Args: 23 outdir: [string] where to save the KML. Default same place as pickle. 24 25 Returns: 26 the KML file as a tuple 27 """ 28 pickpath, trajname = os.path.split(picklename) 29 data = loadPickle(pickpath, trajname).toJson() 30 jsd = json.loads(data) 31 lats = [] 32 lons = [] 33 hts = [] 34 times = [] 35 for js in jsd['observations']: 36 k = list(js.keys())[0] 37 thisstat = js[k] 38 lats += thisstat['model_lat'] 39 lons += thisstat['model_lon'] 40 hts += thisstat['model_ht'] 41 times += thisstat['time_data'] 42 df = pd.DataFrame({"lats": np.degrees(lats), "lons": np.degrees(lons), "alts": hts, "times": times}) 43 df = df.sort_values(by=['times', 'lats']) 44 os.makedirs(outdir, exist_ok=True) 45 return trackCsvtoKML(trajname.replace('.pickle', 'csv'), df, saveOutput=True, outdir=outdir)
Create a KML file of the trajectory in a solution pickle
Arguments:
picklename: [string] full path to the solution pickle file
Keyword Args:
outdir: [string] where to save the KML. Default same place as pickle.
Returns:
the KML file as a tuple
def
pickleTo2dTrack(picklename, outdir=None):
48def pickleTo2dTrack(picklename, outdir=None): 49 """Create a 2d graph of the trajectory in a solution pickle 50 51 Arguments: 52 picklename: [string] full path to the solution pickle file 53 54 Keyword Args: 55 outdir: [string] where to save the plot. Default same place as pickle. 56 57 Returns: 58 none 59 """ 60 pickpath, trajname = os.path.split(picklename) 61 data = loadPickle(pickpath, trajname).toJson() 62 jsd = json.loads(data) 63 alts = [] 64 times = [] 65 rngs = [] 66 for js in jsd['observations']: 67 k = list(js.keys())[0] 68 thisstat = js[k] 69 alts += thisstat['model_ht'] 70 times += thisstat['time_data'] 71 rngs += thisstat['model_range'] 72 73 plt.clf() 74 fig = plt.gcf() 75 fig.set_size_inches(11.6, 8.26) 76 77 plt.plot(times, alts, linewidth=2) 78 ax = plt.gca() 79 ax.set(xlabel="Time(s)", ylabel="Altitude (m)") 80 #print(min(alts), max(alts)) 81 ax.set_ylim(bottom = min(min(alts), 25000), top=max(max(alts), 120000)) 82 orig, fname = os.path.split(picklename) 83 if outdir is None: 84 outdir = orig 85 fname = fname.replace('.pickle', '_2dtrack.png') 86 f3dname = os.path.join(outdir, fname) 87 88 plt.title('Trajectory of {}'.format(fname[:15])) 89 plt.tight_layout() 90 plt.savefig(f3dname, dpi=200) 91 plt.close() 92 93 plt.clf() 94 fig = plt.gcf() 95 fig.set_size_inches(11.6, 8.26) 96 97 plt.plot(rngs, alts, linewidth=2) 98 ax = plt.gca() 99 ax.set(xlabel="Range (m)", ylabel="Altitude (m)") 100 #print(min(alts), max(alts)) 101 ax.set_ylim(bottom = min(min(alts), 25000), top=max(max(alts), 120000)) 102 orig, fname = os.path.split(picklename) 103 if outdir is None: 104 outdir = orig 105 fname = fname.replace('.pickle', '_2drange.png') 106 f3dname = os.path.join(outdir, fname) 107 108 plt.title('Trajectory of {}'.format(fname[:15])) 109 plt.tight_layout() 110 plt.savefig(f3dname, dpi=200) 111 plt.close() 112 return
Create a 2d graph of the trajectory in a solution pickle
Arguments:
picklename: [string] full path to the solution pickle file
Keyword Args:
outdir: [string] where to save the plot. Default same place as pickle.
Returns:
none