|
|
|
"""DurhamTrees |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1Hvt3Y131OjTl7oGQGS55S_v7-aYu1Yj8 |
|
""" |
|
|
|
from datasets import DatasetBuilder, DownloadManager, DatasetInfo, SplitGenerator, Split |
|
from datasets.features import Features, Value, ClassLabel |
|
import pandas as pd |
|
import geopandas as gpd |
|
import matplotlib.pyplot as plt |
|
import csv |
|
import json |
|
import os |
|
from typing import List |
|
import datasets |
|
|
|
|
|
class DurhamTrees(DatasetBuilder): |
|
_URLS = { |
|
"csv": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy", |
|
"geojson": "https://drive.google.com/uc?export=download&id=1jpFVanNGy7L5tVO-Z_nltbBXKvrcAoDo" |
|
} |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
def _info(self): |
|
|
|
return DatasetInfo( |
|
description="This dataset contains information about tree planting sites from CSV and GeoJSON files.", |
|
features=Features({ |
|
"geometry": Value("string"), |
|
"OBJECTID": Value("int64"), |
|
"streetaddress": Value("string"), |
|
"city": Value("string"), |
|
"zipcode": Value("int64"), |
|
"facilityid": Value("int64"), |
|
"present": Value("string"), |
|
"genus": Value("string"), |
|
"species": Value("string"), |
|
"commonname": Value("string"), |
|
"diameterin": Value("float64"), |
|
"heightft": Value("float64"), |
|
"condition": Value("string"), |
|
"contractwork": Value("string"), |
|
"neighborhood": Value("string"), |
|
"program": Value("string"), |
|
"plantingw": Value("string"), |
|
"plantingcond": Value("string"), |
|
"underpwerlins": Value("string"), |
|
"GlobalID": Value("string"), |
|
"created_user": Value("string"), |
|
"last_edited_user": Value("string"), |
|
"isoprene": Value("float64"), |
|
"monoterpene": Value("float64"), |
|
"coremoved_ozperyr": Value("float64"), |
|
"coremoved_dolperyr": Value("float64"), |
|
"o3removed_ozperyr": Value("float64"), |
|
"o3removed_dolperyr": Value("float64"), |
|
"no2removed_ozperyr": Value("float64"), |
|
"no2removed_dolperyr": Value("float64"), |
|
"so2removed_ozperyr": Value("float64"), |
|
"so2removed_dolperyr": Value("float64"), |
|
"pm10removed_ozperyr": Value("float64"), |
|
"pm10removed_dolperyr": Value("float64"), |
|
"pm25removed_ozperyr": Value("float64"), |
|
"o2production_lbperyr": Value("float64"), |
|
"replacevalue_dol": Value("float64"), |
|
"carbonstorage_lb": Value("float64"), |
|
"carbonstorage_dol": Value("float64"), |
|
"grosscarseq_lbperyr": Value("float64"), |
|
"X": Value("float64"), |
|
"Y": Value("float64"), |
|
}), |
|
supervised_keys=None, |
|
homepage="https://github.com/AuraMa111?tab=repositories", |
|
citation="Citation for the dataset", |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
|
|
urls_to_download = self._URLS |
|
|
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=Split.TRAIN, gen_kwargs={ |
|
"csv_path": downloaded_files["csv"], |
|
"geojson_path": downloaded_files["geojson"] |
|
}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"geojson_path": downloaded_files["geojson"]}), |
|
] |
|
|
|
def _generate_examples(self, csv_path, geojson_path): |
|
|
|
|
|
|
|
csv_data = pd.read_csv(csv_path) |
|
|
|
|
|
geojson_data = gpd.read_file(geojson_path) |
|
|
|
|
|
merged_data = geojson_data.merge(csv_data, on='OBJECTID') |
|
|
|
|
|
merged_data.drop(columns=[col for col in merged_data if col.endswith('_y')], inplace=True) |
|
|
|
|
|
merged_data.rename(columns=lambda x: x.rstrip('_x'), inplace=True) |
|
|
|
|
|
columns_to_extract = [ "geometry", |
|
"OBJECTID", |
|
"streetaddress", |
|
"city", |
|
"zipcode", |
|
"facilityid", |
|
"present", |
|
"genus", |
|
"species", |
|
"commonname", |
|
"diameterin", |
|
"heightft", |
|
"condition", |
|
"contractwork", |
|
"neighborhood", |
|
"program", |
|
"plantingw", |
|
"plantingcond", |
|
"underpwerlins", |
|
"GlobalID", |
|
"created_user", |
|
"last_edited_user", |
|
"isoprene", |
|
"monoterpene", |
|
"coremoved_ozperyr", |
|
"coremoved_dolperyr", |
|
"o3removed_ozperyr", |
|
"o3removed_dolperyr", |
|
"no2removed_ozperyr", |
|
"no2removed_dolperyr", |
|
"so2removed_ozperyr", |
|
"so2removed_dolperyr", |
|
"pm10removed_ozperyr", |
|
"pm10removed_dolperyr", |
|
"pm25removed_ozperyr", |
|
"o2production_lbperyr", |
|
"replacevalue_dol", |
|
"carbonstorage_lb", |
|
"carbonstorage_dol", |
|
"grosscarseq_lbperyr", |
|
"X", |
|
"Y"] |
|
|
|
|
|
df = merged_data[columns_to_extract] |
|
|
|
|
|
for index, row in df.iterrows(): |
|
|
|
yield index, row.to_dict() |
|
|
|
|