Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiprocessing capability to make_image.py #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions polyxsim/check_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,35 +189,35 @@ def check(self):
if type(val) == type(1):
#assert val == 0, 'Wrong number of arguments for %s' %key
if val != 0:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
else:
val = [0, 0]
self.param[key] = val
else:
#assert len(val) <= 3, 'Wrong number of arguments for %s' %key
if len(val) > 5:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif key == 'sample_cyl' or key == 'gen_pos':
#assert len(val) == 2 , 'Wrong number of arguments for %s' %key
if len(val) != 2:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif key == 'sample_xyz' or 'pos_grains' in key:
#assert len(val) == 3, 'Wrong number of arguments for %s' %key
if len(val) != 3:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif 'gen_size' in key:
#assert len(val) == 4, 'Wrong number of arguments for %s' %key
if len(val) != 4:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif 'gen_eps' in key:
if type(val) == type(1):
#assert val == 0, 'Wrong number of arguments for %s' %key
if val != 0:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
else:
#assert len(val) == 5, 'Wrong number of arguments for %s' %key
if len(val) != 5:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif key == 'gen_phase':
try:
dummy = len(val)
Expand All @@ -226,23 +226,23 @@ def check(self):
self.param[key] = val
#assert len(val) > 0, 'Wrong number of arguments for %s' %key
if len(val) < 1:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif key == 'unit_cell' or 'eps_grains' in key:
#assert len(val) == 6, 'Wrong number of arguments for %s' %key
if len(val) != 6:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
elif 'U_grains' in key:
if len(val) != 3:
#assert len(val) == 9, 'Wrong number of arguments for %s' %key
if len(val) != 9:
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
else:
self.param[key] = n.array(self.param[key])
self.param[key].shape = (3,3)
else:
#assert val.shape == (3,3), 'Wrong number of arguments for %s' %key
if val.shape != (3,3):
self.errors[key] = 'Wrong number of arguments'
self.errors[key] = 'Wrong number of arguments for %s' %key
# reshape U-matrices
elif key == 'output':
for item in val:
Expand Down
114 changes: 59 additions & 55 deletions polyxsim/gopolyxsim.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
#This module has been made by Gaelle for the GUI. This is a copy of the script.
# This module has been made by Gaelle for the GUI. This is a copy of the script.
# Modules to import
from __future__ import absolute_import
from __future__ import print_function
import sys,os
import sys, os
from polyxsim import check_input
from polyxsim import file_io
from polyxsim import find_refl
Expand All @@ -12,36 +12,40 @@
from polyxsim import make_imagestack
from polyxsim import reflections
from polyxsim import help_input
#import logging
#logging.basicConfig(level=logging.INFO,format='\n%(levelname)s: %(message)s')
# import logging
# logging.basicConfig(level=logging.INFO,format='\n%(levelname)s: %(message)s')

from optparse import OptionParser

def get_options(parser):

