From 3aec3516594ae007c9d4d4605ad04e5be4135033 Mon Sep 17 00:00:00 2001 From: Joseph Cruz Date: Tue, 19 Apr 2016 22:12:43 -0700 Subject: [PATCH] assignment10 --- .idea/.name | 1 + .idea/assignment_10.iml | 12 + .idea/encodings.xml | 6 + .idea/misc.xml | 14 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 493 ++++++++++++++++++++++++++++++++ Assignment 10.ipynb | 620 ++++++++++++++++++++++++++++++++++++++++ io_geojson.py | 100 +++++++ point.py | 430 ++++++++++++++++++++++++++++ view.py | 38 +++ 11 files changed, 1728 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/assignment_10.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Assignment 10.ipynb create mode 100644 io_geojson.py create mode 100644 point.py create mode 100644 view.py diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..ccf6ee9 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +assignment_10 \ No newline at end of file diff --git a/.idea/assignment_10.iml b/.idea/assignment_10.iml new file mode 100644 index 0000000..6f63a63 --- /dev/null +++ b/.idea/assignment_10.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f9edad6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0aafca3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..20243a6 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,493 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1461033612685 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Assignment 10.ipynb b/Assignment 10.ipynb new file mode 100644 index 0000000..acb1654 --- /dev/null +++ b/Assignment 10.ipynb @@ -0,0 +1,620 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import io_geojson as iogj" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "tweets = iogj.process_tweets(\"tweets.json\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "key: 716470349609603072\n", + "key: 716470350465212416\n", + "key: 716470661938458626\n", + "key: 716471347937804291\n", + "key: 716471107658776580\n", + "key: 716472702282784773\n", + "key: 716470828750143488\n", + "key: 716470736739667969\n", + "key: 716472933711917064\n", + "key: 716472952288481289\n", + "key: 716470746030080002\n", + "key: 716472956830912512\n", + "key: 716471361250729987\n", + "key: 716471516485984260\n", + "key: 716470426654744576\n", + "key: 716470698978385921\n", + "key: 716473393487286272\n", + "key: 716472288405630976\n", + "key: 716473434226556933\n", + "key: 716472126006407168\n", + "key: 716473632822681600\n", + "key: 716470653340225536\n", + "key: 716470366881841153\n", + "key: 716470577779712000\n", + "key: 716470492887027712\n", + "key: 716471588661514240\n", + "key: 716472287164129280\n", + "key: 716471900755533824\n", + "key: 716473707242205184\n", + "key: 716470941262282753\n", + "key: 716471687898771456\n", + "key: 716471541286903809\n", + "key: 716470418664611840\n", + "key: 716471029288144897\n", + "key: 716472807761154048\n", + "key: 716472078954684416\n", + "key: 716471429550579712\n", + "key: 716472970240069632\n", + "key: 716472686520602624\n", + "key: 716471216018554882\n", + "key: 716472060176797696\n", + "key: 716472336044523520\n", + "key: 716471292740767745\n", + "key: 716472566106337280\n", + "key: 716473776897007616\n", + "key: 716473656285614081\n", + "key: 716472600784977921\n", + "key: 716473581480194048\n", + "key: 716472345641103360\n", + "key: 716471752830750720\n", + "key: 716472621936709633\n", + "key: 716471666633613313\n", + "key: 716472750886490112\n", + "key: 716472636717400067\n", + "key: 716470365912834048\n", + "key: 716470564114862080\n", + "key: 716471798397845505\n", + "key: 716470415690862593\n", + "key: 716470519969619968\n", + "key: 716470772638691329\n", + "key: 716472329266593793\n", + "key: 716473644428361729\n", + "key: 716472487165333504\n", + "key: 716472291425525760\n", + "key: 716472797917130753\n", + "key: 716472766183112708\n", + "key: 716472922102104064\n", + "key: 716472234789896192\n", + "key: 716472658070622208\n", + "key: 716472699879428096\n", + "key: 716473750753902592\n", + "key: 716473636207591429\n", + "key: 716473722895409153\n", + "key: 716470840716472321\n", + "key: 716473711210049536\n", + "key: 716473659569754112\n", + "key: 716471509691211776\n", + "key: 716473511343050753\n", + "key: 716473220845572096\n", + "key: 716471869163982848\n", + "key: 716473425691222016\n", + "key: 716471160188248065\n", + "key: 716473297370615808\n", + "key: 716470620641497088\n", + "key: 716473399300632576\n", + "key: 716472055286226944\n", + "key: 716470643189878785\n", + "key: 716471091473068032\n", + "key: 716473402614108160\n", + "key: 716470477712019456\n", + "key: 716472105940832256\n", + "key: 716472064383660032\n", + "key: 716472900295864320\n", + "key: 716473659854983169\n", + "key: 716472411185504256\n", + "key: 716471318741278720\n", + "key: 716470661019860993\n", + "key: 716472912216129536\n", + "key: 716472999411523584\n", + "key: 716471023621771265\n", + "key: 716473024531136513\n", + "key: 716472290142105600\n", + "key: 716472347662770176\n", + "key: 716473056202346496\n", + "key: 716471547599261698\n", + "key: 716470350767194112\n", + "key: 716470391712034816\n", + "key: 716471352077606913\n", + "key: 716472943073595392\n", + "key: 716473389683113984\n", + "key: 716472784319172608\n", + "key: 716473731720286209\n", + "key: 716471651253227520\n", + "key: 716473107423354880\n", + "key: 716472494522109952\n", + "key: 716470778988863489\n", + "key: 716470855383945218\n", + "key: 716473751496339456\n", + "key: 716471477692866560\n", + "key: 716472116640505856\n", + "key: 716473561280421888\n", + "key: 716472516701597697\n", + "key: 716470742901100546\n", + "key: 716473383391592448\n", + "key: 716471354338324480\n", + "key: 716472082041733121\n", + "key: 716473189769949184\n", + "key: 716472697149132801\n", + "key: 716470655072350208\n", + "key: 716473135764279296\n", + "key: 716470660055207936\n", + "key: 716471525071785988\n", + "key: 716472477904285696\n", + "key: 716470474771795968\n", + "key: 716471318300860416\n", + "key: 716472773464313857\n", + "key: 716472234823458817\n", + "key: 716472583370092545\n", + "key: 716473035444752385\n", + "key: 716471701190488064\n", + "key: 716471579283050497\n", + "key: 716473301338570752\n", + "key: 716473282745098241\n", + "key: 716470421084901376\n", + "key: 716472675678363649\n", + "key: 716472683471306752\n", + "key: 716470724202921984\n", + "key: 716470782495338496\n", + "key: 716472499492356096\n", + "key: 716472565510774785\n", + "key: 716471250877435904\n", + "key: 716471657565528064\n", + "key: 716473797759467520\n", + "key: 716471025223880704\n", + "key: 716471807155408896\n", + "key: 716470578299801600\n", + "key: 716472514453450752\n", + "key: 716473761457766401\n", + "key: 716470952607899648\n", + "key: 716473444359995392\n", + "key: 716472272811200512\n", + "key: 716473431647072256\n", + "key: 716472241425231873\n", + "key: 716472226074079233\n", + "key: 716471673860403200\n", + "key: 716471854009942016\n", + "key: 716471957525385216\n", + "key: 716472262430314497\n", + "key: 716471082262376448\n", + "key: 716473726036877312\n", + "key: 716472899343765504\n", + "key: 716472526726045696\n", + "key: 716473530431344642\n", + "key: 716471442133483520\n", + "key: 716472544891506688\n", + "key: 716471462060630017\n", + "key: 716473369420410880\n", + "key: 716470497404268545\n", + "key: 716471961438715904\n", + "key: 716470903681327105\n", + "key: 716472454298775553\n", + "key: 716472696410734592\n", + "key: 716472825997975554\n", + "key: 716470598134697985\n", + "key: 716470388364947456\n", + "key: 716470920177553408\n", + "key: 716472590169202689\n", + "key: 716470500621299713\n", + "key: 716472107870228480\n", + "key: 716470527045476352\n", + "key: 716470925080666112\n", + "key: 716472335700635648\n", + "key: 716471083499585537\n", + "key: 716471204555534336\n", + "key: 716472283666092032\n", + "key: 716473425145913344\n", + "key: 716472238623449089\n", + "key: 716472727465406466\n", + "key: 716471393378902016\n", + "key: 716472571122692096\n", + "key: 716473113920151552\n", + "key: 716471787844861952\n", + "key: 716472124106354688\n", + "key: 716470785313902592\n", + "key: 716473507375230976\n", + "key: 716471670635044866\n", + "key: 716470580652802048\n", + "key: 716471233114537984\n", + "key: 716470593000869888\n", + "key: 716471293307068417\n", + "key: 716471972511657985\n", + "key: 716471406020571136\n", + "key: 716471953851199488\n", + "key: 716471522546700288\n", + "key: 716472695198625793\n", + "key: 716471209408397312\n", + "key: 716471757138321408\n", + "key: 716471983748227072\n", + "key: 716473694575415296\n", + "key: 716473139698401281\n", + "key: 716470628702769152\n", + "key: 716472542496555009\n", + "key: 716472207887638529\n", + "key: 716473155259228161\n", + "key: 716472197380857856\n", + "key: 716471760321847296\n", + "key: 716473043980136448\n", + "key: 716472208659361794\n", + "key: 716473572437299201\n", + "key: 716470925932101632\n", + "key: 716471667304718336\n", + "key: 716472547655553025\n", + "key: 716472229987418112\n", + "key: 716473231121588224\n", + "key: 716472093320171521\n", + "key: 716473200117284865\n", + "key: 716472337474854912\n", + "key: 716472186639286272\n", + "key: 716472966297456640\n", + "key: 716471238256754688\n", + "key: 716472725254983680\n", + "key: 716471456926797824\n", + "key: 716472653087903744\n", + "key: 716472988166565888\n", + "key: 716470930239676417\n", + "key: 716470660659326977\n", + "key: 716472585844690944\n", + "key: 716473470805094400\n", + "key: 716470506115837952\n", + "key: 716470534955933696\n", + "key: 716470488877244416\n", + "key: 716471857096962049\n", + "key: 716473609225527296\n", + "key: 716471469975281664\n", + "key: 716471964408283137\n", + "key: 716471038528258049\n", + "key: 716470992088870912\n", + "key: 716471401222287362\n", + "key: 716470515922145280\n", + "key: 716473689672265728\n", + "key: 716473712002732036\n", + "key: 716470555998703616\n", + "key: 716471418209181696\n", + "key: 716470513367789568\n", + "key: 716472716962897920\n", + "key: 716471052155506688\n", + "key: 716471306628149248\n", + "key: 716472070800998400\n", + "key: 716472033450729472\n", + "key: 716471495979978753\n", + "key: 716472779088867328\n", + "key: 716473586588889089\n", + "key: 716472957141262337\n", + "key: 716470495118434305\n", + "key: 716471685709303808\n", + "key: 716473705199611904\n", + "key: 716472767214825472\n", + "key: 716472998882988032\n", + "key: 716472702446485505\n", + "key: 716470963970310144\n", + "key: 716471251447853056\n", + "key: 716471381492244480\n", + "key: 716472286505664512\n", + "key: 716472932168392705\n", + "key: 716472806507094016\n", + "key: 716473070060318720\n", + "key: 716473717753131008\n", + "key: 716471908854661121\n", + "key: 716471802864730113\n", + "key: 716471339041693697\n", + "key: 716472743521181696\n", + "key: 716473032387092480\n", + "key: 716473553151926273\n", + "key: 716472741218504704\n", + "key: 716473761520717824\n", + "key: 716470460502769664\n", + "key: 716473599792549888\n", + "key: 716470906554437633\n", + "key: 716473180009930753\n", + "key: 716473529391140864\n", + "key: 716473658026418177\n", + "key: 716471111987306498\n", + "key: 716473392191307776\n", + "key: 716473015412719616\n", + "key: 716470466093813760\n", + "key: 716471944208453632\n", + "key: 716471823987122177\n", + "key: 716472843618267137\n", + "key: 716473732089315328\n", + "key: 716470724974682112\n", + "key: 716473405571096576\n", + "key: 716471278853431296\n", + "key: 716472805789806595\n", + "key: 716472716262387713\n", + "key: 716470979057295360\n", + "key: 716472611610361857\n", + "key: 716471570969931776\n", + "key: 716473676548341760\n", + "key: 716470529113231360\n", + "key: 716473770794434564\n", + "key: 716470959578853376\n", + "key: 716472285884854272\n", + "key: 716470993548484608\n", + "key: 716472392344686592\n", + "key: 716471343928086528\n", + "key: 716472899834503168\n", + "key: 716472708322623490\n", + "key: 716473363380641792\n", + "key: 716473434549538816\n", + "key: 716470559115124737\n", + "key: 716471933085220864\n", + "key: 716472284744011777\n", + "key: 716471865053552640\n", + "key: 716471036749852672\n", + "key: 716473403524325376\n", + "key: 716471448479485953\n", + "key: 716471051970945024\n", + "key: 716472556526641152\n", + "key: 716472016233058304\n", + "key: 716473462890438657\n", + "key: 716472832637599744\n", + "key: 716471558689071104\n", + "key: 716473724984172544\n", + "key: 716473190784978944\n", + "key: 716473008810885120\n", + "key: 716471531904196608\n", + "key: 716471555773964289\n", + "key: 716473545425981440\n", + "key: 716470927567892481\n", + "key: 716472586536783873\n", + "key: 716472828061614081\n", + "key: 716471118643593216\n", + "key: 716473005702942721\n", + "key: 716473445597339649\n", + "key: 716471292929515520\n", + "key: 716470900619542528\n", + "key: 716472311419789312\n", + "key: 716473166965506048\n", + "key: 716471435963666432\n", + "key: 716471678432190465\n", + "key: 716471624480915456\n", + "key: 716470401283428352\n", + "key: 716471653656502272\n", + "key: 716472329371410432\n", + "key: 716470582548832256\n", + "key: 716472231769939968\n", + "key: 716473412214894593\n", + "key: 716472375487770625\n", + "key: 716470963597017088\n", + "key: 716472431221714945\n", + "key: 716472432098344961\n", + "key: 716472676533964800\n", + "key: 716472995682787329\n", + "key: 716471258498539521\n", + "key: 716473484163960836\n", + "key: 716471219558592512\n", + "key: 716471991281135616\n", + "key: 716473226516246528\n", + "key: 716472893417267201\n", + "key: 716472764148809728\n", + "key: 716473737558695937\n", + "key: 716471630571003904\n", + "key: 716472758318682112\n", + "key: 716472905194803200\n", + "key: 716472242004078593\n", + "key: 716470692124884993\n", + "key: 716471298818330625\n", + "key: 716473033754423296\n", + "key: 716473278831824896\n", + "key: 716471131587289089\n", + "key: 716472830137802752\n", + "key: 716472398862659584\n", + "key: 716472265131429888\n", + "key: 716472956449230848\n", + "key: 716472455804510209\n", + "key: 716473251678040065\n", + "key: 716473438454480897\n", + "key: 716473229531959296\n", + "key: 716473311643852801\n", + "key: 716473178239807488\n", + "key: 716472903504502784\n", + "key: 716471256602714112\n", + "key: 716473328035180545\n", + "key: 716471419035451393\n", + "key: 716473080642555904\n", + "key: 716472415224619008\n", + "key: 716473024308862976\n", + "key: 716470456870641665\n", + "key: 716471086641053696\n", + "key: 716471544986230786\n", + "key: 716470853198675968\n", + "key: 716472938875133952\n", + "key: 716473441805664256\n", + "key: 716470625091465216\n", + "key: 716470622734299137\n", + "key: 716471364622819329\n", + "key: 716472791894110208\n", + "key: 716473272993341441\n", + "key: 716472931182772224\n", + "key: 716473155745751040\n", + "key: 716471164168577026\n", + "key: 716472871376125953\n", + "key: 716473188545273856\n", + "key: 716470979728248832\n", + "key: 716472798726631424\n", + "key: 716470973524869120\n", + "key: 716472198886653952\n", + "key: 716473487926276096\n", + "key: 716473075768762368\n", + "key: 716471139451572225\n", + "key: 716472665339338752\n", + "key: 716470381482090496\n", + "key: 716470779810951169\n", + "key: 716472971418738688\n", + "key: 716471595053678593\n", + "key: 716470668821278720\n", + "key: 716472491586129920\n", + "key: 716470377854013440\n", + "key: 716471564330356737\n", + "key: 716470710009344000\n", + "key: 716472027515736064\n", + "key: 716471386638712832\n", + "key: 716472173154541569\n", + "key: 716472736969728000\n", + "key: 716472512859648001\n", + "key: 716472840342495233\n", + "key: 716473525180047360\n", + "key: 716470683291688962\n", + "key: 716472558040657920\n", + "key: 716470418232594433\n", + "key: 716471030701821952\n", + "key: 716473382817017856\n", + "key: 716470472297226241\n", + "key: 716471073370279936\n", + "key: 716471070124060672\n", + "key: 716472402184523776\n", + "key: 716472327072919552\n", + "key: 716471941654192128\n", + "key: 716473049286066176\n", + "key: 716471757415145472\n", + "key: 716470681781665792\n", + "key: 716471981445545984\n", + "key: 716470691894312960\n", + "key: 716472274010787840\n", + "key: 716471407761186816\n", + "key: 716472101880737792\n", + "key: 716470930780753920\n", + "key: 716472333859291136\n", + "key: 716473212574404608\n", + "key: 716472408006209536\n", + "key: 716472179689283584\n", + "key: 716472510384963584\n", + "key: 716471019821600769\n", + "key: 716470485836386304\n", + "key: 716470880906428416\n", + "key: 716471170845921281\n", + "key: 716470411291013120\n", + "key: 716472218872455169\n", + "key: 716472496967393281\n", + "key: 716473204752191488\n", + "key: 716472406005579776\n", + "key: 716473090461437952\n", + "key: 716472659500859392\n", + "key: 716471148146364417\n", + "key: 716470648227254273\n", + "key: 716471835194302467\n", + "key: 716470626664382464\n", + "key: 716471877149937664\n", + "key: 716470584859697152\n", + "key: 716471863421972481\n", + "key: 716470870516994048\n", + "key: 716471451348508672\n", + "key: 716472046595616769\n", + "key: 716473693258575872\n", + "key: 716471278278840320\n", + "key: 716470887050940416\n", + "key: 716472030581751808\n", + "key: 716471709189079040\n", + "key: 716470882844028928\n", + "key: 716471462232633344\n" + ] + } + ], + "source": [ + "for key in tweets:\n", + " print (\"key: %s\" % (key))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"it's pass 8 and I still haven't eaten dinner yet.... AGAIN⁉️‼️\"" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tweets[716470349609603072]['text']" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n" + ] + } + ], + "source": [ + "for i in range(4):\n", + " print (i)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/io_geojson.py b/io_geojson.py new file mode 100644 index 0000000..1e299c9 --- /dev/null +++ b/io_geojson.py @@ -0,0 +1,100 @@ +import json # for the geojson stuff + +# ------------------------------------------------------------------ +# +# Joseph Cruz +# io_geojson.py +# +# Stores the functions from point_pattern.py that are a form of +# utility needed for use in other functions +# ------------------------------------------------------------------ + + +def process_tweets(input_file): + tweets_gj = read_geojson(input_file) + tweets_out = 0 + + list_tweet_ids = [] + for j in range(len(tweets_gj)): + list_tweet_ids.append(tweets_gj[j]['id']) + + tweets_out = {} + for i in range(len(list_tweet_ids)): + id_in = tweets_gj[i]['id'] + tweets_out[id_in] = tweets_gj[i] + + return tweets_out + + +def read_geojson(input_file): + """ + Read a geojson file + + Parameters + ---------- + input_file : str + The PATH to the data to be read + + Returns + ------- + gj : dict + An in memory version of the geojson + """ + # Please use the python json module (imported above) + # to solve this one. + with open(input_file) as iFile: + gj = json.load(iFile) + return gj + + +def find_largest_city(gj): + """ + Iterate through a geojson feature collection and + find the largest city. Assume that the key + to access the maximum population is 'pop_max'. + + Parameters + ---------- + gj : dict + A GeoJSON file read in as a Python dictionary + + Returns + ------- + city : str + The largest city + + population : int + The population of the largest city + """ + gj_features = gj['features'] + city = None + max_population = 0 + + for nextFeature in gj_features: + if nextFeature['pop_max'] > max_population: + city = nextFeature['name'] + max_population = nextFeature['pop_max'] + + return city, max_population + + +def write_your_own(gj): + """ + Here you will write your own code to find + some attribute in the supplied geojson file. + + Take a look at the attributes available and pick + something interesting that you might like to find + or summarize. This is totally up to you. + + Do not forget to write the accompanying test in + tests.py! + """ + #Counts the number of world cities + gj_features = gj['features'] + numWorldCities = 0 + + for nextFeature in gj_features: + if nextFeature['worldcity'] != 0: + numWorldCities += 1 + return numWorldCities diff --git a/point.py b/point.py new file mode 100644 index 0000000..5842ec4 --- /dev/null +++ b/point.py @@ -0,0 +1,430 @@ +import random +import math +import numpy as np +import scipy.spatial as ss +import pysal as ps +import io_geojson as iogj +import folium + + +# [Joseph] I decided to have Tweet incorporate a Point class +# I can avoid inheritance and just use point data and methods +# as if it were an attribute of Tweet. +class Tweet: + def __init__(self): + self.point_data = Point() + self.text = "" + self.latitutde = 0.0 + self.longitutde = 0.0 + self.interesting = [] + + +class TweetPattern: + def __init__(self): + self.Tweets = [] + + def assign_lat_long(self, input_file): + set_tweets = iogj.process_tweets(input_file) + new_tweet = Tweet() + + for key in set_tweets: + in_text = set_tweets[key]['text'] + + lat_min = 999 + lat_max = -999 + long_min = 999 + long_max = -999 + + for i in range(4): + if i == 0: + long_min = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][0] + long_max = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][0] + + lat_min = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][1] + lat_max = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][1] + else: + if set_tweets[key]['place']['bounding_box']['coordinates'][0][i][0] > long_max: + long_max = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][0] + if set_tweets[key]['place']['bounding_box']['coordinates'][0][i][0] < long_min: + long_min = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][0] + + if set_tweets[key]['place']['bounding_box']['coordinates'][0][i][1] > lat_max: + lat_max = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][1] + if set_tweets[key]['place']['bounding_box']['coordinates'][0][i][1] < lat_min: + lat_min = set_tweets[key]['place']['bounding_box']['coordinates'][0][i][1] + + x = random.uniform(long_min, long_max) + y = random.uniform(lat_min,lat_max) + + new_tweet.latitude = y + new_tweet.longitutde = x + new_tweet.text = in_text + self.Tweets.append(new_tweet) + + + def build_folium_map(self): + map_tweets = folium.map(location=[33.42,-112.065]) + for j in range(len(self.Tweets)): + folium.marker([self.Tweets[j].y,self.Tweets[j].x],popup = self.Tweets[j].text) + +class Point: + """ + For whatever reason, cannot get import to work, just moved functionality + into this file instead. + """ + def __init__(self,x = 0,y = 0,mark = ""): + self.x = x + self.y = y + self.mark = mark + + def __eq__(self, other): + return self.x == other.x and self.y == other.y + + def __gt__(self, other): + direction = "" + if self.y > other.y: + direction += "N" + elif self.y == other.y: + direction += "-" + else: + direction += "S" + if self.x > other.x: + direction += "E" + elif self.x == other.y: + direction += "-" + else: + direction += "W" + + return direction + + def __neg__(self): + return Point(-self.x,-self.y,self.mark) + + def shift_point(self,x_move,y_move): + this_point = (self.x,self.y) + self.x += x_move + self.y += y_move + + """ + Made redundant by __eq__ + def coincident(self, check_point): + if check_point.x == self.x and check_point.y == self.y: + return True + else: + return False + """ + + +class PointPattern: + def __init__(self): + self.set_of_points = [] + + def avg_nearest_neighbor_dist(self,mark): + average_nearest_neighbor_distance(self.set_of_points, mark) + + def num_coincident_points(self): + coincident_points = 0 + len_list = len(self.set_of_points) + for i in range(len_list): + if i == len_list-1: + break + for j in range(len_list+1): + if self.set_of_points[i] == self.set_of_points[j]: + coincident_points += 1 + + return coincident_points + + def list_marks(self): + mark_list = [] + len_list = len(self.set_of_points) + for i in range(len_list): + if not mark_list: + mark_list.append(self.set_of_points[i].mark) + elif self.set_of_points[i].mark not in mark_list: + mark_list.append(self.set_of_points[i].mark) + + return mark_list + + def list_mark_subsets(self): + mark_list = PointPattern.list_marks(self) + mark_count = [] + sub_set = [] + for i in range(len(mark_list)): + sub_set = [] + for j in range(len(self.set_of_points)): + if mark_list[i] == self.set_of_points[j].mark: + sub_set.append(self.set_of_points[j]) + mark_count.append(sub_set) + + return mark_count + + def create_random_points(self, n=100, marks = []): + if not marks: + self.set_of_points = create_random_unmarked_points(n) + else: + self.set_of_points = create_random_marked_points(n,marks) + + def k_realizations(self,k = 99): + return permutations(k,n = 100) + + def critical_points(self,realizations): + return find_crit_points(realizations) + + def compute_g(self, min_dist): + gs = 0 + len_list = len(self.set_of_points) + all_pts_min_dists = [] + for i in range(len_list): + local_nn = 0 + for j in range(len_list): + if i != j: + new_distance = euclidean_distance(self.set_of_points[i],self.set_of_points[j]) + if local_nn == 0: + local_nn = new_distance + elif new_distance < local_nn: + local_nn = new_distance + + all_pts_min_dists.append(local_nn) + + for k in range(len(all_pts_min_dists)): + if all_pts_min_dists[k]<=min_dist: + gs += 1 + + return gs + """ + Assignment 8 stuff + """ + + def nearest_neighbor_kdtree(self, mark=""): + buffer = build_np_array(self.set_of_points, mark) + kdtree = ss.KDTree(buffer) + calc_distances = [] + values = [] + for i in buffer: + nn_distance, nn = kdtree.query(i, k=2) + #do we remove the first one since it is the coincident? + calc_distances.append(nn_distance[1]) + values.append(nn) + distances = np.array(calc_distances) + return distances + + def nn_kdtree_avg(self, mark=""): + return np.mean(self.nearest_neighbor_kdtree(mark)) + + def np_compute_g(self, min_dist, mark=""): + buffer = build_np_array(self.set_of_points, mark) + g = 0 + n = len(self.set_of_points) + list_of_min_dists = [] + for i in range(len(self.set_of_points)): + local_nn = 0 + for j in range(len(self.set_of_points)): + if i != j: + new_dist = ss.distance.euclidean(buffer[i],buffer[j]) + if local_nn == 0: + local_nn = new_dist + elif new_dist < local_nn: + local_nn = new_dist + list_of_min_dists.append(local_nn) + + for k in range(len(list_of_min_dists)): + if list_of_min_dists[k] <= min_dist: + g += 1 + + return g/n + + def np_gen_random_points(self, n = 100, dom_spec = False): + lop = [] + if dom_spec: + lx,ly,mx,my = minimum_bounding_rectangle(self.set_of_points) + for i in range(n): + x = np.random.uniform(lx, mx) + y = np.random.uniform(ly, my) + n_p = Point(x,y) + lop.append(n_p) + else: + for i in range(n): + tuples = np.random.uniform(0,1,(1,2)) + n_p = Point(tuples[0][0],tuples[0][1]) + lop.append(n_p) + + return lop + + +""" +Assignment_08 +""" + + +def build_np_array(points, mark=""): + if not points: + return "No Points in List" + point_buffer = [] + + if mark == "": + for i in range(len(points)): + new_tuple = [points[i].x,points[i].y] + point_buffer.append(new_tuple) + + else: + for i in range(len(points)): + if points[i].mark == mark: + new_tuple = [points[i].x,points[i].y] + point_buffer.append(new_tuple) + + return np.array(point_buffer) + + +def nn_kdtree(points): + tree = ss.KDTree(points) + distances = [] + values = [] + for i in points: + nn_distance, nn = tree.query(i, k=2) + distances.append(nn_distance) + values.append(nn) + + return distances,values + + +def np_create_rand_points(self, n, specified): + lop = [] + if not specified: + for i in range(n): + tup = np.random.uniform(0,1,(1,2)) + point_n = Point(tup[0],tup[1]) + lop.append(point_n) + else: + minimum_bounding_rectangle(self.set_of_points) + + return lop + + +""" +Old Assignment +""" + + +def create_random_marked_points(n, marks = []): + list_of_tuples = [(random.uniform(0,1), random.uniform(0,1)) for i in range(n)] + list_of_marks = [random.choice(marks) for i in range(n)] + list_of_points = [] + for j in range(n): + new_point = Point(list_of_tuples[j][0],list_of_tuples[j][1],list_of_marks[j]) + list_of_points.append(new_point) + + return list_of_points + + +def create_random_unmarked_points(n): + list_of_tuples = [(random.uniform(0,1), random.uniform(0,1)) for i in range(n)] + list_of_points = [] + for j in range(n): + new_point = Point(list_of_tuples[j][0],list_of_tuples[j][1], "") + list_of_points.append(new_point) + + return list_of_points + + +def euclidean_distance(a, b): + distance = math.sqrt((a.x - b.x)**2 + (a.y - b.y)**2) + return distance + + +def average_nearest_neighbor_distance(points, mark=""): + mean_d = 0 + total = 0 + local_nn = 0 + num_of_points = len(points) + + if not mark: + for i in range(num_of_points): + local_nn = 0 + for j in range(num_of_points): + if i != j: + new_distance = euclidean_distance(points[i],points[j]) + if local_nn == 0: + local_nn = new_distance + elif new_distance < local_nn: + local_nn = new_distance + + total += local_nn + + else: + for i in range(num_of_points): + local_nn = 0 + for j in range(num_of_points): + if i != j and points[i].mark == points[j].mark: + new_distance = euclidean_distance(points[i],points[j]) + if local_nn == 0: + local_nn = new_distance + elif new_distance < local_nn: + local_nn = new_distance + + total += local_nn + + mean_d = total/num_of_points + + return mean_d + + +def permutations(p = 99, n = 100): + list_means = [] + + for i in range(p): + marks = ["elf", "dwarf", "human", "orc"] + rand_points = create_random_marked_points(n, marks) + newMean = average_nearest_neighbor_distance(rand_points) + list_means.append(newMean) + + return list_means + + +def find_crit_points(list_means): + entries = list_means + maxEntry = 0 + minEntry = 2 + for i in range(len(list_means)): + if entries[i] > maxEntry: + maxEntry = entries[i] + if entries[i] < minEntry: + minEntry = entries[i] + + return minEntry,maxEntry + + +def crit_point_check(minEntry, maxEntry, observed): + if observed < minEntry or observed > maxEntry: + return True + else: + return False + +def minimum_bounding_rectangle(points): + """ + Given a set of points, compute the minimum bounding rectangle. + + Parameters + ---------- + points : list + A list of points in the form (x,y) + + Returns + ------- + : list + Corners of the MBR in the form [xmin, ymin, xmax, ymax] + """ + mbr = [0,0,0,0] + numOfPoints = len(points) + for i in range(numOfPoints): + #Check for min and max x + if points[i][0] < mbr[0]: + mbr[0] = points[i][0] + if points[i][0] > mbr[2]: + mbr[2] = points[i][0] + #Check for min and max y + if points[i][1] < mbr[1]: + mbr[1] = points[i][1] + if points[i][1] > mbr[3]: + mbr[3] = points[i][1] + + return mbr \ No newline at end of file diff --git a/view.py b/view.py new file mode 100644 index 0000000..a1287de --- /dev/null +++ b/view.py @@ -0,0 +1,38 @@ +import sys +from PyQt4 import QtGui + + +class Example(QtGui.QMainWindow): + + def __init__(self): + super(Example, self).__init__() + + self.initUI() + + + def initUI(self): + + exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), 'Exit', self) + exitAction.setShortcut('Ctrl+Q') + exitAction.triggered.connect(QtGui.qApp.quit) + + webview = QtGui.QWebView() + + self.toolbar = self.addToolBar('Exit') + self.toolbar.addAction(exitAction) + + self.setGeometry(300, 300, 300, 200) + self.setWindowTitle('Assignment_09') + self.setWindowIcon(QtGui.QIcon('globe.png')) + self.show() + + +def main(): + + app = QtGui.QApplication(sys.argv) + ex = Example() + sys.exit(app.exec_()) + + +if __name__ == '__main__': + main() \ No newline at end of file