Creating Graphs for the Data
Here is my code along with my outputs. I have my comments in bold and the outputs are highlighted for less confusion hopefully.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv(‘MarsCraterData.csv’,low_memory = False)
# upper case all DataFrame column names, meant for less confusion
data.columns = map(str.upper, data.columns)
# bug fix for display runtime errors
pd.set_option('display.float_format’, lambda x: ’%f’%x)
print(len(data))
print(len(data.columns))
# C = counts P = percentage
c1 = data['LATITUDE_CIRCLE_IMAGE’].value_counts(sort=False)
# print('count latitude’,c1)
p1 = data['LATITUDE_CIRCLE_IMAGE’].value_counts(sort=False,normalize = True)
# print(’% latitude’,p1)
c2 = data['LONGITUDE_CIRCLE_IMAGE’].value_counts(sort=False)
# print('count longitude’,c2)
p2 = data['LONGITUDE_CIRCLE_IMAGE’].value_counts(sort=False,normalize = True)
# print(’% longitude’,p2)
c3 = data['DEPTH_RIMFLOOR_TOPOG’].value_counts(sort=False)
# print('count depth’,c3)
p3 = data['DEPTH_RIMFLOOR_TOPOG’].value_counts(sort=False,normalize = True)
# print(’% depth’,p3)
c4 = data['NUMBER_LAYERS’].value_counts(sort=False)
# print('count layers’,c4)
p4 = data['NUMBER_LAYERS’].value_counts(sort=False,normalize = True)
# print(’% layers’,p4)
ct4 = data.groupby('NUMBER_LAYERS’).size()
print('groupby data’,ct4)
pt4 = data.groupby('NUMBER_LAYERS’).size()*100/len(data)
print(’% groupby data’,pt4)
groupby data NUMBER_LAYERS 0 59840 1 3895 2 1556 3 184 4 22 5 2 dtype: int64 % groupby data NUMBER_LAYERS 0 91.360173 1 5.946656 2 2.375609 3 0.280920 4 0.033588 5 0.003053 dtype: float64
Making a subset of data. Craters that have 1 or more layers and that are at least 0.5 meters in depth. This is to be used for comparison later on.
sub1 = data[(data['NUMBER_LAYERS’] >= 1) &
(data['DEPTH_RIMFLOOR_TOPOG’] >= 0.5)]
# Making a copy
sub2 = sub1.copy()
CRATER_ID CRATER_NAME LATITUDE_CIRCLE_IMAGE LONGITUDE_CIRCLE_IMAGE \ 1 01-000001 Korolev 72.760000 164.464000 20 01-000020 65.135000 177.982000 25 01-000025 70.051000 -7.939000 26 01-000026 70.884000 -166.427000 27 01-000027 66.330000 39.798000 28 01-000028 Louth 70.173000 103.226000 37 01-000037 77.116000 89.130000 39 01-000039 66.394000 144.036000 40 01-000040 73.909000 -173.606000 47 01-000047 67.909000 92.848000 DIAM_CIRCLE_IMAGE DEPTH_RIMFLOOR_TOPOG MORPHOLOGY_EJECTA_1 \ 1 82.020000 1.970000 Rd/MLERS 20 45.710000 1.860000 Rd/DLEPC/DLERS 25 39.510000 2.080000 SLERS 26 36.850000 1.980000 MLERS 27 36.410000 1.900000 MLERS 28 36.280000 1.410000 SLERS 37 30.880000 0.710000 SLERS 39 29.460000 1.770000 Rd/DLERS 40 28.450000 1.410000 MLERS 47 27.230000 1.850000 Rd/DLERC/DLERS MORPHOLOGY_EJECTA_2 MORPHOLOGY_EJECTA_3 NUMBER_LAYERS 1 HuBL 3 20 HuBL 2 25 HuSL 1 26 HuBL Inner is Small-Crown 4 27 HuBL 3 28 HuBL 1 37 HuSL 1 39 HuBL 2 40 HuBL 3 47 HuBL 2
# dividing Mars into 2 quadrants (upper and lower)
def LOCATION(row):
if row['LATITUDE_CIRCLE_IMAGE’] >= 0 and row['LONGITUDE_CIRCLE_IMAGE’] >= 0 :
return 1
else :
return 2
data['LOCATION’] = data.apply(lambda row: LOCATION(row), axis=1)
sub2['LOCATION’] = sub2.apply(lambda row: LOCATION(row), axis=1)
# this uses all data sets
sub3 = data[['CRATER_ID’,'LATITUDE_CIRCLE_IMAGE’,
'LONGITUDE_CIRCLE_IMAGE’,'DEPTH_RIMFLOOR_TOPOG’,
'NUMBER_LAYERS’,'LOCATION’]]
CRATER_ID LATITUDE_CIRCLE_IMAGE LONGITUDE_CIRCLE_IMAGE \ 0 01-000000 84.367000 108.746000 1 01-000001 72.760000 164.464000 2 01-000002 69.244000 -27.240000 3 01-000003 70.107000 160.575000 4 01-000004 77.996000 95.617000 5 01-000005 68.547000 137.849000 6 01-000006 69.492000 169.751000 7 01-000007 78.716000 -87.249000 8 01-000008 75.539000 13.829000 9 01-000009 69.371000 75.147000 DEPTH_RIMFLOOR_TOPOG NUMBER_LAYERS LOCATION 0 0.220000 0 1 1 1.970000 3 1 2 0.090000 0 2 3 0.130000 0 1 4 0.110000 0 1 5 0.190000 0 1 6 0.100000 0 1 7 0.050000 0 2 8 0.110000 0 1 9 0.000000 0 1
# This is the data with 1 or more layers to the craters edge.
sub4 = sub2[['CRATER_ID’,'LATITUDE_CIRCLE_IMAGE’,
'LONGITUDE_CIRCLE_IMAGE’,'DEPTH_RIMFLOOR_TOPOG’,
'NUMBER_LAYERS’,'LOCATION’]]
CRATER_ID LATITUDE_CIRCLE_IMAGE LONGITUDE_CIRCLE_IMAGE \ 1 01-000001 72.760000 164.464000 20 01-000020 65.135000 177.982000 25 01-000025 70.051000 -7.939000 26 01-000026 70.884000 -166.427000 27 01-000027 66.330000 39.798000 28 01-000028 70.173000 103.226000 37 01-000037 77.116000 89.130000 39 01-000039 66.394000 144.036000 40 01-000040 73.909000 -173.606000 47 01-000047 67.909000 92.848000 DEPTH_RIMFLOOR_TOPOG NUMBER_LAYERS LOCATION 1 1.970000 3 1 20 1.860000 2 1 25 2.080000 1 2 26 1.980000 4 2 27 1.900000 3 1 28 1.410000 1 1 37 0.710000 1 1 39 1.770000 2 1 40 1.410000 3 2 47 1.850000 2 1
print('Quadrant of craters with 1 or more layers’)
p5 = sub2['LOCATION’].value_counts(sort = False)
print(p5)
print('Quadrant of craters’)
p6 = data['LOCATION’].value_counts(sort = False)
print(p6)
Quadrant of craters with 1 or more layers 1 286 2 793 Name: LOCATION, dtype: int64 Quadrant of craters 1 34297 2 31202 Name: LOCATION, dtype: int64
pt5 = sub2.groupby('LOCATION’).size()*100/len(sub2)
print(’% groupby’,pt5)
pt6 = data.groupby('LOCATION’).size()*100/len(data)
print(’% groupby all data’,pt6)
% groupby LOCATION 1 26.506024 2 73.493976 dtype: float64 % groupby all data LOCATION 1 52.362631 2 47.637369 dtype: float64
From this data we can see that over 73% of the larger impact craters (ie. 1 or more layers) landed on the lower half of Mars where as an almost even distribution of craters 52% and 47% are recorded using all of the data.
# Categorial
seaborn.countplot(x = 'LOCATION', data = sub2)
plt.xlabel('Location')
plt.ylabel('Number of Craters with more than 1 layer')
plt.title('Mars Craters Location')
# Categorial
seaborn.countplot(x = 'LOCATION', data = data)
plt.xlabel('Location')
plt.ylabel('Number of Craters ')
plt.title('Mars Craters Location')
# Distributions of depth of craters formed on Mars
mean = data['DEPTH_RIMFLOOR_TOPOG'].mean()
print(mean)
mode = data['DEPTH_RIMFLOOR_TOPOG'].mode()
print(mode)
data['DEPTH_RIMFLOOR_TOPOG'].describe()
0.04500709934502822 0 0.000000 dtype: float64
count 65499.000000 mean 0.045007 std 0.164268 min -0.030000 25% 0.000000 50% 0.000000 75% 0.000000 max 3.140000 Name: DEPTH_RIMFLOOR_TOPOG, dtype: float64
sub2['DEPTH_RIMFLOOR_TOPOG'].describe()
count 1079.000000 mean 0.841409 std 0.309688 min 0.500000 25% 0.620000 50% 0.760000 75% 0.970000 max 2.260000 Name: DEPTH_RIMFLOOR_TOPOG, dtype: float64
This gives us more information because there is such a large number of zero layered craters that gave us very low values of distributions.
scat1 = seaborn.regplot(x = 'LONGITUDE_CIRCLE_IMAGE',
y = 'LATITUDE_CIRCLE_IMAGE',
fit_reg = False, data = data)
plt.xlabel('Longitude decimal degrees East')
plt.ylabel('Latitude decimal degrees North')
plt.title('Scatter plot of location of Craters on Mars all data')
This graph is useless because there are so many data points clustered that you cannot decipher anything.
scat2 = seaborn.regplot(x = 'LONGITUDE_CIRCLE_IMAGE',
y = 'LATITUDE_CIRCLE_IMAGE',
fit_reg = False, data = sub2)
plt.xlabel('Longitude decimal degrees East')
plt.ylabel('Latitude decimal degrees North')
plt.title('Scatter plot of location of Craters on Mars all data')
This is a very interesting plot because there is a large amount of empty space in the graph roughly between longitude -80-180 with latitude 0-30. This could possibly be from lack of data on that part of Mars.
data['NUMBER_LAYERS'] = data['NUMBER_LAYERS'].convert_objects(convert_numeric=True)
scat3 = seaborn.factorplot(x = 'NUMBER_LAYERS',
y ='DEPTH_RIMFLOOR_TOPOG',
data = data, ci = None)
plt.xlabel('Number of Layers')
plt.ylabel('Depth of crater rim in $km$')
plt.title('Association between crater depth and layers of all data')
scat4 = seaborn.factorplot(x = 'NUMBER_LAYERS',
y ='DEPTH_RIMFLOOR_TOPOG',
data = sub2, ci = None)
plt.xlabel('Number of Layers')
plt.ylabel('Depth of crater rim in $km$')
plt.title('Association between crater depth and layers excluding \n zero layers data and depth less than 0.5 $km$')
These last two graphs show the association between crater depth and the layers around the crater rim. As you can see there is a large correlation between a deeper crater and the number of layers around it.