Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spatial unit classes #928

Merged
merged 144 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
8b885e2
Add SpatialMapping classes for polygon, admin and grid
jc-harrison Mar 5, 2019
b933617
Add SpatialMapping class for lat-lon
jc-harrison Mar 6, 2019
aa38533
Rename SpatialMapping back to SpatialUnit; simplify base class; add c…
jc-harrison Mar 8, 2019
ae7e8b1
Restructure PolygonSpatialUnit to inherit from SpatialUnit, and corre…
jc-harrison Mar 8, 2019
f3ead37
Add docstrings to SpatialUnit classes
jc-harrison Mar 11, 2019
0ab2408
Move get_alias to utils.py; add tests
jc-harrison Mar 11, 2019
4a37124
Update JoinToLocation to take a SpatialUnit object instead of a string
jc-harrison Mar 11, 2019
88ae520
Remove the option to pass SQL strings to JoinToLocation
jc-harrison Mar 11, 2019
2a76b53
Remove option to specify polygon_table as a SQL string in PolygonSpat…
jc-harrison Mar 11, 2019
ab2f658
Add geo_augment() method to SpatialUnit classes
jc-harrison Mar 12, 2019
de68a23
Update GeoDataMixin._geo_augmented_query to call SpatialUnit.geo_augment
jc-harrison Mar 12, 2019
db6bb13
Update JoinToLocation tests
jc-harrison Mar 12, 2019
4e6abaf
Move Grid into flowmachine.core to avoid circular import
jc-harrison Mar 18, 2019
e87e7b4
Import spatial units in test_join_to_location.py
jc-harrison Mar 18, 2019
a50b4de
Remove unused "date" kwarg in DistanceMatrix
jc-harrison Mar 18, 2019
3804c89
Refactor DistanceMatrix, moving the query construction into SpatialUnit
jc-harrison Mar 18, 2019
f8aabba
Fix SpatialUnit column_names property
jc-harrison Mar 19, 2019
1c8d653
Add tests for geo_augment and distance_matrix_query methods
jc-harrison Mar 19, 2019
86cab6b
Fix JoinToLocation column names test
jc-harrison Mar 19, 2019
e8f7c06
Update docstrings
jc-harrison Mar 19, 2019
e64c4d8
Update pwo model to take a SpatialUnit argument
jc-harrison Mar 19, 2019
551cca6
Update dialy_location, locate_subscribers, Displacement and Multiloca…
jc-harrison Mar 19, 2019
d883bed
Update DayTrajectories and ModalLocation
jc-harrison Mar 19, 2019
d6a1a6f
Add exemplar_spatial_unit_param fixture
jc-harrison Mar 19, 2019
8d18674
Update tests for daily_location, Displacement, Multilocation, DayTraj…
jc-harrison Mar 19, 2019
0b07858
Update LastLocation and MostFrequentLocation
jc-harrison Mar 19, 2019
0914e1e
Update subscriber_locations
jc-harrison Mar 19, 2019
081c96e
Use exemplar_spatial_unit_param in test_join_to_location.py and test_…
jc-harrison Mar 20, 2019
13283ad
Update UniqueSubscriberCounts
jc-harrison Mar 20, 2019
c4f8086
Remove 'time_col' argument from subscriber_locations
jc-harrison Mar 20, 2019
cc657e4
Define CellSpatialUnit class, with location_columns property
jc-harrison Mar 20, 2019
699c44f
Update TotalNetworkObjects and AggregateNetworkObjects
jc-harrison Mar 20, 2019
f7763f5
Fix tests for JoinToLocation and spatial_unit.py
jc-harrison Mar 20, 2019
1736525
Merge branch 'master' into spatial-mapping
jc-harrison May 29, 2019
8611cc1
Add comment to explain reason for using GeoTable
jc-harrison May 29, 2019
3f679e0
Add 'location_joined_query' helper function
jc-harrison May 29, 2019
6790a01
Add test for location_joined_query
jc-harrison May 30, 2019
a666bab
Don't pass "radius" parameter to subscriber_locations
jc-harrison May 30, 2019
08363b3
Remove "radius" argument from daily_location
jc-harrison May 30, 2019
89e3cec
Fix TotalNetworkObjects
jc-harrison May 30, 2019
ce7ee87
Use location_joined_query in TotalNetworkObjects and subscriber_loca…
jc-harrison May 30, 2019
5fe78e0
Use spatial_unit instead of level in SpatialAggregate and JoinedSpati…
jc-harrison May 30, 2019
e01e208
Define __eq__ for spatial units
jc-harrison May 31, 2019
13bdf4e
Refactor spatial_unit.geo_augment to take a sql string instead of Query
jc-harrison May 31, 2019
5b700f9
Use SpatialUnit objects in Flows
jc-harrison May 31, 2019
f83f8e4
Format subscriber_locations.py
jc-harrison Jun 3, 2019
6f7a56e
Update Query.index_cols to use spatial_unit attribute instead of level
jc-harrison Jun 3, 2019
cd186c3
Remove a few mentions of "level"
jc-harrison Jun 3, 2019
40ada92
Replace AdminSpatialUnit and GridSpatialUnit with helper functions
jc-harrison Jun 3, 2019
086da03
Return an integer from BaseSpatialUnit.__hash__
jc-harrison Jun 3, 2019
0cd1e5b
Fix flows test
jc-harrison Jun 3, 2019
167b4b7
Handle AttributeError in BaseSpatialUnit.__eq__
jc-harrison Jun 3, 2019
ae4c4f4
Fix docstring
jc-harrison Jun 3, 2019
2600bb9
Test Flows to_geojson_string
jc-harrison Jun 3, 2019
c2413e0
Test __eq__ method of spatial units
jc-harrison Jun 3, 2019
a18f6e2
Fix Flows._geo_augmented_query for multiple location columns
jc-harrison Jun 3, 2019
60cdb6a
Remove distance_matrix_query method
jc-harrison Jun 4, 2019
feba6aa
Rename 'geom_col', and use a Table instead of GeoTable
jc-harrison Jun 4, 2019
59c86b8
Don't leave bits of incomplete functions lying around
jc-harrison Jun 4, 2019
3820549
Add 'get_geom_query' method
jc-harrison Jun 4, 2019
e45663c
Use 'get_geom_query' method in DistanceMatrix
jc-harrison Jun 4, 2019
41d2868
Use 'get_geom_query' in GeoDataMixin
jc-harrison Jun 4, 2019
15739be
Remove _get_location_join
jc-harrison Jun 4, 2019
2878fa5
Use get_geom_query in Flows._geo_augmented_query
jc-harrison Jun 4, 2019
21e2d7e
Add spatial_unit attribute to AggregateNetworkObjects
jc-harrison Jun 4, 2019
bb2cca0
Add tests for _geo_augmented_query raising an error, and move Flows g…
jc-harrison Jun 4, 2019
631b880
Remove geo_augment method
jc-harrison Jun 4, 2019
b5695b4
Add test for columns of get_geom_query()
jc-harrison Jun 4, 2019
c2c0bf8
Make internal attributes immutable
jc-harrison Jun 5, 2019
cc335d3
Fix get_geom_query test
jc-harrison Jun 5, 2019
3f42bd7
Remove VersionedCellSpatialUnit, VersionedSiteSpatialUnit and LatLonS…
jc-harrison Jun 5, 2019
a7ee3ab
Remove **kwargs from displacement.py
jc-harrison Jun 5, 2019
ebc73c5
Add a helper function to create spatial units.
jc-harrison Jun 5, 2019
37ab542
Add tests for make_spatial_unit
jc-harrison Jun 5, 2019
fd9beac
Use make_spatial_unit everywhere
jc-harrison Jun 5, 2019
f761085
Add SpatialUnitMixin and InvalidSpatialUnitError
jc-harrison Jun 6, 2019
04fe2f4
Use spatial_unit.verify_criterion anywhere that needs it
jc-harrison Jun 6, 2019
2e959e5
Update get_name_and_alias
jc-harrison Jun 6, 2019
720d217
Rename 'location_columns' to 'location_id_columns'
jc-harrison Jun 6, 2019
29fa6db
Refactor SpatialUnit classes
jc-harrison Jun 7, 2019
a466fe5
Import make_spatial_unit from flowmachine.core
jc-harrison Jun 7, 2019
edf0464
Update RadiusOfGyration
jc-harrison Jun 7, 2019
b6444e6
Update LocationIntroversion
jc-harrison Jun 7, 2019
f04ec82
Update PerLocationEventStats
jc-harrison Jun 8, 2019
f48b0e6
Update TotalLocationEvents
jc-harrison Jun 8, 2019
26ff2ed
Updated EventScore
jc-harrison Jun 8, 2019
5e90de0
Update PerLocationSubscriberCallDurations, PairedPerLocationSubscribe…
jc-harrison Jun 8, 2019
310fedc
Update CallDays
jc-harrison Jun 8, 2019
6318bf4
Update subscriber_location_cluster
jc-harrison Jun 8, 2019
b041537
Update MeaningfulLocationsAggregate and MeaningfulLocationsOD
jc-harrison Jun 9, 2019
47f759f
Combine _SubscriberCells and subscriber_locations
jc-harrison Jun 9, 2019
135aca0
Fix test_utils.py
jc-harrison Jun 9, 2019
f916a34
Update ContactReferenceLocationStats
jc-harrison Jun 9, 2019
ea49cca
Update LocationEntropy
jc-harrison Jun 9, 2019
75a5f29
Update LocationVisits
jc-harrison Jun 9, 2019
4e9cc22
Raise InvalidSpatialUnitError in location_joined_query
jc-harrison Jun 9, 2019
514f1dd
Update UniqueLocationCounts
jc-harrison Jun 9, 2019
0db0e8e
Update FirstLocation
jc-harrison Jun 10, 2019
942e2e3
Start implementing location_subset_clause
jc-harrison Jun 10, 2019
117f61c
Fix LatLonSpatialUnit
jc-harrison Jun 10, 2019
73b0da4
Fix test_cache_utils.py
jc-harrison Jun 10, 2019
1d6c18e
Fix versioned-site spatial unit
jc-harrison Jun 10, 2019
6ac9ca8
Use (lon,lat) order everywhere, for consistency with ST_Point
jc-harrison Jun 10, 2019
23760b1
Use location_id_columns in spatial aggregates
jc-harrison Jun 10, 2019
7166f8a
Fix test_query_formatting
jc-harrison Jun 10, 2019
567c59c
No need for GeomSpatialUnit to be abstract
jc-harrison Jun 10, 2019
ec759f6
Implement location_subset_clause
jc-harrison Jun 10, 2019
5cfd4c0
Add tests for location_subset_clause
jc-harrison Jun 10, 2019
b06dd3c
Add test for versioned-site SQL
jc-harrison Jun 10, 2019
5807d02
Update approved SQL files
jc-harrison Jun 10, 2019
9108494
Update _get_stored_dependencies tests
jc-harrison Jun 10, 2019
365c9f6
Ensure differrent instances of CellSpatialUnit don't result in differ…
jc-harrison Jun 11, 2019
94613b5
Fix test_query_formatting
jc-harrison Jun 11, 2019
f9bc629
Fix test_print_dependency_tree
jc-harrison Jun 11, 2019
efa3c4f
Merge branch 'master' into spatial-unit
jc-harrison Jun 11, 2019
e7439d7
Remove now-redundant level utilities
jc-harrison Jun 11, 2019
f72ffd5
Put back closing bracket
jc-harrison Jun 11, 2019
13c0300
Create spatial unit objects in marshmallow schemas
jc-harrison Jun 11, 2019
d8bf609
Update test_query_object_construction approved
jc-harrison Jun 11, 2019
06e546a
Fix integration tests
jc-harrison Jun 11, 2019
ca35d3f
Update approved query IDs again (due to spatial unit change)
jc-harrison Jun 11, 2019
653f1db
Add Geography class
jc-harrison Jun 11, 2019
f288582
Use Geography query for getting geography
jc-harrison Jun 11, 2019
07f53c8
Update worked examples
jc-harrison Jun 11, 2019
a7eccf7
Correct Geography query_id
jc-harrison Jun 11, 2019
f45c97a
Update CHANGELOG.md
jc-harrison Jun 11, 2019
5669dae
Return geography error messages through FlowAPI
jc-harrison Jun 12, 2019
d3810ac
Add comment about query_kind parameter
jc-harrison Jun 12, 2019
45b6a10
Add geojson_sql property
jc-harrison Jun 12, 2019
b0c19b0
Docstring and consistent gid
jc-harrison Jun 12, 2019
ee3f00b
Change one more 'level' to 'spatial_unit'
jc-harrison Jun 12, 2019
415208f
Fix cache_queries.py
jc-harrison Jun 12, 2019
a9c80d4
Merge branch 'master' into spatial-unit
jc-harrison Jun 12, 2019
cf87e7d
Merge branch 'master' into spatial-unit
jc-harrison Jun 27, 2019
d846eee
Update UniqueLocationCountsExposed to pass a spatial_unit parameter
jc-harrison Jun 27, 2019
d4439c5
Add test for AggregateNetworkObjects
jc-harrison Jun 27, 2019
4e6fc2e
Add subscriber_location_cluster tests
jc-harrison Jun 27, 2019
900c0d6
Add tests for Displacement
jc-harrison Jun 27, 2019
edf6c37
Fix Hartigan test
jc-harrison Jun 27, 2019
41b9ee5
Merge branch 'master' into spatial-unit
jc-harrison Jun 28, 2019
1848050
Add type annotations
jc-harrison Jun 28, 2019
b2783af
Fix type annotation
jc-harrison Jun 28, 2019
b007f8b
Fix typo
jc-harrison Jun 28, 2019
d6bd9cf
Merge branch 'master' into spatial-unit
greenape Jul 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added

