updated to take inputs from poni file
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
import regex as re
|
import regex as re
|
||||||
|
from scipy import constants
|
||||||
import argparse
|
import argparse
|
||||||
import os, sys
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
date = datetime.today().strftime('%y%m%d')
|
date = datetime.today().strftime('%y%m%d')
|
||||||
|
|
||||||
@@ -25,6 +26,35 @@ def calculate_new_corner_positions( beam_x, beam_y ):
|
|||||||
|
|
||||||
return corner_df
|
return corner_df
|
||||||
|
|
||||||
|
def scrub_poni( path_to_poni_file ):
|
||||||
|
|
||||||
|
# open poni file
|
||||||
|
poni_file = open( path_to_poni_file, "r" ).read()
|
||||||
|
|
||||||
|
# regex patterns to scrub poni data
|
||||||
|
clen_m_pattern = r"Distance:\s(\d\.\d*)"
|
||||||
|
poni1_m_pattern = r"Poni1:\s(\d\.\d*)"
|
||||||
|
poni2_m_pattern = r"Poni2:\s(\d\.\d*)"
|
||||||
|
wave_pattern = r"Wavelength:\s(\d\.\d*)e(-\d+)"
|
||||||
|
|
||||||
|
# regex seach
|
||||||
|
clen = re.search( clen_m_pattern, poni_file ).group( 1 )
|
||||||
|
poni1_m = re.search( poni1_m_pattern, poni_file ).group( 1 )
|
||||||
|
poni2_m = re.search( poni2_m_pattern, poni_file ).group( 1 )
|
||||||
|
wave = re.search( wave_pattern, poni_file ).group( 1, 2 )
|
||||||
|
|
||||||
|
# calulate proper wavelength
|
||||||
|
wave = float(wave[0]) * np.float_power( 10, int( wave[1]) )
|
||||||
|
|
||||||
|
# calculate beam_centre
|
||||||
|
poni1_p = float( poni1_m ) / 0.000000075
|
||||||
|
poni2_p = float( poni2_m ) / 0.000000075
|
||||||
|
|
||||||
|
# calculate beam energy in eV
|
||||||
|
eV = ( ( constants.c * constants.h ) / wave ) / constants.electron_volt
|
||||||
|
|
||||||
|
# return poni1 = y, poni2 = x and energy
|
||||||
|
return poni1_p, poni2_p, eV, round( float( clen )*1000, 5 )
|
||||||
|
|
||||||
|
|
||||||
def write_new_positions( path_to_geom, beam_x, beam_y, clen, energy ):
|
def write_new_positions( path_to_geom, beam_x, beam_y, clen, energy ):
|
||||||
@@ -70,11 +100,14 @@ def write_new_positions( path_to_geom, beam_x, beam_y, clen, energy ):
|
|||||||
f.write( current_geom_file )
|
f.write( current_geom_file )
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# return new_geom_name
|
||||||
|
return new_geom_name
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-p",
|
"-g",
|
||||||
"--path_to_geom",
|
"--path_to_geom",
|
||||||
help="give the path to the cristallina 8M geom file to be updated",
|
help="give the path to the cristallina 8M geom file to be updated",
|
||||||
type=str,
|
type=str,
|
||||||
@@ -108,6 +141,24 @@ if __name__ == "__main__":
|
|||||||
type=int,
|
type=int,
|
||||||
default=12400
|
default=12400
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-p",
|
||||||
|
"--poni",
|
||||||
|
help="path to poni file",
|
||||||
|
type=str,
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
# run geom converter
|
# run geom converter
|
||||||
write_new_positions( args.path_to_geom, args.beam_x, args.beam_y, args.clen, args.energy )
|
|
||||||
|
# import pdb;pdb.set_trace()
|
||||||
|
if args.poni is not None:
|
||||||
|
print( "reading poni file" )
|
||||||
|
beam_y, beam_x, eV, clen = scrub_poni( args.poni )
|
||||||
|
print( "beam x, beam_y = {0}, {1}\nphoton_energy = {2}\nclen = {3}".format( beam_x, beam_y, eV, clen ) )
|
||||||
|
new_geom_name = write_new_positions( args.path_to_geom, beam_x, beam_y, clen, eV )
|
||||||
|
print( "updated .geom file with poni calculations\n new .geom = {0}".format( new_geom_name ) )
|
||||||
|
else:
|
||||||
|
print( "manually input positions" )
|
||||||
|
print( "beam x, beam_y = {0}, {1}\nphoton_energy = {2}\nclen = {3}".format( args.beam_x, args.beam_y, args.energy, args.clen ) )
|
||||||
|
new_geom_name = write_new_positions( args.path_to_geom, args.beam_x, args.beam_y, args.clen, args.energy )
|
||||||
|
print( "updated .geom file with poni calculations\nnew .geom = {0}".format( new_geom_name ) )
|
||||||
Reference in New Issue
Block a user