|
|
|
"""DurhamTrees |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1W5gDhKokcuqoA8AK4a6JR7PIeCUdmrTU |
|
""" |
|
|
|
import datasets |
|
import pandas as pd |
|
import geopandas as gpd |
|
from datasets import DatasetBuilder, DownloadManager, DatasetInfo, SplitGenerator, Split |
|
from datasets.features import Features, Value, ClassLabel |
|
import matplotlib.pyplot as plt |
|
import csv |
|
import json |
|
import os |
|
from typing import List |
|
|
|
_URLS = { |
|
"first_domain1": { |
|
"csv_file": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy", |
|
"geojson_file": "https://drive.google.com/uc?export=download&id=1cbn7EY7RofXN7c6Ph0eIGFIZowPZ5lKE", |
|
}, |
|
"first_domain2": { |
|
"csv_file2": "https://drive.google.com/uc?export=download&id=1RVdaI5dSTPStjhOHO40ypDv2cAQZpi_Y", |
|
}, |
|
} |
|
|
|
|
|
class DurhamTrees(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
|
datasets.BuilderConfig(name="class1_domain1", description="this is combined of csv and geojson"), |
|
|
|
datasets.BuilderConfig(name="class2_domain1", description="this is csv file"), |
|
|
|
] |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
description="This dataset combines information from both classes.", |
|
features=datasets.Features({ |
|
|
|
"feature1_from_class1": Value("string"), |
|
"geometry": Value("string"), |
|
"OBJECTID": Value("int64"), |
|
"X": Value("float64"), |
|
"Y": Value("float64"), |
|
|
|
|
|
"feature1_from_class2": Value("string"), |
|
"geometry": Value("string"), |
|
"OBJECTID": Value("int64"), |
|
"streetaddress": Value("string"), |
|
"city": Value("string"), |
|
"facilityid": Value("int64"), |
|
"present": Value("string"), |
|
"genus": Value("string"), |
|
"species": Value("string"), |
|
"commonname": Value("string"), |
|
"diameterin": Value("float64"), |
|
"condition": Value("string"), |
|
"contractwork": Value("string"), |
|
"neighborhood": Value("string"), |
|
"program": Value("string"), |
|
"plantingw": Value("string"), |
|
"plantingcond": Value("string"), |
|
"underpwerlins": Value("string"), |
|
"GlobalID": Value("string"), |
|
"created_user": Value("string"), |
|
"last_edited_user": Value("string"), |
|
"isoprene": Value("float64"), |
|
"monoterpene": Value("float64"), |
|
|
|
}), |
|
supervised_keys=None, |
|
homepage="https://github.com/AuraMa111?tab=repositories", |
|
citation="Citation for the combined dataset", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
|
|
"class1_data_file": downloaded_files["first_domain1"]["csv_file"], |
|
"class1_geojson_file": downloaded_files["first_domain1"]["geojson_file"], |
|
|
|
|
|
"class2_data_file": downloaded_files["first_domain2"]["csv_file2"], |
|
|
|
|
|
"split": "train", |
|
}, |
|
), |
|
|
|
] |
|
|
|
def _generate_examples(self, class1_data_file, class1_geojson_file, class2_data_file, split): |
|
|
|
for example in self._generate_examples_from_class1(class1_data_file, class1_geojson_file): |
|
yield example |
|
|
|
|
|
for example in self._generate_examples_from_class2(class2_data_file): |
|
yield example |
|
|
|
def _generate_examples_from_class1(self, csv_filepath, geojson_filepath): |
|
columns_to_extract = ["geometry", "OBJECTID", "X", "Y"] |
|
csv_data = pd.read_csv(csv_filepath) |
|
|
|
with open(geojson_filepath, 'r') as file: |
|
geojson_dict = json.load(file) |
|
gdf = gpd.GeoDataFrame.from_features(geojson_dict['features']) |
|
merged_data = gdf.merge(csv_data, on='OBJECTID') |
|
final_data = merged_data[columns_to_extract] |
|
for id_, row in final_data.iterrows(): |
|
example = row.to_dict() |
|
yield id_, example |
|
|
|
def _generate_examples_from_class2(self, csv_filepath2): |
|
columns_to_extract = ["geometry", "OBJECTID", "streetaddress", "city", "facilityid", "present", "genus", "species", "commonname", "diameterin", "condition", "contractwork", "neighborhood", "program", "plantingw", "plantingcond", "underpwerlins", "GlobalID", "created_user", "last_edited_user", "isoprene", "monoterpene", "coremoved_ozperyr", "coremoved_dolperyr", "o3removed_ozperyr", "o3removed_dolperyr", "no2removed_ozperyr", "no2removed_dolperyr", "so2removed_ozperyr", "so2removed_dolperyr", "pm10removed_ozperyr", "pm10removed_dolperyr", "pm25removed_ozperyr", "o2production_lbperyr", "replacevalue_dol", "carbonstorage_lb", "carbonstorage_dol", "grosscarseq_lbperyr", "X", "Y"] |
|
|
|
|
|
csv_data2 = pd.read_csv(csv_filepath2) |
|
|
|
|
|
final_data = csv_data2[columns_to_extract] |
|
|
|
|
|
for id_, row in final_data.iterrows(): |
|
|
|
example = row.to_dict() |
|
|
|
|
|
yield id_, example |