-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext-output.py
41 lines (36 loc) · 1.13 KB
/
text-output.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
"""
Simple script to convert HDF files to text output
Authors
-------
Bryan Webber, Nick Curtis
2017
"""
# coding: utf-8
from netCDF4 import Dataset
import os
import numpy as np
delt = 0.17
t0 = 2.4*60
# find directories to check starting from cwd
dirs = next(os.walk('.'))[1]
for d in dirs:
files = os.listdir(d)
for file in files:
# find all CDF files in dir
if file.endswith('.CDF'):
# open datasets and find total intensity
rootgrp = Dataset(file, 'r')
print(os.path.join(d, file))
total_intensity = rootgrp.variables['total_intensity']
num_points = len(total_intensity)
# load time for intensity values
time = np.zeros(num_points)
for j in range(num_points):
time[j] = t0 + delt*j
time = time/60 # Convert to minutes
output = np.transpose(np.vstack((time, total_intensity)))
# save to csv
outfile = file.rstrip('.CDF') + '.csv'
outloc = os.path.join(d, outfile)
np.savetxt(fname=outloc, X=output, delimiter=',')
rootgrp.close()