Created
August 1, 2016 09:48
-
-
Save janfreyberg/ad1fc26b89771c040eebb54c888b9e82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import re # regular expressions | |
import csv | |
from matplotlib import pyplot as pl | |
from scipy.stats.stats import pearsonr | |
def parse_dms(dms): | |
parts = re.split('[^\d\w]+', dms) | |
lat = dms2dd(parts[0], parts[1], parts[2]) | |
# lng = dms2dd(parts[4], parts[5], parts[6], parts[7]) | |
return lat | |
def dms2dd(degrees, minutes, direction): | |
dd = float(degrees) + float(minutes) / 60 | |
if direction == 'S' or direction == 'W': | |
dd *= -1 | |
return dd | |
# Create dictionaries of geolocation: | |
with open('geoposition.csv', 'rU') as geofile: | |
georeader = csv.reader(geofile, delimiter=',') | |
next(georeader, None) # skip header | |
latitudes = {row[0]: parse_dms(row[1]) for row in georeader} | |
with open('geoposition.csv', 'rU') as geofile: | |
georeader = csv.reader(geofile, delimiter=',') | |
next(georeader, None) # skip header | |
longitudes = {row[0]: parse_dms(row[2]) for row in georeader} | |
# Create dictionary of roundedness: | |
with open('roundedness.csv', 'rU') as geofile: | |
roundreader = csv.reader(geofile, delimiter=',') | |
next(roundreader, None) # skip header | |
roundedness = {row[0]: float(row[1]) for row in roundreader} | |
xround = [] | |
ylatit = [] | |
ylongi = [] | |
# Create lists to determine correlation: | |
for index, roundkey in enumerate(roundedness): | |
for geokey in latitudes: | |
if roundkey in geokey: | |
xround.append(roundedness[roundkey]) | |
ylatit.append(latitudes[geokey]) | |
ylongi.append(longitudes[geokey]) | |
fig = pl.figure() | |
pl.scatter(np.absolute(ylongi), xround) | |
trendline = np.poly1d(np.polyfit(np.absolute(ylongi), xround, 1)) | |
pl.plot(np.absolute(ylongi), trendline(np.absolute(ylongi)), 'r--') | |
pl.xlabel('Longitude of Capital') | |
pl.ylabel('Roundness of Country') | |
print(pearsonr(np.absolute(ylongi), xround)) | |
pl.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Country | Latitude | Longitude | |
---|---|---|---|
Afghanistan | 34'28'N | 69'11'E | |
Albania | 41'18'N | 19'49'E | |
Algeria | 36'42'N | 03'08'E | |
American Samoa | 14'16'S | 170'43'W | |
Andorra | 42'31'N | 01'32'E | |
Angola | 08'50'S | 13'15'E | |
Antigua and Barbuda | 17'20'N | 61'48'W | |
Argentina | 36'30'S | 60'00'W | |
Armenia | 40'10'N | 44'31'E | |
Aruba | 12'32'N | 70'02'W | |
Australia | 35'15'S | 149'08'E | |
Austria | 48'12'N | 16'22'E | |
Azerbaijan | 40'29'N | 49'56'E | |
Bahamas | 25'05'N | 77'20'W | |
Bahrain | 26'10'N | 50'30'E | |
Bangladesh | 23'43'N | 90'26'E | |
Barbados | 13'05'N | 59'30'W | |
Belarus | 53'52'N | 27'30'E | |
Belgium | 50'51'N | 04'21'E | |
Belize | 17'18'N | 88'30'W | |
Benin | 06'23'N | 02'42'E | |
Bhutan | 27'31'N | 89'45'E | |
Bolivia | 16'20'S | 68'10'W | |
Bosnia and Herzegovina | 43'52'N | 18'26'E | |
Botswana | 24'45'S | 25'57'E | |
Brazil | 15'47'S | 47'55'W | |
British Virgin Islands | 18'27'N | 64'37'W | |
Brunei Darussalam | 04'52'N | 115'00'E | |
Bulgaria | 42'45'N | 23'20'E | |
Burkina Faso | 12'15'N | 01'30'W | |
Burundi | 03'16'S | 29'18'E | |
Cambodia | 11'33'N | 104'55'E | |
Cameroon | 03'50'N | 11'35'E | |
Canada | 45'27'N | 75'42'W | |
Cape Verde | 15'02'N | 23'34'W | |
Cayman Islands | 19'20'N | 81'24'W | |
Central African Republic | 04'23'N | 18'35'E | |
Chad | 12'10'N | 14'59'E | |
Chile | 33'24'S | 70'40'W | |
China | 39'55'N | 116'20'E | |
Colombia | 04'34'N | 74'00'W | |
Comros | 11'40'S | 43'16'E | |
Congo | 04'09'S | 15'12'E | |
Costa Rica | 09'55'N | 84'02'W | |
Cote d'Ivoire | 06'49'N | 05'17'W | |
Croatia | 45'50'N | 15'58'E | |
Cuba | 23'08'N | 82'22'W | |
Cyprus | 35'10'N | 33'25'E | |
Czech Republic | 50'05'N | 14'22'E | |
Democratic People's Republic of North Korea | 39'09'N | 125'30'E | |
Democratic Republic of the Congo | 04'20'S | 15'15'E | |
Denmark | 55'41'N | 12'34'E | |
Djibouti | 11'08'N | 42'20'E | |
Dominica | 15'20'N | 61'24'W | |
Dominica Republic | 18'30'N | 69'59'W | |
East Timor | 08'29'S | 125'34'E | |
Ecuador | 00'15'S | 78'35'W | |
Egypt | 30'01'N | 31'14'E | |
El Salvador | 13'40'N | 89'10'W | |
Equatorial Guinea | 03'45'N | 08'50'E | |
Eritrea | 15'19'N | 38'55'E | |
Estonia | 59'22'N | 24'48'E | |
Ethiopia | 09'02'N | 38'42'E | |
Falkland Islands (Malvinas) | 51'40'S | 59'51'W | |
Faroe Islands | 62'05'N | 06'56'W | |
Fiji | 18'06'S | 178'30'E | |
Finland | 60'15'N | 25'03'E | |
France | 48'50'N | 02'20'E | |
French Guiana | 05'05'N | 52'18'W | |
French Polynesia | 17'32'S | 149'34'W | |
Gabon | 00'25'N | 09'26'E | |
Gambia | 13'28'N | 16'40'W | |
Georgia | 41'43'N | 44'50'E | |
Germany | 52'30'N | 13'25'E | |
Ghana | 05'35'N | 00'06'W | |
Greece | 37'58'N | 23'46'E | |
Greenland | 64'10'N | 51'35'W | |
Guadeloupe | 16'00'N | 61'44'W | |
Guatemala | 14'40'N | 90'22'W | |
Guernsey | 49'26'N | 02'33'W | |
Guinea | 09'29'N | 13'49'W | |
Guinea-Bissau | 11'45'N | 15'45'W | |
Guyana | 06'50'N | 58'12'W | |
Haiti | 18'40'N | 72'20'W | |
Heard Island and McDonald Islands | 53'00'S | 74'00'E | |
Honduras | 14'05'N | 87'14'W | |
Hungary | 47'29'N | 19'05'E | |
Iceland | 64'10'N | 21'57'W | |
India | 28'37'N | 77'13'E | |
Indonesia | 06'09'S | 106'49'E | |
Iran (Islamic Republic of) | 35'44'N | 51'30'E | |
Iraq | 33'20'N | 44'30'E | |
Ireland | 53'21'N | 06'15'W | |
Israel | 31'47'N | 35'12'E | |
Italy | 41'54'N | 12'29'E | |
Jamaica | 18'00'N | 76'50'W | |
Jordan | 31'57'N | 35'52'E | |
Kazakhstan | 51'10'N | 71'30'E | |
Kenya | 01'17'S | 36'48'E | |
Kiribati | 01'30'N | 173'00'E | |
Kuwait | 29'30'N | 48'00'E | |
Kyrgyzstan | 42'54'N | 74'46'E | |
Lao People's Democratic Republic | 17'58'N | 102'36'E | |
Latvia | 56'53'N | 24'08'E | |
Lebanon | 33'53'N | 35'31'E | |
Lesotho | 29'18'S | 27'30'E | |
Liberia | 06'18'N | 10'47'W | |
Libyan Arab Jamahiriya | 32'49'N | 13'07'E | |
Liechtenstein | 47'08'N | 09'31'E | |
Lithuania | 54'38'N | 25'19'E | |
Luxembourg | 49'37'N | 06'09'E | |
Macao, China | 22'12'N | 113'33'E | |
Madagascar | 18'55'S | 47'31'E | |
Malawi | 14'00'S | 33'48'E | |
Malaysia | 03'09'N | 101'41'E | |
Maldives | 04'00'N | 73'28'E | |
Mali | 12'34'N | 07'55'W | |
Malta | 35'54'N | 14'31'E | |
Martinique | 14'36'N | 61'02'W | |
Mauritania | 20'10'S | 57'30'E | |
Mayotte | 12'48'S | 45'14'E | |
Mexico | 19'20'N | 99'10'W | |
Micronesia (Federated States of) | 06'55'N | 158'09'E | |
Moldova, Republic of | 47'02'N | 28'50'E | |
Mozambique | 25'58'S | 32'32'E | |
Myanmar | 16'45'N | 96'20'E | |
Namibia | 22'35'S | 17'04'E | |
Nepal | 27'45'N | 85'20'E | |
Netherlands | 52'23'N | 04'54'E | |
Netherlands Antilles | 12'05'N | 69'00'W | |
New Caledonia | 22'17'S | 166'30'E | |
New Zealand | 41'19'S | 174'46'E | |
Nicaragua | 12'06'N | 86'20'W | |
Niger | 13'27'N | 02'06'E | |
Nigeria | 09'05'N | 07'32'E | |
Norfolk Island | 45'20'S | 168'43'E | |
Northern Mariana Islands | 15'12'N | 145'45'E | |
Norway | 59'55'N | 10'45'E | |
Oman | 23'37'N | 58'36'E | |
Pakistan | 33'40'N | 73'10'E | |
Palau | 07'20'N | 134'28'E | |
Panama | 09'00'N | 79'25'W | |
Papua New Guinea | 09'24'S | 147'08'E | |
Paraguay | 25'10'S | 57'30'W | |
Peru | 12'00'S | 77'00'W | |
Philippines | 14'40'N | 121'03'E | |
Poland | 52'13'N | 21'00'E | |
Portugal | 38'42'N | 09'10'W | |
Puerto Rico | 18'28'N | 66'07'W | |
Qatar | 25'15'N | 51'35'E | |
Republic of Korea | 37'31'N | 126'58'E | |
Romania | 44'27'N | 26'10'E | |
Russian Federation | 55'45'N | 37'35'E | |
Rawanda | 01'59'S | 30'04'E | |
Saint Kitts and Nevis | 17'17'N | 62'43'W | |
Saint Lucia | 14'02'N | 60'58'W | |
Saint Pierre and Miquelon | 46'46'N | 56'12'W | |
Saint vincent and the Grenadines | 13'10'N | 61'10'W | |
Samoa | 13'50'S | 171'50'W | |
San Marino | 43'55'N | 12'30'E | |
Sao Tome and Principe | 00'10'N | 06'39'E | |
Saudi Arabia | 24'41'N | 46'42'E | |
Senegal | 14'34'N | 17'29'W | |
Sierra Leone | 08'30'N | 13'17'W | |
Slovakia | 48'10'N | 17'07'E | |
Slovenia | 46'04'N | 14'33'E | |
Solomon Islands | 09'27'S | 159'57'E | |
Somalia | 02'02'N | 45'25'E | |
South Africa | 25'44'S | 28'12'E | |
Spain | 40'25'N | 03'45'W | |
Sudan | 15'31'N | 32'35'E | |
Suriname | 05'50'N | 55'10'W | |
Swaziland | 26'18'S | 31'06'E | |
Sweden | 59'20'N | 18'03'E | |
Switzerland | 46'57'N | 07'28'E | |
Syrian Arab Republic | 33'30'N | 36'18'E | |
Tajikistan | 38'33'N | 68'48'E | |
Thailand | 13'45'N | 100'35'E | |
The Former Yugoslav Republic of Macedonia | 42'01'N | 21'26'E | |
Togo | 06'09'N | 01'20'E | |
Tonga | 21'10'S | 174'00'W | |
Tunisia | 36'50'N | 10'11'E | |
Turkey | 39'57'N | 32'54'E | |
Turkmenistan | 38'00'N | 57'50'E | |
Tuvalu | 08'31'S | 179'13'E | |
Uganda | 00'20'N | 32'30'E | |
Ukraine | 50'30'N | 30'28'E | |
United Arab Emirates | 24'28'N | 54'22'E | |
United Kingdom of Great Britain and Northern Ireland | 51'36'N | 00'05'W | |
United Republic of Tanzania | 06'08'S | 35'45'E | |
United States of America | 39'91'N | 77'02'W | |
United States of Virgin Islands | 18'21'N | 64'56'W | |
Uruguay | 34'50'S | 56'11'W | |
Uzbekistan | 41'20'N | 69'10'E | |
Vanuatu | 17'45'S | 168'18'E | |
Venezuela | 10'30'N | 66'55'W | |
Viet Nam | 21'05'N | 105'55'E | |
Yugoslavia | 44'50'N | 20'37'E | |
Zambia | 15'28'S | 28'16'E | |
Zimbabwe | 17'43'S | 31'02'E |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Name | Roundness | |
---|---|---|
Sierra Leone | 0.934 | |
Nauru | 0.923 | |
Zimbabwe | 0.915 | |
Vatican | 0.908 | |
Poland | 0.903 | |
Scarborough Reef | 0.901 | |
Ivory Coast | 0.899 | |
Suriname | 0.897 | |
Swaziland | 0.896 | |
Uruguay | 0.894 | |
Romania | 0.894 | |
Sudan | 0.891 | |
Ethiopia | 0.888 | |
Botswana | 0.886 | |
San Marino | 0.886 | |
Kosovo | 0.881 | |
Monaco | 0.88 | |
Andorra | 0.879 | |
Belarus | 0.876 | |
Egypt | 0.875 | |
Macedonia | 0.866 | |
Nicaragua | 0.866 | |
Nigeria | 0.862 | |
Gabon | 0.861 | |
Bajo Nuevo Bank (Petrel Is.) | 0.86 | |
Uganda | 0.859 | |
Montenegro | 0.858 | |
Democratic Republic of the Congo | 0.858 | |
United Republic of Tanzania | 0.857 | |
Algeria | 0.856 | |
Lithuania | 0.856 | |
Cambodia | 0.855 | |
Antarctica | 0.855 | |
Germany | 0.853 | |
Kenya | 0.852 | |
Lesotho | 0.852 | |
Bolivia | 0.849 | |
Angola | 0.849 | |
Bosnia and Herzegovina | 0.847 | |
Mauritania | 0.847 | |
Senegal | 0.836 | |
Ecuador | 0.833 | |
Niger | 0.832 | |
Spain | 0.831 | |
Mauritius | 0.831 | |
Colombia | 0.83 | |
Libya | 0.827 | |
Afghanistan | 0.823 | |
Ireland | 0.822 | |
Syria | 0.82 | |
South Korea | 0.819 | |
Switzerland | 0.817 | |
Sri Lanka | 0.816 | |
Estonia | 0.813 | |
Iceland | 0.811 | |
Saudi Arabia | 0.81 | |
Chad | 0.81 | |
Rwanda | 0.81 | |
Equatorial Guinea | 0.81 | |
Luxembourg | 0.808 | |
Australia | 0.808 | |
Burundi | 0.807 | |
South Sudan | 0.804 | |
Iran | 0.804 | |
Guatemala | 0.802 | |
Belgium | 0.802 | |
Brazil | 0.802 | |
South Africa | 0.8 | |
Djibouti | 0.799 | |
Serranilla Bank | 0.798 | |
Ghana | 0.796 | |
Barbados | 0.794 | |
Bhutan | 0.793 | |
Iraq | 0.792 | |
Azerbaijan | 0.792 | |
Bulgaria | 0.791 | |
Kuwait | 0.79 | |
Sao Tome and Principe | 0.788 | |
Czech Republic | 0.783 | |
Slovenia | 0.781 | |
Saint Vincent and the Grenadines | 0.778 | |
Venezuela | 0.777 | |
Singapore | 0.776 | |
Cameroon | 0.776 | |
Siachen Glacier | 0.775 | |
Saint Lucia | 0.775 | |
Austria | 0.769 | |
Armenia | 0.768 | |
India | 0.767 | |
Republic of Serbia | 0.766 | |
Hungary | 0.766 | |
Namibia | 0.761 | |
Netherlands | 0.76 | |
Dominican Republic | 0.759 | |
Trinidad and Tobago | 0.758 | |
Kazakhstan | 0.756 | |
Denmark | 0.752 | |
Thailand | 0.75 | |
Somaliland | 0.749 | |
Honduras | 0.749 | |
Bangladesh | 0.748 | |
Burkina Faso | 0.747 | |
Qatar | 0.744 | |
Mongolia | 0.744 | |
Grenada | 0.744 | |
Ukraine | 0.739 | |
Guinea Bissau | 0.737 | |
China | 0.729 | |
Dominica | 0.728 | |
Eritrea | 0.728 | |
North Korea | 0.725 | |
Liberia | 0.724 | |
Argentina | 0.723 | |
Myanmar | 0.723 | |
Canada | 0.722 | |
Cyprus | 0.72 | |
Malta | 0.716 | |
Latvia | 0.705 | |
Turkmenistan | 0.705 | |
Tunisia | 0.705 | |
Benin | 0.703 | |
Guinea | 0.703 | |
Georgia | 0.702 | |
Central African Republic | 0.7 | |
Jordan | 0.699 | |
Paraguay | 0.699 | |
Zambia | 0.698 | |
Mali | 0.696 | |
United States of America | 0.695 | |
Taiwan | 0.693 | |
Kyrgyzstan | 0.69 | |
Yemen | 0.689 | |
Liechtenstein | 0.687 | |
Slovakia | 0.685 | |
Guyana | 0.685 | |
Madagascar | 0.683 | |
Papua New Guinea | 0.683 | |
Jamaica | 0.681 | |
Finland | 0.68 | |
Peru | 0.679 | |
Albania | 0.679 | |
Pakistan | 0.673 | |
Moldova | 0.673 | |
United Arab Emirates | 0.673 | |
Belize | 0.672 | |
Oman | 0.671 | |
El Salvador | 0.671 | |
Costa Rica | 0.667 | |
Russia | 0.663 | |
Lebanon | 0.662 | |
Turkey | 0.661 | |
Mozambique | 0.654 | |
Haiti | 0.652 | |
Bahrain | 0.649 | |
Tajikistan | 0.648 | |
Brunei | 0.638 | |
Greece | 0.634 | |
Mexico | 0.63 | |
Republic of Congo | 0.625 | |
Antigua and Barbuda | 0.624 | |
Laos | 0.622 | |
Croatia | 0.603 | |
East Timor | 0.6 | |
Morocco | 0.598 | |
Portugal | 0.597 | |
Nepal | 0.591 | |
Israel | 0.587 | |
Uzbekistan | 0.58 | |
Fiji | 0.578 | |
United Kingdom | 0.575 | |
France | 0.573 | |
Samoa | 0.573 | |
Italy | 0.56 | |
Northern Cyprus | 0.559 | |
Palau | 0.554 | |
Somalia | 0.549 | |
Saint Kitts and Nevis | 0.54 | |
Malawi | 0.538 | |
Federated States of Micronesia | 0.538 | |
Togo | 0.533 | |
Sweden | 0.514 | |
Panama | 0.503 | |
Norway | 0.502 | |
Comoros | 0.484 | |
Vietnam | 0.45 | |
New Zealand | 0.437 | |
Cuba | 0.425 | |
Philippines | 0.421 | |
Japan | 0.416 | |
Indonesia | 0.396 | |
Malaysia | 0.392 | |
Tonga | 0.378 | |
Gambia | 0.375 | |
Seychelles | 0.355 | |
Kiribati | 0.351 | |
Western Sahara | 0.347 | |
The Bahamas | 0.342 | |
Vanuatu | 0.34 | |
Solomon Islands | 0.333 | |
Cape Verde | 0.299 | |
Chile | 0.297 | |
Maldives | 0.289 | |
Tuvalu | 0.278 | |
Cyprus No Mans Area | 0.26 | |
Spratly Islands | 0.199 | |
Marshall Islands | 0.116 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment