Skip to content

Commit 9cef8e7

Browse files
author
Your Name
committed
updated the usage docs
1 parent 48da7b2 commit 9cef8e7

5 files changed

Lines changed: 93 additions & 77 deletions

File tree

docs/images/contact_matrix.png

17.8 KB
Loading

docs/images/hotspot.png

47.7 KB
Loading

docs/images/mobility.png

28.8 KB
Loading

docs/images/pandemic.png

39.6 KB
Loading

docs/usage.rst

Lines changed: 93 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -22,61 +22,72 @@ you can use the ``hotspot_analyzer.hotspot_analyzer()`` function to generate dif
2222

2323
.. autofunction:: hotspot_analyzer.hotspot_analyzer
2424

25-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
26-
The ``start_date`` and ``end_date`` parameters take the start and end date of the time frame for which the analysis is to be done.
25+
The ``df`` parameter takes a pandas DataFrame as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
26+
The ``city_zipcode_map`` parameter takes a pandas DataFrame mapping cities to zip codes.
27+
The ``start_date`` and ``end_date`` parameters take the start and end date of the time frame for which the analysis is to be done.
2728
The ``city`` parameter takes the name of the city for which the analysis is to be done.
29+
The ``default_city`` parameter specifies the fallback city for unmapped zip codes.
2830
The ``epsilon`` parameter takes the value of epsilon for differential privacy.
2931

3032
For example:
3133

3234
>>> from DP_epidemiology import hotspot_analyzer
3335
>>> from datetime import datetime
36+
>>> import pandas as pd
3437
>>> df = pd.read_csv('data.csv')
35-
>>> hotspot_analyzer.hotspot_analyzer(df,datetime(2020, 9, 1),datetime(2021, 3, 31),"Medellin",10)
36-
df_nb_transactions postal_code
37-
0 182274 500001
38-
1 184207 500002
39-
2 181038 500003
40-
3 178536 500004
41-
4 202206 500005
42-
5 189752 500006
43-
44-
45-
To visulize the hotspot,
38+
>>> city_zipcode_map = pd.read_csv('city_zipcode_map.csv')
39+
>>> hotspot_analyzer.hotspot_analyzer(df, city_zipcode_map, datetime(2020, 9, 1), datetime(2021, 3, 31), "Medellin", "Bogota", 10)
40+
nb_transactions merch_postal_code
41+
0 182274 500001
42+
1 184207 500002
43+
2 181038 500003
44+
3 178536 500004
45+
4 202206 500005
46+
5 189752 500006
47+
48+
To visualize the hotspot,
4649
you can use the ``viz.create_hotspot_dash_app()`` function:
4750

4851
.. autofunction:: viz.create_hotspot_dash_app
4952

50-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
53+
The ``df`` parameter takes a pandas DataFrame as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
54+
The ``city_zipcode_map`` parameter takes a pandas DataFrame mapping cities to zip codes.
55+
The ``default_city`` parameter specifies the fallback city for unmapped zip codes.
5156

5257
For example:
5358

5459
>>> from DP_epidemiology import viz
60+
>>> import pandas as pd
5561
>>> df = pd.read_csv('data.csv')
56-
>>> app=viz.create_hotspot_dash_app(df)
62+
>>> city_zipcode_map = pd.read_csv('city_zipcode_map.csv')
63+
>>> app = viz.create_hotspot_dash_app(df, city_zipcode_map, "Bogota")
5764
>>> app.run_server(debug=True)
5865

5966
.. image:: images/hotspot.png
6067
:alt: hotspot
6168

6269

6370
To do mobility inference,
64-
you can use the ``mobility_analyzer.mobility_analyzer()`` function to generate differential private time series of trnsactional data in the ``retail_and_recreation``, ``grocery_and_pharmacy`` and ``transit_stations`` super categories:
71+
you can use the ``mobility_analyzer.mobility_analyzer()`` function to generate differentially private time series of transactional data in various merchant supercategories:
6572

6673
.. autofunction:: mobility_analyzer.mobility_analyzer
6774

68-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
69-
The ``start_date`` and ``end_date`` parameters take the start and end date of the time frame for which the analysis is to be done.
75+
The ``df`` parameter takes a pandas DataFrame as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
76+
The ``city_zipcode_map`` parameter takes a pandas DataFrame mapping cities to zip codes.
77+
The ``start_date`` and ``end_date`` parameters take the start and end date of the time frame for which the analysis is to be done.
7078
The ``city`` parameter takes the name of the city for which the analysis is to be done.
71-
The ``category`` parameter takes the value of ``retail_and_recreation``, ``grocery_and_pharmacy`` or ``transit_stations`` for which the analysis is to be done.
79+
The ``default_city`` parameter specifies the fallback city for unmapped zip codes.
80+
The ``category`` parameter takes the value of a merchant supercategory (e.g., ``retail_and_recreation``, ``grocery_and_pharmacy``, or ``transit_stations``) for which the analysis is to be done.
7281
The ``epsilon`` parameter takes the value of epsilon for differential privacy.
7382

