Changeset fc4fec8 in sasview for src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py
- Timestamp:
- Sep 28, 2017 11:29:40 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 7d353af
- Parents:
- 01cda57
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/ResolutionCalculatorPanel.py
r01cda57 rfc4fec8 17 17 import sys 18 18 import logging 19 import math20 19 import os 21 20 import re … … 32 31 BG_WHITE = "background-color: rgb(255, 255, 255);" 33 32 BG_RED = "background-color: rgb(244, 170, 164);" 34 35 _INTENSITY = 36842836 _LAMBDA_ARRAY = [[0, 1e+16], [_INTENSITY, _INTENSITY]]37 33 38 34 … … 85 81 # dQ 2d image 86 82 self.image = None 87 # results of sigmas88 self.sigma_strings = ' '89 83 # Source selection dic 90 84 self.source_mass = _SOURCE_MASS … … 237 231 text_edit.setStyleSheet(QtCore.QString(BG_RED)) 238 232 self.cmdCompute.setEnabled(False) 239 logging.info('Qx and Qy are lists ofcomma-separated numbers.')233 logging.info('Qx and Qy should contain one or more comma-separated numbers.') 240 234 else: 241 235 text_edit.setStyleSheet(QtCore.QString(BG_WHITE)) … … 256 250 self.cmdCompute.setEnabled(False) 257 251 logging.info( 258 'Qx and Qy have the same number of elements.')252 'Qx and Qy should have the same number of elements.') 259 253 260 254 else: … … 410 404 411 405 self.image = None 412 self.sigma_strings = ' '413 406 self.source_mass = _SOURCE_MASS 414 407 self.det_coordinate = 'cartesian' … … 496 489 ymax = max(self.qy) 497 490 if not self._validate_q_input(self.qx, self.qy): 498 raise 491 raise ValueError("Invalid Q input") 499 492 except: 500 493 msg = "An error occurred during the resolution computation." … … 502 495 logging.warning(msg) 503 496 return 504 # raise ValueError, "Invalid Q Input..."505 497 506 498 # Validate the q inputs … … 523 515 # Compute and get the image plot 524 516 try: 525 self.sigma_strings = '\nResolution: Computation is finished. \n' 526 cal_res = threads.deferToThread(self.complete, 527 map(self._map_func, 528 self.qx, 529 self.qy, 530 qx_min, 531 qx_max, 532 qy_min, qy_max)[0], 533 self.image) 534 535 cal_res.addCallback(self.new2DPlot) 536 537 logging.info("Computation is in progress...") 517 cal_res = threads.deferToThread(self.map_wrapper, 518 self.calc_func, 519 self.qx, 520 self.qy, 521 qx_min, 522 qx_max, 523 qy_min, qy_max) 524 525 cal_res.addCallback(self.complete) 526 527 # logging.info("Computation is in progress...") 538 528 self.cmdCompute.setText('Wait...') 539 529 self.cmdCompute.setEnabled(False) … … 541 531 raise 542 532 543 def complete(self, image , elapsed=None):533 def complete(self, image): 544 534 """ 545 535 Complete computation … … 559 549 self.txt1DSigma.setText(str(sigma_1d)) 560 550 561 msg = self.sigma_strings562 logging.info(msg + '\n stop')563 551 self.cmdCompute.setText('Compute') 564 552 self.cmdCompute.setEnabled(True) 553 554 self.new2DPlot() 555 565 556 return 566 557 567 def _map_func(self, qx, qy, qx_min, qx_max, qy_min, qy_max):558 def map_wrapper(self, func, qx, qy, qx_min, qx_max, qy_min, qy_max): 568 559 """ 569 560 Prepare the Mapping for the computation … … 571 562 : return: image (numpy array) 572 563 """ 564 image = map(func, qx, qy, 565 qx_min, qx_max, 566 qy_min, qy_max)[0] 567 return image 568 569 def calc_func(self, qx, qy, qx_min, qx_max, qy_min, qy_max): 570 """ 571 Perform the calculation for a given set of Q values. 572 : return: image (numpy array) 573 """ 573 574 try: 574 575 qx_value = float(qx) 575 576 qy_value = float(qy) 576 except: 577 raise 577 except : 578 raise ValueError 579 578 580 # calculate 2D resolution distribution image 579 581 image = self.resolution.compute_and_plot(qx_value, qy_value, … … 581 583 qy_max, 582 584 self.det_coordinate) 583 # record sigmas584 self.sigma_strings += " At Qx = %s, Qy = %s; \n" % (qx_value, qy_value)585 self._sigma_strings()586 logging.info(self.sigma_strings)587 588 585 return image 589 586 … … 591 588 # Legacy validators 592 589 # ################################# 593 def _sigma_strings(self): 594 """ 595 Recode sigmas as strings 596 """ 597 sigma_r = self.formatNumber(self.resolution.sigma_1) 598 sigma_phi = self.formatNumber(self.resolution.sigma_2) 599 sigma_lamd = self.formatNumber(self.resolution.sigma_lamd) 600 sigma_1d = self.formatNumber(self.resolution.sigma_1d) 601 # Set output values 602 self.sigma_strings += " sigma_x = %s\n" % sigma_r 603 self.sigma_strings += " sigma_y = %s\n" % sigma_phi 604 self.sigma_strings += " sigma_lamd = %s\n" % sigma_lamd 605 self.sigma_strings += " sigma_1D = %s\n" % sigma_1d 606 607 def _string2list(self, string): 590 def _string2list(self, input_string): 608 591 """ 609 592 Change NNN, NNN to list,ie. [NNN, NNN] where NNN is a number 610 593 """ 611 new_ string= []594 new_numbers_list = [] 612 595 # check the number of floats 613 596 try: 614 strg = float( string)615 new_ string.append(strg)597 strg = float(input_string) 598 new_numbers_list.append(strg) 616 599 except: 617 string_split = string.split(',')600 string_split = input_string.split(',') 618 601 if len(string_split) == 2: 619 602 str_1 = string_split[0] 620 603 str_2 = string_split[1] 621 new_ string.append(float(str_1))622 new_ string.append(float(str_2))604 new_numbers_list.append(float(str_1)) 605 new_numbers_list.append(float(str_2)) 623 606 elif len(string_split) == 1: 624 607 str_1 = string_split[0] 625 new_ string.append(float(str_1))608 new_numbers_list.append(float(str_1)) 626 609 else: 627 msg = "The numbers must be one or two (separated by ',') ..."610 msg = "The numbers must be one or two (separated by ',')" 628 611 logging.info(msg) 629 612 raise RuntimeError, msg 630 613 631 return new_ string632 633 def _string2inputlist(self, string):614 return new_numbers_list 615 616 def _string2inputlist(self, input_string): 634 617 """ 635 618 Change NNN, NNN,... to list,ie. [NNN, NNN,...] where NNN is a number 636 : return new_string: string like list 637 """ 638 new_string = [] 639 string_split = string.split(',') 640 length = len(string_split) 641 for ind in range(length): 642 try: 643 value = float(string_split[ind]) 644 new_string.append(value) 645 except: 646 logging.error(sys.exc_value) 647 648 return new_string 649 650 def _str2longlist(self, string): 651 """ 652 Change NNN, NNN,... to list, NNN - NNN ; NNN to list, or float to list 653 : return new_string: string like list 654 """ 619 : return new_list: string like list 620 """ 621 new_list = [] 622 string_split = input_string.split(',') 623 try: 624 new_list = [float(t) for t in string_split] 625 except: 626 logging.error(sys.exc_value) 627 return new_list 628 629 def _str2longlist(self, input_string): 630 """ 631 Change NNN, NNN,... to list, NNN - NNN ; NNN to list, or float to list 632 : return new_string: string like list 633 """ 655 634 try: 656 635 # is float 657 out = [float( string)]636 out = [float(input_string)] 658 637 return out 659 638 except: … … 663 642 try: 664 643 # has a '-' 665 if string.count('-') > 0:666 value = string.split('-')644 if input_string.count('-') > 0: 645 value = input_string.split('-') 667 646 if value[1].count(';') > 0: 668 647 # has a ';' 669 648 last_list = value[1].split(';') 670 num = math.ceil(float(last_list[1]))649 num = numpy.ceil(float(last_list[1])) 671 650 max_value = float(last_list[0]) 672 651 self.num_wave = num … … 677 656 min_value = float(value[0]) 678 657 # make a list 679 bin_size = math.fabs(max_value - min_value) / (num - 1)658 bin_size = numpy.fabs(max_value - min_value) / (num - 1) 680 659 out = [min_value + bin_size * bnum for bnum in 681 660 range(num)] 682 661 return out 683 if string.count(',') > 0:684 out = self._string2inputlist( string)662 if input_string.count(',') > 0: 663 out = self._string2inputlist(input_string) 685 664 return out 686 665 except: … … 739 718 self.plotter = Plotter2DWidget(self, quickplot=True) 740 719 self.plotter.scale = 'linear' 720 self.plotter.cmap = None 741 721 layout = QtGui.QHBoxLayout() 742 722 layout.setContentsMargins(0, 0, 0, 0) … … 744 724 layout.addWidget(self.plotter) 745 725 746 def new2DPlot(self , res_cal):726 def new2DPlot(self): 747 727 """ 748 728 Create a new 2D data instance based on computing results
Note: See TracChangeset
for help on using the changeset viewer.