-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadData.py
56 lines (35 loc) · 1.3 KB
/
ReadData.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
"""
Simple example of how to read and plot L1 MAG data from DSCOVR
"""
import numpy as np
import matplotlib.pyplot as plt
#-----------------------------------------------------------------------------
# open file for reading
dir = '/home/mark.miesch/data/DSCOVR/MAG/L1/'
# Feb 5
file = dir+'oe_mg1_dscovr_s20220205000000_e20220205235959_p20220206013755_pub.nc'
#-----------------------------------------------------------------------------
# old school netcdf3 approach seems to work:
from scipy.io import netcdf
dfile = netcdf.NetCDFFile(file,'r')
tdata = dfile.variables['time']
time = tdata[:].copy().astype('float') - tdata[0]
bzdata = dfile.variables['bz_gsm']
bz = bzdata[:].copy().astype('float')
dfile.close()
#-----------------------------------------------------------------------------
# an alternative, using the netcdf4 package
from netCDF4 import Dataset
rootgrp = Dataset(file, "r", format="NETCDF3")
tvar = rootgrp.variables['time']
time2 = tvar[:] - tvar[0]
bzvar = rootgrp.variables['bz_gsm']
bz2 = bzvar[:].copy()
#-----------------------------------------------------------------------------
i1 = 2000
i2 = i1 + 50
plt.plot(time[i1:i2],bz[i1:i2])
plt.plot(time2[i1:i2],bz2[i1:i2],'bo')
plt.show()
#-----------------------------------------------------------------------------
rootgrp.close()