- The dev provisioning Ansible playbook now automatically generates an SSH key pair for the `flowkit` user. [#892](https://github.com/Flowminder/FlowKit/issues/892)
- Added new classes to represent spatial units in FlowMachine.
- Added a `Geography` query class, to get geography data for a spatial unit.
- FlowAPI's 'joined_spatial_aggregate' endpoint now exposes unique location counts.[#949](https://github.com/Flowminder/FlowKit/issues/949)
- FlowAPI's 'joined_spatial_aggregate' endpoint now exposes subscriber degree.[#969](https://github.com/Flowminder/FlowKit/issues/969)
- Flowdb now contains an auxiliary table to record outcomes of queries that can be run as part of the regular ETL process [#988](https://github.com/Flowminder/FlowKit/issues/988)

### Changed

- The quick-start script now only pulls the docker images for the services that are actually started up. [#898](https://github.com/Flowminder/FlowKit/issues/898)
- Location-related FlowMachine queries now take a `spatial_unit` parameter instead of `level`.
- The quick-start script now uses the environment variable `GIT_REVISION` to control the version to be deployed.
- Create token page permission and spatial aggregation checkboxes are now hidden by default.[#834](https://github.com/Flowminder/FlowKit/issues/834)
- The flowetl mounted directories `archive, dump, ingest, quarantine` were replaced with a single `files` directory and files are no longer moved. [#946](https://github.com/Flowminder/FlowKit/issues/946)
Expand All @@ -28,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- The quick-start script now works correctly with branches. [#902](https://github.com/Flowminder/FlowKit/issues/902)

### Removed
- Removed `cell_mappings.py`, `get_columns_for_level` and `BadLevelError`.

- The FlowDB tables `infrastructure.countries` and `infrastructure.operators` have been removed. [#958](https://github.com/Flowminder/FlowKit/issues/958)

Expand Down
67 changes: 45 additions & 22 deletions docs/cache_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,41 @@

print("Constructing query objects")

admin1_spatial_unit = flowmachine.core.make_spatial_unit("admin", level=1)
admin3_spatial_unit = flowmachine.core.make_spatial_unit("admin", level=3)
vsite_spatial_unit = flowmachine.core.make_spatial_unit("versioned-site")
vcell_spatial_unit = flowmachine.core.make_spatial_unit("versioned-cell")

# FlowClient example usage
example_usage_queries = [
flowmachine.features.utilities.spatial_aggregates.SpatialAggregate(
locations=flowmachine.features.daily_location(
date="2016-01-01", level="admin3", method="last"
date="2016-01-01", spatial_unit=admin3_spatial_unit, method="last"
)
),
flowmachine.features.utilities.spatial_aggregates.SpatialAggregate(
locations=flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
date=dl_date, level="admin3", method="last"
date=dl_date, spatial_unit=admin3_spatial_unit, method="last"
)
for dl_date in pd.date_range("2016-01-01", "2016-01-03", freq="D")
]
)
),
flowmachine.features.Flows(
flowmachine.features.daily_location(
date="2016-01-01", level="admin1", method="last"
date="2016-01-01", spatial_unit=admin1_spatial_unit, method="last"
),
flowmachine.features.daily_location(
date="2016-01-07", level="admin1", method="last"
date="2016-01-07", spatial_unit=admin1_spatial_unit, method="last"
),
),
flowmachine.features.TotalLocationEvents(
start="2016-01-01", stop="2016-01-08", level="admin3", interval="hour"
start="2016-01-01",
stop="2016-01-08",
spatial_unit=admin3_spatial_unit,
interval="hour",
),
]

Expand All @@ -57,7 +65,9 @@
locations=flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
date=dl_date.strftime("%Y-%m-%d"), level="admin3", method="last"
date=dl_date.strftime("%Y-%m-%d"),
spatial_unit=admin3_spatial_unit,
method="last",
)
for dl_date in dates
]
Expand All @@ -69,15 +79,19 @@
flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
date=dl_date.strftime("%Y-%m-%d"), level="admin3", method="last"
date=dl_date.strftime("%Y-%m-%d"),
spatial_unit=admin3_spatial_unit,
method="last",
)
for dl_date in date_ranges["benchmark"]
]
),
flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
date=dl_date.strftime("%Y-%m-%d"), level="admin3", method="last"
date=dl_date.strftime("%Y-%m-%d"),
spatial_unit=admin3_spatial_unit,
method="last",
)
for dl_date in date_ranges[period2]
]
Expand Down Expand Up @@ -134,8 +148,10 @@
meaningful_locations=flowmachine.features.MeaningfulLocations(
clusters=flowmachine.features.HartiganCluster(
calldays=flowmachine.features.CallDays(
subscriber_locations=flowmachine.features.subscriber_locations(
start="2016-01-01", stop="2016-01-07", level="versioned-site"
subscriber_locations=flowmachine.features.SubscriberLocations(
start="2016-01-01",
stop="2016-01-07",
spatial_unit=vsite_spatial_unit,
)
),
radius=1.0,
Expand All @@ -148,20 +164,22 @@
stop="2016-01-07",
score_hour=hour_scores,
score_dow=day_scores,
level="versioned-site",
spatial_unit=vsite_spatial_unit,
),
label=label,
),
level="admin3",
spatial_unit=admin3_spatial_unit,
)
for label in ["home", "work"]
] + [
flowmachine.features.MeaningfulLocationsOD(
meaningful_locations_a=flowmachine.features.MeaningfulLocations(
clusters=flowmachine.features.HartiganCluster(
calldays=flowmachine.features.CallDays(
subscriber_locations=flowmachine.features.subscriber_locations(
start="2016-01-01", stop="2016-01-07", level="versioned-site"
subscriber_locations=flowmachine.features.SubscriberLocations(
start="2016-01-01",
stop="2016-01-07",
spatial_unit=vsite_spatial_unit,
)
),
radius=1.0,
Expand All @@ -174,15 +192,17 @@
stop="2016-01-07",
score_hour=hour_scores,
score_dow=day_scores,
level="versioned-site",
spatial_unit=vsite_spatial_unit,
),
label="home",
),
meaningful_locations_b=flowmachine.features.MeaningfulLocations(
clusters=flowmachine.features.HartiganCluster(
calldays=flowmachine.features.CallDays(
subscriber_locations=flowmachine.features.subscriber_locations(
start="2016-01-01", stop="2016-01-07", level="versioned-site"
subscriber_locations=flowmachine.features.SubscriberLocations(
start="2016-01-01",
stop="2016-01-07",
spatial_unit=vsite_spatial_unit,
)
),
radius=1.0,
Expand All @@ -195,11 +215,11 @@
stop="2016-01-07",
score_hour=hour_scores,
score_dow=day_scores,
level="versioned-site",
spatial_unit=vsite_spatial_unit,
),
label="work",
),
level="admin3",
spatial_unit=admin3_spatial_unit,
)
]

Expand All @@ -209,22 +229,25 @@
start="2016-01-01",
stop="2016-01-07",
table="events.mds",
level="versioned-cell",
spatial_unit=vcell_spatial_unit,
interval="hour",
)
]

