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

Delete durhamtreesplantingsitesdataset.py

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