-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment6.py
More file actions
91 lines (78 loc) · 2.43 KB
/
Copy pathAssignment6.py
File metadata and controls
91 lines (78 loc) · 2.43 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# %%
#Load data and libraries
import numpy as np
import pandas as pd
import xarray as xr
import seaborn as sns
import matplotlib.pyplot as plt
dset = xr.open_dataset(r"C:/Users/Em/Desktop/phd/Geo-modelling/Data/ERA5_Data/download.nc")
# %%
#Extracting the data
t2m = np.array(dset.variables['t2m'])
tp = np.array(dset.variables['tp'])
latitude = np.array(dset.variables['latitude'])
longitude = np.array(dset.variables['longitude'])
time_dt = np.array(dset.variables['time'])
# %%
#Convert temperature to Celsius and precipitation to mm/h
t2m = t2m - 273.15
tp = tp * 1000
# %%
#Computing mean across the second dimension
if t2m.ndim == 4:
t2m = np.nanmean(t2m, axis=1)
tp = np.nanmean(tp, axis=1)
tp
# %%
#Defining location of wadi within the data
df_era5 = pd.DataFrame(index=time_dt)
df_era5['t2m'] = t2m[:,3,2]
df_era5['tp'] = tp[:,3,2]
df_era5
# %%
#Plot time series of temperature and precipitation on same axes
plt.figure(figsize=(10, 6))
df_era5.plot()
plt.xlabel('Date')
plt.ylabel('Values')
plt.title('Time Series Plot')
plt.legend()
plt.savefig('Time_Series_Plot.png')
plt.show()
# %%
#Resample data to annual values and find the mean precipitation
annual_precip = df_era5['tp'].resample('A').mean()*24*365.25
mean_annual_precip = np.nanmean(annual_precip)
mean_annual_precip
# %%
#Deriving the maximum, minimum, and mean daily temperatures from the dataset
tmin = df_era5['t2m'].resample('D').min().values
tmax = df_era5['t2m'].resample('D').max().values
tmean = df_era5['t2m'].resample('D').mean().values
lat = 21.25
doy = df_era5['t2m'].resample('D').mean().index.dayofyear
# %%
#Computing PE
import tools
pe = tools.hargreaves_samani_1982(tmin, tmax, tmean, lat, doy)
pe
# %%
#Plotting PE time series
ts_index = np.array(df_era5['t2m'].resample('D').mean().index)
plt.figure(figsize=(10, 6), tight_layout=True)
plt.plot(ts_index, pe, label='Potential Evaporation')
plt.xlabel('Date')
plt.ylabel('PE [mm day−1]')
plt.title('Potential Evaporation Time Series')
plt.grid(True)
# %%
# Calculating mean annual PE in mm y−1
df_pe = pd.Series(pe, index=ts_index)
mean_annual_pe = df_pe.resample('A').mean()*365.25
mean_annual_pe = np.nanmean(mean_annual_pe)
mean_annual_pe
# %%
# Calculating mean volume of water evaporated in m3 y−1 over 1.6 km2 of wadi area
wadi_area = 1.6e6
mean_volume_evaporated = (mean_annual_pe/1000) * wadi_area
mean_volume_evaporated