Skip to content
Snippets Groups Projects
Commit d67eaeca authored by Ilaria Carlomagno's avatar Ilaria Carlomagno
Browse files

Added comment in the hdf5 file

parent 06e200f0
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,8 @@ def cut_reshape(in_file, out_fold):
with h5py.File(in_file, 'r') as f:
move_ver = False
comment_line = ''
for run in f.keys():
date_str = 'Run%Y%m%d %H%M%S'
# the first part of the string contains date and time of acquisition
......@@ -42,8 +43,8 @@ def cut_reshape(in_file, out_fold):
sample_name = run[19:]
new_map = './'+ NEW_FOLDER + sample_name + date_acq.strftime('_%Y-%m-%d_%H-%M-%S')
print ("Sample_name: %s." %sample_name)
print (date_acq.strftime('\tAcquisition time: %d/%m/%Y - %H:%M:%S.'))
print("Sample_name: %s." %sample_name)
print(date_acq.strftime('\tAcquisition time: %d/%m/%Y - %H:%M:%S.'))
try:
x = f[run+PATH_SCALAR+"/X"][...]
......@@ -59,7 +60,7 @@ def cut_reshape(in_file, out_fold):
# The following section fixes this issue. The output file will be shown
# in the correct orientation on PyMCA.
try:
x, y, move_ver = orientation(x, y)
x, y, move_ver = orientation(x, y)
except ValueError:
print('\tx x x x x x x x x x x x x x x x x x x x x x x x')
print('\tx Size not valid for map. Please check file. x ')
......@@ -85,6 +86,7 @@ def cut_reshape(in_file, out_fold):
row = shape_x
col = math.floor(valid_pixels/shape_x)
new_map += '_rot'
comment_line += 'This map has been rotated.\n'
else:
col = shape_y
row = math.floor(valid_pixels/shape_y)
......@@ -93,50 +95,49 @@ def cut_reshape(in_file, out_fold):
print(' !\tValid pixels = %s out of %s' %(valid_pixels, shape_x*shape_y))
if not beam_lost:
print('\tIncomplete map collection found.')
comment_line += 'Incomplete map collection found'
print('\tNew map shape: (%d, %d)' %(row, col))
new_map += '_cut'
if (row*col==shape_x*shape_y):
print('\tNo cutting, just reshaping.\n')
comment_line += 'This map was not cut. Only reshaping has been done.'
print('\tNew map shape: (%d, %d)' %(row, col))
new_map += '.h5'
with h5py.File(new_map, 'w') as fout:
final_points = row * col
my_comment = 'Test_ciao !!'
fout.create_dataset("Comments", data=my_comment)
# Reshaping TransientVectorData
for vectorData in f[run+PATH_VECTOR].keys():
v = f[run+PATH_VECTOR+"/"+vectorData][...]
v = v[0:final_points]
v = v.reshape(row,col,v.shape[-1])
fout = h5py.File(new_map, 'w')
final_points = row * col
fout.create_dataset("Comments", data=comment_line)
# Reshaping TransientVectorData
for vectorData in f[run+PATH_VECTOR].keys():
v = f[run+PATH_VECTOR+"/"+vectorData][...]
v = v[0:final_points]
v = v.reshape(row,col,v.shape[-1])
# the rotation of the map is done here:
if move_ver:
v = np.rot90(v, -1, axes=(1,0))
fout.create_dataset(run+"/Detector_data/"+vectorData, data=v, compression = "gzip", shuffle=True)
# Reshaping TransientScalarData:')
for scalarData in f[run+PATH_SCALAR].keys():
if scalarData in AcceptedList:
s = f[run+PATH_SCALAR+"/"+scalarData][...]
s = s[0:final_points]
if s.shape[0] == final_points:
s = s.reshape(row, col)
# the rotation of the map is done here:
if move_ver:
v = np.rot90(v, -1, axes=(1,0))
fout.create_dataset(run+"/Detector_data/"+vectorData, data=v, compression = "gzip", shuffle=True)
# Reshaping TransientScalarData:')
for scalarData in f[run+PATH_SCALAR].keys():
if scalarData in AcceptedList:
s = f[run+PATH_SCALAR+"/"+scalarData][...]
s = s[0:final_points]
if s.shape[0] == final_points:
s = s.reshape(row, col)
if move_ver:
s = np.rot90(s, -1, axes=(1,0))
fout.create_dataset(run+"/Motor_positions/"+scalarData, data=s)
# Reshaping Positioners (i.e. motor position before map collection)
for motor_position in f[run+POSITIONERS].keys():
p = f[run+POSITIONERS+"/"+motor_position][...]
fout.create_dataset(run+"/Starting_positions/"+motor_position, data=p)
s = np.rot90(s, -1, axes=(1,0))
fout.create_dataset(run+"/Motor_positions/"+scalarData, data=s)
# Reshaping Positioners (i.e. motor position before map collection)
for motor_position in f[run+POSITIONERS].keys():
p = f[run+POSITIONERS+"/"+motor_position][...]
fout.create_dataset(run+"/Starting_positions/"+motor_position, data=p)
####################################################################
......@@ -161,15 +162,14 @@ def run():
if len(file_list) == 0:
print("\t-> Can't do much with 0 files! Sorry!")
print("\t-> Move the maps in the same folder as the program and try again!")
print("\t-> Move the maps in the same folder as the program and try again!")
else:
print("\t-> All the files mentioned above will be cut and reshaped.")
print("\t-> Don't worry: overwriting raw data is not an option. ;) \n")
print("\t-> Don't worry: overwriting raw data is not an option. ;) \n")
if not os.path.exists(out_path):
os.makedirs(out_path)
os.makedirs(out_path)
for filename, i in zip(file_list, range(len(file_list))):
filename = filename[2:]
cut_reshape(filename, out_path)
......@@ -178,4 +178,4 @@ def run():
print('\tHave a nice day.\n')
if __name__ == "__main__":
run()
\ No newline at end of file
run()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment