cityiq package¶
Subpackages¶
Submodules¶
cityiq.api module¶
-
class
cityiq.api.
CacheFile
(cache_path, access_object, fetch_func=None, event_type=None, dt=None, end_time=None, group=None, format='json')[source]¶ Bases:
object
Represents a cached file of records for one location or asset, one type of event, and one day. Or, if the date and event type are omitted, just the information about an asset or location
-
property
path
¶ The filesystem path to the cache file
-
property
-
class
cityiq.api.
CityIq
(config=None, cache_metadata=True, **kwargs)[source]¶ Bases:
object
-
asset_url_suffix
= '/api/v2/metadata/assets/{uid}'¶
-
property
assets
¶ Return all system assets
-
assets_search_suffix
= '/api/v2/metadata/assets/search'¶
-
property
cameras
¶ Return camera assets
-
convert_time
(t)[source]¶ Convert a variety of time formats into the millisecond format used by the CityIQ interface. Converts naieve times to the configured timezone
-
property
em_sensors
¶ Return some other kind of sensor. Electro-magnetic?
-
property
env_sensors
¶ Return environmental sensors
-
events_url_suffix
= '/api/v2/event/locations/events'¶
-
get_locations
(location_type=None, zone=None, bbox=None)[source]¶ Get all locations, options for a zone or bounding box
-
http_get
(url, zone=None, params=None, *args, **kwargs)[source]¶ Get the events of one type :param start_time: :param span: time span in seconds :param event_type: :param tz_name: :return:
-
location_url_suffix
= '/api/v2/metadata/locations/{uid}'¶
-
property
locations
¶ Return all locations
-
property
locations_dataframe
¶
-
locations_search_suffix
= '/api/v2/metadata/locations/search'¶
-
make_tasks
(objects, events, start_time, end_time, task_class=None)[source]¶ Fetch, and cache, events requests for a set of assets or locations
-
property
mics
¶ Return microphone assets
-
property
nodes
¶ Return all nodes
-
object_sub_dir
= 'object'¶
-
property
parking_zones
¶
-
run_async
(tasks, workers=4)[source]¶ Run a set of tasks, created with make_tasks, with multiple workers
-
property
token
¶
-
property
total_bounds
¶ Return a bounding box for the system from all of the assets. This will be affected by the bbox set in the config, so it should usually be smaller than the one in the config
Order is: lat_max, lon_min, lat_min, lon_max
-
property
total_bounds_str
¶ Total bounds bounding box, in the form of the city_iq config
-
property
traffic_lanes
¶
-
property
walkways
¶
-
-
class
cityiq.api.
CityIqObject
(client, data, use_cache=True)[source]¶ Bases:
object
-
property
events_url
¶ Return the URL for fetching events, called from get_events() in the base class.
-
property
geometry
¶ Return a Shapely polygon for the coordinates
-
property
-
class
cityiq.api.
Event
(client, data, use_cache=True)[source]¶ Bases:
cityiq.api.CityIqObject
-
types
= ['PKIN', 'PKOUT', 'PEDEVT', 'TFEVT', 'TEMPERATURE', 'PRESSURE', 'ORIENTATION', 'METROLOGY', 'HUMIDITY', 'ENERGY_TIMESERIES', 'ENERGY_ALERT']¶
-
cityiq.asset module¶
-
class
cityiq.asset.
Asset
(client, data, use_cache=True)[source]¶ Bases:
cityiq.api.CityIqObject
-
property
children
¶ Sub assets of this asset
-
children_url_suffix
= '/api/v2/metadata/assets/{}/subAssets'¶
-
dclass_map
= {'CAMERA': <class 'cityiq.asset.CameraAsset'>, 'EM_SENSOR': <class 'cityiq.asset.EmSensorAsset'>, 'ENV_SENSOR': <class 'cityiq.asset.EnvSensorAsset'>, 'MIC': <class 'cityiq.asset.MicSensorAsset'>, 'NODE': <class 'cityiq.asset.NodeAsset'>}¶
-
property
detail
¶ Asset details, which appears to be just re-fetching the object data. On some systems it may return additional data.
Most importantly, the read is not cached, so it can be used to return the online/offline state of an asset without a time delay.
-
detail_url_suffix
= '/api/v2/metadata/assets/{}'¶
-
property
event_types
¶ Return event types records
-
events_url_suffix
= '/api/v2/event/assets/{uid}/events'¶
-
property
lat
¶
-
property
locations
¶ Locations at this asset
-
locations_url_suffix
= '/api/v2/metadata/assets/{}/locations'¶
-
property
lon
¶
-
object_sub_dir
= 'asset'¶
-
property
parent
¶
-
row_header
= ['assetUid', 'assetType', 'parentAssetUid', 'mediaType', 'events', 'geometry']¶
-
types
= ['NODE', 'EM_SENSOR', 'MIC', 'ENV_SENSOR', 'CAMERA']¶
-
property
uid
¶
-
uid_key
= 'assetUid'¶
-
property
-
class
cityiq.asset.
CameraAsset
(client, data, use_cache=True)[source]¶ Bases:
cityiq.asset.Asset
-
class
cityiq.asset.
EmSensorAsset
(client, data, use_cache=True)[source]¶ Bases:
cityiq.asset.Asset
-
class
cityiq.asset.
EnvSensorAsset
(client, data, use_cache=True)[source]¶ Bases:
cityiq.asset.Asset
-
class
cityiq.asset.
MicSensorAsset
(client, data, use_cache=True)[source]¶ Bases:
cityiq.asset.Asset
-
class
cityiq.asset.
NodeAsset
(client, data, use_cache=True)[source]¶ Bases:
cityiq.asset.Asset
cityiq.clean_events module¶
Clean events, removing duplicates
-
cityiq.clean_events.
clean_events
(s, use_tqdm=True, locations=None)[source]¶ Given an event scraper that has has
cityiq.config module¶
cityiq.exceptions module¶
cityiq.location module¶
-
class
cityiq.location.
Location
(client, data, use_cache=True)[source]¶ Bases:
cityiq.api.CityIqObject
-
property
assets
¶ Assets at this location
-
assets_url_suffix
= '/api/v2/metadata/locations/{}/assets'¶
-
dclass_map
= {'PARKING_ZONE': <class 'cityiq.location.ParkingZoneLocation'>, 'TRAFFIC_LANE': <class 'cityiq.location.TrafficLaneLocation'>, 'WALKWAY': <class 'cityiq.location.WalkwayLocation'>}¶
-
property
detail
¶ Return a new Location after making a non-cached call to the API. The response value is cached, so this will update the cache.
-
detail_url_suffix
= '/api/v2/metadata/locations/{}'¶
-
events_url_suffix
= '/api/v2/event/locations/{uid}/events'¶
-
object_sub_dir
= 'location'¶
-
property
row
¶ Return most important fields in a row format
-
row_header
= ['locationUid', 'locationType', 'parentLocationUid', 'geometry']¶
-
types
= ['WALKWAY', 'TRAFFIC_LANE', 'PARKING_ZONE']¶
-
property
uid
¶
-
uid_key
= 'locationUid'¶
-
property
-
class
cityiq.location.
ParkingZoneLocation
(client, data, use_cache=True)[source]¶ Bases:
cityiq.location.Location
-
class
cityiq.location.
TrafficLaneLocation
(client, data, use_cache=True)[source]¶ Bases:
cityiq.location.Location
-
class
cityiq.location.
WalkwayLocation
(client, data, use_cache=True)[source]¶ Bases:
cityiq.location.Location
cityiq.task module¶
-
class
cityiq.task.
DownloadTask
(access_object: cityiq.api.CityIqObject, event_type, start_date: datetime.date, end_date: datetime.date)[source]¶ Bases:
cityiq.task.EventTask
-
classmethod
make_tasks
(objects: Sequence[cityiq.api.CityIqObject], event_types: Sequence[str], start_date: datetime.date, end_date: datetime.date)[source]¶
-
classmethod
-
class
cityiq.task.
EventTask
(access_object: cityiq.api.CityIqObject, event_type, start_date: datetime.date, end_date: datetime.date)[source]¶ Bases:
object
Base class for operations on a single object, event type and day. These tasks can be run in parallel and be subclassed to provide specific operations.
-
classmethod
make_tasks
(objects: Sequence[cityiq.api.CityIqObject], event_types: Sequence[str], start_date: datetime.date, end_date: datetime.date)[source]¶
-
classmethod
-
class
cityiq.task.
EventWorker
(client, events, queue)[source]¶ Bases:
threading.Thread
Thread worker for websocket events
-
static
events_async
(client, events=['PKIN', 'PKOUT'])[source]¶ Use the websocket to get events. The websocket is run in a thread, and this function is a generator that returns results.
-
run
() → None[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
static
-
cityiq.task.
generate_days
(start_time, end_time, include_end=False)[source]¶ Generate day ranges for the request
- Parameters
start_time –
end_time –
include_end – If True, range will include end date, if False, it will stop one day before
- Returns
-
cityiq.task.
generate_months
(start_time, end_time, include_end=False)[source]¶ Generate month ranges from the start time to the end time
- Parameters
start_time –
end_time –
include_end – If True, range will include end date, if False, it will stop one day before
- Returns
cityiq.token module¶
-
cityiq.token.
get_cached_token
(cache_path, uaa, client, secret)[source]¶ Return a cached access token from the CityIQ service. Returns just the token. Use _get_token() to get the full response
- Parameters
cache_path – Directory where cached token will be stored, if a directory or token name if a file
uaa – Url to the user authentication service
client –
secret –
- Returns
A token string
If a directory is specified in cache_dir, the file name will be ‘cityiq-token-<crc>.json’, with the CRC32 of the source url. The token will be expired after 8 hours.
cityiq.util module¶
-
cityiq.util.
json_serial
(obj)[source]¶ JSON serializer for objects not serializable by default json code