-
Notifications
You must be signed in to change notification settings - Fork 18
finished assignment #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smortime
wants to merge
2
commits into
Geospatial-Python:master
Choose a base branch
from
smortime:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ def read_geojson(input_file): | |
""" | ||
# Please use the python json module (imported above) | ||
# to solve this one. | ||
gj = None | ||
with open(input_file, 'r') as f: | ||
gj = json.load(f) | ||
return gj | ||
|
||
|
||
|
@@ -56,9 +57,15 @@ def find_largest_city(gj): | |
population : int | ||
The population of the largest city | ||
""" | ||
city = None | ||
temp = gj['features'] | ||
city = "" | ||
max_population = 0 | ||
|
||
for i in temp: | ||
if (i['properties']['pop_max'] > max_population): | ||
max_population = i['properties']['pop_max'] | ||
city = i['properties']['name'] | ||
|
||
return city, max_population | ||
|
||
|
||
|
@@ -74,7 +81,16 @@ def write_your_own(gj): | |
Do not forget to write the accompanying test in | ||
tests.py! | ||
""" | ||
return | ||
#Finds how many megacities there are in the geoJSON | ||
temp = gj['features'] | ||
megacities = 0 | ||
|
||
for i in temp: | ||
if(i['properties']['megacity'] == 1): | ||
megacities += 1 | ||
|
||
|
||
return megacities | ||
|
||
def mean_center(points): | ||
""" | ||
|
@@ -93,8 +109,16 @@ def mean_center(points): | |
y : float | ||
Mean y coordinate | ||
""" | ||
x = None | ||
y = None | ||
|
||
x = 0 | ||
y = 0 | ||
|
||
for point in points: | ||
x += point[0] | ||
y += point[1] | ||
|
||
x = x / len(points) | ||
y = y / len(points) | ||
|
||
return x, y | ||
|
||
|
@@ -119,7 +143,20 @@ def average_nearest_neighbor_distance(points): | |
Measure of Spatial Relationships in Populations. Ecology. 35(4) | ||
p. 445-453. | ||
""" | ||
mean_d = 0 | ||
|
||
nearest = [] | ||
|
||
for i, point in enumerate(points): | ||
nearest.append(None) | ||
for point2 in points: | ||
if point is not point2: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works for this dataset, but what if the points are coincident? |
||
dist = euclidean_distance(point, point2) | ||
if nearest[i] == None: | ||
nearest[i] = dist | ||
elif nearest[i] > dist: | ||
nearest[i] = dist | ||
|
||
mean_d = sum(nearest) / len(points) | ||
|
||
return mean_d | ||
|
||
|
@@ -139,17 +176,34 @@ def minimum_bounding_rectangle(points): | |
Corners of the MBR in the form [xmin, ymin, xmax, ymax] | ||
""" | ||
|
||
first = True | ||
mbr = [0,0,0,0] | ||
|
||
for point in points: | ||
if first: | ||
first = False | ||
mbr[0] = point[0] | ||
mbr[1] = point[1] | ||
mbr[2] = point[0] | ||
mbr[3] = point[1] | ||
|
||
if point[0] < mbr[0]: | ||
mbr[0] = point[0] | ||
if point[1] < mbr[1]: | ||
mbr[1] = point[1] | ||
if point[0] > mbr[2]: | ||
mbr[2] = point[0] | ||
if point[1] > mbr[3]: | ||
mbr[3] = point[1] | ||
|
||
return mbr | ||
|
||
|
||
def mbr_area(mbr): | ||
""" | ||
Compute the area of a minimum bounding rectangle | ||
""" | ||
area = 0 | ||
|
||
area = (mbr[1] - mbr[3]) * (mbr[0] - mbr[2]) | ||
return area | ||
|
||
|
||
|
@@ -173,7 +227,7 @@ def expected_distance(area, n): | |
The number of points | ||
""" | ||
|
||
expected = 0 | ||
expected = 0.5 * (area / n) ** 0.5 | ||
return expected | ||
|
||
|
||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I image that something along these lines, but more robust will be part of your twitter work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of, so far I am pulling all the tweets from the the Twitter API and parsing the JSON for a handful of attributes and then writing them to a .csv (one column per tweet). However, when I start pulling from the Twitter Stream, it might be beneficial to just save summary stats from the JSON instead of every individual tweet, since I am not interested in everything from the stream data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled maybe 30 days of geoloacated data off the twitter stream. The approach I landed on was to use MongoDB (it has a good Python API) to store the data (the raw tweet). Then I analyzed the data in an iPython notebook using a combination of MongoDB database queries and raw Python. That might be a viable workflow that preserves the raw data?