Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(
self,
*,
meaningful_locations: MeaningfulLocations,
spatial_unit: Optional[AnySpatialUnit] = None,
) -> None:
self.meaningful_locations = meaningful_locations
if spatial_unit is None:
self.spatial_unit = make_spatial_unit("admin", level=3)
else:
self.spatial_unit = spatial_unit
self.spatial_unit.verify_criterion("is_polygon")
super().__init__()
def __init__(
self,
*,
meaningful_locations_a: MeaningfulLocations,
meaningful_locations_b: MeaningfulLocations,
spatial_unit: Optional[AnySpatialUnit] = None,
) -> None:
self.flow = meaningful_locations_a.join(
meaningful_locations_b,
on_left="subscriber",
left_append="_from",
right_append="_to",
)
if spatial_unit is None:
self.spatial_unit = make_spatial_unit("admin", level=3)
else:
self.spatial_unit = spatial_unit
self.spatial_unit.verify_criterion("is_polygon")
super().__init__()
# The purpose is to speed up execution of the example notebooks,
# by caching some of the queries beforehand (which is currently
# not possible using flowclient directly).
import flowmachine
import pandas as pd
import networkx as nx
import concurrent.futures
from flowmachine.core.errors import UnstorableQueryError
flowmachine.connect()
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", spatial_unit=admin3_spatial_unit, method="last"
)
),
flowmachine.features.utilities.spatial_aggregates.SpatialAggregate(
locations=flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
date=dl_date, spatial_unit=admin3_spatial_unit, method="last"
)
# This file is executed in build.sh before building the docs.
# The purpose is to speed up execution of the example notebooks,
# by caching some of the queries beforehand (which is currently
# not possible using flowclient directly).
import flowmachine
import pandas as pd
import networkx as nx
import concurrent.futures
from flowmachine.core.errors import UnstorableQueryError
flowmachine.connect()
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", spatial_unit=admin3_spatial_unit, method="last"
)
),
flowmachine.features.utilities.spatial_aggregates.SpatialAggregate(
locations=flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
date=dl_date, spatial_unit=admin3_spatial_unit, method="last"
def __init__(
self,
start,
stop,
*,
spatial_unit: AnySpatialUnit = make_spatial_unit("cell"),
hours="all",
tables="all",
subscriber_identifier="msisdn",
ignore_nulls=True,
subscriber_subset=None,
):
self.ul = UniqueLocations(
SubscriberLocations(
start=start,
stop=stop,
spatial_unit=spatial_unit,
hours=hours,
table=tables,
subscriber_identifier=subscriber_identifier,
ignore_nulls=ignore_nulls,
# by caching some of the queries beforehand (which is currently
# not possible using flowclient directly).
import flowmachine
import pandas as pd
import networkx as nx
import concurrent.futures
from flowmachine.core.errors import UnstorableQueryError
flowmachine.connect()
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", spatial_unit=admin3_spatial_unit, method="last"
)
),
flowmachine.features.utilities.spatial_aggregates.SpatialAggregate(
locations=flowmachine.features.ModalLocation(
*[
flowmachine.features.daily_location(
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")
# Rename the columns to match what we'll join to
# sort the dataframe so we'll have a consistent md5
self.departure_rate = departure_rate.rename(
columns=lambda x: x if x == "rate" else f"{x}_from"
).apply(lambda x: x.sort_values().values)
self.departure_rate = self.departure_rate.reindex(
columns=sorted(self.departure_rate.columns)
)
elif isinstance(departure_rate, float):
self.departure_rate = departure_rate
else:
raise TypeError(f"{departure_rate} must be a float or dataframe")
self.start = standardise_date(start)
self.stop = standardise_date(stop)
if spatial_unit is None:
self.spatial_unit = make_spatial_unit("versioned-site")
else:
self.spatial_unit = spatial_unit
self.distance_matrix = DistanceMatrix(
spatial_unit=self.spatial_unit, return_geometry=True
)
self.population_object = ModalLocation(
*[
daily_location(
d,
spatial_unit=self.spatial_unit,
hours=hours,
method=method,
table=table,
subscriber_identifier=subscriber_identifier,
ignore_nulls=True,
self,
start,
stop,
spatial_unit: Optional[AnySpatialUnit] = None,
hours="all",
table="all",
subscriber_identifier="msisdn",
*,
ignore_nulls=True,
subscriber_subset=None,
):
self.start = standardise_date(start)
self.stop = standardise_date(stop)
if spatial_unit is None:
self.spatial_unit = make_spatial_unit("admin", level=3)
else:
self.spatial_unit = spatial_unit
self.hours = hours
self.table = table
self.subscriber_identifier = subscriber_identifier
self.subscriber_locs = SubscriberLocations(
start=self.start,
stop=self.stop,
spatial_unit=self.spatial_unit,
hours=self.hours,
table=self.table,
subscriber_identifier=self.subscriber_identifier,
ignore_nulls=ignore_nulls,
subscriber_subset=subscriber_subset,
)
super().__init__()
ignore_nulls=True,
subscriber_subset=None,
):
self.unit = unit.lower()
if unit not in self.allowed_units:
raise ValueError(
f"Unrecognised unit {unit}, use one of {self.allowed_units}"
)
self.start = standardise_date(start)
self.stop = standardise_date(stop)
self.ul = SubscriberLocations(
self.start,
self.stop,
spatial_unit=make_spatial_unit("lon-lat"),
hours=hours,
table=table,
subscriber_subset=subscriber_subset,
subscriber_identifier=subscriber_identifier,
ignore_nulls=ignore_nulls,
)
super().__init__()