def collect_detector_seq(range_degrees,image_width,exposure_period,fileprefix,data_directory_name,file_number,z_target=0): #works for pilatus global image_started,allow_overwrite,abort_flag print "data directory = " + data_directory_name test_filename = "%s_%05d.cbf" % (fileprefix,int(file_number)) # if (os.path.exists(test_filename) and allow_overwrite == 0): # gui_message("You are about to overwrite " + test_filename + " If this is OK, push Continue, else Abort.&") # pause_data_collection() # check_pause() # time.sleep(1.0) # destroy_gui_message() # if (abort_flag): # print "collect sequence aborted" # return 0 # else: # allow_overwrite = 1 number_of_images = round(range_degrees/image_width) range_seconds = number_of_images*exposure_period exposure_time = exposure_period - .0024 file_prefix_minus_directory = str(fileprefix) try: file_prefix_minus_directory = file_prefix_minus_directory[file_prefix_minus_directory.rindex("/")+1:len(file_prefix_minus_directory)] except ValueError: pass print "collect pilatus %f degrees for %f seconds %d images exposure_period = %f exposure_time = %f" % (range_degrees,range_seconds,number_of_images,exposure_period,exposure_time) detector_set_period(exposure_period) detector_set_exposure_time(exposure_time) detector_set_numimages(number_of_images) detector_set_filepath(data_directory_name) detector_set_fileprefix(file_prefix_minus_directory) detector_set_filenumber(file_number) detector_set_fileheader(get_field(get_field("scan_axis")),get_field("inc0"),get_field("distance"),12398.5/beamline_lib.get_mono_energy(),get_field("theta"),get_field("exptime0"),get_field("xbeam"),get_field("ybeam"),get_field("scan_axis"),get_field("omega"),get_field("kappa"),get_field("phi")) print "collect pilatus %f degrees for %f seconds %d images exposure_period = %f exposure_time = %f" % (range_degrees,range_seconds,number_of_images,exposure_period,exposure_time) detector_start() image_started = range_seconds time.sleep(1.0) #4/15 - why so long? # time.sleep(0.3) set_field("state","Expose") ########## set_epics_pv_nowait("xtz","VAL",z_target) #this is for grid!!!!!!!! gon_osc(get_field("scan_axis"),0.0,range_degrees,range_seconds) #0.0 is the angle start that's not used image_started = 0 set_field("state","Idle") #### detector_wait() daq_macros.fakeDC(data_directory_name,file_prefix_minus_directory,int(file_number),int(number_of_images)) return number_of_images
def dna_execute_collection3( dna_start, dna_range, dna_number_of_images, dna_exptime, dna_directory, prefix, start_image_number, overlap, dna_run_num, charRequest, ): global collect_and_characterize_success, dna_have_strategy_results, dna_have_index_results, picture_taken global dna_strategy_exptime, dna_strategy_start, dna_strategy_range, dna_strategy_end, dna_strat_dist global screeningoutputid characterizationParams = charRequest["request_obj"]["characterizationParams"] dna_res = float(characterizationParams["aimed_resolution"]) print "dna_res = " + str(dna_res) dna_filename_list = [] print "number of images " + str(dna_number_of_images) + " overlap = " + str(overlap) + " dna_start " + str( dna_start ) + " dna_range " + str(dna_range) + " prefix " + prefix + " start number " + str(start_image_number) + "\n" collect_and_characterize_success = 0 dna_have_strategy_results = 0 dna_have_index_results = 0 dg2rd = 3.14159265 / 180.0 if daq_utils.detector_id == "ADSC-Q315": det_radius = 157.5 elif daq_utils.detector_id == "ADSC-Q210": det_radius = 105.0 elif daq_utils.detector_id == "PILATUS-6": det_radius = 212.0 else: # default Pilatus det_radius = 212.0 ##### theta_radians = daq_lib.get_field("theta") * dg2rd theta_radians = 0.0 wave = 12398.5 / beamline_lib.get_mono_energy() # for now dx = det_radius / (tan(2.0 * (asin(wave / (2.0 * dna_res))) - theta_radians)) print "distance = ", dx # skinner - could move distance and wave and scan axis here, leave wave alone for now print "skinner about to take reference images." for i in range(0, int(dna_number_of_images)): print "skinner prefix7 = " + prefix[0:7] + " " + str(start_image_number) + "\n" if len(prefix) > 8: if (prefix[0:7] == "postref") and (start_image_number == 1): print "skinner postref bail\n" time.sleep(float(dna_number_of_images * float(dna_exptime))) break # skinner roi - maybe I can measure and use that for dna_start so that first image is face on. dna_start = daq_lib.get_field("datum_omega") colstart = float(dna_start) + (i * (abs(overlap) + float(dna_range))) dna_prefix = "ref-" + prefix + "_" + str(dna_run_num) image_number = start_image_number + i dna_prefix_long = dna_directory + "/" + dna_prefix filename = daq_utils.create_filename(dna_prefix_long, image_number) beamline_lib.mva("Omega", float(colstart)) ##### daq_lib.move_axis_absolute(daq_lib.get_field("scan_axis"),colstart) ##### daq_lib.take_image(colstart,dna_range,dna_exptime,filename,daq_lib.get_field("scan_axis"),0,1) daq_utils.take_crystal_picture(reqID=charRequest["request_id"]) ######### BECAUSE I FAKE IT imagesAttempted = collect_detector_seq(dna_range,dna_range,dna_exptime,dna_prefix,dna_directory,image_number) if i == 0: commFake = "ln -sf /h/pxuser/skinner/testdata/B1GGTApo_9_00001.cbf " + filename else: commFake = "ln -sf /h/pxuser/skinner/testdata/B1GGTApo_9_00181.cbf " + filename os.system(commFake) dna_filename_list.append(filename) diffImgJpegData = daq_utils.diff2jpeg(filename, reqID=charRequest["request_id"]) # returns a dictionary # diffImgJpegData["timestamp"] = time.time() # imgRef = db_lib.addFile(diffImgJpegData["data"]) # diffImgJpegData["data"] = imgRef # imgRef = db_lib.addFile(diffImgJpegData["thumbData"]) # diffImgJpegData["thumbData"] = imgRef picture_taken = 1 # xml_from_file_list(flux,x_beamsize,y_beamsize,max_exptime_per_dc,aimed_completeness,file_list): edna_energy_ev = (12.3985 / wave) * 1000.0 ##### xbeam_size = beamline_lib.get_motor_pos("slitHum") ##### ybeam_size = beamline_lib.get_motor_pos("slitVum") # if (xbeam_size == 0.0 or ybeam_size == 0.0): #don't know where to get these from yet if 1: xbeam_size = 0.1 ybeam_size = 0.16 else: xbeam_size = xbeam_size / 1000 ybeam_size = ybeam_size / 1000 aimed_completeness = characterizationParams["aimed_completeness"] aimed_multiplicity = characterizationParams["aimed_multiplicity"] aimed_resolution = characterizationParams["aimed_resolution"] aimed_ISig = characterizationParams["aimed_ISig"] timeout_check = 0 ##### while(not os.path.exists(dna_filename_list[len(dna_filename_list)-1])): #this waits for edna images if 0: timeout_check = timeout_check + 1 time.sleep(1.0) if timeout_check > 10: break print "generating edna input\n" # edna_input_filename = edna_input_xml.xml_from_file_list(edna_energy_ev,xbeam_size,ybeam_size,1000000,aimed_completness,aimed_ISig,aimed_multiplicity,aimed_resolution,dna_filename_list) ##### flux = 10000000000 * beamline_lib.get_epics_pv("flux","VAL") flux = 600000000.0 # for now edna_input_filename = dna_directory + "/adsc1_in.xml" edna_input_xml_command = ( "/h/data/backed-up/pxsys/skinner/edna_header_code/makeAnEDNAXML-bnl.sh 1232 %s %s none %f %f 4000 0.01 0.01 0 xh1223_2_ %f %f %f > %s" % (dna_directory, dna_prefix, 3, aimed_ISig, flux, xbeam_size, ybeam_size, edna_input_filename) ) ##### edna_input_xml_command = "ssh swill \"/h/data/backed-up/pxsys/skinner/edna_header_code/makeAnEDNAXML-bnl.sh 1232 %s %s none %f %f 4000 0.01 0.01 0 xh1223_2_ %f %f %f\" > %s" % (daq_lib.data_directory_name,dna_prefix,3,aimed_ISig,flux,xbeam_size,ybeam_size,edna_input_filename) print edna_input_xml_command comm_sss = "echo " + edna_input_xml_command + "> edna_comm.txt" os.system(comm_sss) os.system(edna_input_xml_command) print "done generating edna input\n" # command_string = "cd %s; /usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data %s" % (dna_directory,edna_input_filename) command_string = "/usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data %s" % ( edna_input_filename ) # command_string = "/usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data /img11/data1/pxuser/staff/skinner/edna_run/adsc1_in.xml" # old command_string = "$EDNA_HOME/mxv1/bin/edna-mxv1-characterisation --data " + edna_input_filename print command_string # for i in range (0,len(dna_filename_list)): # command_string = command_string + " " + dna_filename_list[i] broadcast_output("\nProcessing with EDNA. Please stand by.\n") if os.path.exists("edna.log"): os.remove("edna.log") if os.path.exists("edna.err"): os.remove("edna.err") edna_execution_status = os.system("%s > edna.log 2> edna.err" % command_string) ##### fEdnaLogFile = open(daq_lib.get_misc_dir_name() + "/edna.log", "r" ) fEdnaLogFile = open("./edna.log", "r") ednaLogLines = fEdnaLogFile.readlines() fEdnaLogFile.close() for outline in ednaLogLines: # for outline in os.popen(command_string,'r',0).readlines(): ####skinner6/11 seg faults? broadcast_output(outline) if string.find(outline, "EdnaDir") != -1: (param, dirname) = string.split(outline, "=") strXMLFileName = ( dirname[0 : len(dirname) - 1] + "/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_3_dataOutput.xml" ) ##### strXMLFileName = dirname[0:len(dirname)-1]+"/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_1_dataOutput.xml" if string.find(outline, "characterisation successful!") != -1: collect_and_characterize_success = 1 if not collect_and_characterize_success: dna_comment = "Indexing Failure" ##### pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment) return 0 xsDataCharacterisation = XSDataResultCharacterisation.parseFile(strXMLFileName) xsDataIndexingResult = xsDataCharacterisation.getIndexingResult() xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution() xsDataStatisticsIndexing = xsDataIndexingSolutionSelected.getStatistics() numSpotsFound = xsDataStatisticsIndexing.getSpotsTotal().getValue() numSpotsUsed = xsDataStatisticsIndexing.getSpotsUsed().getValue() numSpotsRejected = numSpotsFound - numSpotsUsed beamShiftX = xsDataStatisticsIndexing.getBeamPositionShiftX().getValue() beamShiftY = xsDataStatisticsIndexing.getBeamPositionShiftY().getValue() spotDeviationR = xsDataStatisticsIndexing.getSpotDeviationPositional().getValue() try: spotDeviationTheta = xsDataStatisticsIndexing.getSpotDeviationAngular().getValue() except AttributeError: spotDeviationTheta = 0.0 diffractionRings = 0 # for now, don't see this in xml except message string reflections_used = 0 # for now reflections_used_in_indexing = 0 # for now rejectedReflections = 0 # for now xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation() xsDataMatrixA = xsDataOrientation.getMatrixA() rawOrientationMatrix_a_x = xsDataMatrixA.getM11() rawOrientationMatrix_a_y = xsDataMatrixA.getM12() rawOrientationMatrix_a_z = xsDataMatrixA.getM13() rawOrientationMatrix_b_x = xsDataMatrixA.getM21() rawOrientationMatrix_b_y = xsDataMatrixA.getM22() rawOrientationMatrix_b_z = xsDataMatrixA.getM23() rawOrientationMatrix_c_x = xsDataMatrixA.getM31() rawOrientationMatrix_c_y = xsDataMatrixA.getM32() rawOrientationMatrix_c_z = xsDataMatrixA.getM33() xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal() xsDataCell = xsDataCrystal.getCell() unitCell_alpha = xsDataCell.getAngle_alpha().getValue() unitCell_beta = xsDataCell.getAngle_beta().getValue() unitCell_gamma = xsDataCell.getAngle_gamma().getValue() unitCell_a = xsDataCell.getLength_a().getValue() unitCell_b = xsDataCell.getLength_b().getValue() unitCell_c = xsDataCell.getLength_c().getValue() mosaicity = xsDataCrystal.getMosaicity().getValue() xsSpaceGroup = xsDataCrystal.getSpaceGroup() spacegroup_name = xsSpaceGroup.getName().getValue() pointGroup = spacegroup_name # for now bravaisLattice = pointGroup # for now statusDescription = "ok" # for now try: spacegroup_number = xsSpaceGroup.getITNumber().getValue() except AttributeError: spacegroup_number = 0 xsStrategyResult = xsDataCharacterisation.getStrategyResult() resolutionObtained = -999 if xsStrategyResult != None: dna_have_strategy_results = 1 xsCollectionPlan = xsStrategyResult.getCollectionPlan() xsStrategySummary = xsCollectionPlan[0].getStrategySummary() resolutionObtained = xsStrategySummary.getRankingResolution().getValue() xsCollectionStrategy = xsCollectionPlan[0].getCollectionStrategy() xsSubWedge = xsCollectionStrategy.getSubWedge() for i in range(0, len(xsSubWedge)): xsExperimentalCondition = xsSubWedge[i].getExperimentalCondition() xsGoniostat = xsExperimentalCondition.getGoniostat() xsDetector = xsExperimentalCondition.getDetector() xsBeam = xsExperimentalCondition.getBeam() dna_strategy_start = xsGoniostat.getRotationAxisStart().getValue() dna_strategy_start = dna_strategy_start - (dna_strategy_start % 0.1) dna_strategy_range = xsGoniostat.getOscillationWidth().getValue() dna_strategy_range = dna_strategy_range - (dna_strategy_range % 0.1) dna_strategy_end = xsGoniostat.getRotationAxisEnd().getValue() dna_strategy_end = (dna_strategy_end - (dna_strategy_end % 0.1)) + dna_strategy_range dna_strat_dist = xsDetector.getDistance().getValue() dna_strat_dist = dna_strat_dist - (dna_strat_dist % 1) dna_strategy_exptime = xsBeam.getExposureTime().getValue() # wtf? dna_strategy_exptime = dna_strategy_exptime-(dna_strategy_exptime%.2) program = "edna-1.0" # for now ##### screeningoutputid = pxdb_lib.insert_dna_index_results(daq_lib.sweep_seq_id,daq_lib.get_field("xtal_id"),program,statusDescription,rejectedReflections,resolutionObtained,spotDeviationR,spotDeviationTheta,beamShiftX,beamShiftY,numSpotsFound,numSpotsUsed,numSpotsRejected,mosaicity,diffractionRings,spacegroup_name,pointGroup,bravaisLattice,rawOrientationMatrix_a_x,rawOrientationMatrix_a_y,rawOrientationMatrix_a_z,rawOrientationMatrix_b_x,rawOrientationMatrix_b_y,rawOrientationMatrix_b_z,rawOrientationMatrix_c_x,rawOrientationMatrix_c_y,rawOrientationMatrix_c_z,unitCell_a,unitCell_b,unitCell_c,unitCell_alpha,unitCell_beta,unitCell_gamma) dna_comment = ( "spacegroup = " + str(spacegroup_name) + " mosaicity = " + str(mosaicity) + " resolutionHigh = " + str(resolutionObtained) + " cell_a = " + str(unitCell_a) + " cell_b = " + str(unitCell_b) + " cell_c = " + str(unitCell_c) + " cell_alpha = " + str(unitCell_alpha) + " cell_beta = " + str(unitCell_beta) + " cell_gamma = " + str(unitCell_gamma) + " status = " + str(statusDescription) ) ##### print "\n\n skinner " + dna_comment + "\n" +str(daq_lib.sweep_seq_id) + "\n" print "\n\n skinner " + dna_comment + "\n" ##### pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment) if dna_have_strategy_results: ##### pxdb_lib.insert_to_screening_strategy_table(screeningoutputid,dna_strategy_start,dna_strategy_end,dna_strategy_range,dna_strategy_exptime,resolutionObtained,program) dna_strat_comment = ( "\ndna Strategy results: Start=" + str(dna_strategy_start) + " End=" + str(dna_strategy_end) + " Width=" + str(dna_strategy_range) + " Time=" + str(dna_strategy_exptime) + " Dist=" + str(dna_strat_dist) ) # characterizationResult = {} characterizationResultObj = {} # characterizationResult["type"] = "characterizationStrategy" # characterizationResult["timestamp"] = time.time() characterizationResultObj = { "strategy": { "start": dna_strategy_start, "end": dna_strategy_end, "width": dna_strategy_range, "exptime": dna_strategy_exptime, "detDist": dna_strat_dist, } } # characterizationResult["resultObj"] = characterizationResultObj db_lib.addResultforRequest("characterizationStrategy", charRequest["request_id"], characterizationResultObj) ##### pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_strat_comment) xsStrategyStatistics = xsCollectionPlan[0].getStatistics() xsStrategyResolutionBins = xsStrategyStatistics.getResolutionBin() now = time.time() # edna_isig_plot_filename = dirname[0:len(dirname)-1] + "/edna_isig_res_" + str(now) + ".txt" edna_isig_plot_filename = dirname[0 : len(dirname) - 1] + "/edna_isig_res.txt" isig_plot_file = open(edna_isig_plot_filename, "w") for i in range(0, len(xsStrategyResolutionBins) - 1): i_over_sigma_bin = xsStrategyResolutionBins[i].getIOverSigma().getValue() maxResolution_bin = xsStrategyResolutionBins[i].getMaxResolution().getValue() print str(maxResolution_bin) + " " + str(i_over_sigma_bin) isig_plot_file.write(str(maxResolution_bin) + " " + str(i_over_sigma_bin) + "\n") isig_plot_file.close() if dna_have_strategy_results: broadcast_output(dna_strat_comment) return 1
def dna_execute_collection3(dna_start,dna_range,dna_number_of_images,dna_exptime,dna_directory,prefix,start_image_number,overlap,dna_run_num,charRequest): global collect_and_characterize_success,dna_have_strategy_results,dna_have_index_results,picture_taken global dna_strategy_exptime,dna_strategy_start,dna_strategy_range,dna_strategy_end,dna_strat_dist global screeningoutputid characterizationParams = charRequest["request_obj"]["characterizationParams"] dna_res = float(characterizationParams["aimed_resolution"]) print("dna_res = " + str(dna_res)) dna_filename_list = [] print("number of images " + str(dna_number_of_images) + " overlap = " + str(overlap) + " dna_start " + str(dna_start) + " dna_range " + str(dna_range) + " prefix " + prefix + " start number " + str(start_image_number) + "\n") collect_and_characterize_success = 0 dna_have_strategy_results = 0 dna_have_index_results = 0 dg2rd = 3.14159265 / 180.0 if (daq_utils.detector_id == "ADSC-Q315"): det_radius = 157.5 elif (daq_utils.detector_id == "ADSC-Q210"): det_radius = 105.0 elif (daq_utils.detector_id == "PILATUS-6"): det_radius = 212.0 else: #default Pilatus det_radius = 212.0 ##### theta_radians = daq_lib.get_field("theta") * dg2rd theta_radians = 0.0 wave = 12398.5/beamline_lib.get_mono_energy() #for now dx = det_radius/(tan(2.0*(asin(wave/(2.0*dna_res)))-theta_radians)) print("distance = ",dx) #skinner - could move distance and wave and scan axis here, leave wave alone for now print("skinner about to take reference images.") for i in range(0,int(dna_number_of_images)): print("skinner prefix7 = " + prefix[0:7] + " " + str(start_image_number) + "\n") if (len(prefix)> 8): if ((prefix[0:7] == "postref") and (start_image_number == 1)): print("skinner postref bail\n") time.sleep(float(dna_number_of_images*float(dna_exptime))) break #skinner roi - maybe I can measure and use that for dna_start so that first image is face on. dna_start = daq_lib.get_field("datum_omega") colstart = float(dna_start) + (i*(abs(overlap)+float(dna_range))) dna_prefix = "ref-"+prefix #12/15 not sure why dna_run_num in prefix dna_prefix = "ref-"+prefix+"_"+str(dna_run_num) image_number = start_image_number+i dna_prefix_long = dna_directory+"/"+dna_prefix filename = daq_utils.create_filename(dna_prefix_long,image_number) beamline_lib.mvaDescriptor("omega",float(colstart)) ##### daq_lib.move_axis_absolute(daq_lib.get_field("scan_axis"),colstart) ##### daq_lib.take_image(colstart,dna_range,dna_exptime,filename,daq_lib.get_field("scan_axis"),0,1) daq_utils.take_crystal_picture(reqID=charRequest["request_id"]) ######### BECAUSE I FAKE IT imagesAttempted = collect_detector_seq(dna_range,dna_range,dna_exptime,dna_prefix,dna_directory,image_number) if (i==0): commFake = "ln -sf /nfs/skinner/testdata/johnPil6/data/B1GGTApo_9_00001.cbf " + filename else: commFake = "ln -sf /nfs/skinner/testdata/johnPil6/data/B1GGTApo_9_00181.cbf " + filename os.system(commFake) print(commFake) dna_filename_list.append(filename) ###4/16, don't bother with image server for now diffImgJpegData = daq_utils.diff2jpeg(filename,reqID=charRequest["request_id"]) #returns a dictionary # diffImgJpegData["timestamp"] = time.time() # imgRef = db_lib.addFile(diffImgJpegData["data"]) # diffImgJpegData["data"] = imgRef # imgRef = db_lib.addFile(diffImgJpegData["thumbData"]) # diffImgJpegData["thumbData"] = imgRef picture_taken = 1 # xml_from_file_list(flux,x_beamsize,y_beamsize,max_exptime_per_dc,aimed_completeness,file_list): edna_energy_ev = (12.3985/wave) * 1000.0 ##### xbeam_size = beamline_lib.get_motor_pos("slitHum") ##### ybeam_size = beamline_lib.get_motor_pos("slitVum") # if (xbeam_size == 0.0 or ybeam_size == 0.0): #don't know where to get these from yet if (1): xbeam_size = .1 ybeam_size = .16 else: xbeam_size = xbeam_size/1000 ybeam_size = ybeam_size/1000 aimed_completeness = characterizationParams['aimed_completeness'] aimed_multiplicity = characterizationParams['aimed_multiplicity'] aimed_resolution = characterizationParams['aimed_resolution'] aimed_ISig = characterizationParams['aimed_ISig'] timeout_check = 0; ##### while(not os.path.exists(dna_filename_list[len(dna_filename_list)-1])): #this waits for edna images if (0): timeout_check = timeout_check + 1 time.sleep(1.0) if (timeout_check > 10): break ##### flux = 10000000000 * beamline_lib.get_epics_pv("flux","VAL") flux = 600000000.0 #for now edna_input_filename = dna_directory + "/adsc1_in.xml" comm_s = "ssh -q xf17id1-srv1 \"" + os.environ["LSDCHOME"] + "/runEdna.py " + dna_directory + " " + dna_prefix + " " + str(aimed_ISig) + " " + str(flux) + " " + str(xbeam_size) + " " + str(ybeam_size) + " " + edna_input_filename + " " + str(charRequest["request_id"]) + "\"" print(comm_s) os.system(comm_s) return 1