├── galaxy_catalogue.npy
├── README.md
├── aerglo_fetch.py
└── galaxy_classifier.py
/galaxy_catalogue.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iamsh4shank/Aerglo/HEAD/galaxy_catalogue.npy
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Aerglo :milky_way:
2 | A python-based tool to fetch astronomical images -
3 | - Astronomical Picture of the Day (APOD)
4 | - taken by Mars Rover
5 | - Earth Polychromatic Imaging Camera (EPIC)
6 | - Earth Observation Data
7 |
8 | By using this tool you will know how beautiful our universe it :heart_eyes: It also allows you to classify galaxies based on the galaxy data which contains parameters like frequency bands, various visual angles, geometry, temperature, etc. All the data is fetched from NASA open [APIs](https://api.nasa.gov/).
9 |
10 |
11 | ## :camera: Screenshots
12 |
13 |
14 |  APOD |
15 |  Mars |
16 |  Earth Observation Data |
17 |
18 |
19 |  EPIC |
20 |  Galaxy Classifier |
21 |  CLI demo |
22 |
23 |
24 |
25 |
26 | ## :question: How it Works
27 |
28 | This tool provides you a feature to fetch images based on your choice. For running this you need to write ```python3.6 aerglo_fetch.py ```. Here `````` can be -
29 | - -apod ------> for APOD
30 | - -marsR ------> for fetching images taken by Mars Rover
31 | - -epic ------> for images by earth polychromatic imaging camera
32 | - -earth ------> for images by earth observation data
33 | - -clGal ------> for galaxy classification
34 | - -help ------> for any help
35 |
36 | It provides data filtering based on various parameters like date, name, id, etc. For galaxy-classification, it provides a demo dataset that contains data of 780 galaxies by SDSS having various kinds of shapes like rectangular, elliptical, merger, spiral, etc. Users can also provide his dataset by providing a file.npy which contains galaxy records.
37 |
38 |
39 |
40 |
41 | ## :satellite: Technology Stack
42 |
43 | * Python 3.6
44 | * NASA open APIs
45 | * Jupyter Notebook
46 | * Astropy library
47 | * Scimage library
48 | * MatplotLib
49 | * Json
50 | * Sklearn library
51 |
52 | ## :key: Contribution
53 | This project is far away from perfect so it would be great if you contribute to make it great. Few ideas I can provide like you can enhance this tool by adding more API functionalities or also enable .csv instead of just processing on .npy for galaxy classification. Also, a lot of analysis part can be introduced in the tool. Hope to see good your contributions.
54 |
55 |
56 | ## :wrench: How to use Aerglo
57 |
58 | 1. Clone the repository
59 | 1. Go to the folder and type ```python3.6 aerglo_fetch ```, for choice see ```How it Works```section.
60 |
61 |
--------------------------------------------------------------------------------
/aerglo_fetch.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import requests
3 | import json
4 | from skimage import io
5 | import matplotlib.pyplot as plt
6 | from galaxy_classifier import initialize, initial
7 |
8 |
9 | def apod(date):
10 | url = "https://api.nasa.gov/planetary/apod?api_key=FyP5abZv4Le0RahAWvkPXySz2LaYJ2Jgtar40V02&date="+date
11 | response = requests.get(url).json()
12 | img = response["hdurl"]
13 | info = response["explanation"]
14 | a = io.imread(img)
15 | plt.imshow(a)
16 | plt.show()
17 | print ("Date: "+ response["date"]+"\n")
18 | print("Info about the image: \n"+info+"\n")
19 |
20 | def marsRover(id):
21 | url = "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=1000&api_key=FyP5abZv4Le0RahAWvkPXySz2LaYJ2Jgtar40V02"
22 | response = requests.get(url).json()
23 | for r in response['photos']:
24 | if (r['id'] == id):
25 | img = r['img_src']
26 | a = io.imread(img)
27 | plt.imshow(a)
28 | plt.show()
29 |
30 | def epic(dateUse, imgName):
31 | imgUrl = 'https://api.nasa.gov/EPIC/archive/natural/'+dateUse+'/png/epic_1b_'+imgName+".png?api_key=FyP5abZv4Le0RahAWvkPXySz2LaYJ2Jgtar40V02"
32 | a = io.imread(imgUrl)
33 | plt.imshow(a)
34 | plt.show()
35 |
36 | def earth(lat, lon):
37 | url = "https://api.nasa.gov/planetary/earth/assets?lon=" + lon+"&lat="+lat + "&date=2018-01-01&&dim=0.10&api_key=FyP5abZv4Le0RahAWvkPXySz2LaYJ2Jgtar40V02"
38 | response = requests.get(url).json()
39 | img = response['url']
40 | a = io.imread(img)
41 | plt.imshow(a)
42 | plt.show()
43 |
44 | argList = []
45 | for arg in sys.argv:
46 | argList.append(arg)
47 | if (len(argList) != 2):
48 | print("Error: No such command exist, enter 'python3.6 aerglo_fetch.py -help' for help")
49 | if (argList[0]+argList[1] == 'aerglo_fetch-help'):
50 | print ('Help...\nEnter "./aerglo_fetch "\nwhere choice can be ->'
51 | '\n -apod for astronomy picture of the day'
52 | '\n -marsR for fetching image taken by mars rover'
53 | '\n -epic for earth polychromatic imaging camera'
54 | '\n -earth for earth observation data'
55 | '\n -clGal Classify galaxy')
56 |
57 | if (argList[1] == '-apod'):
58 | date = str(input("Enter date(YYYY-MM-DD) to fetch image: "))
59 | apod(date)
60 | elif (argList[1] == '-marsR'):
61 | id = int(input("Enter id: "))
62 | marsRover(id)
63 | elif (argList[1] == '-epic'):
64 | dateUse = str(input("Enter date(YYYY/MM/DD): "))
65 | imgName = str(input("Enter image name: "))
66 | epic(dateUse, imgName)
67 | elif (argList[1] == '-earth'):
68 | lat = str(input("Enter latitude: "))
69 | lon = str(input("Enter longitude: "))
70 | earth(lat, lon)
71 | elif (argList[1] == '-clGal'):
72 | print ("Do you want to use demo data(Y/N): ")
73 | ch = str(input())
74 | if (ch.lower() == 'y'):
75 | initialize()
76 | elif (ch.lower() == 'n'):
77 | fName = str(input("Enter NumPy file name: "))
78 | initial(fName)
79 | else:
80 | print ("Enter correct choice in Y or N")
81 | else:
82 | print("No such options found, enter 'python3.6 aerglo_fetch -help' for help")
--------------------------------------------------------------------------------
/galaxy_classifier.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import itertools
3 | from matplotlib import pyplot as plt
4 | from sklearn.metrics import confusion_matrix
5 | from sklearn.model_selection import cross_val_predict
6 | from sklearn.ensemble import RandomForestClassifier
7 |
8 | def calculate_accuracy(predicted_classes, actual_classes, ):
9 | return sum(actual_classes[:] == predicted_classes[:]) / len(actual_classes)
10 |
11 |
12 | def generate_features_targets(data):
13 | output_targets = np.empty(shape=(len(data)), dtype=' thresh else "black")
62 |
63 | plt.tight_layout()
64 | plt.ylabel('Ground Truth')
65 | plt.xlabel('Prediction')
66 |
67 | def rf_predict_actual(data, n_estimators):
68 | # generate the features and targets
69 | features, targets = generate_features_targets(data)
70 |
71 | # instantiate a random forest classifier
72 | rfc = RandomForestClassifier(n_estimators=n_estimators)
73 |
74 | # get predictions using 10-fold cross validation with cross_val_predict
75 | predicted = cross_val_predict(rfc, features, targets, cv=10)
76 |
77 | # return the predictions and their actual classes
78 | return predicted, targets
79 |
80 |
81 | def initialize():
82 | data = np.load('galaxy_catalogue.npy')
83 |
84 | # get the predicted and actual classes
85 | number_estimators = 50 # Number of trees
86 | predicted, actual = rf_predict_actual(data, number_estimators)
87 |
88 | # calculate the model score using your function
89 | accuracy = calculate_accuracy(predicted, actual)
90 | print("Accuracy score:", accuracy)
91 |
92 | # calculate the models confusion matrix using sklearns confusion_matrix function
93 | class_labels = list(set(actual))
94 | model_cm = confusion_matrix(y_true=actual, y_pred=predicted, labels=class_labels)
95 |
96 | # plot the confusion matrix using the provided functions.
97 | plt.figure()
98 | plot_confusion_matrix(model_cm, classes=class_labels, normalize=False)
99 | plt.show()
100 |
101 | def initial(fName):
102 | data = np.load(fName)
103 |
104 | # get the predicted and actual classes
105 | number_estimators = 50 # Number of trees
106 | predicted, actual = rf_predict_actual(data, number_estimators)
107 |
108 | # calculate the model score using your function
109 | accuracy = calculate_accuracy(predicted, actual)
110 | print("Accuracy score:", accuracy)
111 |
112 | # calculate the models confusion matrix using sklearns confusion_matrix function
113 | class_labels = list(set(actual))
114 | model_cm = confusion_matrix(y_true=actual, y_pred=predicted, labels=class_labels)
115 |
116 | # plot the confusion matrix using the provided functions.
117 | plt.figure()
118 | plot_confusion_matrix(model_cm, classes=class_labels, normalize=False)
119 | plt.show()
120 |
--------------------------------------------------------------------------------