-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfape
67 lines (51 loc) · 2.11 KB
/
cfape
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import ConvexHull
def load_data(csv_file_path):
"""Load carbon emission data from a CSV file."""
df = pd.read_csv(csv_file_path)
return df
def calculate_overlapping_points(df):
"""Calculate overlapping emission points based on atomic weight and emission value."""
atomic_weights = df['atomic_weight'].values
emissions = df['emission_value'].values
# Normalize emission values for comparison
normalized_emissions = (emissions - np.min(emissions)) / (np.max(emissions) - np.min(emissions))
# Define a threshold for overlap
threshold = 0.5
overlapping_points = [(aw, em) for aw, em in zip(atomic_weights, normalized_emissions) if em > threshold]
return np.array(overlapping_points)
def extrapolate_polygon_edges(points):
"""Extrapolate the polygon edges using Convex Hull."""
if len(points) < 3:
raise ValueError("At least 3 points are required to form a polygon.")
hull = ConvexHull(points)
edges = []
for simplex in hull.simplices:
edges.append((points[simplex[0]], points[simplex[1]]))
return edges
def plot_polygon_edges(points, edges):
"""Plot the polygon edges based on the extrapolated edges."""
plt.figure()
plt.scatter(points[:, 0], points[:, 1], color='blue', label='Overlapping Points')
for edge in edges:
plt.plot([edge[0][0], edge[1][0]], [edge[0][1], edge[1][1]], 'r-')
plt.xlabel('Atomic Weight')
plt.ylabel('Normalized Emission Value')
plt.title('Polygon Edges Extrapolation of Carbon Emission Points')
plt.legend()
plt.grid(True)
plt.show()
def main():
# Load data
csv_file_path = 'carbon_emissions.csv' # Path to your CSV file
data = load_data(csv_file_path)
# Calculate overlapping points
overlapping_points = calculate_overlapping_points(data)
# Extrapolate polygon edges
edges = extrapolate_polygon_edges(overlapping_points)
# Plot the results
plot_polygon_edges(overlapping_points, edges)
if __name__ == "__main__":
main()