Skip to content

Commit 1dfe565

Browse files
committed
Create correlation bar chart and line graph for temperature and NDVI
1 parent 1ca0be7 commit 1dfe565

File tree

2 files changed

+126
-3
lines changed

2 files changed

+126
-3
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<template>
2+
<v-container>
3+
<h2 class="pb-10">Temperature vs. NDVI</h2>
4+
<v-row justify="center">
5+
<div
6+
id="plotlyGraphTemperatureNdvi"
7+
style="width: 100%; height: 400px"
8+
class="d-flex justify-center"
9+
></div>
10+
</v-row>
11+
</v-container>
12+
</template>
13+
14+
<script>
15+
import axios from 'axios'
16+
import Plotly from 'plotly.js-dist-min'
17+
import { onMounted, ref, render } from 'vue'
18+
19+
export default {
20+
name: 'TemperatureNdviBarAndLine',
21+
setup() {
22+
const temperatureData = ref(null)
23+
const ndviData = ref(null)
24+
const startDate = ref(1514761200) // 2018-01-01
25+
const endDate = ref(1704063599) // 2023-12-31
26+
const temporalResolution = ref("Monthly")
27+
const aggregation = ref("Mean")
28+
29+
const fetchTemperatureData = async () => {
30+
const apiUrl = 'http://localhost:8000/weather/index'
31+
const params = {
32+
weatherVariable: "temperature_2m",
33+
startDate: startDate.value,
34+
endDate: endDate.value,
35+
location: "TEMPELHOFER_FELD",
36+
temporalResolution: temporalResolution.value.toUpperCase(),
37+
aggregation: aggregation.value.toUpperCase()
38+
}
39+
40+
try {
41+
const response = await axios.get(apiUrl, { params })
42+
temperatureData.value = response.data
43+
renderPlot()
44+
} catch (error) {
45+
console.error("Error fetching temperature data:", error)
46+
}
47+
}
48+
49+
const fetchNdviData = async () => {
50+
const apiUrl = 'http://localhost:8000/index/ndvi'
51+
const params = {
52+
startDate: startDate.value,
53+
endDate: endDate.value,
54+
location: "TEMPELHOFER_FELD",
55+
temporalResolution: temporalResolution.value.toUpperCase(),
56+
aggregation: aggregation.value.toUpperCase()
57+
}
58+
59+
try {
60+
const response = await axios.get(apiUrl, { params })
61+
ndviData.value = response.data
62+
renderPlot()
63+
} catch (error) {
64+
console.error("Error fetching NDVI data:", error)
65+
}
66+
}
67+
68+
const renderPlot = () => {
69+
if (temperatureData.value && ndviData.value) {
70+
const tempTimestamps = temperatureData.value.data.map(entry =>
71+
new Date(entry.timestamp * 1000).toISOString().split('T')[0]
72+
)
73+
const tempValues = temperatureData.value.data.map(entry => entry.value)
74+
const ndviTimestamps = ndviData.value.data.map(entry => new Date(entry.timestamp * 1000))
75+
const ndviValues = ndviData.value.data.map(entry => entry.value)
76+
77+
const tempTrace = {
78+
x: tempTimestamps,
79+
y: tempValues,
80+
type: 'bar',
81+
name: 'Temperature (°C)',
82+
marker: { color: 'red' }
83+
};
84+
85+
const ndviTrace = {
86+
x: ndviTimestamps,
87+
y: ndviValues,
88+
mode: 'lines+markers',
89+
name: 'NDVI',
90+
line: { color: 'blue' },
91+
yaxis: 'y2',
92+
};
93+
94+
const layout = {
95+
title: 'NDVI vs. Monthly Temperature for Tempelhofer Feld (2018-2023)',
96+
xaxis: { title: 'Date', type: 'date', rangeslider: { visible: true } },
97+
yaxis: { title: 'NDVI' },
98+
yaxis2: {
99+
title: 'Temperature (°C)',
100+
overlaying: 'y',
101+
side: 'right',
102+
},
103+
legend: { x: 1.1, y: 0.5 },
104+
template: 'plotly_white'
105+
};
106+
107+
Plotly.newPlot('plotlyGraphTemperatureNdvi', [tempTrace, ndviTrace], layout);
108+
}
109+
}
110+
111+
onMounted(() => {
112+
fetchTemperatureData()
113+
fetchNdviData()
114+
})
115+
}
116+
}
117+
</script>
118+
119+
<style scoped></style>

frontend/src/components/MainSection.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<template>
22
<v-container class="main-section" fluid>
3-
<Images />
3+
<!-- <Images />
44
<NdviComparisonGraph />
55
<NdviSelectMonthGraph />
66
<NdviOverlayGraph />
77
<MedianTempGraph />
88
<MeanSoilTempGraph />
99
<MeanSoilMoistureGraph />
1010
<AugustMeanSoilTempGraph />
11-
<SelectMonthMeanSoilTempGraph />
11+
<SelectMonthMeanSoilTempGraph /> -->
12+
<TemperatureNdviBarAndLine />
1213
</v-container>
1314
</template>
1415

@@ -22,6 +23,8 @@ import MeanSoilTempGraph from "./WeatherGraphs/SoilTempGraph.vue"
2223
import MeanSoilMoistureGraph from "./WeatherGraphs/SoilMoistureGraph.vue"
2324
import AugustMeanSoilTempGraph from "./WeatherGraphs/AugustSoilTempGraph.vue"
2425
import SelectMonthMeanSoilTempGraph from "./WeatherGraphs/SelectMonthSoilTempGraph.vue"
26+
import TemperatureNdviGraph from "./CorrelationGraphs/TemperatureNdviBarAndLine.vue"
27+
import TemperatureNdviBarAndLine from "./CorrelationGraphs/TemperatureNdviBarAndLine.vue"
2528
2629
export default {
2730
name: 'MainSection',
@@ -34,7 +37,8 @@ export default {
3437
MeanSoilTempGraph,
3538
MeanSoilMoistureGraph,
3639
AugustMeanSoilTempGraph,
37-
SelectMonthMeanSoilTempGraph
40+
SelectMonthMeanSoilTempGraph,
41+
TemperatureNdviBarAndLine
3842
}
3943
}
4044
</script>

0 commit comments

Comments
 (0)