Skip to content

Commit

Permalink
decouple geojson grid submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
RELNO committed Nov 22, 2019
1 parent 63680e7 commit 98fbd9e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 104 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

30 changes: 11 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
# 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

```
cityscopy_settings_path = "__path__/__settings__.json"
```

- initiate the `Cityscopy` class
- initiate the `Cityscopy` class (see `run.py` example)

```
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`

Expand All @@ -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
Expand Down
117 changes: 54 additions & 63 deletions cityscopy.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>
"@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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion grid_geojson
Submodule grid_geojson deleted from cfe15c
6 changes: 0 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
##################################################
'''
)

Expand All @@ -68,6 +63,5 @@
cityscopy = Cityscopy(cityscopy_settings_path)
# run CityScopy main methods
# cityscopy.keystone()
# cityscopy.gridMaker()
cityscopy.scan()
# # cityscopy.udp_listener()
1 change: 0 additions & 1 deletion settings/cityscopy.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"grid": [],
"objects": {
"cityscopy": {
"makeGrid": false,
"scan": false,
"interval": 250,
"gui": true,
Expand Down
10 changes: 0 additions & 10 deletions settings/csepel.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion settings/urbam.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit 98fbd9e

Please sign in to comment.