-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonly_codes_read_NetCDF_Stat.py
More file actions
162 lines (71 loc) · 1.82 KB
/
only_codes_read_NetCDF_Stat.py
File metadata and controls
162 lines (71 loc) · 1.82 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import xarray as xr
import numpy as np
import pandas as pd
# In[3]:
#load water eden water depth data 2021 q3
ds = xr.open_dataset ("C:/Users/ihasan2020/Desktop/2011_q3_depth_v3.nc")
da =ds ["depth"]
da
# In[4]:
#variables are in our dataset
ds.data_vars
# In[5]:
#monthly_data = ds.resample (freq = 'm', dim = 'time', how = 'mean')
# In[6]:
#look at the NetCDF representation
ds.info()
# In[7]:
#slelect one variable and pick the first entry along the first axis (time)
ds.depth [0]
# In[8]:
#plot depth of one date
ds.depth [0].plot()
# In[10]:
#dataset dimensions
ds.dims
# In[11]:
#dataset coordinates
ds.coords
# In[12]:
#The actual (numpy) arrray
ds.depth.data
# In[13]:
#Looking at the attribute
ds.attrs
# In[24]:
#demonstrating customised time-seris data
ds.sel(time= slice("2021-07-01","2021-08-30"))
# In[25]:
#performing arithmetic operation on the data set (+)
da + 1.5
# In[26]:
da_mean =da.mean(dim="time")
da_mean
# In[27]:
#Calculating standard deviation of water depth and ploting across time
da.std (dim =["y","x"]).plot()
# In[31]:
#compute monthly mean depth
m_mean = ds.groupby("time.month").mean()
m_mean
# In[29]:
#Calculating median vlaue of water depth and ploting across time
da.median (dim =["y","x"]).plot()
# In[34]:
#Resample to 5days mean (experimental)
ds.depth.resample (time ="5D").mean()
# In[47]:
#resample to tri_monthly mean uisng data form 2021-07-01 to 2021-09-30
F_mean = ds.depth.resample (time ="3MS").mean().plot()
F_mean
# In[48]:
#for exportable file
F_mean = ds.depth.resample (time ="3MS").mean()
F_mean
# In[50]:
#Exporting final mean of water deapth data as.nc format to import in ArcMap
F_mean.to_netcdf("C:/Users/ihasan2020/Desktop/watrDpt_mean.nc")
# In[ ]: