Skip to content

Commit

Permalink
added debris by activity
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyfolkesson committed May 1, 2024
1 parent 23f1840 commit 092c21f
Show file tree
Hide file tree
Showing 4 changed files with 2,624 additions and 57 deletions.
2,566 changes: 2,516 additions & 50 deletions SOS_cleanup_data.ipynb

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,14 @@ def read_col_config(column_config='column_categories.yml'):
material = 'Mixed'
required = False
col_type = 'int'
activity = 'Various'
if col_info is not None:
if 'sources' in col_info:
source_names += col_info['sources']
if 'material' in col_info:
material = col_info['material']
if 'activity' in col_info:
activity = col_info['activity']
if 'required' in col_info and isinstance(col_info['required'], bool):
required = col_info['required']
if 'type' in col_info and isinstance(col_info['type'], str):
Expand All @@ -291,13 +294,17 @@ def read_col_config(column_config='column_categories.yml'):
'sources': source_names,
'type': col_type,
'required': required,
'material': material}
'material': material,
'activity': activity,
}
# Add 'Other' to config as well
config['Other'] = {
'sources': ['Any items not in config'],
'type': 'int',
'required': False,
'material': 'Mixed'}
'material': 'Mixed',
'activity': 'Various',
}
return config


Expand Down
57 changes: 57 additions & 0 deletions column_categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,92 @@ Date:
type: datetime
required: True
material: "NA"
activity: 'NA'
Cleanup Site:
sources: ['Cleanup Site/Sitio De Limpieza']
type: str
required: True
material: "NA"
activity: 'NA'
Cleaned Size (Sq Miles):
sources: ['Estimated Size Of Location Cleaned (Sq Miles)',
'Cleanup Area']
type: int
required: False
material: "NA"
activity: 'NA'
Data Collection:
sources: ['Data Collection Method']
type: str
material: "NA"
activity: 'NA'
Duration (Hrs):
sources: ['Total Cleanup Duration (Hrs)']
type: int
required: True
material: "NA"
activity: 'NA'
Adult Volunteers:
sources: ['# Of Volunteers']
type: int
required: True
material: "NA"
activity: 'NA'
Youth Volunteers:
material: "NA"
activity: 'NA'
Trash (lbs):
sources: ['Pounds Of Trash Collected', 'Pounds Of Trash']
type: float
material: "NA"
activity: 'NA'
Recycling (lbs):
sources: ['Pounds Of Recycle Collected', 'Pounds Of Recycling']
type: float
material: "NA"
activity: 'NA'
County/City:
sources: ['County/City Where The Event Was Held?', 'County', 'City/County']
type: str
material: "NA"
activity: 'NA'
Type Of Cleanup:
sources: []
type: 'str'
material: "NA"
activity: 'NA'
Aluminum Foil:
sources: []
material: 'Metal'
activity: "Various"
Appliances:
sources: ['Appliances (Refrigerators, Washers, Etc.)']
material: 'Metal'
activity: 'Dumping/Disaster'
Bagged Pet Waste:
sources: ['Dog Poop Bags']
activity: "Recreation"
Balloons:
sources: ['Balloons Or Ribbon']
material: 'Plastic'
activity: "Recreation"
Bandaids:
sources: ['Bandaids Or Bandages']
activity: "Hygiene"
Batteries:
material: 'Metal'
activity: 'Dumping/Disaster'
Beverage Pouches:
sources: ['Beverages Sachets/Pouches', 'Beverages Sachets']
material: 'Plastic'
activity: "Eating/Drinking"
Beach Gear:
sources: ['Toys And Beach Accessories', 'Beach Chairs, Toys Umbrellas', 'Sunglasses']
activity: "Recreation"
Bikes:
sources: ['Bikes Or Bike Parts']
material: 'Metal'
activity: "Recreation"
Bottle Caps:
sources: ['Bottle Caps And Rings',
'Metal Bottle Caps',
Expand All @@ -78,26 +99,35 @@ Bottle Caps:
'Bottle Caps (Plastic)',
'Bottle Caps (Metal)']
material: 'Mixed'
activity: "Various"
Cans:
sources: ['Beverage Cans',
'Beer Cans',
'Soda Cans',
'Metal Beverage Cans']
material: 'Metal'
activity: "Eating/Drinking"
Car Parts:
activity: 'Dumping/Disaster'
Cigar Tips:
activity: 'Smoking'
Cigarette Butts:
material: 'Plastic'
activity: 'Smoking'
Clothes:
sources: ['Clothes, Cloth', 'Clothes Or Towels']
activity: 'Recreation'
Construction Materials:
sources: []
activity: 'Dumping/Disaster'
E-Waste:
sources: ['Vape Items/ E-Smoking Devices',
'E-Cigarettes']
material: 'Mixed'
activity: 'Smoking'
Fireworks:
sources: ['Fireworkds']
activity: 'Recreation'
Fishing Gear:
sources: ['Fishing Gear (Lures, Nets, Etc.)',
'Fishing Lines, Nets, Traps, Ropes, Pots',
Expand All @@ -111,6 +141,7 @@ Fishing Gear:
'Fishing Pole',
'Fishing Line']
material: 'Mixed'
activity: 'Fishing'
Food Containers:
sources: ['Food Containers, Cups, Plates, Bowls',
'Food Containers (Plastic)',
Expand All @@ -135,30 +166,38 @@ Food Containers:
'Plastic Cups, Lids, Plates, Utensils',
'Styrofoam Cups, Plates And Bowls New']
material: 'Mixed'
activity: 'Eating/Drinking'
Food Wrappers:
sources: ['Plastic Food Wrappers',
'Food Wrappers',
'Food Wrapper',
'Plastic Food Wrappers (Ie Chips Or Candy)']
material: 'Plastic'
activity: 'Eating/Drinking'
Footwear:
sources: ['Footwear (Shoes/Slippers)', 'Shoes']
activity: 'Recreation'
Glass Bottles:
sources: ['Beverage Bottles (Glass)']
material: 'Glass'
activity: 'Eating/Drinking'
Glass Pieces:
sources: ['Glass Pieces And Chunks', 'Pieces And Chunks']
material: 'Glass'
activity: 'Various'
Lighters:
sources: ['Cigarette Lighters',
'Disposable Lighters',
'Disposable Cigarette Lighters']
material: 'Mixed'
activity: 'Smoking'
Nails:
sources: ['Metal Nails']
material: 'Metal'
activity: 'Dumping/Disaster'
Paper Pieces:
material: 'Wood'
activity: 'Various'
Paper/Cardboard:
sources: ['Cardboard',
'Paper Cardboard',
Expand All @@ -167,6 +206,7 @@ Paper/Cardboard:
'Paper Newpapers/ Magazines',
'Newspapers/Magazines']
material: 'Wood'
activity: 'Various'
Personal Hygiene:
sources: ['Condoms',
'Diapers',
Expand All @@ -177,6 +217,7 @@ Personal Hygiene:
'Wipes',
'Feminine Hygeine Products']
material: 'Mixed'
activity: 'Hygiene'
Plastic Bags:
sources: ['Shopping Bags',
'Other Plastic Bags',
Expand All @@ -187,28 +228,33 @@ Plastic Bags:
'Grocery Bags (Plastic)',
'Plastic Bags (Trash) New']
material: 'Plastic'
activity: 'Eating/Drinking'
Plastic Bottles:
sources: ['Other Plastic Bottles (Oil, Bleach, Etc.)',
'Plastic Motor Oil Bottles',
'Other Plastic Bottles',
'Beverage Bottles (Plastic)']
material: 'Plastic'
activity: 'Various'
Lids:
sources: ['Lids (Plastic)', 'Plastic Lids']
material: 'Plastic'
activity: 'Various'
Packaging:
sources: ['Foam Packaging',
'Other Plastic/ Foam Packaging',
'Other Plastic/Foam Packaging',
'Other Packaging (Clean Swell)',
'Styrofoam Peanuts Or Packing Materials']
material: 'Plastic'
activity: 'Various'
Plastic Pieces:
sources: ['Polystyrene Pieces',
'Foam Dock Pieces',
'Styrofoam Pieces',
'Foam Pieces']
material: 'Plastic'
activity: 'Various'
To-Go Items:
sources: ['Plastic To-Go Items',
'Plastic Polystyrene Food "To-Go" Containers',
Expand All @@ -217,39 +263,50 @@ To-Go Items:
'Take Out/Away (Plastic',
'Take Out/Away (Foam)']
material: 'Plastic'
activity: 'Eating/Drinking'
PPE:
sources: ['Personal Protective Equipment (Masks, Gloves)',
'Personal Protective Equipment']
material: 'Mixed'
activity: 'Hygiene'
Rope:
sources: ['Rope (Yard Pieces)', 'Rope', 'Rope (1 Yard/Meter = 1 Piece)']
activity: 'Various'
Strapping Bands:
activity: 'Various'
Straws:
sources: ['Straws/Stirrers',
'Straws And Stirrers',
'Plastic Straws Or Stirrers']
material: 'Plastic'
activity: 'Eating/Drinking'
Syringes:
sources: ['Syringes/Needles', 'Syringes Or Needles', 'Syringes']
material: 'Metal'
activity: 'Hygiene'
Tires:
activity: 'Dumping/Disaster'
Tobacco:
sources: ['Smoking, Tobacco (Not E-Waste Or Butts)',
'Tobacco Packaging/Wrap',
'Smoking, Tobacco, Vape Items (Not Butts)',
'Cigarette Box Or Wrappers',
'Other Tobacco (Packaging, Lighter, Etc.)']
activity: 'Smoking'
Utensils:
sources: ['Utensils (Plastic)', 'Forks, Knives, Spoons']
material: 'Plastic'
activity: 'Eating/Drinking'
Wood Pieces:
sources: ['Wood Pallets, Pieces And Processed Wood',
'Wood Pieces',
'Pallets Or Wood']
material: 'Wood'
activity: 'Dumping/Disaster'
6-Pack Holders:
sources: ['Plastic Six-Pack Rings', '6Ppack Holders']
material: 'Plastic'
activity: 'Eating/Drinking'



