39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import os
|
|
import json
|
|
|
|
#root_dir = os.path.abspath(os.curdir)
|
|
#sys.path.append(root_dir)
|
|
#print(__file__)
|
|
|
|
#from instruments.readers import set_dima_path as configpath
|
|
#configpath.set_dima_path()
|
|
|
|
from utils import g5505_utils
|
|
|
|
|
|
def read_jsonflag_as_dict(path_to_file):
|
|
|
|
|
|
file_dict = {}
|
|
path_tail, path_head = os.path.split(path_to_file)
|
|
|
|
file_dict['name'] = path_head
|
|
# TODO: review this header dictionary, it may not be the best way to represent header data
|
|
file_dict['attributes_dict'] = {}
|
|
file_dict['datasets'] = []
|
|
|
|
try:
|
|
with open(path_to_file, 'r') as stream:
|
|
flag = json.load(stream)#, Loader=json.FullLoader)
|
|
except (FileNotFoundError, json.JSONDecodeError) as exc:
|
|
print(exc)
|
|
|
|
dataset = {}
|
|
dataset['name'] = 'data_table'#_numerical_variables'
|
|
dataset['data'] = g5505_utils.convert_attrdict_to_np_structured_array(flag) #df_numerical_attrs.to_numpy()
|
|
dataset['shape'] = dataset['data'].shape
|
|
dataset['dtype'] = type(dataset['data'])
|
|
|
|
file_dict['datasets'].append(dataset)
|
|
|
|
return file_dict |