Beispiel #1
0
# 
#error http://cityio.media.mit.edu/api/table/lomas/GEOGRID/properties/types are not updated!
#Input :  table_name (make sure is an existing table)
# 
#Output : new table https://cityscope.media.mit.edu/CS_cityscopeJS/?cityscope=table_name
#

import json
import requests
import shapely
from shapely.geometry.polygon import Polygon
from shapely.geometry import shape
from brix import Handler

table_name='lomas'
H = Handler(table_name,quietly=False)

#Polygon importred from PoW web
lat_point_list = [20.764781341419358, 20.76303528674933, 20.763215914030038, 20.762031797925214, 20.76134942171894,20.76124907201699,20.761430386498358,20.75675402210621, 20.756071622073794, 20.75657338710328, 20.756891146354917, 20.75557076509179, 20.757716955908744, 20.758852159932292, 20.7593438806329, 20.761691654649997, 20.76670887497622, 20.769215940307845, 20.769356147330143, 20.770700755657085, 20.771041923030506, 20.76811216984444, 20.765182062242182]
lon_point_list = [-103.36270688388338,-103.36274981993364,-103.3615690785509,-103.36227752338053,-103.36176229077716,-103.36077476162069,-103.35710590345617,-103.35873747336686,-103.35841545298975, -103.36019729907642,-103.36146340784991,-103.36176355384579,-103.36681530234735,-103.36631873727687,-103.36723112834531,-103.36669703771352,-103.37101723758293,-103.36673933187646,-103.36523770894898,-103.36399256349084,-103.36373494718914,-103.3603015332957,-103.36216925148294]
polygon_geom = Polygon(zip(lon_point_list, lat_point_list))

default_type = 'No_Technology'
timing_now_type = '2021_Year'
timing_future_type = '2025_Year'
new_types=json.load(open('type_definitions/lomas_types.json'))

## CHANGE OPACITY OF TYPES IN THE RGB ##
for i in new_types:
  default_color_hex = new_types[i]['color'].lstrip('#')
  default_color_rgb = list(int(default_color_hex[i:i+2], 16) for i in (0, 2, 4))
Beispiel #2
0
# This script integrates the indicators and any modification of the grid
#

from brix import Handler

from my_indicators import Energy_related_Indicators  #Access_to_Sanitation, etc
from my_gridmodification import collapse_technology

H = Handler('lomas', quietly=False)

# Another way to make: '**{k:H.get_table_properties()[k] for k in ['cellSize','latitude','longitude']}'
# props = H.get_table_properties()
# Energy = Energy_related_Indicators(
#         longitude=props['longitude'],
#         cellSize =props['cellSize'],
#         latitude =props['latitude']
# )
Energy = Energy_related_Indicators(**{
    k: H.get_table_properties()[k]
    for k in ['cellSize', 'latitude', 'longitude']
})
#Sanitation = Access_to_Sanitation()

H.add_geogrid_data_update_function(collapse_technology)
H.add_indicators([
    Energy  #, 
    #Sanitation, ect
])
H.listen()
# print(H.update_package())
Beispiel #3
0
from brix import Handler
from indicators import Corona

if __name__ == '__main__':
    # Create a handler for our table
    H = Handler('yourtest', quietly=False)
    #     geogrid_data = H.get_geogrid_data()

    # Create a new instance of the Corona indicator
    heat = Corona()

    # Add the desired indicators to the table
    H.add_indicators([heat])

    print(H.list_indicators())
    print(H.return_indicator("corona"))

    # Listen for updates to the table to recompute indicator data
    H.listen()
Beispiel #4
0
  default_type = 'No_Technology'
  default_color_hex = new_types[default_type]['color'].lstrip('#')

  for cell in grid_geo['features']:
    cell_shape = shape(cell['geometry'])
    if not cell_shape.centroid.within(settlement_polygon):
      cell['properties']['name']='Street_NoInteractive'
      cell['properties']['color'] = [0,0,0,0]
      cell['properties'].pop('interactive',None)
    else:
      cell['properties']['name'] = default_type
      #cell['properties']['color'] = default_color_hex
      cell['properties']['interactive'] = 'Web'

  ## POST GRID TO CITY IO ##
  new_grid.commit_grid()
  print('POST GRID works')

  ## CHANGE OPACITY ## #not working
  H = Handler(table_name)
  H.set_opacity({'Street_NoInteractive':0}, default_alpha = 0.7)

  H.reset_geogrid_data()

  ## SAVE THE NEW GRID##
  geogrid_out_fname = 'grid_'+ table_name +'.json'
  save_json = input(f'Do you want to save your new table {geogrid_out_fname}? (y/n)')
  if save_json=='y':
    with open(geogrid_out_fname, 'w') as f:
      json.dump(grid_geo, f)