7483
For example:
7584

7685
>>> from DP_epidemiology import mobility_analyzer
7786
>>> from datetime import datetime
87+
>>> import pandas as pd
7888
>>> df = pd.read_csv('data.csv')
79-
>>> mobility_analyzer.mobility_analyzer(df,datetime(2020, 9, 1),datetime(2021, 3, 31),"Medellin","retail_and_recreation",10)
89+
>>> city_zipcode_map = pd.read_csv('city_zipcode_map.csv')
90+
>>> mobility_analyzer.mobility_analyzer(df, city_zipcode_map, datetime(2020, 9, 1), datetime(2021, 3, 31), "Medellin", "Bogota", "retail_and_recreation", 10)
8091
nb_transactions date
8192
0 1258 2020-09-01
8293
1 1328 2020-09-08
@@ -85,42 +96,45 @@ For example:
8596
4 1182 2020-09-29
8697
5 1264 2020-10-06
8798

88-
89-
To visulize the mobility,
99+
To visualize mobility,
90100
you can use the ``viz.create_mobility_dash_app()`` function:
91101

92102
.. autofunction:: viz.create_mobility_dash_app
93103

94-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
104+
The ``df`` parameter takes a pandas DataFrame as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
105+
The ``city_zipcode_map`` parameter takes a pandas DataFrame mapping cities to zip codes.
106+
The ``default_city`` parameter specifies the fallback city for unmapped zip codes.
95107

96108
For example:
97109

98110
>>> from DP_epidemiology import viz
111+
>>> import pandas as pd
99112
>>> df = pd.read_csv('data.csv')
100-
>>> app=viz.create_mobility_dash_app(df)
113+
>>> city_zipcode_map = pd.read_csv('city_zipcode_map.csv')
114+
>>> app = viz.create_mobility_dash_app(df, city_zipcode_map, "Bogota")
101115
>>> app.run_server(debug=True)
102116

103117
.. image:: images/mobility.png
104-
:alt: hotspot
118+
:alt: mobility
105119

106120

107-
To do pandemic stage inference,
108-
you can use the ``pandemic_adherence_analyzer.pandemic_stage_analyzer()`` function to generate differential private time series of trnsactional data for luxurious or essential goods:
121+
To do pandemic adherence inference,
122+
you can use the ``pandemic_adherence_analyzer.pandemic_adherence_analyzer()`` function to generate differential private time series of transactional data for luxury or essential goods:
109123

110-
.. autofunction:: pandemic_adherence_analyzer.pandemic_stage_analyzer
124+
.. autofunction:: pandemic_adherence_analyzer.pandemic_adherence_analyzer
111125

