20
20
import squarify
21
21
22
22
23
- def __get_general_modality_plot (df ):
23
+ def __create_general_modality_plot (df ):
24
24
modality_counts = df ["generalmodality" ].value_counts ()
25
25
26
26
plt .figure (figsize = (10 , 6 ))
@@ -70,11 +70,23 @@ def __get_lable_dict(name_lst):
70
70
}
71
71
72
72
73
- def __get_general_modality_treemap (df ):
73
+ def __create_general_modality_treemap (df ):
74
74
"""
75
- input: dataframe
76
- output: tree map that displays the frequencies of "generalmodality" that occur in dataframe
75
+ Create a treemap visualization for the general modality data.
76
+
77
+ This function takes a pandas DataFrame as input and generates a treemap visualization based on
78
+ the counts of different modalities in the 'generalmodality' column of the DataFrame. The function
79
+ utilizes the Squarify library to create the treemap.
80
+
81
+ Parameters:
82
+ df (pandas.DataFrame): The input DataFrame containing the 'generalmodality' column.
83
+
84
+ Returns:
85
+ None: The function generates a treemap and saves it as an image file, but it does not return any value.
86
+ The treemap is saved with a filename in the format 'treemap-general-modality-YYYYMMDD.png', where
87
+ 'YYYYMMDD' represents the current date in year-month-day format.
77
88
"""
89
+
78
90
modality_counts = df ["generalmodality" ].value_counts ().to_dict ()
79
91
plt .figure (figsize = (14 , 10 ))
80
92
values = list (modality_counts .values ())
@@ -94,7 +106,9 @@ def __get_general_modality_treemap(df):
94
106
plt .legend (
95
107
legend_patches , name , loc = "upper left" , bbox_to_anchor = (1 , 1 ), fontsize = "medium"
96
108
)
97
- plt .show ()
109
+
110
+ filename = f'treemap-general-modality-{ datetime .now ().strftime ("%Y%m%d" )} .png'
111
+ plt .savefig (filename )
98
112
99
113
100
114
def __get_pretty_size_statistics (df ):
@@ -184,21 +198,24 @@ def get_date(df):
184
198
day = dateList [2 ] # get day
185
199
return f"{ yr } -{ day } -{ mnt } " # format in year-day-month
186
200
201
+
187
202
import geoip2 .database
188
203
from geopy .geocoders import Nominatim
189
204
import folium
190
205
import math
191
206
import urllib .request
192
207
193
- """print(c.get_country_cities(country_code_iso="DE"))"""
208
+ """print(c.get_country_cities(country_code_iso="DE"))"""
194
209
"""
195
210
Geopy: input: University #correct some data (do later) Output: Address, lat, lon
196
211
folium or Ivan's
197
212
Must choose module to make the map
198
213
"""
199
214
215
+
200
216
def __get_affiliations (df ):
201
- return df ['affiliation' ].value_counts ().keys ()
217
+ return df ["affiliation" ].value_counts ().keys ()
218
+
202
219
203
220
def __get_coordin (university ):
204
221
geolocator = Nominatim (user_agent = "my_geocoding_app" )
@@ -207,20 +224,22 @@ def __get_coordin(university):
207
224
if location :
208
225
return location .latitude , location .longitude
209
226
else :
210
- return (0 ,0 )
227
+ return (0 , 0 )
211
228
except :
212
229
print (f"Geocoding service is unavailable for { university } " )
213
230
return 0 , 0
214
231
232
+
215
233
def get_zero_coords (affiliation_coordinates ):
216
234
total = 0
217
235
zeros = 0
218
236
for university in affiliation_coordinates :
219
- if affiliation_coordinates [university ] == (0 , 0 ):
220
- zeros += 1
221
- print (affiliation_coordinates [university ],university ,"ain't working" )
237
+ if affiliation_coordinates [university ] == (0 , 0 ):
238
+ zeros += 1
239
+ print (affiliation_coordinates [university ], university , "ain't working" )
222
240
total += 1
223
- return zeros , total , math .ceil (zeros / total * 100 )/ 100
241
+ return zeros , total , math .ceil (zeros / total * 100 ) / 100
242
+
224
243
225
244
def __get_affilation_coordinates (df ):
226
245
affiliations_dict = {}
@@ -230,6 +249,7 @@ def __get_affilation_coordinates(df):
230
249
affiliations_dict [university ] = (latitude , longitude )
231
250
return affiliations_dict
232
251
252
+
233
253
if __name__ == "__main__" :
234
254
affiliation_coordinates = __get_affilation_coordinates (df )
235
255
print (affiliation_coordinates )
@@ -1033,16 +1053,18 @@ def report():
1033
1053
1034
1054
return report
1035
1055
1056
+
1036
1057
import pandas as pd
1037
1058
import urllib .request
1038
1059
import geoip2 .database
1039
1060
from geopy .geocoders import Nominatim
1040
1061
import folium
1041
- '''
1062
+
1063
+ """
1042
1064
Import modules that will be used to create the world map, find coordinates of affiliations, and
1043
- '''
1065
+ """
1044
1066
1045
- url = ' https://download.brainimagelibrary.org/inventory/daily/reports/today.json'
1067
+ url = " https://download.brainimagelibrary.org/inventory/daily/reports/today.json"
1046
1068
file_path , _ = urllib .request .urlretrieve (url )
1047
1069
df = pd .read_json (file_path )
1048
1070
df
@@ -1056,8 +1078,8 @@ def report():
1056
1078
from tqdm import tqdm
1057
1079
1058
1080
for index , row in tqdm (df .iterrows ()):
1059
- city = row [' city' ]
1060
- lat = row [' lat' ]
1061
- lon = row [' lng' ]
1062
- folium .Marker ([lat , lon ], popup = city ).add_to (map )
1063
- map .save (' project_map.html' )
1081
+ city = row [" city" ]
1082
+ lat = row [" lat" ]
1083
+ lon = row [" lng" ]
1084
+ folium .Marker ([lat , lon ], popup = city ).add_to (map )
1085
+ map .save (" project_map.html" )
0 commit comments