47 changes: 42 additions & 5 deletions graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,40 @@ def map_graph(df, map_bounds=None, w=None, h=None, single_color=True):
return fig


def activity_graph(df, col_config):
col_sum = df.copy()
# Drop non-activity columns
nonitem_cols = list(col_config.loc[col_config['activity'].isnull()]['name'])
# Sum total items
col_sum.drop(nonitem_cols, axis=1, inplace=True)
col_sum = col_sum.sum(axis=0, numeric_only=True)
col_sum = col_sum.sort_values(ascending=False)
# Add activity to dataframe
col_sum = col_sum.to_frame(name='count')
col_sum.insert(0, 'name', col_sum.index)
col_sum.reset_index(drop=True, inplace=True)
col_sum = pd.merge(col_sum, col_config, how='left', on="name")
# Bar plot
fig = px.bar(col_sum, x='activity', y='count', color='name', text="name")
fig.update_layout(
autosize=False,
width=1000,
height=700,
title="Total Number of Items Collected By Activity, 2013-23",
yaxis_title='Total Number of Items',
xaxis_title='Activity',
legend_title='Item Category',
xaxis={'categoryorder': 'total descending'},
)
fig.update_traces(
textfont_size=10,
textangle=0,
textposition="inside",
cliponaxis=False,
)
return fig


