Changes in / [c7634fd:6bd4235] in sasview


Ignore:
Files:
1 added
7 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • build_tools/requirements.txt

    rc16172d r36ca21e  
    33pylint 
    44unittest-xml-reporting==1.10.0 
    5 pyparsing>=2.0 
     5pyparsing==1.5.5 
    66html5lib==0.95 
    77reportlab==2.5 
  • docs/sphinx-docs/source/user/marketplace.rst

    r1eb86a5 r59dfb53  
    66plug-in fitting models for *SasView* for all to use. 
    77 
    8 .. note::  
    9     These plug-in models require SasView version 4.0 or later. However,  
    10     not *all* models may work with *every* version of SasView because  
    11     of changes to our API. 
     8.. note:: These plug-in models require SasView version 4.0 or later. 
    129 
    1310Contributed models should be written in Python (only version 2.7.x is 
     
    1512combination of Python and C. You only need to upload the .py/.c source 
    1613code files to the Marketplace! 
    17  
    18 Please put a comment in your code to indicate which version of SasView you  
    19 wrote the model for. 
    2014 
    2115For guidance on how to write a plugin model see :ref:`Writing_a_Plugin` . It 
  • setup.py

    rc16172d r1a3602d  
    402402 
    403403required = [ 
    404     'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0', 
     404    'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing<2.0.0', 
    405405 
    406406    # 'lxml>=2.2.2', 
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    r4a8d55c ra58b5a0  
    3131FIELDS_2D = ('data', 'qx_data', 'qy_data', 'q_data', 'err_data', 
    3232                 'dqx_data', 'dqy_data', 'mask') 
    33 DEPRECATION_MESSAGE = ("\rThe extension of this file suggests the data set migh" 
    34                        "t not be fully reduced. Support for the reader associat" 
    35                        "ed with this file type has been removed. An attempt to " 
    36                        "load the file was made, but, should it be successful, " 
    37                        "SasView cannot guarantee the accuracy of the data.") 
     33 
    3834 
    3935class FileReader(object): 
     
    4440    # List of allowed extensions 
    4541    ext = ['.txt'] 
    46     # Deprecated extensions 
    47     deprecated_extensions = ['.asc', '.nxs'] 
    4842    # Bypass extension check and try to load anyway 
    4943    allow_all = False 
     
    9387                    if not self.f_open.closed: 
    9488                        self.f_open.close() 
    95                     if any(filepath.lower().endswith(ext) for ext in 
    96                            self.deprecated_extensions): 
    97                         self.handle_error_message(DEPRECATION_MESSAGE) 
    9889                    if len(self.output) > 0: 
    9990                        # Sort the data that's been loaded 
     
    155146        else: 
    156147            logger.warning(msg) 
    157             raise NoKnownLoaderException(msg) 
    158148 
    159149    def send_to_output(self): 
  • src/sas/sascalc/dataloader/loader.py

    r4a8d55c rdc8d1c2  
    9090            ascii_loader = ascii_reader.Reader() 
    9191            return ascii_loader.read(path) 
    92         except NoKnownLoaderException: 
    93             pass  # Try the Cansas XML reader 
    9492        except DefaultReaderException: 
    9593            pass  # Loader specific error to try the cansas XML reader 
     
    102100            cansas_loader = cansas_reader.Reader() 
    103101            return cansas_loader.read(path) 
    104         except NoKnownLoaderException: 
    105             pass  # Try the NXcanSAS reader 
    106102        except DefaultReaderException: 
    107103            pass  # Loader specific error to try the NXcanSAS reader 
  • src/sas/sascalc/fit/pagestate.py

    r3b070a0 r574adc7  
    646646                    name = value.split(':', 1)[1].strip() 
    647647                    file_value = "File name:" + name 
    648                     #Truncating string so print doesn't complain of being outside margins 
    649                     if sys.platform != "win32": 
    650                         MAX_STRING_LENGHT = 50 
    651                         if len(file_value) > MAX_STRING_LENGHT: 
    652                             file_value = "File name:.."+file_value[-MAX_STRING_LENGHT+10:] 
    653648                    file_name = CENTRE % file_value 
    654649                    if len(title) == 0: 
     
    726721        html_str, text_str, title = self._get_report_string() 
    727722        # Allow 2 figures to append 
    728         #Constraining image width for OSX and linux, so print doesn't complain of being outside margins 
    729         if sys.platform == "win32": 
    730             image_links = [FEET_2%fig for fig in fig_urls] 
    731         else: 
    732             image_links = [FEET_2_unix%fig for fig in fig_urls] 
     723        image_links = [FEET_2%fig for fig in fig_urls] 
     724 
    733725        # final report html strings 
    734726        report_str = html_str + ELINE.join(image_links) 
    735         report_str += FEET_3 
     727 
    736728        return report_str, text_str 
    737729 
     
    13761368""" 
    13771369FEET_2 = \ 
    1378 """<img src="%s"></img> 
    1379 """ 
    1380 FEET_2_unix = \ 
    1381 """<img src="%s" width="540"></img> 
     1370"""<img src="%s" ></img> 
    13821371""" 
    13831372FEET_3 = \ 
  • src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py

    r2924532 r20fa5fe  
    185185            try: 
    186186                message = "Loading {}...\n".format(p_file) 
    187                 self.load_update(message=message, info="info") 
     187                self.load_update(output=output, message=message, info="info") 
    188188                temp = self.loader.load(p_file, format) 
    189189                if not isinstance(temp, list): 
     
    201201                        else: 
    202202                            file_errors[basename] = [error_message] 
    203  
    204                 self.load_update(message="Loaded {}\n".format(p_file), 
    205                                  info="info") 
     203                        self.load_update(output=output, 
     204                            message=error_message, info="warning") 
     205 
     206                self.load_update(output=output, 
     207                message="Loaded {}\n".format(p_file), 
     208                info="info") 
    206209 
    207210            except NoKnownLoaderException as e: 
    208211                exception_occurred = True 
     212                logger.error(e.message) 
     213 
    209214                error_message = "Loading data failed!\n" + e.message 
    210                 self.load_complete(output=None, 
    211                                    message=error_message, 
    212                                    info="warning") 
     215                self.load_update(output=None, message=e.message, info="warning") 
    213216 
    214217            except Exception as e: 
    215218                exception_occurred = True 
     219                logger.error(e.message) 
     220 
    216221                file_err = "The Data file you selected could not be " 
    217222                file_err += "loaded.\nMake sure the content of your file" 
     
    220225                file_err += " following:\n" 
    221226                file_err += e.message 
    222                 self.load_complete(output=None, 
    223                                    message=file_err, 
    224                                    info="error") 
     227                file_errors[basename] = [file_err] 
    225228 
    226229        if len(file_errors) > 0: 
    227230            error_message = "" 
    228231            for filename, error_array in file_errors.iteritems(): 
    229                 error_message += "The following issues were found whilst " 
     232                error_message += "The following errors occured whilst " 
    230233                error_message += "loading {}:\n".format(filename) 
    231234                for message in error_array: 
    232235                    error_message += message + "\n" 
    233                 error_message = error_message[:-1] 
    234             self.load_complete(output=output, 
    235                                message=error_message, 
    236                                info="error") 
    237  
    238         elif not exception_occurred: # Everything loaded as expected 
     236                error_message += "\n" 
     237            if not exception_occurred: # Some data loaded but with errors 
     238                self.load_update(output=output, message=error_message, info="error") 
     239 
     240        if not exception_occurred: # Everything loaded as expected 
    239241            self.load_complete(output=output, message="Loading data complete!", 
    240242                               info="info") 
     
    242244            self.load_complete(output=None, message=error_message, info="error") 
    243245 
    244     def load_update(self, message="", info="warning"): 
     246 
     247    def load_update(self, output=None, message="", info="warning"): 
    245248        """ 
    246249        print update on the status bar 
    247250        """ 
    248251        if message != "": 
    249             wx.PostEvent(self.parent, StatusEvent(status=message, 
    250                                                   info=info, 
     252            wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    251253                                                  type="progress")) 
    252254 
     
    255257         post message to status bar and return list of data 
    256258        """ 
    257         wx.PostEvent(self.parent, StatusEvent(status=message, 
    258                                               info=info, 
     259        wx.PostEvent(self.parent, StatusEvent(status=message, info=info, 
    259260                                              type="stop")) 
    260261        if output is not None: 
  • src/sas/sasgui/guiframe/media/data_formats_help.rst

    r1eb86a5 r959eb01  
    2828 
    2929*  .TXT 
     30*  .ASC 
    3031*  .DAT 
    3132*  .XML (in canSAS format v1.0 and 1.1) 
    32 *  .H5  (as NeXus NXcanSAS only) 
    33 *  .NXS (as NeXus NXcanSAS only) 
    34  
    35 .. note:: 
    36     From SasView version 4.2 onwards files written in the NIST .ASC format are no longer read. This is because that  
    37     format normally represents *raw* and not reduced data. 
    3833 
    3934If using CSV output from, for example, a spreadsheet, ensure that it is not using commas as delimiters for thousands. 
     
    4540 
    4641For a description of the ISIS 1D format see: 
    47 https://www.isis.stfc.ac.uk/Pages/colette-ascii-file-format-descriptions.pdf 
     42http://www.isis.stfc.ac.uk/instruments/loq/software/colette-ascii-file-format-descriptions9808.pdf 
    4843 
    4944For a description of the NXcanSAS format see: 
     
    6358-------------- 
    6459 
    65 SasView will read ASCII ('text') files in the NIST 2D format (with the extension .DAT) or files in the NeXus NXcanSAS (HDF5) format (with the extension .H5 or .NXS). File extensions are not case-sensitive. Both of these formats are written by the `Mantid Framework <http://www.mantidproject.org/>`_. 
     60SasView will read ASCII ('text') files in the NIST 2D format (with the extensions .ASC or .DAT) or files in the NeXus NXcanSAS (HDF5) format (with the extension .H5). File extensions are not case-sensitive. Both of these formats are written by the `Mantid Framework <http://www.mantidproject.org/>`_. 
    6661 
    6762Most of the header lines in the NIST 2D format can actually be removed except the last line, and only the first three columns (*Qx, Qy,* and *I(Qx,Qy)*) are actually required. 
    68  
    69 .. note:: 
    70     From SasView version 4.2 onwards files written in the NIST .ASC format are no longer read. This is because that  
    71     format normally represents *raw* and not reduced data. 
    72  
    73 .. note:: 
    74     SasView does not read the standard NeXus format, only the NXcanSAS subset.  
    7563 
    7664The SasView :ref:`File_Converter_Tool` available in SasView 4.1 onwards can be used to convert data sets in the 2D BSL/OTOKO format into the NeXus NXcanSAS (HDF5) format. 
  • src/sas/sasgui/guiframe/report_dialog.py

    r91552b5 r69a6897  
    2727class BaseReportDialog(wx.Dialog): 
    2828 
    29     def __init__(self, report_list, imgRAM, fig_urls, *args, **kwds): 
     29    def __init__(self, report_list, *args, **kwds): 
    3030        """ 
    3131        Initialization. The parameters added to Dialog are: 
     
    3737        kwds["image"] = 'Dynamic Image' 
    3838 
    39         #MemoryFSHandle for storing images 
    40         self.imgRAM = imgRAM 
    41         #Images location in urls 
    42         self.fig_urls = fig_urls 
    4339        # title 
    4440        self.SetTitle("Report") 
     
    7975        hbox.Add(button_print) 
    8076 
    81         if sys.platform != "darwin": 
    82             button_save = wx.Button(self, wx.NewId(), "Save") 
    83             button_save.SetToolTipString("Save this report.") 
    84             button_save.Bind(wx.EVT_BUTTON, self.onSave, id=button_save.GetId()) 
    85             hbox.Add(button_save) 
     77        button_save = wx.Button(self, wx.NewId(), "Save") 
     78        button_save.SetToolTipString("Save this report.") 
     79        button_save.Bind(wx.EVT_BUTTON, self.onSave, id=button_save.GetId()) 
     80        hbox.Add(button_save) 
    8681 
    8782        # panel for report page 
     
    116111        printh.PrintText(self.report_html) 
    117112 
    118  
    119113    def OnClose(self, event=None): 
    120114        """ 
     
    122116        : event: Close button event 
    123117        """ 
    124         for fig in self.fig_urls: 
    125             self.imgRAM.RemoveFile(fig) 
    126  
    127118        self.Close() 
    128119 
  • src/sas/sasgui/perspectives/calculator/calculator.py

    r61bfd36 r235f514  
    8686                ("Generic Scattering Calculator", 
    8787                        gensas_help, self.on_gen_model), 
    88                 ("Orientation Viewer", "Show 3-D view of oriented shape", self.on_show_orientation), 
    8988                ("Python Shell/Editor", pyconsole_help, self.on_python_console), 
    9089                ("Image Viewer", imageviewer_help, self.on_image_viewer), ] 
     
    191190            self.gen_frame.Show(False) 
    192191        self.gen_frame.Show(True) 
    193  
    194     def on_show_orientation(self, event): 
    195         """ 
    196         Make sasmodels orientation & jitter viewer available 
    197         """ 
    198         from sasmodels.jitter import run 
    199         run() 
    200192 
    201193    def on_image_viewer(self, event): 
  • src/sas/sasgui/perspectives/calculator/media/resolution_calculator_help.rst

    r3bd58f0 r5ed76f8  
    2929   careful to note that distances are specified in cm! 
    3030 
    31 4) Enter values for the source wavelength(s), $\lambda$, and its spread (= $\mathrm{FWHM}/\lambda$). 
     314) Enter values for the source wavelength(s), $\lambda$, and its spread (= $\text{FWHM}/\lambda$). 
    3232 
    3333   For monochromatic sources, the inputs are just one value. For TOF sources, 
     
    5858   region near the beam block/stop 
    5959 
    60    [i.e., $Q < (2 \pi \cdot w) / (d_s \cdot \lambda_\mathrm{min})$, where $w$ is the beam block diameter, $d_s$ is the sample-to-detector distance, and $\lambda_\mathrm{min}$ is the minimum wavelength.] 
     60   [i.e., $Q < (2 \pi \cdot \text{beam block diameter}) / (\text{sample-to-detector distance} \cdot \lambda_\text{min})$] 
    6161 
    6262   the variance is slightly under estimated. 
  • src/sas/sasgui/perspectives/calculator/media/sas_calculator_help.rst

    r55abe4f r1b67f3e  
    8888 
    8989Now let us assume that the angles of the $\vec Q$ vector and the spin-axis ($x'$) 
    90 to the $x$-axis are $\phi$ and $\theta_\mathrm{up}$ respectively (see above). Then, 
     90to the $x$-axis are $\phi$ and $\theta_\text{up}$ respectively (see above). Then, 
    9191depending upon the polarization (spin) state of neutrons, the scattering 
    9292length densities, including the nuclear scattering length density ($\beta_N$) 
     
    107107.. math:: 
    108108 
    109     M_{\perp x'} &= M_{0q_x}\cos\theta_\mathrm{up} + M_{0q_y}\sin\theta_\mathrm{up} \\ 
    110     M_{\perp y'} &= M_{0q_y}\cos\theta_\mathrm{up} - M_{0q_x}\sin\theta_\mathrm{up} \\ 
     109    M_{\perp x'} &= M_{0q_x}\cos\theta_\text{up} + M_{0q_y}\sin\theta_\text{up} \\ 
     110    M_{\perp y'} &= M_{0q_y}\cos\theta_\text{up} - M_{0q_x}\sin\theta_\text{up} \\ 
    111111    M_{\perp z'} &= M_{0z} \\ 
    112112    M_{0q_x} &= (M_{0x}\cos\phi - M_{0y}\sin\phi)\cos\phi \\ 
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    rd247504b r2469df7  
    391391        self._msg_box.SetLabel(msg) 
    392392        self._msg_box.SetForegroundColour(color) 
    393         self._set_model_list() 
    394393        if self.parent.parent is not None: 
    395394            from sas.sasgui.guiframe.events import StatusEvent 
     
    433432        if len(main_list) > 1: 
    434433            main_list.sort() 
    435         self.model1.Clear() 
    436         self.model2.Clear() 
    437434        for idx in range(len(main_list)): 
    438435            self.model1.Append(str(main_list[idx]), idx) 
     
    663660        Do the layout for parameter related widgets 
    664661        """ 
    665         param_txt = wx.StaticText(self, -1, 'Fit Parameters: ') 
    666  
    667         param_tip = "#Set the parameters and their initial values.\n" 
     662        param_txt = wx.StaticText(self, -1, 'Fit Parameters NOT requiring' + \ 
     663                                  ' polydispersity (if any): ') 
     664 
     665        param_tip = "#Set the parameters NOT requiring polydispersity " + \ 
     666        "and their initial values.\n" 
    668667        param_tip += "#Example:\n" 
    669668        param_tip += "A = 1\nB = 1" 
     
    679678                                  (self.param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
    680679 
     680        # Parameters with polydispersity 
     681        pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring ' + \ 
     682                                     'polydispersity (if any): ') 
     683 
     684        pd_param_tip = "#Set the parameters requiring polydispersity and " + \ 
     685        "their initial values.\n" 
     686        pd_param_tip += "#Example:\n" 
     687        pd_param_tip += "C = 2\nD = 2" 
     688        newid = wx.NewId() 
     689        self.pd_param_tcl = EditWindow(self, newid, wx.DefaultPosition, 
     690                                    wx.DefaultSize, 
     691                                    wx.CLIP_CHILDREN | wx.SUNKEN_BORDER) 
     692        self.pd_param_tcl.setDisplayLineNumbers(True) 
     693        self.pd_param_tcl.SetToolTipString(pd_param_tip) 
     694 
     695        self.param_sizer.AddMany([(pd_param_txt, 0, wx.LEFT, 10), 
     696                                  (self.pd_param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
    681697 
    682698    def _layout_function(self): 
     
    880896            description = self.desc_tcl.GetValue() 
    881897            param_str = self.param_tcl.GetText() 
     898            pd_param_str = self.pd_param_tcl.GetText() 
    882899            func_str = self.function_tcl.GetText() 
    883900            # No input for the model function 
     
    885902                if func_str.count('return') > 0: 
    886903                    self.write_file(self.fname, name, description, param_str, 
    887                                     func_str) 
     904                                    pd_param_str, func_str) 
    888905                    try: 
    889906                        result, msg = check_model(self.fname), None 
     
    925942        self.warning = msg 
    926943 
    927     def write_file(self, fname, name, desc_str, param_str, func_str): 
     944    def write_file(self, fname, name, desc_str, param_str, pd_param_str, func_str): 
    928945        """ 
    929946        Write content in file 
     
    932949        :param desc_str: content of the description strings 
    933950        :param param_str: content of params; Strings 
     951        :param pd_param_str: content of params requiring polydispersity; Strings 
    934952        :param func_str: content of func; Strings 
    935953        """ 
     
    945963        # Write out parameters 
    946964        param_names = []    # to store parameter names 
     965        pd_params = [] 
    947966        out_f.write('parameters = [ \n') 
    948967        out_f.write('#   ["name", "units", default, [lower, upper], "type", "description"],\n') 
     
    951970            out_f.write("    ['%s', '', %s, [-inf, inf], '', '%s'],\n" 
    952971                        % (pname, pvalue, desc)) 
     972        for pname, pvalue, desc in self.get_param_helper(pd_param_str): 
     973            param_names.append(pname) 
     974            pd_params.append(pname) 
     975            out_f.write("    ['%s', '', %s, [-inf, inf], 'volume', '%s'],\n" 
     976                        % (pname, pvalue, desc)) 
    953977        out_f.write('    ]\n') 
    954978 
    955979        # Write out function definition 
    956         out_f.write('\n') 
    957980        out_f.write('def Iq(%s):\n' % ', '.join(['x'] + param_names)) 
    958981        out_f.write('    """Absolute scattering"""\n') 
     
    964987            out_f.write('    import numpy as np') 
    965988        for func_line in func_str.split('\n'): 
    966             out_f.write('%s%s\n' % ('    ', func_line)) 
     989            out_f.write('%s%s\n' % (spaces4, func_line)) 
    967990        out_f.write('## uncomment the following if Iq works for vector x\n') 
    968991        out_f.write('#Iq.vectorized = True\n') 
     992 
     993        # If polydisperse, create place holders for form_volume, ER and VR 
     994        if pd_params: 
     995            out_f.write('\n') 
     996            out_f.write(CUSTOM_TEMPLATE_PD % {'args': ', '.join(pd_params)}) 
    969997 
    970998        # Create place holder for Iqxy 
     
    10971125description = """%(description)s""" 
    10981126 
     1127''' 
     1128 
     1129CUSTOM_TEMPLATE_PD = '''\ 
     1130def form_volume(%(args)s): 
     1131    """ 
     1132    Volume of the particles used to compute absolute scattering intensity 
     1133    and to weight polydisperse parameter contributions. 
     1134    """ 
     1135    return 0.0 
     1136 
     1137def ER(%(args)s): 
     1138    """ 
     1139    Effective radius of particles to be used when computing structure factors. 
     1140 
     1141    Input parameters are vectors ranging over the mesh of polydispersity values. 
     1142    """ 
     1143    return 0.0 
     1144 
     1145def VR(%(args)s): 
     1146    """ 
     1147    Volume ratio of particles to be used when computing structure factors. 
     1148 
     1149    Input parameters are vectors ranging over the mesh of polydispersity values. 
     1150    """ 
     1151    return 1.0 
    10991152''' 
    11001153 
  • src/sas/sasgui/perspectives/calculator/resolution_calculator_panel.py

    r1cf490b6 r7432acb  
    1818matplotlib.use('WXAgg') 
    1919from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas 
    20 from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as Toolbar 
     20from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar 
    2121from matplotlib.backend_bases import FigureManagerBase 
    2222# Wx-Pylab magic for displaying plots within an application's window. 
  • src/sas/sasgui/perspectives/corfunc/media/corfunc_help.rst

    r501712f rad476d1  
    188188*   Average Hard Block Thickness :math:`= L_c` 
    189189*   Average Core Thickness :math:`= D_0` 
    190 *   Average Interface Thickness :math:`= D_{tr}` 
    191 *   Polydispersity :math:`= \Gamma_{\mathrm{min}}/\Gamma_{\mathrm{max}}` 
     190*   Average Interface Thickness :math:`\text{} = D_{tr}` 
     191*   Polydispersity :math:`= \Gamma_{\text{min}}/\Gamma_{\text{max}}` 
    192192*   Local Crystallinity :math:`= L_c/L_p` 
    193193 
     
    203203*   Bound Fraction :math:`= <p>` 
    204204*   Second Moment :math:`= \sigma` 
    205 *   Maximum Extent :math:`= \delta_{\mathrm{h}}` 
     205*   Maximum Extent :math:`= \delta_{\text{h}}` 
    206206*   Adsorbed Amount :math:`= \Gamma` 
    207207 
  • src/sas/sasgui/perspectives/file_converter/media/file_converter_help.rst

    rfafb396 r59decb81  
    1919    or with a comma or semi-colon delimiter 
    2020*   2D `ISIS ASCII formatted 
    21     <https://www.isis.stfc.ac.uk/Pages/colette-ascii-file-format-descriptions.pdf>`_ data 
     21    <http://www.isis.stfc.ac.uk/instruments/loq/software/ 
     22    colette-ascii-file-format-descriptions9808.pdf>`_ data 
    2223*   `1D BSL/OTOKO format 
    2324    <http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/ 
  • src/sas/sasgui/perspectives/fitting/basepage.py

    rc192960 r58a8f76  
    641641        # get the strings for report 
    642642        report_str, text_str = self.state.report(fig_urls=refs) 
     643 
    643644        # Show the dialog 
    644645        report_list = [report_str, text_str, images] 
    645         dialog = ReportDialog(report_list, imgRAM, refs, None, wx.ID_ANY, "") 
     646        dialog = ReportDialog(report_list, None, wx.ID_ANY, "") 
    646647        dialog.Show() 
    647648 
     
    676677            refs.append('memory:' + name) 
    677678            imgRAM.AddFile(name, canvas.bitmap, wx.BITMAP_TYPE_PNG) 
     679 
    678680            # append figs 
    679681            images.append(fig) 
     
    13651367            except Exception: 
    13661368                logger.error(traceback.format_exc()) 
    1367             index, selection = self._find_polyfunc_selection(disp_model) 
     1369            selection = self._find_polyfunc_selection(disp_model) 
    13681370            for list in self.fittable_param: 
    13691371                if list[1] == key and list[7] is not None: 
    1370                     list[7].SetSelection(index) 
     1372                    list[7].SetSelection(selection) 
    13711373                    # For the array disp_model, set the values and weights 
    1372                     if selection == 'array': 
     1374                    if selection == 1: 
    13731375                        disp_model.set_weights(self.values[key], 
    13741376                                               self.weights[key]) 
     
    13831385                            logger.error(traceback.format_exc()) 
    13841386            # For array, disable all fixed params 
    1385             if selection == 'array': 
     1387            if selection == 1: 
    13861388                for item in self.fixed_param: 
    13871389                    if item[1].split(".")[0] == key.split(".")[0]: 
     
    14701472            # we need to check here ourselves. 
    14711473            if not is_modified: 
    1472                 is_modified = self._check_value_enter(self.fittable_param) 
    1473                 is_modified = self._check_value_enter( 
    1474                     self.fixed_param) or is_modified 
    1475                 is_modified = self._check_value_enter( 
    1476                     self.parameters) or is_modified 
     1474                is_modified = (self._check_value_enter(self.fittable_param) 
     1475                               or self._check_value_enter(self.fixed_param) 
     1476                               or self._check_value_enter(self.parameters)) 
    14771477 
    14781478            # Here we should check whether the boundaries have been modified. 
     
    15361536                        data=[self.data]) 
    15371537            # Check the values 
    1538             is_modified = self._check_value_enter(self.fittable_param) 
    1539             is_modified = self._check_value_enter(self.fixed_param) or is_modified 
    1540             is_modified = self._check_value_enter(self.parameters) or is_modified 
     1538            is_modified = (self._check_value_enter(self.fittable_param) 
     1539                           or self._check_value_enter(self.fixed_param) 
     1540                           or self._check_value_enter(self.parameters)) 
    15411541 
    15421542            # If qmin and qmax have been modified, update qmin and qmax and 
     
    23242324 
    23252325            # Update value in model if it has changed 
    2326             if (value != self.model.getParam(name) or 
    2327                     (np.isnan(value) and np.isnan(self.model.getParam(name)))): 
     2326            if value != self.model.getParam(name): 
    23282327                self.model.setParam(name, value) 
    23292328                is_modified = True 
     
    26692668    def _find_polyfunc_selection(self, disp_func=None): 
    26702669        """ 
    2671         Find Combobox selection from disp_func 
     2670        FInd Comboox selection from disp_func 
    26722671 
    26732672        :param disp_function: dispersion distr. function 
     
    26762675        if disp_func is not None: 
    26772676            try: 
    2678                 return (list(POLYDISPERSITY_MODELS).index(disp_func.type), 
    2679                        disp_func.type) 
     2677                return POLYDISPERSITY_MODELS.values().index(disp_func.__class__) 
    26802678            except ValueError: 
    26812679                pass  # Fall through to default class 
    2682         return (list(POLYDISPERSITY_MODELS).index('gaussian'), 'gaussian') 
     2680        return POLYDISPERSITY_MODELS.keys().index('gaussian') 
    26832681 
    26842682    def on_reset_clicked(self, event): 
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    ra7c6f38 rbfeb823  
    365365        # StaticText for chi2, N(for fitting), Npts + Log/linear spacing 
    366366        self.tcChi = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 
    367         self.tcChi.SetToolTipString("Chi2/DOF (DOF=Npts-Npar fitted)") 
     367        self.tcChi.SetToolTipString("Chi2/Npts(Fit)") 
    368368        self.Npts_fit = BGTextCtrl(self, wx.ID_ANY, "-", size=(75, 20), style=0) 
    369369        self.Npts_fit.SetToolTipString( 
     
    391391        self.points_sizer.Add(self.pointsbox) 
    392392 
    393         box_description_1 = wx.StaticText(self, wx.ID_ANY, 'Reduced Chi2') 
     393        box_description_1 = wx.StaticText(self, wx.ID_ANY, '   Chi2/Npts') 
    394394        box_description_2 = wx.StaticText(self, wx.ID_ANY, 'Npts(Fit)') 
    395395 
  • src/sas/sasgui/perspectives/fitting/media/fitting_help.rst

    r8b89396 r5005ae0  
    180180*checked*\ . 
    181181 
     182Also note that the 'Fit Parameters' have been split into two sections: those 
     183which can be polydisperse (shape and orientation parameters) and those which are 
     184not (eg, scattering length densities). 
     185 
    182186A model file generated by this option can be viewed and further modified using 
    183187the :ref:`Advanced_Plugin_Editor` . 
    184188 
    185 Note that the New Plugin Model Feature currently does not allow for parameters 
    186 to be polydisperse.  However they can be edited in the Advanced Editor. 
    187  
    188  
    189 **SasView version 4.2** made it possible to specify whether a plugin created 
    190 with the *New Plugin Model* dialog is actually a form factor P(Q) or a structure 
    191 factor S(Q). To do this, simply add one or other of the following lines under 
    192 the *import* statements. 
     189**SasView version 4.2** made it possible to specify whether a plugin created with 
     190the *New Plugin Model* dialog is actually a form factor P(Q) or a structure factor 
     191S(Q). To do this, simply add one or other of the following lines under the *import* 
     192statements. 
    193193 
    194194For a form factor:: 
     
    200200     structure_factor = True 
    201201 
    202 If the plugin is a structure factor it is *also* necessary to add two variables 
    203 to the parameter list:: 
     202If the plugin is a structure factor it is *also* necessary to add two variables to 
     203the parameter list:: 
    204204 
    205205     parameters = [ 
     
    426426See :ref:`Assessing_Fit_Quality`. 
    427427 
    428 The objective of model-fitting is to find a *physically-plausible* model, and 
    429 set of model parameters, that generate a theory that reproduces the experimental 
    430 data and minimizes the values of the residuals. 
     428The objective of model-fitting is to find a *physically-plausible* model, and set 
     429of model parameters, that generate a theory that reproduces the experimental data 
     430and gives residual values as close to zero as possible. 
    431431 
    432432Change the default values of the model parameters by hand until the theory line 
    433 starts to represent the experimental data. Then check the tick boxes alongside 
    434 the 'background' and 'scale' parameters. Click the *Fit* button. SasView 
    435 will optimise the values of the 'background' and 'scale' and also display the 
    436 corresponding uncertainties on the optimised values. 
    437  
    438 .. note:: 
    439    If the uncertainty on a fitted parameter is unrealistically large, or if it 
    440    displays as NaN, the model is most likely a poor representation of the data, 
    441    the parameter in question is highly correlated with one or more of the other 
    442    fitted parameters, or the model is relatively insensitive to the value of 
    443    that particular parameter. 
    444  
    445 In the bottom left corner of the *Fit Page* is a box displaying a normalised 
    446 value of the statistical $\chi^2$ parameter (the reduced $\chi^2$, 
    447 See :ref:`Assessing_Fit_Quality`) returned by the optimiser. 
     433starts to represent the experimental data. Then uncheck the tick boxes alongside 
     434all parameters *except* the 'background' and the 'scale'. Click the *Fit* button. 
     435SasView will optimise the values of the 'background' and 'scale' and also display 
     436the corresponding uncertainties on the optimised values. 
     437 
     438*NB: If no uncertainty is shown it generally means that the model is not very* 
     439*dependent on the corresponding parameter (or that one or more parameters are* 
     440*'correlated').* 
     441 
     442In the bottom left corner of the *Fit Page* is a box displaying the normalised value 
     443of the statistical $\chi^2$ parameter returned by the optimiser. 
    448444 
    449445Now check the box for another model parameter and click *Fit* again. Repeat this 
    450 process until all relevant parameters are checked and have been optimised. As 
    451 the fit of the theory to the experimental data improves, the value of 'Reduced 
    452 Chi2' will decrease. A good model fit should produce values of Reduced Chi2 
    453 close to one, and certainly << 100. See :ref:`Assessing_Fit_Quality`. 
     446process until most or all parameters are checked and have been optimised. As the 
     447fit of the theory to the experimental data improves the value of 'chi2/Npts' will 
     448decrease. A good model fit should easily produce values of 'chi2/Npts' that are 
     449close to one, and certainly <100. See :ref:`Assessing_Fit_Quality`. 
    454450 
    455451SasView has a number of different optimisers (see the section :ref:`Fitting_Options`). 
     
    466462*the Data Explorer is checked (see the section* :ref:`Loading_data` *).* 
    467463 
    468 This mode is an extension of the :ref:`Single_Fit_Mode` that allows for some 
    469 relatively extensive constraints between fitted parameters in a single *FitPage* 
    470 or between several *FitPage*'s (eg, to constrain all fitted parameters to be the 
    471 same in a contrast series of *FitPages* except for the solvent sld parameter, 
    472 constrain the length to be twice that of the radius in a single *FitPage*, 
    473 fix the radius of the sphere in one *FitPage* to be the same as the radius of 
    474 the cylinder in a second *FitPage*, etc). 
     464This mode is an extension of the :ref:`Single_Fit_Mode` that fits two or more data 
     465sets *to the same model* simultaneously. If necessary it is possible to constrain 
     466fit parameters between data sets (eg, to fix a background level, or radius, etc). 
    475467 
    476468If the data to be fit are in multiple files, load each file, then select each file 
     
    509501next to *Add Constraint?* in the *Fit Constraints* box. 
    510502 
    511 To constrain all identically named parameters to fit *simultaneously* to the 
    512 same value across all the *Fitpages* use the *Easy Setup* drop-down buttons in 
    513 the *Const & Simul Fit* page. 
    514  
    515503*NB: You can only constrain parameters that are set to refine.* 
     504 
     505When ready, click the *Fit* button on the *Const & Simul Fit* page, NOT the *Fit* 
     506button on the individual *FitPage*'s. 
     507 
     508Simultaneous Fits without Constraints 
     509^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
     510 
     511The results of the model-fitting will be returned to each of the individual 
     512*FitPage*'s. 
     513 
     514Note that the chi2/Npts value returned is the SUM of the chi2/Npts of each fit. To 
     515see the chi2/Npts value for a specific *FitPage*, click the *Compute* button at the 
     516bottom of that *FitPage* to recalculate. Also see :ref:`Assessing_Fit_Quality`. 
     517 
     518Simultaneous Fits with Constraints 
     519^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
     520 
     521Use the *Easy Setup* drop-down buttons in the *Const & Simul Fit* page to set 
     522up constraints between *FitPage*'s. 
    516523 
    517524Constraints will generally be of the form 
     
    528535Many constraints can be entered for a single fit. 
    529536 
    530 When ready, click the *Fit* button on the *Const & Simul Fit* page, NOT the *Fit* 
    531 button on the individual *FitPage*'s. 
    532  
    533537The results of the model-fitting will be returned to each of the individual 
    534538*FitPage*'s. 
    535539 
    536 Note that the Reduced Chi2 value returned is the SUM of the Reduced Chi2 of 
    537 each fit. To see the Reduced Chi2 value for a specific *FitPage*, click the  
    538 *Compute* button at the bottom of that *FitPage* to recalculate. Note that in 
    539 doing so the degrees of freedom will be set to Npts. 
    540 See :ref:`Assessing_Fit_Quality`.  Moreover in the case of constraints the 
    541 degrees of freedom are less than one might think due to those constraints. 
     540Note that the chi2/Npts value returned is the SUM of the chi2/Npts of each fit. To 
     541see the chi2/Npts value for a specific *FitPage*, click the *Compute* button at the 
     542bottom of that *FitPage* to recalculate. Also see :ref:`Assessing_Fit_Quality`. 
    542543 
    543544.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     
    765766.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    766767 
    767 .*Document History* 
    768  
    769 | 2017-09-10 Paul Butler 
    770 | 2017-09-15 Steve King 
    771 | 2018-03-05 Paul Butler 
     768.. note::  This help document was last changed by Paul Butler, 10 September 
     769   2017 
  • src/sas/sasgui/perspectives/fitting/media/residuals_help.rst

    r84ac3f1 r99ded31  
    2727 
    2828$\chi^2$ is a statistical parameter that quantifies the differences between 
    29 an observed data set and an expected dataset (or 'theory') calculated as 
     29an observed data set and an expected dataset (or 'theory'). 
     30 
     31When showing the a model with the data, *SasView* displays this parameter 
     32normalized to the number of data points, $N_\mathrm{pts}$ such that 
    3033 
    3134.. math:: 
    3235 
    33   \chi^2 
    34   =  \sum[(Y_i - \mathrm{theory}_i)^2 / \mathrm{error}_i^2] 
     36  \chi^2_N 
     37  =  \sum[(Y_i - \mathrm{theory}_i)^2 / \mathrm{error}_i^2] / N_\mathrm{pts} 
    3538 
    36 Fitting typically minimizes the value of $\chi^2$.  For assessing the quality of 
    37 the model and its "fit" however, *SasView* displays the traditional reduced 
    38 $\chi^2_R$ which normalizes this parameter by dividing it by the number of 
    39 degrees of freedom (or DOF). The DOF is the number of data points being 
    40 considered, $N_\mathrm{pts}$, reduced by the number of free (i.e. fitted) 
    41 parameters, $N_\mathrm{par}$. Note that model parameters that are kept fixed do 
    42 *not* contribute to the DOF (they are not "free"). This reduced value is then 
    43 given as 
     39When performing a fit, *SasView* instead displays the reduced $\chi^2_R$, 
     40which takes into account the number of fitting parameters $N_\mathrm{par}$ 
     41(to calculate the number of 'degrees of freedom'). This is computed as 
    4442 
    4543.. math:: 
     
    4947  / [N_\mathrm{pts} - N_\mathrm{par}] 
    5048 
    51 Note that this means the displayed value will vary depending on the number of 
    52 parameters used in the fit. In particular, when doing a calculation without a 
    53 fit (e.g. manually changing a parameter) the DOF will now equal $N_\mathrm{pts}$ 
    54 and the $\chi^2_R$ will be the smallest possible for that combination of model, 
    55 data set, and set of parameter values. 
    56  
    57 When $N_\mathrm{pts} \gg N_\mathrm{par}$ as it should for proper fitting, the 
    58 value of the reduced $\chi^2_R$ will not change very much. 
     49The normalized $\chi^2_N$ and the reduced $\chi^2_R$ are very close to each 
     50other when $N_\mathrm{pts} \gg N_\mathrm{par}$. 
    5951 
    6052For a good fit, $\chi^2_R$ tends to 1. 
     
    9890| 2015-06-08 Steve King 
    9991| 2017-09-28 Paul Kienzle 
    100 | 2018-03-04 Paul Butler 
  • src/sas/sasview/sasview.py

    r1270e3c r20fa5fe  
    4343        from sas.sasgui.guiframe.gui_manager import SasViewApp 
    4444        self.gui = SasViewApp(0) 
    45         if sys.platform == "darwin": 
    46             self.check_sasmodels_compiler() 
    4745        # Set the application manager for the GUI 
    4846        self.gui.set_manager(self) 
     
    132130        self.gui.MainLoop() 
    133131 
    134     def check_sasmodels_compiler(self): 
    135         """ 
    136         Checking c compiler for sasmodels and raises xcode command line 
    137         tools for installation 
    138         """ 
    139         #wx should be importable at this stage 
    140         import wx 
    141         import subprocess 
    142         #Generic message box created becuase standard MessageBox is not moveable 
    143         class GenericMessageBox(wx.Dialog): 
    144             def __init__(self, parent, text, title = ''): 
    145  
    146                 wx.Dialog.__init__(self, parent, -1, title = title, 
    147                                size = (360,200), pos=(20,60), 
    148                                style = wx.STAY_ON_TOP | wx.DEFAULT_DIALOG_STYLE) 
    149                 panel = wx.Panel(self, -1) 
    150                 top_row_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    151  
    152                 error_bitmap = wx.ArtProvider.GetBitmap( 
    153                     wx.ART_ERROR, wx.ART_MESSAGE_BOX 
    154                 ) 
    155                 error_bitmap_ctrl = wx.StaticBitmap(panel, -1) 
    156                 error_bitmap_ctrl.SetBitmap(error_bitmap) 
    157                 label = wx.StaticText(panel, -1, text) 
    158                 top_row_sizer.Add(error_bitmap_ctrl, flag=wx.ALL, border=10) 
    159                 top_row_sizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL) 
    160  
    161                 #Create the OK button in the bottom row. 
    162                 ok_button = wx.Button(panel, wx.ID_OK ) 
    163                 self.Bind(wx.EVT_BUTTON, self.on_ok, source=ok_button) 
    164                 ok_button.SetFocus() 
    165                 ok_button.SetDefault() 
    166  
    167                 sizer = wx.BoxSizer(wx.VERTICAL) 
    168                 sizer.Add(top_row_sizer) 
    169                 sizer.Add(ok_button, flag=wx.ALIGN_CENTER | wx.ALL, border=5) 
    170                 panel.SetSizer(sizer) 
    171  
    172             def on_ok(self, event): 
    173                 self.Destroy() 
    174  
    175         logger = logging.getLogger(__name__) 
    176         try: 
    177             subprocess.check_output(["cc","--version"], stderr=subprocess.STDOUT) 
    178         except subprocess.CalledProcessError as exc: 
    179             dlg = GenericMessageBox(parent=None, 
    180             text='No compiler installed. Please install command line\n' 
    181                 'developers tools by clicking \"Install\" in another winodw\n\n' 
    182                 'Alternatively click \"Not Now\" and use OpenCL\n' 
    183                  'compiler, which can be set up from menu Fitting->OpenCL Options\n\n', 
    184             title = 'Compiler Info') 
    185             dlg.Show() 
    186             logger.error("No compiler installed. %s\n"%(exc)) 
    187             logger.error(traceback.format_exc()) 
    188132 
    189133def setup_logging(): 
  • test/corfunc/test/utest_corfunc.py

    r6ef75fa6 rf53d684  
    7474        while True: 
    7575            time.sleep(0.001) 
    76             if (not self.calculator.transform_isrunning() and 
    77                 self.transformation is not None): 
     76            if not self.calculator.transform_isrunning(): 
    7877                break 
    7978 
    80         transform1, transform3, idf = self.transformation 
     79    def transform_callback(self, transforms): 
     80        transform1, transform3, idf = transforms 
    8181        self.assertIsNotNone(transform1) 
    8282        self.assertAlmostEqual(transform1.y[0], 1) 
    8383        self.assertAlmostEqual(transform1.y[-1], 0, 5) 
    84  
    85     def transform_callback(self, transforms): 
    8684        self.transformation = transforms 
    8785 
  • test/sascalculator/test/utest_sas_gen.py

    r39a018b rf53d684  
    6060        Test that the calculator calculates. 
    6161        """ 
    62         f = self.omfloader.read(find("A_Raw_Example-1.omf")) 
     62        f = self.omfloader.read("A_Raw_Example-1.omf") 
    6363        omf2sld = sas_gen.OMF2SLD() 
    6464        omf2sld.set_data(f) 
  • test/sasdataloader/test/utest_generic_file_reader_class.py

    r4a8d55c rf53d684  
    88import numpy as np 
    99 
    10 from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D, Data1D 
    11 from sas.sascalc.dataloader.loader import Loader 
    12 from sas.sascalc.dataloader.loader_exceptions import NoKnownLoaderException 
     10from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 
    1311from sas.sascalc.dataloader.file_reader_base_class import FileReader 
    1412 
     
    2624        self.bad_file = find("ACB123.txt") 
    2725        self.good_file = find("123ABC.txt") 
    28         self.generic_reader = Loader() 
    29         self.deprecated_file_type = find("FEB18012.ASC") 
    3026 
    3127    def test_bad_file_path(self): 
    32         self.assertRaises(NoKnownLoaderException, self.reader.read, 
    33                           self.bad_file) 
     28        output = self.reader.read(self.bad_file) 
     29        self.assertEqual(output, []) 
    3430 
    3531    def test_good_file_path(self): 
     
    4036        self.assertEqual(len(output), 1) 
    4137        self.assertEqual(output[0].meta_data["blah"], '123ABC exists!') 
    42  
    43     def test_old_file_types(self): 
    44         f = self.generic_reader.load(self.deprecated_file_type) 
    45         last_f = f[0] 
    46         if hasattr(last_f, "errors"): 
    47             self.assertEquals(len(last_f.errors), 1) 
    48         else: 
    49             self.fail("Errors did not propogate to the file properly.") 
    50  
    51     def test_same_file_unknown_extensions(self): 
    52         # Five files, all with the same content, but different file extensions 
    53         no_ext = find("test_data//TestExtensions") 
    54         not_xml = find("test_data//TestExtensions.notxml") 
    55         # Deprecated extensions 
    56         asc_dep = find("test_data//TestExtensions.asc") 
    57         nxs_dep = find("test_data//TestExtensions.nxs") 
    58         # Native extension as a baseline 
    59         xml_native = find("test_data//TestExtensions.xml") 
    60         # Load the files and check contents 
    61         no_ext_load = self.generic_reader.load(no_ext) 
    62         asc_load = self.generic_reader.load(asc_dep) 
    63         nxs_load = self.generic_reader.load(nxs_dep) 
    64         not_xml_load = self.generic_reader.load(not_xml) 
    65         xml_load = self.generic_reader.load(xml_native) 
    66         self.check_unknown_extension(no_ext_load[0]) 
    67         self.check_unknown_extension(asc_load[0]) 
    68         self.check_unknown_extension(nxs_load[0]) 
    69         self.check_unknown_extension(not_xml_load[0]) 
    70         self.check_unknown_extension(xml_load[0]) 
    71         # Be sure the deprecation warning is passed with the file 
    72         self.assertEquals(len(asc_load[0].errors), 1) 
    73         self.assertEquals(len(nxs_load[0].errors), 1) 
    74  
    75     def check_unknown_extension(self, data): 
    76         self.assertTrue(isinstance(data, Data1D)) 
    77         self.assertEquals(len(data.x), 138) 
    78         self.assertEquals(data.sample.ID, "TK49 c10_SANS") 
    79         self.assertEquals(data.meta_data["loader"], "CanSAS XML 1D") 
    8038 
    8139    def tearDown(self): 
Note: See TracChangeset for help on using the changeset viewer.