Beispiel #5
0
from brix import Handler
from indicators import Giants

table_name = 'minerva'
H = Handler(table_name, quietly=False)
giants = Giants(quietly=False, color_method='quantile')
H.add_indicator(giants)
H.listen()
Beispiel #6
0
            'ref_value': 0.1,
            'viz_type': 'radar'
        }

    def post_trips(self, deckgl_trips):
        post_url = 'https://cityio.media.mit.edu/api/table/' + self.table_name
        r = requests.post(post_url + '/ABM2',
                          data=json.dumps(deckgl_trips),
                          headers={'Content-Type': 'application/json'})
        print('Post ABM: {}'.format(r))


if __name__ == "__main__":
    table_name = sys.argv[1]

    # Load the saved data
    geogrid = gpd.read_file('tables/{}/geogrid.geojson'.format(table_name))
    zones = gpd.read_file('tables/{}/zones.geojson'.format(table_name))
    zones['GEOID'] = zones['GEOID'].astype(int)
    zones = zones.set_index('GEOID')
    simpop_df = pd.read_csv('tables/{}/simpop_df.csv'.format(table_name))

    H = Handler(table_name=table_name)
    H.reset_geogrid_data()

    d = Density_Indicator(zones=zones)
    p = Proximity_Indicator(zones=zones, geogrid=geogrid)
    m = Mobility_indicator(zones, geogrid, table_name, simpop_df)
    H.add_indicators([d, p, m])

    H.listen()
Beispiel #7
0
from brix import Handler
import time
import json
import os
import hashlib

# Predefined mapping of scanned Lego types to building types
types = {
    -1: "Invalid",
    0: "Institutional",
    1: "Office",
    2: "Park",
}

H = Handler('yourtest', quietly=False)
geogrid_data = H.get_geogrid_data()


def perform_update():
    H.update_geogrid_data(update_types)


def update_types(geogrid_data):
    scanned = [-1, -1]
    with open('CS_CityScoPy/scanner_data.txt') as json_file:
        scanned = json.load(json_file)

    print(f"Updating grid to \n{scanned}")

    # Make sure the data is in the right format
    if not type(scanned[0]) == list:
Beispiel #8
0
    shapefile.loc[
        shapefile[colname].isna(),
        colname] = shapefile[shapefile[colname].isna()]['AREA'] * density

#New variables density_POB_BY_VIV, VIV_W_ELEC, POB_W_ELEC
density_POB_BY_VIV = (shapefile['POBTOT'] / shapefile['VIVTOT'])
shapefile['VIV_WO_ELEC'] = (shapefile['VIVTOT'] - shapefile['VPH_C_ELEC'])
shapefile['POB_WO_ELEC'] = (shapefile['VIV_WO_ELEC'] * density_POB_BY_VIV)

shapefile[[
    'CVEGEO', "VIVTOT", 'VIV_WO_ELEC', 'POBTOT', 'POB_WO_ELEC', 'geometry'
]]  #columns of the shapefile that I am interested on

######################## This part takes care of loading the geogrid from the table: lomas ########################

H = Handler('lomas', quietly=False)

#make sure table is connected
geogrid_data = H.get_geogrid_data()
geogrid_data = geogrid_data.remove_noninteractive().as_df(
    include_geometries=True)

######################## join the two GeoDataFrames ########################
data_join = gpd.sjoin(
    geogrid_data[['id', 'geometry']],
    shapefile[[
        'CVEGEO', "VIVTOT", 'VIV_WO_ELEC', 'POBTOT', 'POB_WO_ELEC', 'geometry'
    ]],
    op='intersects'
)  #geopandas.sjoin(left_df, right_df, how='inner', op='intersects', lsuffix='left', rsuffix='right')
data_join = pd.merge(