Changeset e73e723 in sasview


Ignore:
Timestamp:
Jul 12, 2016 10:10:33 AM (8 years ago)
Author:
lewis
Branches:
master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
20e09c6
Parents:
5878a9ea
Message:

Move string conversion from calculator class to panel

Location:
src/sas
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/corfunc/corfunc_calculator.py

    r5878a9ea re73e723  
    226226        } 
    227227 
    228         for key, val in params.iteritems(): 
    229             params[key] = self._round_sig_figs(val, 6) 
    230  
    231228        return params 
    232229 
     
    276273 
    277274        return s2 
    278  
    279     def _round_sig_figs(self, x, sigfigs): 
    280         """ 
    281         Round a number to a given number of significant figures. 
    282  
    283         :param x: The value to round 
    284         :param sigfigs: How many significant figures to round to 
    285         :return rounded_str: x rounded to the given number of significant 
    286             figures, as a string 
    287         """ 
    288         # Index of first significant digit 
    289         significant_digit = -int(np.floor(np.log10(np.abs(x)))) 
    290         # Number of digits required for correct number of sig figs 
    291         digits = significant_digit + (sigfigs - 1) 
    292         rounded = np.round(x, decimals=digits) 
    293         rounded_str = "{1:.{0}f}".format(sigfigs -1  + significant_digit, 
    294             rounded) 
    295         return rounded_str 
  • src/sas/sasgui/perspectives/corfunc/corfunc_panel.py

    r5878a9ea re73e723  
    11import wx 
    22import sys 
     3import numpy as np 
    34from wx.lib.scrolledpanel import ScrolledPanel 
    45from sas.sasgui.guiframe.events import PlotQrangeEvent 
     
    313314                error = True 
    314315            for key, value in params.iteritems(): 
    315                 self._output_boxes[key].SetValue(value) 
     316                rounded = self._round_sig_figs(value, 6) 
     317                self._output_boxes[key].SetValue(rounded) 
    316318        if error: 
    317319            msg = 'Not all parameters were able to be calculated' 
     
    605607        self._qmax2_input.Enable() 
    606608        self._background_input.Enable() 
     609 
     610    def _round_sig_figs(self, x, sigfigs): 
     611        """ 
     612        Round a number to a given number of significant figures. 
     613 
     614        :param x: The value to round 
     615        :param sigfigs: How many significant figures to round to 
     616        :return rounded_str: x rounded to the given number of significant 
     617            figures, as a string 
     618        """ 
     619        # Index of first significant digit 
     620        significant_digit = -int(np.floor(np.log10(np.abs(x)))) 
     621        # Number of digits required for correct number of sig figs 
     622        digits = significant_digit + (sigfigs - 1) 
     623        rounded = np.round(x, decimals=digits) 
     624        rounded_str = "{1:.{0}f}".format(sigfigs -1  + significant_digit, 
     625            rounded) 
     626        return rounded_str 
  • src/sas/sasgui/perspectives/corfunc/corfunc_state.py

    rd4f5637 re73e723  
    178178            for item in output_list: 
    179179                element = new_doc.createElement(item[0]) 
    180                 element.appendChild(new_doc.createTextNode(self.outputs[item[0]])) 
     180                value = self.outputs[item[0]] 
     181                element.appendChild(new_doc.createTextNode(str(value))) 
    181182                output.appendChild(element) 
    182183 
     
    240241                    parameter = get_content("ns:{}".format(item[0]), entry) 
    241242                    if parameter is not None: 
    242                         self.outputs[item[0]] = parameter.text.strip() 
     243                        self.outputs[item[0]] = float(parameter.text.strip()) 
    243244 
    244245 
Note: See TracChangeset for help on using the changeset viewer.