Skip to content

Commit

Permalink
added beamline conf parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bfrosik committed Apr 9, 2021
1 parent 4d44633 commit bd6b5f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
21 changes: 12 additions & 9 deletions scripts/create_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def create_conf_disp(conf_dir):
f.close()


def create_exp(prefix, scan, working_dir, specfile=None):
def create_exp(prefix, scan, working_dir, **args):
"""
Concludes experiment name, creates directory, and "conf" subdirectory with initial configuration files.
Expand Down Expand Up @@ -219,17 +219,17 @@ def create_exp(prefix, scan, working_dir, specfile=None):
conf_map['working_dir'] = '"' + working_dir + '"'
conf_map['experiment_id'] = '"' + prefix + '"'
conf_map['scan'] = '"' + scan + '"'
if specfile is not None:
conf_map['specfile'] = '"' + specfile + '"'
if 'specfile' in args:
conf_map['specfile'] = '"' + args['specfile'] + '"'
if 'beamline' in args:
conf_map['beamline'] = '"' + args['beamline'] + '"'

temp_file = os.path.join(experiment_conf_dir, 'temp')
with open(temp_file, 'a') as f:
for key in conf_map:
value = conf_map[key]
if len(value) > 0:
f.write(key + ' = ' + conf_map[key] + '\n')
if specfile is None:
f.write('// specfile = "/path/to/specfile/specfile"\n')
f.close()
if not ver.ver_config(temp_file):
print('please check the entered parameters. Cannot save this format')
Expand All @@ -251,19 +251,22 @@ def main(arg):
parser.add_argument("id", help="prefix to name of the experiment/data reconstruction")
parser.add_argument("scan", help="a range of scans to prepare data from")
parser.add_argument("working_dir", help="directory where the created experiment will be located")
parser.add_argument('--beamline', action='store')
parser.add_argument('--specfile', action='store')

args = parser.parse_args()
scan = args.scan
id = args.id
working_dir = args.working_dir

varpar = {}
if args.specfile and os.path.isfile(args.specfile):
specfile = args.specfile
else:
specfile = None
varpar['specfile'] = args.specfile

if args.beamline:
varpar['beamline'] = args.beamline

return create_exp(id, scan, working_dir, specfile=specfile)
return create_exp(id, scan, working_dir, **varpar)


if __name__ == "__main__":
Expand Down
7 changes: 7 additions & 0 deletions scripts/setup_34idc.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def setup_rundirs(prefix, scan, conf_dir, **kwargs):
try:
with open(main_conf, 'r') as f:
config_map = cfg.Config(f.read())
print(config_map)
except Exception as e:
print('Please check the configuration file ' + main_conf + '. Cannot parse ' + str(e))
return
Expand Down Expand Up @@ -137,6 +138,12 @@ def setup_rundirs(prefix, scan, conf_dir, **kwargs):
conf_map['scan'] = '"' + scan + '"'
if specfile is not None:
conf_map['specfile'] = '"' + specfile + '"'
print (conf_map)
try:
conf_map['beamline'] = '"' + config_map.beamline + '"'
except:
pass

temp_file = os.path.join(experiment_conf_dir, 'temp')
with open(temp_file, 'a') as f:
for key in conf_map:
Expand Down

0 comments on commit bd6b5f8

Please sign in to comment.