Ziyuan111 commited on
Commit
e838a26
1 Parent(s): 8556559

Delete durhamtrees.py

Browse files
Files changed (1) hide show
  1. durhamtrees.py +0 -179
durhamtrees.py DELETED
@@ -1,179 +0,0 @@
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/1W5gDhKokcuqoA8AK4a6JR7PIeCUdmrTU
8
- """
9
-
10
- !pip install datasets
11
- import datasets
12
- import pandas as pd
13
- import geopandas as gpd
14
- from datasets import DatasetBuilder, DownloadManager, DatasetInfo, SplitGenerator, Split
15
- from datasets.features import Features, Value, ClassLabel
16
- import matplotlib.pyplot as plt
17
- import csv
18
- import json
19
- import os
20
- from typing import List
21
-
22
-
23
- _URLS = {
24
- "first_domain": {
25
- "csv_file": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy",
26
- "geojson_file": "https://drive.google.com/uc?export=download&id=1jpFVanNGy7L5tVO-Z_nltbBXKvrcAoDo",
27
- },
28
- # Add other domains if necessary
29
- }
30
-
31
- columns_to_extract = [ "geometry", # Geometry feature, usually spatial data (GeoJSON format)
32
- "OBJECTID", # Unique identifier for each record
33
- "streetaddress", # Street address of the tree planting site
34
- "city", # City where the tree planting site is located
35
- "zipcode", # Zip code of the tree planting site (changed to string)
36
- "facilityid", # Identifier for the facility
37
- "present", # Presence status, assumed to be string
38
- "genus", # Genus of the tree
39
- "species", # Species of the tree
40
- "commonname", # Common name of the tree
41
- "diameterin", # Diameter in inches
42
- "heightft", # Height in feet (changed to "float64")
43
- "condition", # Condition of the tree
44
- "contractwork", # Contract work information
45
- "neighborhood", # Neighborhood where the tree is located
46
- "program", # Program under which the tree was planted
47
- "plantingw", # Width available for planting
48
- "plantingcond", # Planting condition
49
- "underpwerlins", # Whether the tree is under power lines
50
- "GlobalID", # Global identifier
51
- "created_user", # User who created the record
52
- "last_edited_user", # User who last edited the record
53
- "isoprene", # Isoprene emission rate
54
- "monoterpene",
55
- "coremoved_ozperyr", # Carbon monoxide removed, in ounces per year
56
- "coremoved_dolperyr", # Monetary value of carbon monoxide removal per year
57
- "o3removed_ozperyr", # Ozone removed, in ounces per year
58
- "o3removed_dolperyr", # Monetary value of ozone removal per year
59
- "no2removed_ozperyr", # Nitrogen dioxide removed, in ounces per year
60
- "no2removed_dolperyr", # Monetary value of nitrogen dioxide removal per year
61
- "so2removed_ozperyr", # Sulfur dioxide removed, in ounces per year
62
- "so2removed_dolperyr", # Monetary value of sulfur dioxide removal per year
63
- "pm10removed_ozperyr", # Particulate matter (10 micrometers or less) removed, in ounces per year
64
- "pm10removed_dolperyr", # Monetary value of particulate matter removal per year
65
- "pm25removed_ozperyr", # Particulate matter (2.5 micrometers or less) removed, in ounces per year
66
- "o2production_lbperyr", # Oxygen production, in pounds per year
67
- "replacevalue_dol", # Replacement value in dollars
68
- "carbonstorage_lb", # Carbon storage, in pounds
69
- "carbonstorage_dol", # Monetary value of carbon storage
70
- "grosscarseq_lbperyr", # Gross carbon sequestration, in pounds per year
71
- "X", # X coordinate (longitude if geographic)
72
- "Y"]
73
-
74
-
75
- class DurhamTrees(datasets.GeneratorBasedBuilder):
76
- # ... [other parts of the script] ...
77
- VERSION = datasets.Version("1.0.0")
78
- def _info(self):
79
- # Specifies the dataset's features
80
- return DatasetInfo(
81
- description="This dataset contains information about tree planting sites from CSV and GeoJSON files.",
82
- features=Features({
83
- "geometry": Value("string"), # Geometry feature, usually spatial data (GeoJSON format)
84
- "OBJECTID": Value("int64"), # Unique identifier for each record
85
- "streetaddress": Value("string"), # Street address of the tree planting site
86
- "city": Value("string"), # City where the tree planting site is located
87
- "zipcode": Value("int64"), # Zip code of the tree planting site
88
- "facilityid": Value("int64"), # Identifier for the facility
89
- "present": Value("string"), # Presence status, assumed to be string
90
- "genus": Value("string"), # Genus of the tree
91
- "species": Value("string"), # Species of the tree
92
- "commonname": Value("string"), # Common name of the tree
93
- "diameterin": Value("float64"), # Diameter in inches
94
- "heightft": Value("float64"), # Height in feet (changed to "float64")
95
- "condition": Value("string"), # Condition of the tree
96
- "contractwork": Value("string"), # Contract work information
97
- "neighborhood": Value("string"), # Neighborhood where the tree is located
98
- "program": Value("string"), # Program under which the tree was planted
99
- "plantingw": Value("string"), # Width available for planting
100
- "plantingcond": Value("string"), # Planting condition
101
- "underpwerlins": Value("string"), # Whether the tree is under power lines
102
- "GlobalID": Value("string"), # Global identifier
103
- "created_user": Value("string"), # User who created the record
104
- "last_edited_user": Value("string"), # User who last edited the record
105
- "isoprene": Value("float64"), # Isoprene emission rate
106
- "monoterpene": Value("float64"),
107
- "coremoved_ozperyr": Value("float64"), # Carbon monoxide removed, in ounces per year
108
- "coremoved_dolperyr": Value("float64"), # Monetary value of carbon monoxide removal per year
109
- "o3removed_ozperyr": Value("float64"), # Ozone removed, in ounces per year
110
- "o3removed_dolperyr": Value("float64"), # Monetary value of ozone removal per year
111
- "no2removed_ozperyr": Value("float64"), # Nitrogen dioxide removed, in ounces per year
112
- "no2removed_dolperyr": Value("float64"), # Monetary value of nitrogen dioxide removal per year
113
- "so2removed_ozperyr": Value("float64"), # Sulfur dioxide removed, in ounces per year
114
- "so2removed_dolperyr": Value("float64"), # Monetary value of sulfur dioxide removal per year
115
- "pm10removed_ozperyr": Value("float64"), # Particulate matter (10 micrometers or less) removed, in ounces per year
116
- "pm10removed_dolperyr": Value("float64"), # Monetary value of particulate matter removal per year
117
- "pm25removed_ozperyr": Value("float64"), # Particulate matter (2.5 micrometers or less) removed, in ounces per year
118
- "o2production_lbperyr": Value("float64"), # Oxygen production, in pounds per year
119
- "replacevalue_dol": Value("float64"), # Replacement value in dollars
120
- "carbonstorage_lb": Value("float64"), # Carbon storage, in pounds
121
- "carbonstorage_dol": Value("float64"), # Monetary value of carbon storage
122
- "grosscarseq_lbperyr": Value("float64"), # Gross carbon sequestration, in pounds per year
123
- "X": Value("float64"), # X coordinate (longitude if geographic)
124
- "Y": Value("float64"), # Y coordinate (latitude if geographic)
125
- }),
126
- supervised_keys=None,
127
- homepage="https://github.com/AuraMa111?tab=repositories",
128
- citation="Citation for the dataset",
129
- )
130
-
131
- def _split_generators(self, dl_manager):
132
- downloaded_files = dl_manager.download_and_extract(_URLS[self.config.name])
133
-
134
- return [
135
- datasets.SplitGenerator(
136
- name=datasets.Split.TRAIN,
137
- gen_kwargs={
138
- "csv_filepath": downloaded_files["first_domain"]["csv_file"],
139
- "geojson_filepath": downloaded_files["first_domain"]["geojson_file"],
140
- "split": "train",
141
- },
142
- ),
143
- # Add additional split generators if available
144
- ]
145
-
146
- def _generate_examples(self, csv_filepath, geojson_filepath, split):
147
- # Load the CSV data into a pandas DataFrame
148
- csv_data = pd.read_csv(csv_filepath)
149
-
150
- # Load the GeoJSON data into a GeoDataFrame
151
- geojson_data = gpd.read_file(geojson_filepath)
152
-
153
- # Merge the CSV data with the GeoJSON data on the 'OBJECTID' field
154
- merged_data = geojson_data.merge(csv_data, on='OBJECTID')
155
-
156
- # Convert the merged GeoDataFrame back into a dictionary to yield examples
157
- merged_dict = json.loads(merged_data.to_json())
158
- final_data = merged_data[columns_to_extract]
159
-
160
- # Iterate over the rows of the final DataFrame and yield each row as an example
161
- for id_, row in final_data.iterrows():
162
- # Convert the row to a dictionary
163
- example = row.to_dict()
164
-
165
- # Correct data types for 'zipcode' and 'heightft' if necessary
166
- example['zipcode'] = str(example['zipcode'])
167
- example['heightft'] = float(example['heightft'])
168
-
169
- # Yield the example
170
- yield id_, example
171
- # Iterate over the features and yield each one as an example
172
- for id_, feature in enumerate(merged_dict['features']):
173
- properties = feature['properties']
174
-
175
- # You might need additional processing here if you want to include the geometry
176
- # or if the properties need further manipulation to fit the datasets.Features structure
177
-
178
- yield id_, properties
179
-