From 5587968632f7700339016d2fa99772554307c89b Mon Sep 17 00:00:00 2001 From: huttona6 Date: Wed, 28 Apr 2021 19:40:49 +0100 Subject: [PATCH] Uploading Final Code JSON conversion and Neural Network Models --- JSONProcessing.py | 301 +++++++++++++++++++++++++ Model.py | 557 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 858 insertions(+) create mode 100644 JSONProcessing.py create mode 100644 Model.py diff --git a/JSONProcessing.py b/JSONProcessing.py new file mode 100644 index 0000000..09b6db8 --- /dev/null +++ b/JSONProcessing.py @@ -0,0 +1,301 @@ +import numpy as np +import json +import csv +import sys +import os +from sgp4.api import Satrec +from sgp4.api import jday +from sgp4 import omm +from sgp4 import exporter +import pandas as pd + +#A set of routines to take a JSON file from space-track.org and manipulate it to produce +#a set of labelled data which can be used to model how to track debris and satellites +#through time. +# +#The features produced are the original position, velocity, eccentricity etc of the +#object plus the time in seconds to the next measurement, and the label is then the +#resulting position and velocity. +# +#The aim is to then generate a model which can be used to establish where debris and +#satellite are after a specific time based on some initial data about where they were. +# +#The model should be trained differently for satellites and debris to see how they differ +#since satellites are relatively large and controlled, and so should be predictable, while +#space debris isn't controlled and something as light as space debris can be severely +#perturbed by a lot of things, in a pretty short time, depending on the height of the +#orbit, and thus drag coefficient +# +#Hence we can get two models, one for satellites and one for debris and then test against +#each other + + +#Opens the satellite data JSON file and returns the list of dicts with all the data +def openJSONFile(jsonFileName): + + print("Reading the JSON File:", jsonFileName) + + #Open a JSON file and returns a list of dict + try: + read_file = open(jsonFileName, "r") + except IOError: + print("Could not open/read file:", jsonFileName) + sys.exit() + + data = json.load(read_file) + read_file.close() + + return(data) + +#end openJSONFile + +#Write a list of dicts into a CSVFile just to easily see what is in there +def writeRaWCSVFile(jsonData): + + csvFileName = "Raw" + jsonData[0]["NORAD_CAT_ID"] + ".csv" + + #Extract individual keys for the dicts, and then create a list with all of the keys + keys = jsonData[0].keys() + csv_columns = [] + for key in keys: + csv_columns.append(key) + + #Open the csvFile. Note that the newline='' stops the writer from inserting extra lines in the csv file + try: + csvFile = open(csvFileName, "w+", newline='') + except IOError: + print("Could not write file:", csvFileName) + sys.exit() + + writer = csv.DictWriter(csvFile, fieldnames=csv_columns) + + #Write the header information, and then for each dict in the list, write out the data which is formated by the csv_columns information + writer.writeheader() + + for item in jsonData: + + writer.writerow(item) + + csvFile.close() + print("Written the CSV File:", csvFileName) + +#end writeRaWCSVFile + +#Since we have the data, then we can do some early wrangling and processing of it +def wrangleData(jsonData): + + defaultRCS_SIZE = "SMALL" + + #sometimes the RCS_SIZE data is empty, so fill it with the existing values + for item in jsonData: + + RCS_SIZE = item["RCS_SIZE"] + + if (RCS_SIZE == "LARGE") or (RCS_SIZE == "MEDIUM") or (RCS_SIZE == "SMALL"): + defaultRCS_SIZE = item["RCS_SIZE"] + else: + item["RCS_SIZE"] = defaultRCS_SIZE + + return(jsonData) + +#end def wrangleData + + +#Setup a format for the data CSV file just so it's all in one place +#type = "f" means the format, type = "d" means the data +def formatCSVFile(oldData,satellite,item,type): + + if type == "f": + + csv_columns = ["OldJD","OldJDFR","OldXPOS","OldYPOS","OldZPOS","OldXVEL","OldYVEL","OldZVEL"] + csv_columns = csv_columns + ["BSTAR","ECCENTRICITY","INCLINATION","MEAN_ANOMALY","MEAN_MOTION","MEAN_MOTION_DDOT","MEAN_MOTION_DOT"] + csv_columns = csv_columns + ["RCS_SIZE","RA_OF_ASC_NODE","ARG_OF_PERICENTER","SEMIMAJOR_AXIS","PERIOD","APOAPSIS","PERIAPSIS"] + csv_columns = csv_columns + ["DeltaTime"] + csv_columns = csv_columns + ["NewXPOS","NewYPOS","NewZPOS"] + return(csv_columns) + + elif type == "d": + + #Change the text describing the size into a number so that everything in the CSV file is numeric + if item["RCS_SIZE"] == "LARGE": + size = 10 + elif item["RCS_SIZE"] == "MEDIUM": + size = 1 + elif item["RCS_SIZE"] == "SMALL": + size = 0.1 + else: + print("Cannot find an RCS_SIZE") + size = 0 + + oldData = oldData + [satellite.bstar,satellite.ecco,satellite.inclo,item["MEAN_ANOMALY"],item["MEAN_MOTION"],item["MEAN_MOTION_DDOT"],item["MEAN_MOTION_DOT"]] + oldData = oldData + [size,item["RA_OF_ASC_NODE"],item["ARG_OF_PERICENTER"],item["SEMIMAJOR_AXIS"],item["PERIOD"],item["APOAPSIS"],item["PERIAPSIS"]] + return(oldData) + + else: + print("Error in formatting of CSVFile") + sys.exit() + +#end def formatCSVFile + +#Use the SGP4 processing library and extract a load of data to a CSV file. The CSV file should be a set of labelled data +#containing the previous time in Julian format, the current time, the previous position and velocity and then a time +#to the next period, and that new position and velocity +def writeLabelledCSVFile(jsonData, Extend): + + firstTimeThrough = True + filterLevel = 500 + firstEPOCH = jsonData[0]["EPOCH"] + year, month, time = firstEPOCH.split("-") + day, time = time.split("T") + firstPeriod = year + month + day + lastEPOCH = jsonData[len(jsonData)-1]["EPOCH"] + year, month, time = lastEPOCH.split("-") + day, time = time.split("T") + lastPeriod = year + month + day + + newCSVFileName = "Labelled" + jsonData[0]["NORAD_CAT_ID"] + "_" + firstPeriod + "_" + lastPeriod + ".csv" + + #Open the csvFile. Note that the newline='' stops the writer from inserting extra lines in the csv file + try: + csvFile = open(newCSVFileName, "w+", newline='') + except IOError: + print("Could not write file:", newCSVFileName) + sys.exit() + + #Create a list with all of the column headers for the CSV file + csv_columns = formatCSVFile(0,0,0,"f") + csv_writer = csv.writer(csvFile) + csv_writer.writerow(csv_columns) # write header + + for item in jsonData: + + TLE1 = item["TLE_LINE1"] + TLE2 = item["TLE_LINE2"] + epoch = item["EPOCH"] + year, month, time = epoch.split("-") + day, time = time.split("T") + hour, minute, sec = time.split(":") + jdBase, frBase = jday(float(year),float(month),float(day),float(hour),float(minute),float(sec)) + + #The call to Satrec.twoline2rv uses the two TLE data elements and extracts a ton of information + satellite = Satrec.twoline2rv(TLE1, TLE2) + + #Extract the Julian Date and the fractional value, which makes all the calculations above somewhat pointless! + jd = satellite.jdsatepoch + jdFr = satellite.jdsatepochF + + #error will be a non-zero error code if the satellite position could not be computed for the given date + #position - the satellite position in kilometers from the center of the earth in True Equator Mean Equinox coordinate frame + #velocity - is the rate at which the position is changing, expressed in kilometers per second. + error, position, velocity = satellite.sgp4(jd, jdFr) + + if error != 0: + print("Error extracting position and velocity") + sys.exit() + + xpos, ypos, zpos = position + xvel, yvel, zvel = velocity + + if firstTimeThrough: + + firstTimeThrough = False + + else: + + DeltaTime = 3600*(jd+jdFr-oldData[0]-oldData[1]) + jumpInX = max(abs(oldData[2] / xpos),abs(xpos / oldData[2])) + jumpInY = max(abs(oldData[3] / ypos),abs(ypos / oldData[3])) + jumpInZ = max(abs(oldData[4] / zpos),abs(zpos / oldData[4])) + + # Data cleanup by filtering out any tiny changes in time due to rounding errors, + # and any massive jumps in position data which will cause outliers + if (DeltaTime > 0.1) and (jumpInX<=filterLevel) and (jumpInY<=filterLevel) and (jumpInZ<=filterLevel): + + newData = [DeltaTime,xpos, ypos, zpos] + row = oldData + newData + csv_writer.writerow(row) + + oldData = [jd, jdFr, xpos, ypos, zpos, xvel, yvel, zvel] + oldData = formatCSVFile(oldData,satellite,item,"d") + + csvFile.close() + print("Written the labelled CSV File:", newCSVFileName) + + if Extend: + extendLabelledCSVFile(newCSVFileName) + +#end def writeLabelledCSVFile: + +#labelledCSVFile = "D:\OneDrive\Desktop\Training\Labelled24946.csv" + +#Take an existing LabelledCSVFile, and extend it by replicating data and change the Delta time +def extendLabelledCSVFile(labelledCSVFile): + + csvFileName = "Ext_" + labelledCSVFile + + df = pd.read_csv(labelledCSVFile) + + columnNames = list(df) + + numberOfValues = len(df) + + print(numberOfValues) + + for x in range(0,numberOfValues): + + if x % 50 == 0: + print(x) + + old_item = df.iloc[x].copy() + + deltaTime = old_item["DeltaTime"] + + newList = [] + + for y in range(x+1,numberOfValues-1): + + new_item = df.iloc[y] + + deltaTime = deltaTime + new_item["DeltaTime"] + + old_item["DeltaTime"] = deltaTime + old_item["NewXPOS"] = new_item["NewXPOS"] + old_item["NewYPOS"] = new_item["NewYPOS"] + old_item["NewZPOS"] = new_item["NewZPOS"] + + zipped = zip(columnNames, old_item.values) + a_dictionary = dict(zipped) + newList.append(a_dictionary) + + df = df.append(newList, True) + + #print(len(df),"an expansion of",len(df)/numberOfValues,"times") + + df.to_csv(csvFileName, index = False) + + print("Written the Extended CSV File:", csvFileName) + +#end def extendLabelledCSVFile + +#Main. Opens a directory, scans for all *.json files, prints each one to a named Raw +#CSVFile, wrangles the data, and prints a Labelled CSV File. Names of the CSV file are +#from the NORAD_CAT_ID in the JSON file +# +#We dump a set of training data to one directory and a set of test data to another +#and then convert them both + +#Directory Variables +directoriesToProcess = ["D:\OneDrive\Desktop\Training","D:\OneDrive\Desktop\Test"] + +for directory in directoriesToProcess: + print("Processing directory:",directory) + os.chdir(directory) + with os.scandir() as entries: + for entry in entries: + if entry.name.split(".")[1] == "json": + jsonData = openJSONFile(entry.name) + writeRaWCSVFile(jsonData) + jsonData = wrangleData(jsonData) + writeLabelledCSVFile(jsonData, True) + + diff --git a/Model.py b/Model.py new file mode 100644 index 0000000..248869f --- /dev/null +++ b/Model.py @@ -0,0 +1,557 @@ +import numpy as np +import tensorflow as tf +# for reproducibility set a seed +np.random.seed(1234) +import pandas as pd +from tensorflow.keras.layers import Activation, Dense +from tensorflow.keras.optimizers import Adam +from tensorflow.keras.metrics import categorical_crossentropy +from keras.models import Sequential +from keras.layers import * +from sklearn.preprocessing import MinMaxScaler, RobustScaler +from keras.models import load_model +import csv +import sys +import os +import math +import joblib +from datetime import datetime + +#Creates the models based on the Training Data, and then saves the X/Y/Z models and the Scaler used to scale things for later use +def createTheModels(TrainingDataCSVFile): + + training_data_df = pd.read_csv(TrainingDataCSVFile) + + #Define the Scaler that will be used for all data + TrainingScaler = MinMaxScaler(feature_range =(0,1)) + TrainingScaler.fit(training_data_df) + ScaledTraining = TrainingScaler.transform(training_data_df) + + #Create the csv file just so we can debug things later + scaled_training_df = pd.DataFrame(ScaledTraining, columns=training_data_df.columns.values) + scaled_training_df.to_csv("D:\OneDrive\Desktop\Scaled_Training_Data.csv", index = False) + + X = scaled_training_df.drop(['NewXPOS', 'NewYPOS', 'NewZPOS'], axis=1).values #<---- Drop them all + inputLength = len(X[0]) + XPOSY = scaled_training_df[['NewXPOS']].values + YPOSY = scaled_training_df[['NewYPOS']].values + ZPOSY = scaled_training_df[['NewZPOS']].values + + modelActivation = 'relu' + modelLevels = [50,100,50,1] + modelOptimizer = "adam" + modelLoss = "mean_squared_error" + + model = Sequential() + model.add(Dense(modelLevels[0], input_dim=inputLength, activation=modelActivation)) + model.add(Dense(modelLevels[1], activation=modelActivation)) + model.add(Dense(modelLevels[2], activation=modelActivation)) + model.add(Dense(modelLevels[3], activation=modelActivation)) + + model.compile(loss=modelLoss, optimizer=modelOptimizer) + + es = tf.keras.callbacks.EarlyStopping(monitor='loss', mode='min', verbose=1, patience=10) + + print("Fitting X ...") + model.fit(X,XPOSY,epochs=50,shuffle=True,verbose=2,callbacks=es) + model.save("Xtrained_model.h5") + + print("Fitting Y ...") + model.fit(X,YPOSY,epochs=50,shuffle=True,verbose=2,callbacks=es) + model.save("Ytrained_model.h5") + + print("Fitting Z ...") + model.fit(X,ZPOSY,epochs=50,shuffle=True,verbose=2,callbacks=es) + model.save("Ztrained_model.h5") + + #Save the Scaler for later use + joblib.dump(TrainingScaler, "scaler.save") + +#end def createTheModels + +#Test how good the models are on a set of testing data +def testTheModels(TestDataCSVFile, simplePrediction): + + # Bring back all three models + Xmodel = load_model("Xtrained_model.h5") + Ymodel = load_model("Ytrained_model.h5") + Zmodel = load_model("Ztrained_model.h5") + + # Load the scaler + Scaler = joblib.load("scaler.save") + + testing_data_df = pd.read_csv(TestDataCSVFile) + + ScaledTesting = Scaler.transform(testing_data_df) + + scaled_testing_df = pd.DataFrame(ScaledTesting, columns=testing_data_df.columns.values) + + #Create the csv file just so we can debug things later + scaled_testing_df.to_csv("D:\OneDrive\Desktop\Scaled_Testing_Data.csv", index = False) + + X_test = scaled_testing_df.drop(['NewXPOS', 'NewYPOS', 'NewZPOS'], axis=1).values #<---- Drop them all + Y_testX = scaled_testing_df[['NewXPOS']].values + Y_testY = scaled_testing_df[['NewYPOS']].values + Y_testZ = scaled_testing_df[['NewZPOS']].values + + test_error_rate = Xmodel.evaluate(X_test, Y_testX, verbose=0) + print("X Mean squared error is: {}".format(test_error_rate)) + + test_error_rate = Ymodel.evaluate(X_test, Y_testY, verbose=0) + print("Y Mean squared error is: {}".format(test_error_rate)) + + test_error_rate = Zmodel.evaluate(X_test, Y_testZ, verbose=0) + print("Z Mean squared error is: {}".format(test_error_rate)) + + if simplePrediction: + + #Load in the simple scaled prediction data + pred = pd.read_csv("D:\OneDrive\Desktop\Scaled_Prediction_Data.csv").values + + else: + + pred = scaled_testing_df.drop(['NewXPOS', 'NewYPOS', 'NewZPOS'], axis=1).values #<---- Drop them all + + predictions = [] + + CompleteXPredictions = Xmodel.predict(pred) + CompleteYPredictions = Ymodel.predict(pred) + CompleteZPredictions = Zmodel.predict(pred) + + for x in range(0,len(pred)): + + Xprediction = CompleteXPredictions[x][0] + Yprediction = CompleteYPredictions[x][0] + Zprediction = CompleteZPredictions[x][0] + + Xpred = (Xprediction * (Scaler.data_max_[23] - Scaler.data_min_[23])) + Scaler.data_min_[23] + Ypred = (Yprediction * (Scaler.data_max_[24] - Scaler.data_min_[24])) + Scaler.data_min_[24] + Zpred = (Zprediction * (Scaler.data_max_[25] - Scaler.data_min_[25])) + Scaler.data_min_[25] + + if simplePrediction: + + print("Prediction of X_POS is {}".format(Xprediction)) + print("Prediction of Y_POS is {}".format(Yprediction)) + print("Prediction of Z_POS is {}".format(Zprediction)) + print("Scaled prediction of X_POS is {}".format(Xpred)) + print("Scaled prediction of Y_POS is {}".format(Ypred)) + print("Scaled prediction of Z_POS is {}".format(Zpred)) + + predictions.append([Xpred,Ypred,Zpred]) + + return(predictions) + +#end def testTheModels + +#Write a CSV file which compares what the actual new X/Y/Z positions are vs. the predicted ones, just so we can see how good or bad things are +def compareActualVsPrediction(TestDataCSVFile, logFile): + + # Load the scaler + Scaler = joblib.load("scaler.save") + + comparisonCSVFile = "Comparison.csv" + + #Open the csvFile. Note that the newline='' stops the writer from inserting extra lines in the csv file + try: + csvFile = open(comparisonCSVFile, "w+", newline='') + except IOError: + print("Could not write file:", comparisonCSVFile) + sys.exit() + + testing_data_df = pd.read_csv(TestDataCSVFile).values + + #Create a list with all of the column headers for the CSV file + csv_columns = ["OldJD","OldJDFR","NewXPOS","NewYPOS","NewZPOS","PredXPOS","PredYPOS","PredZPOS","XErrorKM","YErrorKM","ZErrorKM"] + csv_writer = csv.writer(csvFile) + csv_writer.writerow(csv_columns) # write header + + predictions = testTheModels(TestDataCSVFile, False) + + count = 0 + LargestXError = 0 + LargestYError = 0 + LargestZError = 0 + + for item in testing_data_df: + + OldJD = item[0] + OldJDFR = item[1] + NewXPOS = item[23] + NewYPOS = item[24] + NewZPOS = item[25] + PredXPOS = predictions[count][0] + PredYPOS = predictions[count][1] + PredZPOS = predictions[count][2] + + XError = math.sqrt((NewXPOS - PredXPOS)**2) + YError = math.sqrt((NewYPOS - PredYPOS)**2) + ZError = math.sqrt((NewZPOS - PredZPOS)**2) + + if XError > LargestXError: + LargestXError = XError + if YError > LargestYError: + LargestYError = YError + if ZError > LargestZError: + LargestZError = ZError + + row = [OldJD,OldJDFR,NewXPOS,NewYPOS,NewZPOS,PredXPOS,PredYPOS,PredZPOS,XError,YError,ZError] + csv_writer.writerow(row) + count = count + 1 + + csvFile.close() + print("Written the CSV File:", comparisonCSVFile) + largestError = max(LargestXError, LargestYError, LargestZError) + print("Largest Absolute Error:", round(largestError,2), "XError:YError:ZError", round(LargestXError,2), round(LargestYError,2), round(LargestZError,2), file=logFile, flush=True) + +#end def testTheModel + +#Main Processing loop which runs all the experiments +#Define what to run, and how long to run it for +#Normally run it twice including training just to get round any restarting inconsistencies +#Or simply set the range to zero to stop running them + +Run24946onTest = 0 +Run24907onTest = 0 +RunMergedSatellite = 0 +Run34367Debris = 0 +Run35479Debris = 0 +Run37558Debris = 0 +RunMergedDebris = 0 + +logFile = open("D:\OneDrive\Desktop\Results.txt", 'w') + +print("Running the experiments ...", file=logFile, flush=True) + +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_Labelled24946_20200101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled24946_20190101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled24946_20180101_20201230.csv"] + +print("Running the first part of the experiments ...", file=logFile, flush=True) + + +for x in range (Run24946onTest): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for ID 24946 (1997-051C) on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on ID 24946 (1997-051C) data on ID 24946 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210101.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210113.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + #See if the 24946 data can be used for the other Satellite 1997-043E – Id: 24907 + print("Testing the model trained on ID 24946 (1997-051C) data on ID 24907 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210101.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210113.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + +print("Running the second part of the experiments ...", file=logFile, flush=True) +#Repeat the test for the 24907 data +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_Labelled24907_20200101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled24907_20190101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled24907_20180101_20201230.csv"] + +for x in range (Run24907onTest): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for ID 24907 (1997-043E) on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on ID 24907 (1997-043E) data on ID 24946 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210101.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210113.csv"] + + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + #See if the 24946 data can be used for the other Satellite 1997-043E – Id: 24907 + print("Testing the model trained on ID 24907 (1997-043E) data on ID 24907 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210101.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210113.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + +print("Running the third part of the experiments ...", file=logFile, flush=True) +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_LabelledM24946_24907_20200101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledM24946_24907_20190101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledM24946_24907_20180101_20201230.csv"] + +for x in range (RunMergedSatellite): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for Merged Dataset of 24946 and 24907 on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on Merged Dataset of 24946 and 24907 on ID 24946 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210101.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled24946_20210101_20210113.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + #See if the 24946 data can be used for the other Satellite 1997-043E – Id: 24907 + print("Testing the model trained on Merged Dataset of 24946 and 24907 on ID 24907 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210101.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled24907_20210101_20210113.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + +print("Running the fourth part of the experiments ...", file=logFile, flush=True) +#Now repeat for one of the debris models +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_Labelled34367_20201201_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled34367_20201001_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled34367_20200701_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled34367_20200401_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled34367_20200101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled34367_20190101_20201230.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled34367_20180101_20201230.csv"] + +for x in range (Run34367Debris): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for ID 34367 (1997-051FK) on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on ID 34367 (1997-051FK) data on ID 34367 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210113.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210120.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210127.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + +print("Running the fifth part of the experiments ...", file=logFile, flush=True) +#Now repeat for another of the debris models +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_Labelled35479_20201201_20201225.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled35479_20201001_20201225.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled35479_20200702_20201225.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled35479_20200401_20201225.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled35479_20200101_20201225.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled35479_20190101_20201225.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled35479_20180101_20201225.csv"] + +for x in range (Run35479Debris): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for ID 35479 (1997-051PZ) on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on ID 35479 (1997-051PZ) data on ID 35479 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210110.csv", + "D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210117.csv", + "D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210124.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + +print("Running the sixth part of the experiments ...", file=logFile, flush=True) +#Now repeat for another of the debris models +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_Labelled37558_20201201_20201228.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled37558_20201002_20201228.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled37558_20200702_20201228.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled37558_20200401_20201228.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled37558_20200101_20201228.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled37558_20190101_20201228.csv", + "D:/OneDrive/Desktop/Training/Ext_Labelled37558_20180101_20201228.csv"] + +for x in range (Run37558Debris): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for ID 37558 (1997-051XT) on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on ID 37558 (1997-051XT) data on ID 37558 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210105.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210112.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210119.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210126.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + +print("Running the seventh and final part of the experiments with merged debris data ...", file=logFile, flush=True) +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_LabelledMergedDec2020.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledMergedOctDec2020.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledMergedJulyDec2020.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledMergedAprDec2020.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledMerged2020.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledMerged2019_2020.csv", + "D:/OneDrive/Desktop/Training/Ext_LabelledMerged2018_2020.csv"] + +for x in range (RunMergedDebris): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for Merged Debris Dataset on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on the merged Debris dataset on ID 34367 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210113.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210120.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210127.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + print("Testing the model trained on the merged Debris dataset on ID 35479 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210110.csv", + "D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210117.csv", + "D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210124.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + print("Testing the model trained on the merged Debris dataset on ID 37558 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210105.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210112.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210119.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210126.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + +#Top up tests +#Now repeat for another of the debris models +print("Running the seventh and final part of the experiments with merged debris data ...", file=logFile, flush=True) +dataToTrainOn = ["D:/OneDrive/Desktop/Training/Ext_LabelledMergedOctDec2020.csv"] + +for x in range (5): + + for trainingData in dataToTrainOn: + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print("Training for Merged Debris Dataset on: ", trainingData, "at:", current_time, file=logFile, flush=True) + + createTheModels(trainingData) + + print("Testing the model trained on the merged Debris dataset on ID 34367 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210103.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210106.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210113.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210120.csv", + "D:/OneDrive/Desktop/Test/Labelled34367_20210101_20210127.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + print("Testing the model trained on the merged Debris dataset on ID 35479 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210110.csv", + "D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210117.csv", + "D:/OneDrive/Desktop/Test/Labelled35479_20210102_20210124.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + print("Testing the model trained on the merged Debris dataset on ID 37558 test data.", file=logFile, flush=True) + dataToTestOn = ["D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210105.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210112.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210119.csv", + "D:/OneDrive/Desktop/Test/Labelled37558_20210103_20210126.csv"] + + for testData in dataToTestOn: + + print("Accuracy for : ", testData, file=logFile, flush=True) + testTheModels(testData,True) + compareActualVsPrediction(testData,logFile) + + + + +logFile.close()