Skip to content

Commit

Permalink
data access path fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SahitiSarva committed Oct 7, 2024
1 parent 64f65ca commit 17c805a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
16 changes: 7 additions & 9 deletions notebooks/acled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 48,
"metadata": {
"tags": [
"remove-cell"
Expand All @@ -14,15 +14,13 @@
"%autoreload 2\n",
"\n",
"import os\n",
"import acled_conflict_analysis.visuals as visuals\n",
"import acled_conflict_analysis.analysis as analysis\n",
"import acled_conflict_analysis.extraction as extraction \n",
"import acled_conflict_analysis as acled\n",
"from acled_conflict_analysis import visuals\n",
"from acled_conflict_analysis import analysis\n",
"from acled_conflict_analysis import extraction\n",
"\n",
"from datetime import date\n",
"from datetime import datetime\n",
"\n",
"bokeh.core.validation.silence(EMPTY_LAYOUT, True)\n",
"bokeh.core.validation.silence(MISSING_RENDERERS, True)"
"from datetime import datetime\n"
]
},
{
Expand All @@ -38,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
Expand Down
13 changes: 12 additions & 1 deletion src/acled_conflict_analysis/extraction.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import os
import requests
import pandas as pd
import pkgutil
import io

def load_country_centroids():
# Access the file from the package using pkgutil
data = pkgutil.get_data('acled_conflict_analysis', 'data/Country_ISO_Code_Map.csv')
iso_country_map = pd.read_csv(io.BytesIO(data))
return iso_country_map

iso_country_map = load_country_centroids()

#iso_country_map = pd.read_csv('./data/Country_ISO_Code_Map.csv')

iso_country_map = pd.read_csv('./data/Country_ISO_Code_Map.csv')

def get_iso_code(country_names):
iso_country = []
Expand Down
11 changes: 9 additions & 2 deletions src/acled_conflict_analysis/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import folium
from folium.plugins import TimestampedGeoJson
import pandas as pd
import importlib.resources as pkg_resources



# Use the silence function to ignore the EMPTY_LAYOUT warning
silence(EMPTY_LAYOUT, True)
Expand Down Expand Up @@ -339,7 +342,11 @@ def get_line_plot(



country_centroids = pd.read_csv('./data/countries_centroids.csv')
def load_country_centroids():
# Access the file from the package using importlib.resources
with pkg_resources.open_text('acled_conflict_analysis.data', 'countries_centroids.csv') as file:
country_centroids = pd.read_csv(file)
return country_centroids

def get_animated_map(data, country='India', threshold=100, measure='nrFatalities', animation_period='P1Y'):

Expand All @@ -348,7 +355,7 @@ def get_animated_map(data, country='India', threshold=100, measure='nrFatalities
elif measure == 'nrEvents':
measure_name = 'Events'


country_centroids = load_country_centroids()
country_centroid = list(country_centroids[country_centroids['COUNTRY'] == country][['latitude', 'longitude']].iloc[0])

# Create the base map
Expand Down

0 comments on commit 17c805a

Please sign in to comment.