class DistlOrganizer(object): def __init__(self,verbose = 0,**kwargs): self.rundir = os.getcwd() self.verbose = verbose self.phil_params = kwargs["phil_params"] if self.phil_params.distl.dxtbx: self.set_dxtbx_input() return if kwargs.has_key('argument_module'): # new interface self.setCommandInput(kwargs['argument_module']) def set_dxtbx_input(self): pass def setCommandInput(self,argument_module): from spotfinder.diffraction.imagefiles import spotfinder_image_files as ImageFiles self.Files = ImageFiles(argument_module,self.phil_params) self.frames = self.Files.frames() def update_spotfinder(self): # used by distl.image_viewer S = spotfinder_factory(self.rundir,self.Files,self.phil_params) self.S = S for frame in self.frames: if self.verbose: pretty_image_stats(S,frame) notes(S,self.frames[0]) def printSpots(self): '''spotfinder and pickle implicitly assumes ADSC format''' if self.phil_params.distl.dxtbx: self.S = S = dxtbx_spotfinder_factory(self.phil_params) else: self.S = S = spotfinder_factory(self.rundir,self.Files,self.phil_params) for frame in self.frames: if self.verbose: pretty_image_stats(S,frame) notes(S,self.frames[0])
def do_POST(self): T = Timer("do_POST") parsed = urlparse(self.path) qs = parse_qs(parsed.query) expect = self.headers.getheaders("Expect") if len(expect) >= 1: if True in [item.find("200") >= 0 for item in expect]: self.send_response( 200) # untested; has no apparent affect on libcurl return # Get arguments by reading body of request. # We read this in chunks to avoid straining # socket.read(); around the 10 or 15Mb mark, some platforms # begin to have problems (bug #792570). max_chunk_size = 10 * 1024 * 1024 size_remaining = int(self.headers["content-length"]) L = [] while size_remaining: chunk_size = min(size_remaining, max_chunk_size) L.append(self.rfile.read(chunk_size)) size_remaining -= len(L[-1]) data = ''.join(L) post_data = StringIO(data) # Parse the multipart/form-data contentTypeHeader = self.headers.getheaders('content-type').pop() # Extract the boundary parameter in the content-type header headerParameters = contentTypeHeader.split(";") boundary = headerParameters[1].split("=") boundary = boundary[1].strip() parts = cgi.parse_multipart( post_data, { "boundary": boundary, "content-disposition": self.headers.getheaders('content-disposition') }) print "*****************************" for item in parts.keys(): if len(parts[item][0]) < 1000: print item, parts[item] print "*****************************" if parts["filename"][0].find("EXIT") >= 0: self.shutdown() return from spotfinder.diffraction.imagefiles import spotfinder_image_files as ImageFiles from spotfinder.diffraction.imagefiles import Spotspickle_argument_module response_params = copy.deepcopy(common_parameters_singleton).extract() Files = ImageFiles(Spotspickle_argument_module(parts["filename"][0]), response_params) print "Final image object:" Files.images[0].show_header() print "beam_center_convention", Files.images[0].beam_center_convention print "beam_center_reference_frame", Files.images[ 0].beam_center_reference_frame logfile = StringIO() if response_params.distl.bins.verbose: sys.stdout = logfile from spotfinder.applications.wrappers import spotfinder_factory S = spotfinder_factory(None, Files, response_params) print sys.stdout = sys.__stdout__ frames = Files.frames() sys.stdout = logfile print "Image: %s" % parts["filename"][0] from spotfinder.applications.stats_distl import pretty_image_stats, notes for frame in frames: #pretty_image_stats(S,frame) #notes(S,frames[0]) module_image_stats(S, frame) sys.stdout = sys.__stdout__ log = logfile.getvalue() print log ctype = 'text/plain' self.send_response(200) self.send_header("Content-type", ctype) self.send_header("Content-length", len(log)) self.end_headers() self.wfile.write(log) self.opt_logging()
def do_POST(self): T = Timer("do_POST") parsed = urlparse(self.path) qs = parse_qs(parsed.query) expect = self.headers.getheaders("Expect") if len(expect)>=1: if True in [item.find("200")>=0 for item in expect]: self.send_response(200) # untested; has no apparent affect on libcurl return # Get arguments by reading body of request. # We read this in chunks to avoid straining # socket.read(); around the 10 or 15Mb mark, some platforms # begin to have problems (bug #792570). max_chunk_size = 10*1024*1024 size_remaining = int(self.headers["content-length"]) L = [] while size_remaining: chunk_size = min(size_remaining, max_chunk_size) L.append(self.rfile.read(chunk_size)) size_remaining -= len(L[-1]) data = ''.join(L) post_data = StringIO.StringIO(data) # Parse the multipart/form-data contentTypeHeader = self.headers.getheaders('content-type').pop() # Extract the boundary parameter in the content-type header headerParameters = contentTypeHeader.split(";") boundary = headerParameters[1].split("=") boundary = boundary[1].strip() parts = cgi.parse_multipart(post_data, {"boundary":boundary, "content-disposition":self.headers.getheaders('content-disposition') }) print "*****************************" for item in parts.keys(): if len(parts[item][0])< 1000: print item, parts[item] print "*****************************" if parts["filename"][0].find("EXIT")>=0: self.shutdown() return from spotfinder.diffraction.imagefiles import spotfinder_image_files as ImageFiles from spotfinder.diffraction.imagefiles import Spotspickle_argument_module response_params = copy.deepcopy(common_parameters_singleton).extract() Files = ImageFiles(Spotspickle_argument_module(parts["filename"][0]),response_params) print "Final image object:" Files.images[0].show_header() print "beam_center_convention",Files.images[0].beam_center_convention print "beam_center_reference_frame",Files.images[0].beam_center_reference_frame logfile = StringIO.StringIO() if response_params.distl.bins.verbose: sys.stdout = logfile from spotfinder.applications.wrappers import spotfinder_factory S = spotfinder_factory(None, Files, response_params) print sys.stdout = sys.__stdout__ frames = Files.frames() sys.stdout = logfile print "Image: %s"%parts["filename"][0] from spotfinder.applications.stats_distl import pretty_image_stats,notes for frame in frames: #pretty_image_stats(S,frame) #notes(S,frames[0]) module_image_stats(S,frame) sys.stdout = sys.__stdout__ log = logfile.getvalue() print log ctype = 'text/plain' self.send_response(200) self.send_header("Content-type", ctype) self.send_header("Content-length",len(log)) self.end_headers() self.wfile.write(log) self.opt_logging()
def setCommandInput(self,argument_module): from spotfinder.diffraction.imagefiles import spotfinder_image_files as ImageFiles self.Files = ImageFiles(argument_module,self.phil_params) self.frames = self.Files.frames()