-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata_process.py
More file actions
33 lines (24 loc) · 839 Bytes
/
data_process.py
File metadata and controls
33 lines (24 loc) · 839 Bytes
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
# this is a first pass at a data extraction script in python
# import necessary modules
import numpy as np
import matplotlib.pyplot as plt
import json
# define complex encoder class - from python docs
class ComplexEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, complex):
return [obj.real, obj.imag]
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
# define arr2json dump function
def arr2json(arr):
return json.dumps(arr.tolist())
# load data
data = np.load('sample_inverse_sdm.npy')
# conver to list
dataList = data.tolist()
# conver to encoded
dataEncode = ComplexEncoder().encode(dataList)
# write out to file
with open('dataFULL.txt', 'w') as outfile:
json.dump(dataEncode, outfile)