def get_options(parser):
parser = OptionParser()
parser.add_option("-i", "--input", action="store",
dest="filename", type="string",
help="Name of the file containing the input parameters")
parser.add_option("-d", "--debug", action="store_true",
dest="debug",default =False,
dest="debug", default=False,
help="Run in debug mode")
parser.add_option("-p", "--print", action="store_true",
dest="print_input",default =False,
dest="print_input", default=False,
help="Show input parameters and syntax")
parser.add_option("-k","--killfile", action="store",
parser.add_option("-k", "--killfile", action="store",
dest="killfile", default=None, type="string",
help="Name of file to create halt PolyXSim")

options , args = parser.parse_args()
parser.add_option("-s", "--singlethreaded", action="store_true",
dest="single_thread", default=False,
help="Run image generation single-threaded")

options, args = parser.parse_args()
return options


def run(options):
# Check for print_input
try:
options.print_input
except:
options.print_input = None;
options.print_input = None
if options.print_input:
print(help_input.show_input())
sys.exit()
Expand All @@ -50,79 +54,78 @@ def run(options):
try:
options.filename
except:
options.filename = None;
options.filename = None
if options.filename == None:
print("\nNo input file supplied [-i filename]\n")
#Gaelle comment : ? sys.exit() and add raise error instead
# Gaelle comment : ? sys.exit() and add raise error instead
sys.exit()
#print 'options = ',options
#print '\n'
# print 'options = ',options
# print '\n'

# Check killfile does not exist
try:
options.killfile
except:
options.killfile = None;
options.killfile = None
if options.killfile is not None and os.path.exists(options.killfile):
print("The purpose of the killfile option is to create that file")
print("only when you want PolyXsim to stop")
print("If the file already exists when you start PolyXsim, it is")
print("stopped immediately")
raise ValueError("Your killfile "+options.killfile+" already exists")
raise ValueError("Your killfile " + options.killfile + " already exists")

# Is the input file available?

# Read and check input

# Make instance of parse_input class
print('Reading input\n')

myinput = check_input.parse_input(input_file=options.filename)
myinput.read() # read input file

myinput.read() # read input file

print('Checking input\n')
myinput.check() # check validity of input
myinput.check() # check validity of input
check_input.interrupt(options.killfile)


# if myinput.missing == True: # if problem exit
# print('MISSING ITEMS')
# sys.exit()


# if myinput.missing == True: # if problem exit
# print('MISSING ITEMS')
# sys.exit()

if len(myinput.errors) > 0:
myinput.show_errors()
sys.exit()

print('Initialize parameters etc\n')
myinput.initialize() # if ok initialize
myinput.initialize() # if ok initialize
check_input.interrupt(options.killfile)

# Generate reflections
hkl = []

for phase in myinput.param['phase_list']:
if ('structure_phase_%i' %phase) in myinput.param:
xtal_structure = reflections.open_structure(myinput.param,phase)
#print 'UNIT CELL', myinput.param['unit_cell_phase_%i' %phase]
if ('structure_phase_%i' % phase) in myinput.param:
xtal_structure = reflections.open_structure(myinput.param, phase)
# print 'UNIT CELL', myinput.param['unit_cell_phase_%i' %phase]
print('Generating miller indices')
hkl_tmp = reflections.gen_miller(myinput.param,phase)
hkl_tmp = reflections.gen_miller(myinput.param, phase)
if myinput.param['structure_factors'] != 0:
print('Structure factor calculation')
hkl.append(reflections.calc_intensity(hkl_tmp,
xtal_structure,
options.killfile))
else:
hkl.append(reflections.add_intensity(hkl,myinput.param))
hkl.append(reflections.add_intensity(hkl, myinput.param))
print('No structure factor calculation')
else:
hkl_tmp = reflections.gen_miller(myinput.param,phase)
hkl.append(reflections.add_intensity(hkl_tmp,myinput.param))
hkl_tmp = reflections.gen_miller(myinput.param, phase)
hkl.append(reflections.add_intensity(hkl_tmp, myinput.param))

check_input.interrupt(options.killfile)
# if options.killfile is not None and os.path.exists(options.killfile):
# raise KeyboardInterrupt()

generate_grains.generate_grains(myinput.param)
check_input.interrupt(options.killfile)
print('Write grains file')
Expand All @@ -131,24 +134,23 @@ def run(options):
print('Write res file')
file_io.write_res(myinput.param)
check_input.interrupt(options.killfile)

if '.hkl' in myinput.param['output']:
print('Write hkl file')
file_io.write_hkl(myinput.param,hkl)
file_io.write_hkl(myinput.param, hkl)
if '.fcf' in myinput.param['output']:
print('Write fcf file')
file_io.write_fcf(myinput.param,hkl)
file_io.write_fcf(myinput.param, hkl)
if '.ubi' in myinput.param['output']:
print('Write UBI file')
file_io.write_ubi(myinput.param)
if '.par' in myinput.param['output']:
print('Write detector.par file')
file_io.write_par(myinput.param)
check_input.interrupt(options.killfile)



# Determine the reflection parameters for grains
graindata = find_refl.find_refl(myinput.param,hkl,options.killfile)
graindata = find_refl.find_refl(myinput.param, hkl, options.killfile)
graindata.frameinfo = myinput.frameinfo
print('Determine reflections positions')
graindata.run()
Expand All @@ -166,14 +168,16 @@ def run(options):
graindata.write_flt()

if myinput.param['make_image'] == 1:
if myinput.param['peakshape'][0] == 2:
image = make_imagestack.make_image(graindata,options.killfile)
if myinput.param['peakshape'][0] == 2:
image = make_imagestack.make_image(graindata, options.killfile) # This is an empty object
image.setup_odf()
image.make_image_array()
image.make_image_array() # Makes sparse arrays that we populate later
image.make_image()
image.correct_image()
else:
image = make_image.make_image(graindata,options.killfile)
image.make_image()

image = make_image.make_image(graindata, options.killfile) # This is an empty object

if options.single_thread:
image.make_images()
else:
image.make_images_multi()
Loading