# Cell Towers Per Region
cell_towers_per_region_queries = [
flowmachine.features.TotalNetworkObjects(
start="2016-01-01", stop="2016-01-08", level="admin3", total_by="month"
start="2016-01-01",
stop="2016-01-08",
spatial_unit=admin3_spatial_unit,
total_by="month",
)
]

# Unique Subscriber Counts
unique_subscriber_counts_queries = [
flowmachine.features.UniqueSubscriberCounts(
start="2016-01-01", stop="2016-01-08", level="admin3"
start="2016-01-01", stop="2016-01-08", spatial_unit=admin3_spatial_unit
)
]

Expand Down
5 changes: 2 additions & 3 deletions docs/source/worked_examples/cell-towers-per-region.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@
"source": [
"towers_per_admin3_geodataframe = (\n",
" regions_geodataframe.join(\n",
" towers_per_admin3.set_index(\"pcod\"), on=\"admin3pcod\", how=\"left\"\n",
" towers_per_admin3.set_index(\"pcod\"), on=\"pcod\", how=\"left\"\n",
" )\n",
" .fillna(0)\n",
" .drop(columns=[\"centroid\", \"datetime\"])\n",
" .rename(\n",
" columns={\n",
" \"admin3pcod\": \"P-code\",\n",
" \"admin3name\": \"Name\",\n",
" \"pcod\": \"P-code\",\n",
" \"value\": \"Number of towers\",\n",
" }\n",
" )\n",
Expand Down
14 changes: 6 additions & 8 deletions docs/source/worked_examples/commuting-patterns.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@
" regions_geodataframe.drop(columns=\"centroid\")\n",
" .join(\n",
" home_locations.drop(columns=\"label\").set_index(\"pcod\"),\n",
" on=\"admin3pcod\",\n",
" on=\"pcod\",\n",
" how=\"left\",\n",
" )\n",
" .join(\n",
" work_locations.drop(columns=\"label\").set_index(\"pcod\"),\n",
" on=\"admin3pcod\",\n",
" on=\"pcod\",\n",
" lsuffix=\"_home\",\n",
" rsuffix=\"_work\",\n",
" how=\"left\",\n",
Expand All @@ -215,8 +215,7 @@
"# Rename columns for map labels\n",
"locations_geodataframe = locations_geodataframe.rename(\n",
" columns={\n",
" \"admin3pcod\": \"P-code\",\n",
" \"admin3name\": \"Name\",\n",
" \"pcod\": \"P-code\",\n",
" \"total_home\": \"Total (home)\",\n",
" \"total_work\": \"Total (work)\",\n",
" }\n",
Expand Down Expand Up @@ -341,10 +340,10 @@
"# Join location counts to geography data\n",
"commuters_geodataframe = (\n",
" regions_geodataframe.drop(columns=\"centroid\")\n",
" .join(commuters_into_region, on=\"admin3pcod\", how=\"left\")\n",
" .join(commuters_into_region, on=\"pcod\", how=\"left\")\n",
" .join(\n",
" commuters_out_from_region,\n",
" on=\"admin3pcod\",\n",
" on=\"pcod\",\n",
" lsuffix=\"_in\",\n",
" rsuffix=\"_out\",\n",
" how=\"left\",\n",
Expand All @@ -355,8 +354,7 @@
"# Rename columns for map labels\n",
"commuters_geodataframe = commuters_geodataframe.rename(\n",
" columns={\n",
" \"admin3pcod\": \"P-code\",\n",
" \"admin3name\": \"Name\",\n",
" \"pcod\": \"P-code\",\n",
" \"total_in\": \"Commuters in\",\n",
" \"total_out\": \"Commuters out\",\n",
" }\n",
Expand Down
8 changes: 4 additions & 4 deletions docs/source/worked_examples/flows-above-normal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@
" home_locations_results[period]\n",
" .set_index(\"pcod\")\n",
" .rename(columns={\"total\": f\"Total ({period} period)\"}),\n",
" on=\"admin3pcod\",\n",
" on=\"pcod\",\n",
" how=\"left\",\n",
" ).fillna(0)\n",
"\n",
"home_locations_geodataframe = home_locations_geodataframe.rename(\n",
" columns={\"admin3pcod\": \"P-code\", \"admin3name\": \"Name\"}\n",
" columns={\"pcod\": \"P-code\"}\n",
")"
]
},
Expand Down Expand Up @@ -389,7 +389,7 @@
"outputs": [],
"source": [
"in_out_flows_geodataframe = (\n",
" regions_geodataframe.set_index(\"admin3pcod\")\n",
" regions_geodataframe.set_index(\"pcod\")\n",
" .join(\n",
" [\n",
" inflows_above_normal.rename(\n",
Expand All @@ -407,7 +407,7 @@
"\n",
"in_out_flows_geodataframe = in_out_flows_geodataframe.drop(\n",
" columns=\"centroid\"\n",
").rename(columns={\"admin3pcod\": \"P-code\", \"admin3name\": \"Name\"})"
").rename(columns={\"pcod\": \"P-code\"})"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion docs/source/worked_examples/mobile-data-usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"outputs": [],
"source": [
"import flowmachine\n",
"from flowmachine.core import make_spatial_unit\n",
"import os\n",
"import numpy as np\n",
"import geopandas as gpd\n",
Expand Down Expand Up @@ -82,7 +83,7 @@
" start=\"2016-01-01\",\n",
" stop=\"2016-01-07\",\n",
" table=\"events.mds\",\n",
" level=\"versioned-cell\",\n",
" spatial_unit=make_spatial_unit(\"versioned-cell\"),\n",
" interval=\"hour\",\n",
")"
]
Expand Down
5 changes: 2 additions & 3 deletions docs/source/worked_examples/unique-subscriber-counts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@
"source": [
"subscribers_per_admin3_geodataframe = (\n",
" regions_geodataframe.join(\n",
" subscribers_per_admin3.set_index(\"pcod\"), on=\"admin3pcod\", how=\"left\"\n",
" subscribers_per_admin3.set_index(\"pcod\"), on=\"pcod\", how=\"left\"\n",
" )\n",
" .fillna(0)\n",
" .drop(columns=[\"centroid\"])\n",
" .rename(\n",
" columns={\n",
" \"admin3pcod\": \"P-code\",\n",
" \"admin3name\": \"Name\",\n",
" \"pcod\": \"P-code\",\n",
" \"unique_subscriber_counts\": \"Number of subscribers\",\n",
" }\n",
" )\n",
Expand Down
6 changes: 5 additions & 1 deletion flowapi/flowapi/geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ async def get_geography(aggregation_unit):
)

if reply["status"] == "error":
return jsonify({"status": "Error", "msg": "Internal server error"}), 500
try:
msg = reply["msg"]
except KeyError:
msg = "Internal server error"
return jsonify({"status": "Error", "msg": msg}), 500

try:
query_state = reply["payload"]["query_state"]
Expand Down
7 changes: 6 additions & 1 deletion flowmachine/flowmachine/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from .geotable import GeoTable
from .init import connect
from .logging import init_logging, set_log_level
from .join_to_location import JoinToLocation
from .spatial_unit import make_spatial_unit
from .join_to_location import JoinToLocation, location_joined_query
from .custom_query import CustomQuery
from .grid import Grid

sub_modules = ["errors", "mixins", "api"]

Expand All @@ -24,8 +26,11 @@
"GeoTable",
"Connection",
"connect",
"make_spatial_unit",
"JoinToLocation",
"location_joined_query",
"CustomQuery",
"Grid",
]

__all__ = methods + sub_modules
9 changes: 7 additions & 2 deletions flowmachine/flowmachine/core/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
from .flowmachine_errors import (
NameTooLongError,
NotConnectedError,
BadLevelError,
InvalidSpatialUnitError,
MissingDateError,
)

__all__ = ["NameTooLongError", "NotConnectedError", "BadLevelError", "MissingDateError"]
__all__ = [
"NameTooLongError",
"NotConnectedError",
"InvalidSpatialUnitError",
"MissingDateError",
]
Loading