112-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
113-
The ``start_date`` and ``end_date`` parameters take the start and end date of the time frame for which the analysis is to be done.
114-
The ``city`` parameter takes the name of the city for which the analysis is to be done.
115-
The``essential_or_luxury`` parameter takes the value of "essential" or "luxury" for which the analysis is to be done.
116-
The ``epsilon`` parameter takes the value of epsilon for differential privacy.
126+
The ``df`` parameter takes a pandas DataFrame as input with columns ``["ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
127+
The ``start_date`` and ``end_date`` parameters specify the time frame for which the analysis is to be conducted.
128+
The ``city`` parameter specifies the city for which the analysis is to be conducted.
129+
The ``essential_or_luxury`` parameter takes the value "essential", "luxury", or "other" depending on the goods to be analyzed.
130+
The ``epsilon`` parameter sets the epsilon value for differential privacy.
117131

118132
For example:
119133

120134
>>> from DP_epidemiology import pandemic_adherence_analyzer
121135
>>> from datetime import datetime
122136
>>> df = pd.read_csv('data.csv')
123-
>>> pandemic_adherence_analyzer.pandemic_adherence_analyzer(df,datetime(2020, 9, 1),datetime(2021, 3, 31),"Medellin",essential_or_luxury="luxury",epsilon=10)
137+
>>> pandemic_adherence_analyzer.pandemic_adherence_analyzer(df, city_zipcode_map, datetime(2020, 9, 1), datetime(2021, 3, 31), "Medellin", default_city="DefaultCity", essential_or_luxury="luxury", epsilon=10)
124138
nb_transactions date
125139
0 1258 2020-09-01
126140
1 1328 2020-09-08
@@ -130,104 +144,106 @@ For example:
130144
5 1264 2020-10-06
131145

132146

133-
To visulize the pandemic stages,
147+
To visualize the pandemic adherence,
134148
you can use the ``viz.create_pandemic_adherence_dash_app()`` function:
135149

136150
.. autofunction:: viz.create_pandemic_adherence_dash_app
137151

138-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
152+
The ``df`` parameter takes a pandas DataFrame as input with columns ``["ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
153+
The ``city_zipcode_map`` parameter specifies the city-zipcode mapping DataFrame.
154+
The ``default_city`` parameter sets the default city for mapping purposes.
139155

140156
For example:
141157

142158
>>> from DP_epidemiology import viz
143159
>>> df = pd.read_csv('data.csv')
144-
>>> app=viz.create_pandemic_adherence_dash_app(df)
160+
>>> city_zipcode_map = pd.read_csv('city_zipcode_map.csv')
161+
>>> app = viz.create_pandemic_adherence_dash_app(df, city_zipcode_map, default_city="DefaultCity")
145162
>>> app.run_server(debug=True)
146163

147164
.. image:: images/pandemic.png
148-
:alt: hotspot
165+
:alt: pandemic adherence
149166

150167

151168

152-
To get the contact matrix,
153-
you need to first get the age group count map using the ``contact_matrix.get_age_group_count_map()`` function:
169+
# To get the contact matrix
170+
#
171+
# You need to first get the age group count map using the `contact_matrix.get_age_group_count_map()` function:
154172

155173
.. autofunction:: contact_matrix.get_age_group_count_map
156174

157-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
158-
The ``start_date`` and ``end_date`` parameters take the start and end date of the time frame for which the analysis is to be done.
159-
The ``pincode_prefix`` parameter indicating the starting digits that is common to all the pincodes of the country.
160-
The ``epsilon`` parameter takes the value of epsilon for differential privacy.
175+
The `df` parameter takes a pandas dataframe as input with columns `[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]`.
176+
The `start_date` and `end_date` parameters take the start and end dates of the time frame for which the analysis is to be performed.
177+
The `city` parameter specifies the city for which the analysis is conducted.
178+
The `epsilon` parameter takes the value of epsilon for differential privacy.
161179

162180
For example:
163181

164182
>>> from DP_epidemiology import contact_matrix
165183
>>> from datetime import datetime
166184
>>> df = pd.read_csv('data.csv')
167-
>>> contact_matrix.get_age_group_count_map(df,datetime(2020, 12, 12),datetime(2021, 1, 31),city="Bogota",epsilon=1.0)
185+
>>> contact_matrix.get_age_group_count_map(df, datetime(2020, 12, 12), datetime(2021, 1, 31), city="Bogota", epsilon=1.0)
168186

169-
Then you can use the ``contact_matrix.get_contact_matrix()`` function to generate differential private contact matrix:
187+
Then you can use the `contact_matrix.get_contact_matrix()` function to generate a differential private contact matrix:
170188

171189
.. autofunction:: contact_matrix.get_contact_matrix
172190

173-
The ``age_group_sample_size`` parameter takes the age group sample size distribution list. This will be generated by using the values from the map returned by the ``get_age_group_count_map()`` function.
174-
The ``age_group_population_distribution`` parameter takes the age group population distribution list for the country.
191+
The `sample_distribution` parameter takes the age group sample size distribution list. This will be generated using the values from the map returned by the `get_age_group_count_map()` function.
192+
The `population_distribution` parameter takes the age group population distribution list for the country.
175193

176194
For example:
177195

178196
>>> from DP_epidemiology import contact_matrix
179197
>>> from datetime import datetime
180198
>>> df = pd.read_csv('data.csv')
181-
>>>age_group_population_distribution = [8231200, 7334319, 6100177]
182-
>>> age_group_count_map = contact_matrix.get_age_group_count_map(df,datetime(2020, 12, 12),datetime(2021, 1, 31),city="Bogota",epsilon=1.0)
183-
>>> contact_matrix.get_contact_matrix(list(age_group_count_map.values()),age_group_population_distribution)
199+
>>> age_group_population_distribution = [8231200, 7334319, 6100177]
200+
>>> age_group_count_map = contact_matrix.get_age_group_count_map(df, datetime(2020, 12, 12), datetime(2021, 1, 31), city="Bogota", epsilon=1.0)
201+
>>> contact_matrix.get_contact_matrix(list(age_group_count_map.values()), age_group_population_distribution)
184202

185203
.. code-block:: console
186-
204+
187205
[[2.8 3.11030655 3.46168911]
188-
[2.77140397 2.8 3.0734998 ]
189-
[2.56547238 2.5563236 2.8 ]]
206+
[2.77140397 2.8 3.0734998 ]
207+
[2.56547238 2.5563236 2.8 ]]
190208
191-
To calculate the country wide contact matrix you can use the ``contact_matrix.get_contact_matrix_country()`` function to generate differential private contact matrix:
209+
To calculate the country-wide contact matrix, you can use the `contact_matrix.get_contact_matrix_country()` function to generate a differential private contact matrix:
192210

193211
.. autofunction:: contact_matrix.get_contact_matrix_country
194212

195-
The ``counts_per_city`` parameter takes the age group count map for each city in the country.
196-
``population_distribution`` parameter takes the age group population distribution list for the country.
197-
``scaling_factor`` parameter takes the scaling factor for the population distribution. This scales the population distribution while estimating total number of contacts across age groups.
213+
The `counts_per_city` parameter takes the age group count map for each city in the country.
214+
The `population_distribution` parameter takes the age group population distribution list for the country.
215+
The `scaling_factor` parameter scales the population distribution while estimating the total number of contacts across age groups.
198216

199217
For example:
200218

201219
>>> from DP_epidemiology import contact_matrix
202220
>>> from datetime import datetime
203221
>>> age_groups = ['0-4', '5-9', '10-14', '15-19', '20-24', '25-29', '30-34', '35-39', '40-44', '45-49', '50-54', '55-59', '60-64', '65-69', '70-74', '75+']
204-
>>>week ="2021-01-05"
205-
>>>start_date = datetime.strptime(week, '%Y-%m-%d')
206-
>>>end_date = datetime.strptime(week, '%Y-%m-%d')
207-
>>>from DP_epidemiology.utilities import make_preprocess_location
208-
>>>df = make_preprocess_location()(df)
209-
>>>cities = data['city'].unique()
210-
>>>age_group_count_map_per_city = []
211-
>>>for city in cities:
212-
age_group_count_map = contact_matrix.get_age_group_count_map(data, age_groups, consumption_distribution, start_date, end_date, city)
213-
age_group_count_map_per_city.append(list(age_group_count_map.values()))
214-
>>>population_distribution = np.array([4136344, 4100716, 3991988, 3934088, 4090149, 4141051, 3895117, 3439202,
215-
3075077, 3025100, 3031855, 2683253, 2187561, 1612948, 1088448, 1394217])
216-
>>>from DP_epidemiology.contact_matrix import get_contact_matrix_country
217-
>>>estimated_contact_matrix = get_contact_matrix_country(age_group_count_map_per_city, population_distribution, scaling_factor)
218-
219-
To visulize the contact matrix,
220-
you can use the ``viz.create_contact_matrix_dash_app()`` function:
222+
>>> week = "2021-01-05"
223+
>>> start_date = datetime.strptime(week, '%Y-%m-%d')
224+
>>> end_date = datetime.strptime(week, '%Y-%m-%d')
225+
>>> from DP_epidemiology.utilities import make_preprocess_location
226+
>>> df = make_preprocess_location()(df)
227+
>>> cities = df['city'].unique()
228+
>>> age_group_count_map_per_city = []
229+
>>> for city in cities:
230+
... age_group_count_map = contact_matrix.get_age_group_count_map(df, city_zipcode_map, age_groups, consumption_distribution, start_date, end_date, city, default_city)
231+
... age_group_count_map_per_city.append(list(age_group_count_map.values()))
232+
>>> population_distribution = [4136344, 4100716, 3991988, 3934088, 4090149, 4141051, 3895117, 3439202, 3075077, 3025100, 3031855, 2683253, 2187561, 1612948, 1088448, 1394217]
233+
>>> from DP_epidemiology.contact_matrix import get_contact_matrix_country
234+
>>> estimated_contact_matrix = get_contact_matrix_country(age_group_count_map_per_city, population_distribution, scaling_factor)
235+
236+
To visualize the contact matrix, you can use the `viz.create_contact_matrix_dash_app()` function:
221237

222238
.. autofunction:: viz.create_contact_matrix_dash_app
223239

224-
The ``df`` parameter take pandas dataframe as input with columns ``[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]``.
240+
The `df` parameter takes a pandas dataframe as input with columns `[ "ID", "date", "merch_category", "merch_postal_code", "transaction_type", "spendamt", "nb_transactions"]`.
225241

226242
For example:
227243

228244
>>> from DP_epidemiology import viz
229245
>>> df = pd.read_csv('data.csv')
230-
>>> app=viz.create_contact_matrix_dash_app(df)
246+
>>> app = viz.create_contact_matrix_dash_app(df)
231247
>>> app.run_server(debug=True)
232248

233249
.. image:: images/contact_matrix.png

0 commit comments

Comments
 (0)