-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotTargetAsteroidSpectra.py
More file actions
60 lines (50 loc) · 1.74 KB
/
Copy pathplotTargetAsteroidSpectra.py
File metadata and controls
60 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Purpose: Plot all asteroid spectra for a single target
import argparse as ap
import createDataframe as cdf
import matplotlib.pyplot as plt
import numpy as np
import os.path as op
import seaborn as sns
import sys
sns.set()
def main(argv):
# Retrieve arguments
parser = ap.ArgumentParser()
parser.add_argument("asteroidSpectraList",
help="File containing spectral data")
parser.add_argument("target",
help="Name of asteroid to build merged spectrum")
args = parser.parse_args()
asteroidSpectraList = args.asteroidSpectraList
target = args.target
# Create dataframe for each file in list that matches target asteroid
data = []
targetNames = []
inputFile = open(asteroidSpectraList)
for spectrum in inputFile:
if target in spectrum:
data.append(cdf.createDataframe(spectrum.rstrip()))
targetNames.append(op.basename(spectrum))
# Extract wavelength and reflectance values
x_values = []
y_values = []
for i in range(len(data)):
x_values.append(
data[i].loc[:, 0].to_numpy()) # Wavelength Unit: micrometer
y_values.append(
data[i].loc[:, 1].to_numpy()) # Reflectance Unit: unitless
# Remove anomalous points
for i in range(len(data)):
pos = np.where(y_values[i] <= 0.8)
x_values[i] = np.delete(x_values[i], pos, 0)
y_values[i] = np.delete(y_values[i], pos, 0)
# Plot spectra
for i in range(len(data)):
plt.plot(x_values[i], y_values[i], '.', label=targetNames[i])
plt.legend()
plt.ylabel("Reflectance")
plt.xlabel("Wavelength")
plt.title(target+" Spectra")
plt.show()
if __name__ == "__main__":
main(sys.argv[1:])