added -j arg. so that the specific jungfrau can be passed from jungfrau utils - script should now also work for Alvra
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from runpy import run_path
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import regex as re
|
||||
from scipy import constants
|
||||
from jungfrau_utils import geometry
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
date = datetime.today().strftime('%y%m%d')
|
||||
|
||||
|
||||
def calculate_new_corner_positions( beam_x, beam_y ):
|
||||
def calculate_new_corner_positions( beam_x, beam_y, jungfrau ):
|
||||
|
||||
# import psi detectors from jungfrau_utils
|
||||
detectors = geometry.detector_geometry
|
||||
|
||||
# get x and y detector corners for the specifc jungfrau detector
|
||||
origin_y = detectors[ jungfrau ].origin_y
|
||||
origin_x = detectors[ jungfrau ].origin_x
|
||||
|
||||
# make df of current corner positions
|
||||
positions = { "current_x" : [ 607, 1646, 607, 1646, 607, 1646, 538, 1577, 538, 1577, 538, 1577, 538, 3212, 514, 3143 ],
|
||||
"current_y" : [ 0, 69, 550, 619, 1100, 1169, 1650, 1719, 2200, 2269, 2750, 2819, 597, 667, 1636, 1706 ]
|
||||
}
|
||||
corner_df = pd.DataFrame( positions )
|
||||
x_df = pd.DataFrame( origin_x, columns=[ "current_x" ] )
|
||||
y_df = pd.DataFrame( origin_y, columns=[ "current_y" ] )
|
||||
corner_df = pd.concat( ( x_df, y_df ), axis=1 )
|
||||
|
||||
# calculate new corner positions
|
||||
corner_df[ "new_x" ] = corner_df.current_x.subtract( beam_x )
|
||||
@@ -57,13 +65,13 @@ def scrub_poni( path_to_poni_file ):
|
||||
return poni1_p, poni2_p, eV, round( float( clen )*1000, 5 )
|
||||
|
||||
|
||||
def write_new_positions( path_to_geom, beam_x, beam_y, clen, energy, p_group ):
|
||||
def write_new_positions( path_to_geom, beam_x, beam_y, clen, energy, jungfrau, p_group ):
|
||||
|
||||
# open current geometry file
|
||||
current_geom_file = open( path_to_geom, "r" ).read()
|
||||
|
||||
# calculate new corner positions
|
||||
corner_df = calculate_new_corner_positions( beam_x, beam_y )
|
||||
corner_df = calculate_new_corner_positions( beam_x, beam_y, jungfrau )
|
||||
|
||||
# replace current corner positions with new ones
|
||||
for i in range(0, 16):
|
||||
@@ -127,6 +135,13 @@ if __name__ == "__main__":
|
||||
type=float,
|
||||
default=1661.99
|
||||
)
|
||||
parser.add_argument(
|
||||
"-j",
|
||||
"--jungfrau",
|
||||
help="name of jungfrau, i.e., JF17T16V01 for Cristallina 8M",
|
||||
type=str,
|
||||
default="JF17T16V01"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--clen",
|
||||
@@ -161,10 +176,14 @@ if __name__ == "__main__":
|
||||
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.geom, beam_x, beam_y, clen, eV, args.p_group )
|
||||
new_geom_name = write_new_positions( args.geom, beam_x, beam_y, clen, eV, args.jungfrau, args.p_group )
|
||||
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.geom, args.beam_x, args.beam_y, args.clen, args.energy, args.p_group )
|
||||
new_geom_name = write_new_positions( args.geom, args.beam_x, args.beam_y, args.clen, args.energy, args.jungfrau, args.p_group )
|
||||
print( "updated .geom file with poni calculations\nnew .geom = {0}".format( new_geom_name ) )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user