def make_and_save_graphs(sos_data, data_dir, ext='.png'):
"""
Manipulate the data frame to extract features, plot graphs, and write
Expand All @@ -244,12 +278,12 @@ def make_and_save_graphs(sos_data, data_dir, ext='.png'):
:param pd.DataFrame sos_data: SOS data collected over the years.
:param str data_dir: Data directory
:param st ext: Graph file extention (default: '.png')
:param str ext: Graph file extention (default: '.png')
"""
# Creates subdirectory for graphs
image_dir = os.path.join(data_dir, "Graphs")
os.makedirs(image_dir, exist_ok=True)
# Read config for columns (created when running cleanup main
# Read config for columns (created when running cleanup main)
col_config = pd.read_csv(os.path.join(data_dir, 'sos_column_info.csv'))
# find column names that do not correspond to items (material is nan)
nonitem_cols = list(col_config.loc[col_config['material'].isnull()]['name'])
Expand All @@ -261,13 +295,13 @@ def make_and_save_graphs(sos_data, data_dir, ext='.png'):

# Create bar graph for years 2013-23
# Add Total Volunteers and Total Items to col config
col_config.loc[len(col_config.index)] = ['Total Volunteers', ['Adult + 0.5*Youth'], 'float', False, np.NaN]
col_config.loc[len(col_config.index)] = ['Total Items', ['Sum of items per event'], 'int', False, np.NaN]
col_config.loc[len(col_config.index)] = ['Total Volunteers', ['Adult + 0.5*Youth'], 'float', False, np.NaN, np.NaN]
col_config.loc[len(col_config.index)] = ['Total Items', ['Sum of items per event'], 'int', False, np.NaN, np.NaN]
# ...and to dataframe
sos_data['Total Volunteers'] = sos_data['Adult Volunteers'].fillna(0) + 0.5 * sos_data['Youth Volunteers'].fillna(0)
items = sos_data.copy()
items.drop(nonitem_cols, axis=1, inplace=True)
sos_data['Total Items'] = items.sum(axis=1, numeric_only=True)
sos_data['Total Volunteers'] = sos_data['Adult Volunteers'].fillna(0) + 0.5 * sos_data['Youth Volunteers'].fillna(0)
# Group by year
annual_data = cleanup.group_by_year(sos_data, col_config)
# Sort items by sum in descending order so it's easier to decipher variables
Expand Down Expand Up @@ -411,6 +445,9 @@ def make_and_save_graphs(sos_data, data_dir, ext='.png'):
)
fig.write_image(os.path.join(image_dir, "Line_graph_smoking_per_volunteers_2013-23" + ext))

# Debris by activity
fig = activity_graph(sos_data, col_config)
fig.write_image(os.path.join(image_dir, "Debris_by_activity_2013-23" + ext))

if __name__ == '__main__':
args = cleanup.parse_args()
Expand Down

0 comments on commit 092c21f

Please sign in to comment.