meteortools.rmsutils.plotCAMSOrbits

 1# Copyright (C) 2018-2023 Mark McIntyre
 2
 3#
 4# python code to plot orbits given a CAMS style Orbit Info file
 5#
 6
 7import sys
 8import os
 9import datetime
10import matplotlib.pyplot as plt
11try:
12    from wmpl.Utils.PlotOrbits import plotOrbits
13except:
14    print('WMPL not available')
15
16
17def plotCAMSOrbits(orbitFile, outdir=None, hideplot=True):
18    """
19    plots a set of orbits from CAMS data, with one line per set of osculations  
20
21    Arguments:  
22        orbitFile:  [string] full path to CAMS orbit details file  
23        outdir:     [string] the location to write to. defaults to folder of CAMS file  
24        hideplot:   [bool] don't display the plot. Default true  
25
26    Returns:  
27        none  
28    """
29    if outdir is None:
30        outdir, _ = os.path.split(orbitFile)
31    
32    evttime = None
33
34    # read in the data file as a list of lines
35    lis = open(orbitFile, 'r').readlines()
36    
37    # create an empty array to contain the orbital elements
38    orb_elements=[]
39
40    # ignore the first two lines, split the remaining lines up and find the 
41    # elements we want
42    for i in range(3,len(lis)):
43        li = lis[i].split()
44        if evttime is None:
45            evttime = li[1]+'T'+li[2][:8]
46        a = float(li[25])
47        e = float(li[26])
48        if a < 0:
49            q = float(li[22])
50            if e==1.0:
51                e=1.0001
52            a = q/(1-e)
53        elemline = [a,e,float(li[28]),float(li[30]),float(li[32])]
54        # print(elemline)
55        # add the elements to the array
56        orb_elements.append(elemline)
57
58    # plot and save the orbits
59    
60    plotOrbits(orb_elements, datetime.datetime.strptime(evttime, '%Y-%m-%dT%H:%M:%S'), color_scheme='light')
61    evttime = evttime.replace(':','-')
62    plt.savefig(os.path.join(outdir, f'CAMS_{evttime}.png'))
63    if not hideplot:
64        plt.show()
65    plt.close()
66
67#    with open(os.path.join(outdir, 'sampleRMSdata.txt'), 'w') as outf:
68#        for li in orb_elements:
69#            outf.write(f'{li[0]},{li[1]},{li[2]},{li[3]},{li[4]},{evttime}\n')
70
71    return 
72
73
74if __name__ == '__main__':
75    if len(sys.argv) < 3:
76        print('usage: python plotCAMSOrbits source_file target_folder')
77
78    plotCAMSOrbits(sys.argv[1], sys.argv[2])
def plotCAMSOrbits(orbitFile, outdir=None, hideplot=True):
18def plotCAMSOrbits(orbitFile, outdir=None, hideplot=True):
19    """
20    plots a set of orbits from CAMS data, with one line per set of osculations  
21
22    Arguments:  
23        orbitFile:  [string] full path to CAMS orbit details file  
24        outdir:     [string] the location to write to. defaults to folder of CAMS file  
25        hideplot:   [bool] don't display the plot. Default true  
26
27    Returns:  
28        none  
29    """
30    if outdir is None:
31        outdir, _ = os.path.split(orbitFile)
32    
33    evttime = None
34
35    # read in the data file as a list of lines
36    lis = open(orbitFile, 'r').readlines()
37    
38    # create an empty array to contain the orbital elements
39    orb_elements=[]
40
41    # ignore the first two lines, split the remaining lines up and find the 
42    # elements we want
43    for i in range(3,len(lis)):
44        li = lis[i].split()
45        if evttime is None:
46            evttime = li[1]+'T'+li[2][:8]
47        a = float(li[25])
48        e = float(li[26])
49        if a < 0:
50            q = float(li[22])
51            if e==1.0:
52                e=1.0001
53            a = q/(1-e)
54        elemline = [a,e,float(li[28]),float(li[30]),float(li[32])]
55        # print(elemline)
56        # add the elements to the array
57        orb_elements.append(elemline)
58
59    # plot and save the orbits
60    
61    plotOrbits(orb_elements, datetime.datetime.strptime(evttime, '%Y-%m-%dT%H:%M:%S'), color_scheme='light')
62    evttime = evttime.replace(':','-')
63    plt.savefig(os.path.join(outdir, f'CAMS_{evttime}.png'))
64    if not hideplot:
65        plt.show()
66    plt.close()
67
68#    with open(os.path.join(outdir, 'sampleRMSdata.txt'), 'w') as outf:
69#        for li in orb_elements:
70#            outf.write(f'{li[0]},{li[1]},{li[2]},{li[3]},{li[4]},{evttime}\n')
71
72    return 

plots a set of orbits from CAMS data, with one line per set of osculations

Arguments:
orbitFile: [string] full path to CAMS orbit details file
outdir: [string] the location to write to. defaults to folder of CAMS file
hideplot: [bool] don't display the plot. Default true

Returns:
none