diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 283add4..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "grid_geojson"] - path = grid_geojson - url = https://github.com/doorleyr/grid_geojson.git diff --git a/README.md b/README.md index d92be57..20320dc 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,25 @@ # CityScoPy -### [=> Download latest release here <=](https://github.com/CityScope/CS_Scanner_Python/releases/) +### [=> Download latest release <=](https://github.com/CityScope/CS_Scanner_Python/releases/) -## A tool for bootstrapping, scanning and networking MIT CityScope Projects in Python +#### A tool for bootstrapping, scanning and networking MIT CityScope Projects in Python CityScoPy is the main component of an interactive MIT CityScope table. -It is used for initiating and later run a interactive CityScope instance in any arbitrary geolocated area in the world. CityScoPy can create a GeoJSON grid, capture, key-stone, scan and send uniquely tagged arrays of 2-dimension physical bricks. +It is used for initiating and later run a interactive CityScope instance in any arbitrary geolocated area in the world. CityScoPy can capture, key-stone, scan and send uniquely tagged arrays of 2-dimension physical bricks. --- ## Usage - install python 3.4 or higher -- clone this repo **recursively** to get submodules. Follow https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules or just: +- clone this repo ``` $ git clone https://github.com/CityScope/CS_CityScoPy.git $ cd CS_CityScoPy -$ git submodule update --init --recursive ``` -- install packages. To produce a list of needed packages, use `pipreqs`, follow istructions https://github.com/bndr/pipreqs. Or, simply run the app and install packages as they appear in errors. +- install packages. To produce a list of needed packages, use `pipreqs`, follow instructions https://github.com/bndr/pipreqs. Or, simply run the app and install packages as they appear in errors. - tweak `__settings__.json` to fit your cityIO table setup. Read [cityIO documentation](https://github.com/cityscope/cs_cityio_backend/wiki) for proper data structure - setup a path to your settings file @@ -28,7 +27,7 @@ $ git submodule update --init --recursive cityscopy_settings_path = "__path__/__settings__.json" ``` -- initiate the `Cityscopy` class +- initiate the `Cityscopy` class (see `run.py` example) ``` cityscopy = Cityscopy(cityscopy_settings_path) @@ -36,12 +35,11 @@ cityscopy = Cityscopy(cityscopy_settings_path) - use one or more of the main methods. 'Blocking' means the method will run forever (while true loop). Advanced users can parallel blocking methods using multithreading. -| Method | Usage | Blocking? | -| -------------------------- | ------------------------------------- | --------- | -| `cityscopy.keystone()` | initial keystone and save to file | x | -| `cityscopy.gridMaker()` | make GeoJSON grids and sent to CityIO | | -| `cityscopy.scan()` | main scanning and sending method | x | -| `cityscopy.udp_listener()` | emulate local UDP server listener | x | +| Method | Usage | Blocking? | +| -------------------------- | --------------------------------- | --------- | +| `cityscopy.keystone()` | initial keystone and save to file | x | +| `cityscopy.scan()` | main scanning and sending method | x | +| `cityscopy.udp_listener()` | emulate local UDP server listener | x | - in terminal run the tool using `$ run.py` @@ -58,12 +56,6 @@ cityscopy = Cityscopy(cityscopy_settings_path) Note: no need to exactly select the corners, as these are only initial guides for `scanner` method - `keystone.txt` and close -### `Cityscopy.gridMaker()` - -##### make GeoJSON grids and sent to CityIO - -Method for creating a GeoJSON grid. This grid represent the abstraction ('LEGO-tizing') of an area in the world. This grid also corresponds to the dimensions of the tangible CityScope table. `gridMaker` should be ran once upon starting a new CityScope instance. It will push the created grid into `cityIO` endpoint so that front-end and analysis modules could make use of it. - ### `Cityscopy.scan()` ##### main scanning and sending method diff --git a/cityscopy.py b/cityscopy.py index 4c12719..2875684 100755 --- a/cityscopy.py +++ b/cityscopy.py @@ -1,5 +1,55 @@ +''' +>>>>>>>>>>>>> Starting CityScope Scanner >>>>>>>>>>>> + + + ||||||||||| + ||||||||||| + ||| + ||| + ||| + ||| |||||||||||| + ||| |||||||||||| + ||| ||| + ||| ||| + ||| ||| + |||||||||||| ||| + |||||||||||| ||| + + +>>>>>>>>>>>>> Starting CityScope Scanner >>>>>>>>>>>> + +Copyright (C) {{ 2018 }} {{ Ariel Noyman }} + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see + +"@context": "https://github.com/CityScope/", "@type": "Person", "address": { +"@type": "75 Amherst St, Cambridge, MA 02139", "addressLocality": +"Cambridge", "addressRegion": "MA",}, +"jobTitle": "Research Scientist", "name": "Ariel Noyman", +"alumniOf": "MIT", "url": "http://arielnoyman.com", +"https://www.linkedin.com/", "http://twitter.com/relno", +https://github.com/RELNO] + + +################################################## +CityScope Python Scanner +Keystone, decode and send over UDP/HTTTP a 2d array +of uniquely tagged LEGO array +################################################## +''' + -# grid maker imports import requests import cv2 import numpy as np @@ -15,14 +65,15 @@ from multiprocessing import Process, Manager from subprocess import Popen import random -from grid_geojson.module import grid_geojson class Cityscopy: + '''sacnner for CityScope''' ################################################## def __init__(self, path): + '''init function ''' # load info from json file self.SETTINGS_PATH = path # get the table settings. This is used bu many metohds @@ -217,8 +268,7 @@ def scanner_function(self, multiprocess_shared_dict): cv2.rectangle(DISTORTED_VIDEO_STREAM, (x+scanner_reduction, y+scanner_reduction), - (x_red, - y_red), + (x_red, y_red), thisColor, 1) # cell counter count = count + 1 @@ -594,65 +644,6 @@ def brick_rotation_check(self, this_16_bits, tagsArray, mapArray): ################################################## - # method to create a geojson grid on init - - def gridMaker(self): - print('\n', '______making GeoJson active and full table grids_______', '\n') - # make full table grid - top_left_lon = self.table_settings['objects']['cityscopy']['grid_full_table']['longitude'] - top_left_lat = self.table_settings['objects']['cityscopy']['grid_full_table']['latitude'] - nrows = self.table_settings['objects']['cityscopy']['grid_full_table']['nrows'] - ncols = self.table_settings['objects']['cityscopy']['grid_full_table']['ncols'] - rotation = self.table_settings['objects']['cityscopy']['grid_full_table']['rotation'] - cell_size = self.table_settings['objects']['cityscopy']['grid_full_table']['cellSize'] - crs_epsg = str(self.table_settings['objects'] - ['cityscopy']['grid_full_table']['projection']) - properties = { - 'id': [i for i in range(nrows*ncols)], - 'usage': [0 for i in range(nrows*ncols)], - 'height': [-100 for i in range(nrows*ncols)], - 'pop_density': [2 for i in range(nrows*ncols)] - } - results_grid = grid_geojson.Grid(top_left_lon, top_left_lat, rotation, - crs_epsg, cell_size, nrows, ncols) - grid_geo = results_grid.get_grid_geojson(properties) - grid_interactive_area = json.dumps(grid_geo) - API_ENDPOINT = "https://cityio.media.mit.edu/api/table/update/" + \ - self.table_settings['header']['name'] + "/grid_full_table/" - self.sendGrid(grid_interactive_area, API_ENDPOINT) - - # make interactive grid - top_left_lon = self.table_settings['header']['spatial']['longitude'] - top_left_lat = self.table_settings['header']['spatial']['latitude'] - nrows = self.table_settings['header']['spatial']['nrows'] - ncols = self.table_settings['header']['spatial']['ncols'] - rotation = self.table_settings['header']['spatial']['rotation'] - cell_size = self.table_settings['header']['spatial']['cellSize'] - crs_epsg = str(self.table_settings['header']['spatial']['projection']) - properties = { - 'id': [i for i in range(nrows*ncols)], - 'usage': [0 for i in range(nrows*ncols)], - 'height': [-100 for i in range(nrows*ncols)], - 'pop_density': [2 for i in range(nrows*ncols)] - } - results_grid = grid_geojson.Grid(top_left_lon, top_left_lat, rotation, - crs_epsg, cell_size, nrows, ncols) - grid_geo = results_grid.get_grid_geojson(properties) - grid_interactive_area = json.dumps(grid_geo) - API_ENDPOINT = "https://cityio.media.mit.edu/api/table/update/" + \ - self.table_settings['header']['name'] + "/grid_interactive_area/" - self.sendGrid(grid_interactive_area, API_ENDPOINT) - ################################################## - - # send geojson grid to cityIO - def sendGrid(self, data, API_ENDPOINT): - req = requests.post(url=API_ENDPOINT, data=data) - if req.status_code != 200: - print("cityIO might be down. so sad.") - print(req) - - ################################################## - def udp_listener(self): UDP_IP = "127.0.0.1" UDP_PORT = 5000 diff --git a/grid_geojson b/grid_geojson deleted file mode 160000 index cfe15c9..0000000 --- a/grid_geojson +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cfe15c998f3b5eceaf1e80a05e70637807114eea diff --git a/run.py b/run.py index fd5ddd3..39efd8a 100755 --- a/run.py +++ b/run.py @@ -51,15 +51,10 @@ ################################################## - CityScope Python Scanner Keystone, decode and send over UDP/HTTTP a 2d array of uniquely tagged LEGO array -# -'grid_geojson' module by Ronan Doorley @doorleyr -# ################################################## - ''' ) @@ -68,6 +63,5 @@ cityscopy = Cityscopy(cityscopy_settings_path) # run CityScopy main methods # cityscopy.keystone() - # cityscopy.gridMaker() cityscopy.scan() # # cityscopy.udp_listener() diff --git a/settings/cityscopy.json b/settings/cityscopy.json index 9ccb552..1a2106f 100644 --- a/settings/cityscopy.json +++ b/settings/cityscopy.json @@ -27,7 +27,6 @@ "grid": [], "objects": { "cityscopy": { - "makeGrid": false, "scan": false, "interval": 250, "gui": true, diff --git a/settings/csepel.json b/settings/csepel.json index 45bd659..5c1c5be 100644 --- a/settings/csepel.json +++ b/settings/csepel.json @@ -27,17 +27,7 @@ "grid": [], "objects": { "cityscopy": { - "makeGrid": false, "scan": false, - "grid_full_table": { - "longitude": 19.050979614257812, - "latitude": 47.43630292431787, - "cellSize": 50, - "rotation": 260, - "nrows": 20, - "ncols": 50, - "projection": 3836 - }, "interval": 250, "gui": true, "cityio": true, diff --git a/settings/urbam.json b/settings/urbam.json index 2af22c5..70fadc1 100644 --- a/settings/urbam.json +++ b/settings/urbam.json @@ -8,7 +8,7 @@ "physical_longitude": -71.1009981, "physical_latitude": 42.3582145, "longitude": 21.028511, - "latitude": 105.804817 + "latitude": 105.804817, "cellSize": 100, "rotation": 0 },