-
florez_j authored
Change import statements with try except to enable explicit import of submodules from import to avoid conflicts with parent project.
florez_j authoredChange import statements with try except to enable explicit import of submodules from import to avoid conflicts with parent project.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
flag_reader.py 1.19 KiB
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()
try:
from dima.utils import g5505_utils as utils
except ModuleNotFoundError:
import utils.g5505_utils as 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