Repository navigation
Expand file tree
/
Copy pathex03_cassini_rpws_multimode.py
More file actions
78 lines (59 loc) · 2.7 KB
/
Copy pathex03_cassini_rpws_multimode.py
File metadata and controls
78 lines (59 loc) · 2.7 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
# das2 module example 3:
# Plotting Cassini RPWS multi-mode spectra using hexbin algorithm
import numpy
import das3
import das3.mpl
import matplotlib
matplotlib.use('Agg') # Draw to files only. Comment out to show plots in a window.
import matplotlib.pyplot as pyplot
import matplotlib.colors as colors
import matplotlib.ticker as ticker
# The Cassini RPWS Survey data source is one of the most complicated das2 data
# sources at U. Iowa. Data consist of multiple frequency sets from multiple
# recivers all attempting to cover the maximum parameter space within a limited
# telemetry alotment and on-board computing power. This example collapses
# all the provided datasets to a single scatter set for plotting
sId = "site:/uiowa/cassini/rpws/survey/das2"
print("Getting data source definition for %s"%sId)
src = das3.get_source(sId)
print("Reading default example Cassini RPWS E-Survey data...")
(hdr, lDs) = src.get()
# Combining multiple spectra into one overall array set
print("Combining arrays...")
lX = []
lY = []
lZ = []
for ds in lDs:
# As of numpy version 1.15, the numpy histogram routines won't work
# with datetime64, and timedelta64 data types. To Working around a
# this problem time data are cast to the int64 type
lX.append(ds['time']['center'].array.flatten().astype("int64"))
lY.append(ds['frequency']['center'].array.flatten() )
lZ.append(ds['amplitude']['center'].array.flatten() )
aX = numpy.ma.concatenate(lX)
aY = numpy.ma.concatenate(lY)
aZ = numpy.ma.concatenate(lZ)
(fig, ax0) = pyplot.subplots()
print("Plotting..")
clrscale = colors.LogNorm(vmin=aZ.min(), vmax=aZ.max())
hb = ax0.hexbin(aX, aY, aZ, yscale='log', gridsize=(400, 200),
cmap='jet', norm=clrscale )
cbar = fig.colorbar(hb, ax=ax0)
# Since matplotlib can't bin datetime64 values, will have to do our
# own axis labeling. das2 plot help functions are useful here.
nMinor = 60
nMajor = 6*60
ax0.xaxis.set_minor_locator(ticker.MultipleLocator(nMinor*60*int(1e9)))
ax0.xaxis.set_major_locator(ticker.MultipleLocator(nMajor*60*int(1e9)))
fmtr = das3.mpl.TimeTicker(aX.min(), aX.max())
ax0.xaxis.set_major_formatter(ticker.FuncFormatter(fmtr.label))
# Plot labels
ax0.set_xlabel(das3.mpl.ns1970_label( ax0.get_xlim() ))
sUnits = lDs[0]['frequency']['center'].units
ax0.set_ylabel("Frequency (%s)"%das3.mpl.label(sUnits))
sUnits = lDs[0]['amplitude']['center'].units
cbar.set_label("Spectral Density (%s)"%das3.mpl.label(sUnits))
# Stream didn't contain a title, use the one from the data source
ax0.set_title( src.props['title'] )
# matplotlib is a little slow displaying this one, expect ~10 sec delay
pyplot.savefig('ex03_cassini_rpws_multimode.png') # Or pyplot.show(), with the backend line above commented out