-
Notifications
You must be signed in to change notification settings - Fork 0
/
nctomap.py
111 lines (61 loc) · 1.98 KB
/
nctomap.py
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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np
import xarray as xr
from matplotlib import pyplot as plt
from matplotlib.colors import LinearSegmentedColormap, Colormap
# In[2]:
cur_dir = "~/IMR/echo-test/hackathon/"
files = "OOI-D20170821-T163049.nc"
# In[3]:
# Open with Xarray, select the beam group
# if we use chunk, we will get almost functionality with numpy's memmap array
# i.e., data is loaded lazyly and per-chunk
ds = xr.open_dataset(cur_dir + files, group = "Beam", chunks={'ping_time': 100})
ds
# In[4]:
da = ds['backscatter_r']
print(da)
da
# In[5]:
# Getting the variables
ping_time = da.coords['ping_time']
print(ping_time)
range_bin = da.coords['range_bin']
print(range_bin)
# In[6]:
# Acccessing single data (wrong)
print(da[0,0,0])
# In[7]:
# Acccessing single data (right)
print(da[0,0,0].load())
# In[8]:
# Accessing using labels (freq= 38khz, time = ...)
da_sub = da.loc["3.8e+04", "2017-08-21T16:30":"2017-08-21T16:31"]
da_sub
# In[9]:
# Still traditional index works
da_sub[0,0]
# In[10]:
# Prepare simrad cmap
simrad_color_table = [(1, 1, 1),
(0.6235, 0.6235, 0.6235),
(0.3725, 0.3725, 0.3725),
(0, 0, 1),
(0, 0, 0.5),
(0, 0.7490, 0),
(0, 0.5, 0),
(1, 1, 0),
(1, 0.5, 0),
(1, 0, 0.7490),
(1, 0, 0),
(0.6509, 0.3255, 0.2353),
(0.4705, 0.2353, 0.1568)]
simrad_cmap = (LinearSegmentedColormap.from_list
('Simrad', simrad_color_table))
simrad_cmap.set_bad(color='grey')
# In[12]:
# Plot it using simple contour
da_sub.plot.contourf(robust = True, cmap=simrad_cmap)
# In[ ]: