meteortools.ukmondb.trajectoryKML

 1# Copyright (C) 2018-2023 Mark McIntyre
 2import numpy as np
 3import requests
 4import json
 5import os 
 6import pandas as pd
 7
 8try:
 9    from ..fileformats import trackCsvtoKML
10except Exception:
11    from meteortools.fileformats import trackCsvtoKML
12
13
14def trajectoryKML(trajname, outdir=None):
15    """
16    Create a 3-d KML file showing the trajectory of a meteor which can be 
17    loaded into Google Maps. 
18    
19    Arguments:  
20        trajname:   [string] trajectory name eg 20230213_025913.678_UK
21        outdir:     [string] where to save the file. Defaults to current location  
22
23    Returns:  
24        kmlfile:    name of the saved KML file  
25    """
26    apiurl = 'https://api.ukmeteors.co.uk/pickle/getpickle'
27    fmt = 'json'
28    apicall = f'{apiurl}?reqval={trajname}&format={fmt}'
29    res = requests.get(apicall, stream=True)
30    if res.status_code == 200:
31        data=b''
32        for chunk in res.iter_content(chunk_size=4096):
33            data = data + chunk
34        jsd = json.loads(data)
35        lats = []
36        lons = []
37        hts = [] 
38        times = []
39        for js in jsd['observations']:
40            k = list(js.keys())[0]
41            thisstat = js[k]
42            lats += thisstat['model_lat']
43            lons += thisstat['model_lon']
44            hts += thisstat['model_ht']
45            times += thisstat['time_data']
46        df = pd.DataFrame({"lats": np.degrees(lats), "lons": np.degrees(lons), "alts": hts, "times": times})
47        df = df.sort_values(by=['times', 'lats'])
48        if outdir is None:
49            outdir = '.'
50            os.makedirs(outdir, exist_ok=True)
51        outfname = os.path.join(outdir, f'{trajname}.kml')
52        trackCsvtoKML(trajname, df, saveOutput=True, outdir=outdir)
53        return outfname
54    else:
55        print('no match')
56        return None
def trajectoryKML(trajname, outdir=None):
15def trajectoryKML(trajname, outdir=None):
16    """
17    Create a 3-d KML file showing the trajectory of a meteor which can be 
18    loaded into Google Maps. 
19    
20    Arguments:  
21        trajname:   [string] trajectory name eg 20230213_025913.678_UK
22        outdir:     [string] where to save the file. Defaults to current location  
23
24    Returns:  
25        kmlfile:    name of the saved KML file  
26    """
27    apiurl = 'https://api.ukmeteors.co.uk/pickle/getpickle'
28    fmt = 'json'
29    apicall = f'{apiurl}?reqval={trajname}&format={fmt}'
30    res = requests.get(apicall, stream=True)
31    if res.status_code == 200:
32        data=b''
33        for chunk in res.iter_content(chunk_size=4096):
34            data = data + chunk
35        jsd = json.loads(data)
36        lats = []
37        lons = []
38        hts = [] 
39        times = []
40        for js in jsd['observations']:
41            k = list(js.keys())[0]
42            thisstat = js[k]
43            lats += thisstat['model_lat']
44            lons += thisstat['model_lon']
45            hts += thisstat['model_ht']
46            times += thisstat['time_data']
47        df = pd.DataFrame({"lats": np.degrees(lats), "lons": np.degrees(lons), "alts": hts, "times": times})
48        df = df.sort_values(by=['times', 'lats'])
49        if outdir is None:
50            outdir = '.'
51            os.makedirs(outdir, exist_ok=True)
52        outfname = os.path.join(outdir, f'{trajname}.kml')
53        trackCsvtoKML(trajname, df, saveOutput=True, outdir=outdir)
54        return outfname
55    else:
56        print('no match')
57        return None

Create a 3-d KML file showing the trajectory of a meteor which can be loaded into Google Maps.

Arguments:
trajname: [string] trajectory name eg 20230213_025913.678_UK outdir: [string] where to save the file. Defaults to current location

Returns:
kmlfile: name of the saved KML file