Datasets:
Upload durhamtrees.py
Browse files- durhamtrees.py +165 -0
durhamtrees.py
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""DurhamTrees
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1Hvt3Y131OjTl7oGQGS55S_v7-aYu1Yj8
|
8 |
+
"""
|
9 |
+
|
10 |
+
from datasets import DatasetBuilder, DownloadManager, DatasetInfo, SplitGenerator, Split
|
11 |
+
from datasets.features import Features, Value, ClassLabel
|
12 |
+
import pandas as pd
|
13 |
+
import geopandas as gpd
|
14 |
+
import matplotlib.pyplot as plt
|
15 |
+
import csv
|
16 |
+
import json
|
17 |
+
import os
|
18 |
+
from typing import List
|
19 |
+
import datasets
|
20 |
+
|
21 |
+
|
22 |
+
class DurhamTrees(DatasetBuilder):
|
23 |
+
_URLS = {
|
24 |
+
"csv": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy",
|
25 |
+
"geojson": "https://drive.google.com/uc?export=download&id=1jpFVanNGy7L5tVO-Z_nltbBXKvrcAoDo"
|
26 |
+
}
|
27 |
+
|
28 |
+
VERSION = datasets.Version("1.0.0")
|
29 |
+
def _info(self):
|
30 |
+
# Specifies the dataset's features
|
31 |
+
return DatasetInfo(
|
32 |
+
description="This dataset contains information about tree planting sites from CSV and GeoJSON files.",
|
33 |
+
features=Features({
|
34 |
+
"geometry": Value("string"), # Geometry feature, usually spatial data (GeoJSON format)
|
35 |
+
"OBJECTID": Value("int64"), # Unique identifier for each record
|
36 |
+
"streetaddress": Value("string"), # Street address of the tree planting site
|
37 |
+
"city": Value("string"), # City where the tree planting site is located
|
38 |
+
"zipcode": Value("int64"), # Zip code of the tree planting site
|
39 |
+
"facilityid": Value("int64"), # Identifier for the facility
|
40 |
+
"present": Value("string"), # Presence status, assumed to be string
|
41 |
+
"genus": Value("string"), # Genus of the tree
|
42 |
+
"species": Value("string"), # Species of the tree
|
43 |
+
"commonname": Value("string"), # Common name of the tree
|
44 |
+
"diameterin": Value("float64"), # Diameter in inches
|
45 |
+
"heightft": Value("float64"), # Height in feet (changed to "float64")
|
46 |
+
"condition": Value("string"), # Condition of the tree
|
47 |
+
"contractwork": Value("string"), # Contract work information
|
48 |
+
"neighborhood": Value("string"), # Neighborhood where the tree is located
|
49 |
+
"program": Value("string"), # Program under which the tree was planted
|
50 |
+
"plantingw": Value("string"), # Width available for planting
|
51 |
+
"plantingcond": Value("string"), # Planting condition
|
52 |
+
"underpwerlins": Value("string"), # Whether the tree is under power lines
|
53 |
+
"GlobalID": Value("string"), # Global identifier
|
54 |
+
"created_user": Value("string"), # User who created the record
|
55 |
+
"last_edited_user": Value("string"), # User who last edited the record
|
56 |
+
"isoprene": Value("float64"), # Isoprene emission rate
|
57 |
+
"monoterpene": Value("float64"),
|
58 |
+
"coremoved_ozperyr": Value("float64"), # Carbon monoxide removed, in ounces per year
|
59 |
+
"coremoved_dolperyr": Value("float64"), # Monetary value of carbon monoxide removal per year
|
60 |
+
"o3removed_ozperyr": Value("float64"), # Ozone removed, in ounces per year
|
61 |
+
"o3removed_dolperyr": Value("float64"), # Monetary value of ozone removal per year
|
62 |
+
"no2removed_ozperyr": Value("float64"), # Nitrogen dioxide removed, in ounces per year
|
63 |
+
"no2removed_dolperyr": Value("float64"), # Monetary value of nitrogen dioxide removal per year
|
64 |
+
"so2removed_ozperyr": Value("float64"), # Sulfur dioxide removed, in ounces per year
|
65 |
+
"so2removed_dolperyr": Value("float64"), # Monetary value of sulfur dioxide removal per year
|
66 |
+
"pm10removed_ozperyr": Value("float64"), # Particulate matter (10 micrometers or less) removed, in ounces per year
|
67 |
+
"pm10removed_dolperyr": Value("float64"), # Monetary value of particulate matter removal per year
|
68 |
+
"pm25removed_ozperyr": Value("float64"), # Particulate matter (2.5 micrometers or less) removed, in ounces per year
|
69 |
+
"o2production_lbperyr": Value("float64"), # Oxygen production, in pounds per year
|
70 |
+
"replacevalue_dol": Value("float64"), # Replacement value in dollars
|
71 |
+
"carbonstorage_lb": Value("float64"), # Carbon storage, in pounds
|
72 |
+
"carbonstorage_dol": Value("float64"), # Monetary value of carbon storage
|
73 |
+
"grosscarseq_lbperyr": Value("float64"), # Gross carbon sequestration, in pounds per year
|
74 |
+
"X": Value("float64"), # X coordinate (longitude if geographic)
|
75 |
+
"Y": Value("float64"), # Y coordinate (latitude if geographic)
|
76 |
+
}),
|
77 |
+
supervised_keys=None,
|
78 |
+
homepage="https://github.com/AuraMa111?tab=repositories",
|
79 |
+
citation="Citation for the dataset",
|
80 |
+
)
|
81 |
+
|
82 |
+
def _split_generators(self, dl_manager: DownloadManager):
|
83 |
+
|
84 |
+
urls_to_download = self._URLS # This should now work as _URLS is defined
|
85 |
+
|
86 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
87 |
+
|
88 |
+
return [
|
89 |
+
SplitGenerator(name=Split.TRAIN, gen_kwargs={
|
90 |
+
"csv_path": downloaded_files["csv"],
|
91 |
+
"geojson_path": downloaded_files["geojson"]
|
92 |
+
}),
|
93 |
+
# If you have additional splits, define them here
|
94 |
+
]
|
95 |
+
|
96 |
+
def _generate_examples(self, csv_path, geojson_path):
|
97 |
+
# Log the information about the CSV file being processed
|
98 |
+
|
99 |
+
# Load the CSV data into a pandas DataFrame
|
100 |
+
csv_data = pd.read_csv(csv_path)
|
101 |
+
|
102 |
+
# Load the GeoJSON data into a GeoDataFrame
|
103 |
+
geojson_data = gpd.read_file(geojson_path)
|
104 |
+
|
105 |
+
# Merge the CSV data with the GeoJSON data on the 'OBJECTID' column
|
106 |
+
merged_data = geojson_data.merge(csv_data, on='OBJECTID')
|
107 |
+
|
108 |
+
# Drop columns with suffix '_y' that might have been created during the merge
|
109 |
+
merged_data.drop(columns=[col for col in merged_data if col.endswith('_y')], inplace=True)
|
110 |
+
|
111 |
+
# Rename columns to remove suffix '_x'
|
112 |
+
merged_data.rename(columns=lambda x: x.rstrip('_x'), inplace=True)
|
113 |
+
|
114 |
+
# Select the desired columns
|
115 |
+
columns_to_extract = [ "geometry", # Geometry feature, usually spatial data (GeoJSON format)
|
116 |
+
"OBJECTID", # Unique identifier for each record
|
117 |
+
"streetaddress", # Street address of the tree planting site
|
118 |
+
"city", # City where the tree planting site is located
|
119 |
+
"zipcode", # Zip code of the tree planting site (changed to string)
|
120 |
+
"facilityid", # Identifier for the facility
|
121 |
+
"present", # Presence status, assumed to be string
|
122 |
+
"genus", # Genus of the tree
|
123 |
+
"species", # Species of the tree
|
124 |
+
"commonname", # Common name of the tree
|
125 |
+
"diameterin", # Diameter in inches
|
126 |
+
"heightft", # Height in feet (changed to "float64")
|
127 |
+
"condition", # Condition of the tree
|
128 |
+
"contractwork", # Contract work information
|
129 |
+
"neighborhood", # Neighborhood where the tree is located
|
130 |
+
"program", # Program under which the tree was planted
|
131 |
+
"plantingw", # Width available for planting
|
132 |
+
"plantingcond", # Planting condition
|
133 |
+
"underpwerlins", # Whether the tree is under power lines
|
134 |
+
"GlobalID", # Global identifier
|
135 |
+
"created_user", # User who created the record
|
136 |
+
"last_edited_user", # User who last edited the record
|
137 |
+
"isoprene", # Isoprene emission rate
|
138 |
+
"monoterpene",
|
139 |
+
"coremoved_ozperyr", # Carbon monoxide removed, in ounces per year
|
140 |
+
"coremoved_dolperyr", # Monetary value of carbon monoxide removal per year
|
141 |
+
"o3removed_ozperyr", # Ozone removed, in ounces per year
|
142 |
+
"o3removed_dolperyr", # Monetary value of ozone removal per year
|
143 |
+
"no2removed_ozperyr", # Nitrogen dioxide removed, in ounces per year
|
144 |
+
"no2removed_dolperyr", # Monetary value of nitrogen dioxide removal per year
|
145 |
+
"so2removed_ozperyr", # Sulfur dioxide removed, in ounces per year
|
146 |
+
"so2removed_dolperyr", # Monetary value of sulfur dioxide removal per year
|
147 |
+
"pm10removed_ozperyr", # Particulate matter (10 micrometers or less) removed, in ounces per year
|
148 |
+
"pm10removed_dolperyr", # Monetary value of particulate matter removal per year
|
149 |
+
"pm25removed_ozperyr", # Particulate matter (2.5 micrometers or less) removed, in ounces per year
|
150 |
+
"o2production_lbperyr", # Oxygen production, in pounds per year
|
151 |
+
"replacevalue_dol", # Replacement value in dollars
|
152 |
+
"carbonstorage_lb", # Carbon storage, in pounds
|
153 |
+
"carbonstorage_dol", # Monetary value of carbon storage
|
154 |
+
"grosscarseq_lbperyr", # Gross carbon sequestration, in pounds per year
|
155 |
+
"X", # X coordinate (longitude if geographic)
|
156 |
+
"Y"]
|
157 |
+
|
158 |
+
# Create the final DataFrame with the selected columns
|
159 |
+
df = merged_data[columns_to_extract]
|
160 |
+
|
161 |
+
# Iterate over each row in the DataFrame and yield it
|
162 |
+
for index, row in df.iterrows():
|
163 |
+
# Convert the row to a dictionary, it's more convenient for yielding
|
164 |
+
yield index, row.to_dict()
|
165 |
+
|