Ziyuan111 commited on
Commit
c9cdec5
·
verified ·
1 Parent(s): 474361f

Delete treesplantingsitesdataset.py

Browse files
Files changed (1) hide show
  1. treesplantingsitesdataset.py +0 -102
treesplantingsitesdataset.py DELETED
@@ -1,102 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """TreesPlantingSitesDataset
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
- !pip install datasets
11
- from datasets import DatasetBuilder, DownloadManager, DatasetInfo, SplitGenerator, Split
12
- from datasets.features import Features, Value, Sequence, ClassLabel
13
- import pandas as pd
14
- import geopandas as gpd
15
- import matplotlib.pyplot as plt
16
- from datasets import Features, Value, ClassLabel
17
-
18
- class TreesPlantingSitesDataset(DatasetBuilder):
19
- VERSION = "1.0.0"
20
-
21
- def _info(self):
22
- # Specifies the dataset's features
23
- return DatasetInfo(
24
- description="This dataset contains information about tree planting sites from CSV and GeoJSON files.",
25
- features=Features({
26
- "OBJECTID": Value("int32"), # Unique identifier for each record
27
- "streetaddress": Value("string"), # Street address of the tree planting site
28
- "city": Value("string"), # City where the tree planting site is located
29
- "zipcode": Value("int32"), # Zip code of the tree planting site
30
- "facilityid": Value("int32"), # Identifier for the facility
31
- "present": ClassLabel(names=["False", "True"]), # Indicates if the tree is present (assuming boolean represented as string)
32
- "neighborhood": Value("string"), # Neighborhood where the tree planting site is located
33
- "plantingwidth": Value("string"), # Width available for planting
34
- "plantingcondition": Value("string"), # Condition of the planting site
35
- "underpowerlines": ClassLabel(names=["False", "True"]), # Indicates if the site is under power lines
36
- "matureheight": Value("string"), # Expected mature height of the tree
37
- "GlobalID": Value("string"), # Global unique identifier
38
- "created_user": Value("string"), # User who created the record
39
- "created_date": Value("string"), # Date when the record was created
40
- "last_edited_user": Value("string"), # User who last edited the record
41
- "last_edited_date": Value("string"), # Date when the record was last edited
42
- "geometry": Value("string") # Geometry feature from GeoJSON
43
- }),
44
- supervised_keys=None, # Provide if the dataset is for supervised learning
45
- homepage="https://example.com/dataset-homepage", # Replace with the actual URL
46
- citation="Citation for the dataset",
47
- )
48
-
49
- def _split_generators(self, dl_manager: DownloadManager):
50
- # Downloads the data and defines the splits
51
- urls_to_download = {
52
- "csv": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy",
53
- "geojson": "https://drive.google.com/uc?export=download&id=1jpFVanNGy7L5tVO-Z_nltbBXKvrcAoDo"
54
- }
55
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
56
-
57
- return [
58
- SplitGenerator(name=Split.TRAIN, gen_kwargs={
59
- "csv_path": downloaded_files["csv"],
60
- "geojson_path": downloaded_files["geojson"]
61
- }),
62
- # If you have additional splits, add them here
63
- ]
64
-
65
- # ... (previous code)
66
-
67
- def _generate_examples(self, csv_path, geojson_path):
68
-
69
- # Load the data into DataFrame and GeoDataFrame
70
- csv_data = pd.read_csv(csv_path)
71
- geojson_data = gpd.read_file(geojson_path)
72
-
73
- # Merge the CSV data with the GeoJSON data on the 'OBJECTID' column
74
- gdf = geojson_data.merge(csv_data, on='OBJECTID')
75
- columns_to_extract = [
76
- "OBJECTID", "streetaddress", "city", "zipcode", "facilityid", "present",
77
- "neighborhood", "plantingwidth", "plantingcondition", "underpowerlines",
78
- "matureheight", "GlobalID", "created_user", "created_date",
79
- "last_edited_user", "last_edited_date", "geometry"
80
- ]
81
-
82
- # Extract the specified columns
83
- extracted_gdf = gdf[columns_to_extract]
84
- # Basic statistics: Count the number of planting sites
85
- number_of_planting_sites = gdf['present'].value_counts()
86
- print("Number of planting sites:", number_of_planting_sites)
87
-
88
- # Spatial analysis: Group by neighborhood to see the distribution of features
89
- neighborhood_analysis = gdf.groupby('neighborhood').size()
90
- print("Distribution by neighborhood:", neighborhood_analysis)
91
-
92
- # Visual analysis: Plot the points on a map
93
- gdf.plot(marker='*', color='green', markersize=5)
94
- plt.title('TreesPlantingSitesDataset')
95
- for id_, row in gdf.iterrows():
96
- yield id_, {
97
- "OBJECTID": row["OBJECTID"],
98
- "neighborhood": row["neighborhood"], # Assuming 'neighborhood' is a column name in your data
99
- "present": row["present"], # Assuming 'present' indicates if a tree is present
100
- "geometry": row["geometry"], # Geometry information from GeoJSON
101
- # Include other fields from your data
102
- }