Ziyuan111 commited on
Commit
46e5b29
·
verified ·
1 Parent(s): 9be20d5

Upload durhamtreesplantingsitesdataset.py

Browse files
Files changed (1) hide show
  1. durhamtreesplantingsitesdataset.py +219 -0
durhamtreesplantingsitesdataset.py ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """durhamTreesPlantingSitesDataset
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
+ import logging
21
+
22
+
23
+ logging.basicConfig(level=logging.INFO)
24
+
25
+ class durhamTreesPlantingSitesDataset(DatasetBuilder):
26
+ VERSION = "1.0.0"
27
+ _URLS = {
28
+ "csv": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy",
29
+ "geojson": "https://drive.google.com/uc?export=download&id=1jpFVanNGy7L5tVO-Z_nltbBXKvrcAoDo"
30
+ }
31
+ def _info(self):
32
+ # Specifies the dataset's features
33
+ return DatasetInfo(
34
+ description="This dataset contains information about tree planting sites from CSV and GeoJSON files.",
35
+ features=Features({
36
+ "geometry": Value("string"), # Geometry feature, usually spatial data (GeoJSON format)
37
+ "OBJECTID": Value("int64"), # Unique identifier for each record
38
+ "streetaddress": Value("string"), # Street address of the tree planting site
39
+ "city": Value("string"), # City where the tree planting site is located
40
+ "zipcode": Value("float64"), # Zip code of the tree planting site (as float due to your data types)
41
+ "facilityid": Value("int64"), # Identifier for the facility
42
+ "present": Value("string"), # Presence status, assumed to be string
43
+ "genus": Value("string"), # Genus of the tree
44
+ "species": Value("string"), # Species of the tree
45
+ "commonname": Value("string"), # Common name of the tree
46
+ "plantingdate": Value("string"), # Planting date of the tree (consider converting to "datetime" for actual dates)
47
+ "diameterin": Value("float64"), # Diameter in inches
48
+ "heightft": Value("string"), # Height in feet (as a string, consider "float64" for numerical values)
49
+ "condition": Value("string"), # Condition of the tree
50
+ "contractwork": Value("string"), # Contract work information
51
+ "neighborhood": Value("string"), # Neighborhood where the tree is located
52
+ "program": Value("string"), # Program under which the tree was planted
53
+ "plantingw": Value("string"), # Width available for planting
54
+ "plantingcond": Value("string"), # Planting condition
55
+ "underpwerlins": Value("string"), # Whether the tree is under power lines
56
+ "GlobalID": Value("string"), # Global identifier
57
+ "created_user": Value("string"), # User who created the record
58
+ "created_date": Value("string"), # Date when the record was created
59
+ "last_edited_user": Value("string"), # User who last edited the record
60
+ "last_edited_date": Value("string"), # Date when the record was last edited
61
+ "isoprene": Value("float64"), # Isoprene emission rate
62
+ "monoterpene": Value("float64"), # Monoterpene emission rate
63
+ "vocs": Value("float64"), # Volatile Organic Compounds removed or emitted
64
+ "coremoved_ozperyr": Value("float64"), # Carbon monoxide removed, in ounces per year
65
+ "coremoved_dolperyr": Value("float64"), # Monetary value of carbon monoxide removal per year
66
+ "o3removed_ozperyr": Value("float64"), # Ozone removed, in ounces per year
67
+ "o3removed_dolperyr": Value("float64"), # Monetary value of ozone removal per year
68
+ "no2removed_ozperyr": Value("float64"), # Nitrogen dioxide removed, in ounces per year
69
+ "no2removed_dolperyr": Value("float64"), # Monetary value of nitrogen dioxide removal per year
70
+ "so2removed_ozperyr": Value("float64"), # Sulfur dioxide removed, in ounces per year
71
+ "so2removed_dolperyr": Value("float64"), # Monetary value of sulfur dioxide removal per year
72
+ "pm10removed_ozperyr": Value("float64"), # Particulate matter (10 micrometers or less) removed, in ounces per year
73
+ "pm10removed_dolperyr": Value("float64"), # Monetary value of particulate matter removal per year
74
+ "pm25removed_ozperyr": Value("float64"), # Particulate matter (2.5 micrometers or less) removed, in ounces per year
75
+ "o2production_lbperyr": Value("float64"), # Oxygen production, in pounds per year
76
+ "replacevalue_dol": Value("float64"), # Replacement value in dollars
77
+ "carbonstorage_lb": Value("float64"), # Carbon storage, in pounds
78
+ "carbonstorage_dol": Value("float64"), # Monetary value of carbon storage
79
+ "grosscarseq_lbperyr": Value("float64"), # Gross carbon sequestration, in pounds per year
80
+ "grosscarseq_dolperyr": Value("float64"), # Monetary value of gross carbon sequestration per year
81
+ "avoidrunoff_ft2peryr": Value("float64"), # Avoided runoff, in square feet per year
82
+ "avoidrunoff_dol2peryr": Value("float64"), # Monetary value of avoided runoff per year
83
+ "polremoved_ozperyr": Value("float64"), # Pollutants removed, in ounces per year
84
+ "polremoved_dolperyr": Value("float64"), # Monetary value of pollutant removal per year
85
+ "totannbenefits_dolperyr": Value("float64"), # Total annual benefits in dollars per year
86
+ "leafarea_sqft": Value("float64"), # Leaf area in square feet
87
+ "potevapotran_cuftperyr": Value("float64"), # Potential evapotranspiration, in cubic feet per year
88
+ "evaporation_cuftperyr": Value("float64"), # Evaporation, in cubic feet per year
89
+ "transpiration_cuftperyr": Value("float64"), # Transpiration, in cubic feet per year
90
+ "h2ointercept_cuftperyr": Value("float64"), # Water interception, in cubic feet per year
91
+ "avoidrunval_cuftperyr": Value("float64"), # Avoided runoff volume, in cubic feet per year
92
+ "avoidrunval_dol2peryr": Value("float64"), # Monetary value of avoided runoff volume per year
93
+ "carbonavoid_lbperyr": Value("float64"), # Avoided carbon emissions, in pounds per year
94
+ "carbonavoid_dolperyr": Value("float64"), # Monetary value of avoided carbon emissions per year
95
+ "heating_mbtuperyr": Value("float64"), # Heating energy saved, in MBTU per year
96
+ "heating_dolperyrmbtu": Value("float64"), # Monetary value of heating energy saved per MBTU per year
97
+ "heating_kwhperyr": Value("float64"), # Heating energy saved, in kWh per year
98
+ "heating_dolperyrmwh": Value("float64"), # Monetary value of heating energy saved per kWh per year
99
+ "cooling_kwhperyr": Value("float64"),
100
+ "X": Value("float64"), # X coordinate (longitude if geographic)
101
+ "Y": Value("float64"), # Y coordinate (latitude if geographic)
102
+ }),
103
+ supervised_keys=None,
104
+ homepage="https://github.com/AuraMa111?tab=repositories",
105
+ citation="Citation for the dataset",
106
+ )
107
+
108
+ def _split_generators(self, dl_manager: DownloadManager):
109
+ # Downloads the data and defines the splits
110
+ urls_to_download = self._URLS
111
+
112
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
113
+
114
+ return [
115
+ SplitGenerator(name=Split.TRAIN, gen_kwargs={
116
+ "csv_path": downloaded_files["csv"],
117
+ "geojson_path": downloaded_files["geojson"]
118
+ }),
119
+ # If you have additional splits, define them here
120
+ ]
121
+
122
+ def _generate_examples(self, csv_path, geojson_path):
123
+ # Log the information about the CSV file being processed
124
+ logging.info("Generating examples from CSV = %s", csv_path)
125
+
126
+ # Load the CSV data into a pandas DataFrame
127
+ csv_data = pd.read_csv(csv_path)
128
+
129
+ # Log the information about the GeoJSON file being processed
130
+ logging.info("Generating examples from GeoJSON = %s", geojson_path)
131
+
132
+ # Load the GeoJSON data into a GeoDataFrame
133
+ geojson_data = gpd.read_file(geojson_path)
134
+
135
+ # Merge the CSV data with the GeoJSON data on the 'OBJECTID' column
136
+ merged_data = geojson_data.merge(csv_data, on='OBJECTID')
137
+
138
+ # Drop columns with suffix '_y' that might have been created during the merge
139
+ merged_data.drop(columns=[col for col in merged_data if col.endswith('_y')], inplace=True)
140
+
141
+ # Rename columns to remove suffix '_x'
142
+ merged_data.rename(columns=lambda x: x.rstrip('_x'), inplace=True)
143
+
144
+ # Select the desired columns
145
+ columns_to_extract = [ "geometry", # Geometry feature, usually spatial data (GeoJSON format)
146
+ "OBJECTID", # Unique identifier for each record
147
+ "streetaddress", # Street address of the tree planting site
148
+ "city", # City where the tree planting site is located
149
+ "zipcode", # Zip code of the tree planting site (as float due to your data types)
150
+ "facilityid", # Identifier for the facility
151
+ "present", # Presence status, assumed to be string
152
+ "genus", # Genus of the tree
153
+ "species", # Species of the tree
154
+ "commonname", # Common name of the tree
155
+ "plantingdate", # Planting date of the tree (consider converting to "datetime" for actual dates)
156
+ "diameterin", # Diameter in inches
157
+ "heightft", # Height in feet (as a string, consider "float64" for numerical values)
158
+ "condition", # Condition of the tree
159
+ "contractwork", # Contract work information
160
+ "neighborhood", # Neighborhood where the tree is located
161
+ "program", # Program under which the tree was planted
162
+ "plantingw", # Width available for planting
163
+ "plantingcond", # Planting condition
164
+ "underpwerlins", # Whether the tree is under power lines
165
+ "GlobalID", # Global identifier
166
+ "created_user", # User who created the record
167
+ "created_date", # Date when the record was created
168
+ "last_edited_user", # User who last edited the record
169
+ "last_edited_date", # Date when the record was last edited
170
+ "isoprene", # Isoprene emission rate
171
+ "monoterpene", # Monoterpene emission rate
172
+ "vocs", # Volatile Organic Compounds removed or emitted
173
+ "coremoved_ozperyr", # Carbon monoxide removed, in ounces per year
174
+ "coremoved_dolperyr", # Monetary value of carbon monoxide removal per year
175
+ "o3removed_ozperyr", # Ozone removed, in ounces per year
176
+ "o3removed_dolperyr", # Monetary value of ozone removal per year
177
+ "no2removed_ozperyr", # Nitrogen dioxide removed, in ounces per year
178
+ "no2removed_dolperyr", # Monetary value of nitrogen dioxide removal per year
179
+ "so2removed_ozperyr", # Sulfur dioxide removed, in ounces per year
180
+ "so2removed_dolperyr", # Monetary value of sulfur dioxide removal per year
181
+ "pm10removed_ozperyr", # Particulate matter (10 micrometers or less) removed, in ounces per year
182
+ "pm10removed_dolperyr", # Monetary value of particulate matter removal per year
183
+ "pm25removed_ozperyr", # Particulate matter (2.5 micrometers or less) removed, in ounces per year
184
+ "o2production_lbperyr", # Oxygen production, in pounds per year
185
+ "replacevalue_dol", # Replacement value in dollars
186
+ "carbonstorage_lb", # Carbon storage, in pounds
187
+ "carbonstorage_dol", # Monetary value of carbon storage
188
+ "grosscarseq_lbperyr", # Gross carbon sequestration, in pounds per year
189
+ "grosscarseq_dolperyr", # Monetary value of gross carbon sequestration per year
190
+ "avoidrunoff_ft2peryr", # Avoided runoff, in square feet per year
191
+ "avoidrunoff_dol2peryr", # Monetary value of avoided runoff per year
192
+ "polremoved_ozperyr", # Pollutants removed, in ounces per year
193
+ "polremoved_dolperyr", # Monetary value of pollutant removal per year
194
+ "totannbenefits_dolperyr", # Total annual benefits in dollars per year
195
+ "leafarea_sqft", # Leaf area in square feet
196
+ "potevapotran_cuftperyr", # Potential evapotranspiration, in cubic feet per year
197
+ "evaporation_cuftperyr", # Evaporation, in cubic feet per year
198
+ "transpiration_cuftperyr", # Transpiration, in cubic feet per year
199
+ "h2ointercept_cuftperyr", # Water interception, in cubic feet per year
200
+ "avoidrunval_cuftperyr", # Avoided runoff volume, in cubic feet per year
201
+ "avoidrunval_dol2peryr", # Monetary value of avoided runoff volume per year
202
+ "carbonavoid_lbperyr", # Avoided carbon emissions, in pounds per year
203
+ "carbonavoid_dolperyr", # Monetary value of avoided carbon emissions per year
204
+ "heating_mbtuperyr", # Heating energy saved, in MBTU per year
205
+ "heating_dolperyrmbtu", # Monetary value of heating energy saved per MBTU per year
206
+ "heating_kwhperyr", # Heating energy saved, in kWh per year
207
+ "heating_dolperyrmwh", # Monetary value of heating energy saved per kWh per year
208
+ "cooling_kwhperyr",
209
+ "X", # X coordinate (longitude if geographic)
210
+ "Y"]
211
+
212
+ # Create the final DataFrame with the selected columns
213
+ df = merged_data[columns_to_extract]
214
+
215
+ # Iterate over each row in the DataFrame and yield it
216
+ for index, row in df.iterrows():
217
+ # Convert the row to a dictionary, it's more convenient for yielding
218
+ yield index, row.to_dict()
219
+