Changeset 53f0402 in sasview
- Timestamp:
- Feb 28, 2017 1:22:40 PM (8 years ago)
- 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:
- 775e0b7
- Parents:
- c221349 (diff), 587ce8c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 1 added
- 1 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/CategoryInstaller.py
r212bfc2 rddbac66 123 123 compile it and install 124 124 :param homefile: Override the default home directory 125 :param model_list: List of model names except customized models 125 :param model_list: List of model names except those in Plugin Models 126 which are user supplied. 126 127 """ 127 128 _model_dict = { model.name: model for model in model_list} -
src/sas/sasgui/perspectives/calculator/model_editor.py
ra08b89b rddbac66 5 5 function of y (usually the intensity). It also provides a drop down of 6 6 standard available math functions. Finally a full python editor panel for 7 complete customizati n is provided.8 9 :TODO the writi ong of the file and name checking (and maybe some other10 fun tions?) should be moved to a computational module which could be called11 fro pm a python script. Basically one just needs to pass the name,7 complete customization is provided. 8 9 :TODO the writing of the file and name checking (and maybe some other 10 functions?) should be moved to a computational module which could be called 11 from a python script. Basically one just needs to pass the name, 12 12 description text and function text (or in the case of the composite editor 13 13 the names of the first and second model and the operator to be used). … … 61 61 """ 62 62 Dialog for easy custom composite models. Provides a wx.Dialog panel 63 to choose two existing models (including pre-existing custom models which63 to choose two existing models (including pre-existing Plugin Models which 64 64 may themselves be composite models) as well as an operation on those models 65 65 (add or multiply) the resulting model will add a scale parameter for summed … … 380 380 color = 'blue' 381 381 except: 382 msg = "Easy Custom Sum/Multipy: Error occurred..."382 msg = "Easy Sum/Multipy Plugin: Error occurred..." 383 383 info = 'Error' 384 384 color = 'red' … … 501 501 self.factor = factor 502 502 self._operator = operator 503 self.explanation = " CustomModel = %s %s (model1 %s model2)\n" % \503 self.explanation = " Plugin Model = %s %s (model1 %s model2)\n" % \ 504 504 (self.factor, f_oper, self._operator) 505 505 self.explanationctr.SetLabel(self.explanation) … … 617 617 class EditorPanel(wx.ScrolledWindow): 618 618 """ 619 Custom model function editor619 Simple Plugin Model function editor 620 620 """ 621 621 def __init__(self, parent, base, path, title, *args, **kwds): … … 652 652 self.msg_sizer = None 653 653 self.warning = "" 654 self._description = "New Custom Model" 654 #This does not seem to be used anywhere so commenting out for now 655 # -- PDB 2/26/17 656 #self._description = "New Plugin Model" 655 657 self.function_tcl = None 656 658 self.math_combo = None … … 991 993 else: 992 994 self._notes = result 993 msg = "Successful! Please look for %s in CustomizedModels."%name995 msg = "Successful! Please look for %s in Plugin Models."%name 994 996 msg += " " + self._notes 995 997 info = 'Info' … … 1138 1140 def on_help(self, event): 1139 1141 """ 1140 Bring up the CustomModel Editor Documentation whenever1142 Bring up the New Plugin Model Editor Documentation whenever 1141 1143 the HELP button is clicked. 1142 1144 … … 1190 1192 #self.Destroy() 1191 1193 1192 ## Templates for custommodels1194 ## Templates for plugin models 1193 1195 1194 1196 CUSTOM_TEMPLATE = """ -
src/sas/sasgui/perspectives/calculator/pyconsole.py
rd472e86 rddbac66 302 302 success = show_model_output(self, fname) 303 303 304 # Update custommodel list in fitpage combobox304 # Update plugin model list in fitpage combobox 305 305 if success and self._manager != None and self.panel != None: 306 306 self._manager.set_edit_menu_helper(self.parent) -
src/sas/sasgui/perspectives/fitting/basepage.py
ra6fccd7 r7a5aedd 53 53 ON_MAC = True 54 54 55 CUSTOM_MODEL = 'Plugin Models' 56 55 57 class BasicPage(ScrolledPanel, PanelBase): 56 58 """ 57 This class provide general structure of fitpanel page59 This class provide general structure of the fitpanel page 58 60 """ 59 61 # Internal name for the AUI manager … … 677 679 def _copy_info(self, flag): 678 680 """ 679 Send event d pemding on flag680 681 : Param flag: flag that distinguish event681 Send event depending on flag 682 683 : Param flag: flag that distinguishes the event 682 684 """ 683 685 # messages depending on the flag … … 1119 1121 :precondition: the page is already drawn or created 1120 1122 1121 :postcondition: the state of the underlying data change as well as the1123 :postcondition: the state of the underlying data changes as well as the 1122 1124 state of the graphic interface 1123 1125 """ … … 1167 1169 self._show_combox(None) 1168 1170 from models import PLUGIN_NAME_BASE 1169 if self.categorybox.GetValue() == 'Customized Models'\1171 if self.categorybox.GetValue() == CUSTOM_MODEL \ 1170 1172 and PLUGIN_NAME_BASE not in state.formfactorcombobox: 1171 1173 state.formfactorcombobox = \ … … 1335 1337 def _selectDlg(self): 1336 1338 """ 1337 open a dialog file to select ed the customized dispersity1339 open a dialog file to select the customized polydispersity function 1338 1340 """ 1339 1341 if self.parent is not None: … … 1760 1762 def _set_multfactor_combobox(self, multiplicity=10): 1761 1763 """ 1762 Set comboBox for mu itfactor of CoreMultiShellModel1764 Set comboBox for multitfactor of CoreMultiShellModel 1763 1765 :param multiplicit: no. of multi-functionality 1764 1766 """ … … 1798 1800 Fill panel's combo box according to the type of model selected 1799 1801 """ 1800 custom_model = 'Customized Models' 1802 1801 1803 mod_cat = self.categorybox.GetStringSelection() 1802 1804 self.structurebox.SetSelection(0) … … 1807 1809 m_list = [] 1808 1810 try: 1809 if mod_cat == custom_model:1811 if mod_cat == CUSTOM_MODEL: 1810 1812 for model in self.model_list_box[mod_cat]: 1811 1813 m_list.append(self.model_dict[model.name]) … … 3453 3455 fills out the category list box 3454 3456 """ 3455 uncat_str = ' CustomizedModels'3457 uncat_str = 'Plugin Models' 3456 3458 self._read_category_info() 3457 3459 … … 3482 3484 self.model_box.Clear() 3483 3485 3484 if category == ' CustomizedModels':3486 if category == 'Plugin Models': 3485 3487 for model in self.model_list_box[category]: 3486 3488 str_m = str(model).split(".")[0] -
src/sas/sasgui/perspectives/fitting/fitpage.py
r3d55219 ref2cdb3 31 31 SMEAR_SIZE_L = 0.00 32 32 SMEAR_SIZE_H = 0.00 33 33 CUSTOM_MODEL = 'Plugin Models' 34 34 35 35 class FitPage(BasicPage): … … 1249 1249 wx.PostEvent(self.parent, new_event) 1250 1250 # update list of plugins if new plugin is available 1251 custom_model = 'Customized Models'1251 custom_model = CUSTOM_MODEL 1252 1252 mod_cat = self.categorybox.GetStringSelection() 1253 1253 if mod_cat == custom_model: -
src/sas/sasgui/perspectives/fitting/fitting.py
r73cbeec rddbac66 225 225 226 226 self.id_edit = wx.NewId() 227 editmodel_help = "Edit customized model sample file"228 227 self.menu1.AppendMenu(self.id_edit, "Plugin Model Operations", 229 self.edit_model_menu , editmodel_help)228 self.edit_model_menu) 230 229 #create menubar items 231 230 return [(self.menu1, self.sub_menu)] … … 260 259 self.update_custom_combo() 261 260 if os.path.isfile(p_path): 262 msg = "Sorry! Could not beable to delete the default "263 msg += " custommodel... \n"261 msg = "Sorry! unable to delete the default " 262 msg += "plugin model... \n" 264 263 msg += "Please manually remove the files (.py, .pyc) " 265 264 msg += "in the 'plugin_models' folder \n" … … 274 273 if item.GetLabel() == label: 275 274 self.edit_menu.DeleteItem(item) 276 msg = "The custommodel, %s, has been deleted." % label275 msg = "The plugin model, %s, has been deleted." % label 277 276 evt = StatusEvent(status=msg, type='stop', info='info') 278 277 wx.PostEvent(self.parent, evt) … … 331 330 temp = self.fit_panel.reset_pmodel_list() 332 331 if temp: 333 # Set the new custommodel list for all fit pages332 # Set the new plugin model list for all fit pages 334 333 for uid, page in self.fit_panel.opened_pages.iteritems(): 335 334 if hasattr(page, "formfactorbox"): … … 1965 1964 ## then kill itself but cannot. Paul Kienzle came up with 1966 1965 ## this fix to prevent threads from stepping on each other 1967 ## which was causing a simple custom model to crash Sasview. 1966 ## which was causing a simple custom plugin model to crash 1967 ##Sasview. 1968 1968 ## We still don't know why the fit sometimes lauched a second 1969 1969 ## thread -- something which should also be investigated. -
src/sas/sasgui/perspectives/fitting/media/fitting_help.rst
r26c8be3 r5295cf5 34 34 * in *Single* fit mode - individual data sets are fitted independently one-by-one 35 35 36 * in *Simultaneous* fit mode - multiple data sets are fitted simultaneously to the *same* model with/without constrained parameters (this might be useful, for example, if you have measured the same sample at different contrasts) 36 * in *Simultaneous* fit mode - multiple data sets are fitted simultaneously to 37 the *same* model with/without constrained parameters (this might be useful, 38 for example, if you have measured the same sample at different contrasts) 37 39 38 40 * in *Batch* fit mode - multiple data sets are fitted sequentially to the *same* model (this might be useful, for example, if you have performed a kinetic or time-resolved experiment and have *lots* of data sets!) … … 43 45 ----------------- 44 46 45 By default, the models in SasView are grouped into five categories 46 47 * *Shapes* - models describing 'objects' (spheres, cylinders, etc) 47 The models in SasView are grouped into categories. By default these consist of: 48 49 * *Cylinder* - cylindrical shapes (disc, right cylinder, cylinder with endcaps 50 etc) 51 * *Ellipsoid* - ellipsoidal shapes (oblate,prolate, core shell, etc) 52 * *Parellelepiped* - as the name implies 53 * *Sphere* - sheroidal shapes (sphere, core multishell, vesicle, etc) 54 * *Lamellae* - lamellar shapes (lamellar, core shell lamellar, stacked 55 lamellar, etc) 48 56 * *Shape-Independent* - models describing structure in terms of density correlation functions, fractals, peaks, power laws, etc 49 * *Customized Models* - SasView- or User-created (non-library) Python models 50 * *Uncategorised* - other models (for reflectivity, etc) 57 * *Paracrystal* - semi ordered structures (bcc, fcc, etc) 51 58 * *Structure Factor* - S(Q) models 59 * *Plugin Models* - User-created (custom/non-library) Python models 52 60 53 61 Use the *Category* drop-down menu to chose a category of model, then select … … 84 92 .. image:: cat_fig0.bmp 85 93 86 The categorization of all models except the customized models can be reassigned,87 added to, and removed using *Category Manager*. Models can also be hidden from view 88 in the drop-down menus.94 The categorization of all models except the user supplied Plugin Models can be 95 reassigned, added to, and removed using *Category Manager*. Models can also be 96 hidden from view in the drop-down menus. 89 97 90 98 .. image:: cat_fig1.bmp … … 93 101 ^^^^^^^^^^^^^^^^^ 94 102 95 To change category, highlight a model in the list by left-clicking on its entry and96 then click the *Modify* button. Use the *Change Category* panel that appears to make 97 t he required changes.103 To change category, highlight a model in the list by left-clicking on its entry 104 and then click the *Modify* button. Use the *Change Category* panel that appears 105 to make the required changes. 98 106 99 107 .. image:: cat_fig2.bmp … … 106 114 ^^^^^^^^^^^^^^^^^^^^^ 107 115 108 Use the *Enable All / Disable All* buttons and the check boxes beside each model to109 select the models to show/hide. To apply the selection, click *Ok*. Otherwise click 110 *Cancel*.116 Use the *Enable All / Disable All* buttons and the check boxes beside each model 117 to select the models to show/hide. To apply the selection, click *Ok*. Otherwise 118 click *Cancel*. 111 119 112 120 *NB: It may be necessary to change to a different category and then back again* … … 118 126 --------------- 119 127 120 For a complete list of all the library models available in SasView, see the `Model Documentation <../../../index.html>`_ . 128 For a complete list of all the library models available in SasView, see 129 the `Model Documentation <../../../index.html>`_ . 121 130 122 131 It is also possible to add your own models. … … 131 140 There are essentially three ways to generate new fitting models for SasView: 132 141 133 * Using the SasView :ref:`New_Plugin_Model` helper dialog (best for beginners and/or relatively simple models) 134 * By copying/editing an existing model (this can include models generated by the *New Plugin Model* dialog) in the :ref:`Python_shell` or :ref:`Advanced_Plugin_Editor` (suitable for all use cases) 135 * By writing a model from scratch outside of SasView (only recommended for code monkeys!) 142 * Using the SasView :ref:`New_Plugin_Model` helper dialog (best for beginners 143 and/or relatively simple models) 144 * By copying/editing an existing model (this can include models generated by 145 the New Plugin Model* dialog) in the :ref:`Python_shell` or 146 :ref:`Advanced_Plugin_Editor` (suitable for all use cases) 147 * By writing a model from scratch outside of SasView (only recommended for code 148 monkeys!) 136 149 137 150 Please read the guidance on :ref:`Writing_a_Plugin` before proceeding. … … 163 176 ^^^^^^^^^^^^^^^^ 164 177 165 Relatively straightforward models can be programmed directly from the SasView GUI166 using the *New Plugin Model Function*.178 Relatively straightforward models can be programmed directly from the SasView 179 GUI using the *New Plugin Model Function*. 167 180 168 181 .. image:: new_model.bmp … … 175 188 *checked*\ . 176 189 177 Also note that the 'Fit Parameters' have been split into two sections: those which178 can be polydisperse (shape and orientation parameters) and those which are not 179 (eg, scattering length densities).190 Also note that the 'Fit Parameters' have been split into two sections: those 191 which can be polydisperse (shape and orientation parameters) and those which are 192 not (eg, scattering length densities). 180 193 181 194 A model file generated by this option can be viewed and further modified using … … 187 200 .. image:: sum_model.bmp 188 201 189 This option creates a custom model of the form::190 191 Custom Model = scale_factor \* {(scale_1 \* model_1) \+ (scale_2 \* model_2)} \+ background202 This option creates a custom Plugin Model of the form:: 203 204 Plugin Model = scale_factor * {(scale_1 * model_1) +/- (scale_2 * model_2)} + background 192 205 193 206 or:: 194 207 195 Custom Model = scale_factor \* model_1 \* model_2 \+ background208 Plugin Model = scale_factor * model_1 /* model_2 + background 196 209 197 210 In the *Easy Sum/Multi Editor* give the new model a function name and brief … … 232 245 Simply highlight the plugin model to be removed. The operation is final!!! 233 246 234 *NB: Plugin models shipped with SasView cannot be removed in this way.*247 *NB: Models shipped with SasView cannot be removed in this way.* 235 248 236 249 Load Plugin Models 237 250 ^^^^^^^^^^^^^^^^^^ 238 251 239 This option loads (or re-loads) all models present in the *~\\.sasview\\plugin_models* folder. 252 This option loads (or re-loads) all models present in the 253 *~\\.sasview\\plugin_models* folder. 240 254 241 255 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ … … 400 414 :ref:`Assessing_Fit_Quality`. 401 415 402 *NB: If you need to use a custom ized model, you must ensure that model is available*403 *first (see* :ref:`Adding_your_own_models` *).*416 *NB: If you need to use a custom Plugin Model, you must ensure that model is 417 available first (see* :ref:`Adding_your_own_models` *).* 404 418 405 419 Method … … 484 498 If multiple data sets are in one file, load just that file. *Unselect All Data*, then 485 499 select a single initial data set to be fitted. Fit that selected data set as described 486 above under :ref:`Single_Fit_Mode` 487 488 *NB: If you need to use a custom ized model, you must ensure that model is available*489 *first (see* :ref:`Adding_your_own_models` *).*500 above under :ref:`Single_Fit_Mode`. 501 502 *NB: If you need to use a custom Plugin Model, you must ensure that model is 503 available first (see* :ref:`Adding_your_own_models` *).* 490 504 491 505 Method -
src/sas/sasgui/perspectives/fitting/media/plugin.rst
rca6cbc1c r5295cf5 27 27 28 28 the next time SasView is started it will compile the plugin and add 29 it to the list of * CustomizedModels* in a FitPage.29 it to the list of *Plugin Models* in a FitPage. 30 30 31 31 SasView models can be of three types: -
src/sas/sasgui/perspectives/fitting/models.py
r0de74af r11b094f 325 325 self.plugins.append(plug) 326 326 self.model_dictionary[name] = plug 327 self.model_combobox.set_list(" CustomizedModels", self.plugins)327 self.model_combobox.set_list("Plugin Models", self.plugins) 328 328 return self.model_combobox.get_list() 329 329 else: … … 346 346 self.model_dictionary[name] = plug 347 347 348 self.model_combobox.reset_list(" CustomizedModels", self.plugins)348 self.model_combobox.reset_list("Plugin Models", self.plugins) 349 349 return self.model_combobox.get_list() 350 350 … … 389 389 # self.shape_indep_list) 390 390 self.model_combobox.set_list("Structure Factors", self.struct_list) 391 self.model_combobox.set_list(" CustomizedModels", self.plugins)391 self.model_combobox.set_list("Plugin Models", self.plugins) 392 392 self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor) 393 393 self.model_combobox.set_list("multiplication", -
src/sas/sasgui/perspectives/fitting/pagestate.py
r6d2b50b r71601312 33 33 from sas.sascalc.dataloader.data_info import Data2D, Collimation, Detector 34 34 from sas.sascalc.dataloader.data_info import Process, Aperture 35 35 36 # Information to read/write state as xml 36 37 FITTING_NODE_NAME = 'fitting_plug_in' 37 38 CANSAS_NS = "cansas1d/1.0" 39 40 CUSTOM_MODEL = 'Plugin Models' 41 CUSTOM_MODEL_OLD = 'Customized Models' 38 42 39 43 LIST_OF_DATA_ATTRIBUTES = [["is_data", "is_data", "bool"], … … 366 370 :return: None 367 371 """ 372 if self.categorycombobox == CUSTOM_MODEL_OLD: 373 self.categorycombobox = CUSTOM_MODEL 368 374 if self.formfactorcombobox == '': 369 375 FIRST_FORM = { … … 378 384 'Sphere' : 'adsorbed_layer', 379 385 'Structure Factor' : 'hardsphere', 380 'Customized Models': ''386 CUSTOM_MODEL : '' 381 387 } 382 388 if self.categorycombobox == '': -
src/sas/sascalc/data_util/qsmearing.py
rd3911e3 r2ffe241 13 13 import logging 14 14 import sys 15 15 import numpy as np # type: ignore 16 from numpy import pi, exp # type:ignore 16 17 from sasmodels.resolution import Slit1D, Pinhole1D 18 from sasmodels.sesans import SesansTransform 17 19 from sasmodels.resolution2d import Pinhole2D 20 from src.sas.sascalc.data_util.nxsunit import Converter 18 21 19 22 def smear_selection(data, model = None): … … 36 39 # Sanity check. If we are not dealing with a SAS Data1D 37 40 # object, just return None 41 # This checks for 2D data (does not throw exception because fail is common) 38 42 if data.__class__.__name__ not in ['Data1D', 'Theory1D']: 39 43 if data == None: … … 41 45 elif data.dqx_data == None or data.dqy_data == None: 42 46 return None 43 return PySmear2D(data , model)44 47 return PySmear2D(data) 48 # This checks for 1D data with smearing info in the data itself (again, fail is likely; no exceptions) 45 49 if not hasattr(data, "dx") and not hasattr(data, "dxl")\ 46 50 and not hasattr(data, "dxw"): … … 48 52 49 53 # Look for resolution smearing data 54 # This is the code that checks for SESANS data; it looks for the file loader 55 # TODO: change other sanity checks to check for file loader instead of data structure? 56 _found_sesans = False 57 #if data.dx is not None and data.meta_data['loader']=='SESANS': 58 if data.dx is not None and data.isSesans: 59 #if data.dx[0] > 0.0: 60 if numpy.size(data.dx[data.dx <= 0]) == 0: 61 _found_sesans = True 62 # if data.dx[0] <= 0.0: 63 if numpy.size(data.dx[data.dx <= 0]) > 0: 64 raise ValueError('one or more of your dx values are negative, please check the data file!') 65 66 if _found_sesans == True: 67 #Pre-compute the Hankel matrix (H) 68 qmax, qunits = data.sample.zacceptance 69 SElength = Converter(data._xunit)(data.x, "A") 70 zaccept = Converter(qunits)(qmax, "1/A"), 71 Rmax = 10000000 72 hankel = SesansTransform(data.x, SElength, zaccept, Rmax) 73 # Then return the actual transform, as if it were a smearing function 74 return PySmear(hankel, model, offset=0) 75 50 76 _found_resolution = False 51 77 if data.dx is not None and len(data.dx) == len(data.x): … … 89 115 Wrapper for pure python sasmodels resolution functions. 90 116 """ 91 def __init__(self, resolution, model ):117 def __init__(self, resolution, model, offset=None): 92 118 self.model = model 93 119 self.resolution = resolution 94 self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 120 if offset is None: 121 offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 122 self.offset = offset 95 123 96 124 def apply(self, iq_in, first_bin=0, last_bin=None): -
src/sas/sascalc/dataloader/data_info.py
r345e7e4 r2ffe241 25 25 import numpy 26 26 import math 27 28 class plottable_sesans1D(object):29 """30 SESANS is a place holder for 1D SESANS plottables.31 32 #TODO: This was directly copied from the plottables_1D. Modified Somewhat.33 #Class has been updated.34 """35 # The presence of these should be mutually36 # exclusive with the presence of Qdev (dx)37 x = None38 y = None39 lam = None40 dx = None41 dy = None42 dlam = None43 ## Slit smearing length44 dxl = None45 ## Slit smearing width46 dxw = None47 48 # Units49 _xaxis = ''50 _xunit = ''51 _yaxis = ''52 _yunit = ''53 54 def __init__(self, x, y, lam, dx=None, dy=None, dlam=None):55 # print "SESANS plottable working"56 self.x = numpy.asarray(x)57 self.y = numpy.asarray(y)58 self.lam = numpy.asarray(lam)59 if dx is not None:60 self.dx = numpy.asarray(dx)61 if dy is not None:62 self.dy = numpy.asarray(dy)63 if dlam is not None:64 self.dlam = numpy.asarray(dlam)65 66 def xaxis(self, label, unit):67 """68 set the x axis label and unit69 """70 self._xaxis = label71 self._xunit = unit72 73 def yaxis(self, label, unit):74 """75 set the y axis label and unit76 """77 self._yaxis = label78 self._yunit = unit79 80 27 81 28 class plottable_1D(object): … … 93 40 ## Slit smearing width 94 41 dxw = None 42 ## SESANS specific params (wavelengths for spin echo length calculation) 43 lam = None 44 dlam = None 95 45 96 46 # Units … … 100 50 _yunit = '' 101 51 102 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None ):52 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None): 103 53 self.x = numpy.asarray(x) 104 54 self.y = numpy.asarray(y) … … 111 61 if dxw is not None: 112 62 self.dxw = numpy.asarray(dxw) 63 if lam is not None: 64 self.lam = numpy.asarray(lam) 65 if dlam is not None: 66 self.dlam = numpy.asarray(dlam) 113 67 114 68 def xaxis(self, label, unit): … … 398 352 ## Details 399 353 details = None 354 ## SESANS zacceptance 355 zacceptance = None 400 356 401 357 def __init__(self): … … 535 491 ## Loading errors 536 492 errors = None 493 ## SESANS data check 494 isSesans = None 495 537 496 538 497 def __init__(self): … … 567 526 ## Loading errors 568 527 self.errors = [] 528 ## SESANS data check 529 self.isSesans = False 569 530 570 531 def append_empty_process(self): … … 586 547 _str += "Title: %s\n" % self.title 587 548 _str += "Run: %s\n" % str(self.run) 549 _str += "SESANS: %s\n" % str(self.isSesans) 588 550 _str += "Instrument: %s\n" % str(self.instrument) 589 551 _str += "%s\n" % str(self.sample) … … 736 698 return self._perform_union(other) 737 699 738 class SESANSData1D(plottable_sesans1D, DataInfo): 739 """ 740 SESANS 1D data class 741 """ 742 x_unit = 'nm' 743 y_unit = 'pol' 744 745 def __init__(self, x=None, y=None, lam=None, dx=None, dy=None, dlam=None): 700 class Data1D(plottable_1D, DataInfo): 701 """ 702 1D data class 703 """ 704 def __init__(self, x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=None): 746 705 DataInfo.__init__(self) 747 plottable_sesans1D.__init__(self, x, y, lam, dx, dy, dlam) 706 plottable_1D.__init__(self, x, y, dx, dy,None, None, lam, dlam) 707 self.isSesans = isSesans 708 try: 709 if self.isSesans: # the data is SESANS 710 self.x_unit = 'A' 711 self.y_unit = 'pol' 712 elif not self.isSesans: # the data is SANS 713 self.x_unit = '1/A' 714 self.y_unit = '1/cm' 715 except: # the data is not recognized/supported, and the user is notified 716 raise(TypeError, 'data not recognized, check documentation for supported 1D data formats') 748 717 749 718 def __str__(self): … … 759 728 return _str 760 729 761 def clone_without_data(self, length=0, clone=None):762 """763 Clone the current object, without copying the data (which764 will be filled out by a subsequent operation).765 The data arrays will be initialized to zero.766 767 :param length: length of the data array to be initialized768 :param clone: if provided, the data will be copied to clone769 """770 from copy import deepcopy771 if clone is None or not issubclass(clone.__class__, Data1D):772 x = numpy.zeros(length)773 dx = numpy.zeros(length)774 y = numpy.zeros(length)775 dy = numpy.zeros(length)776 clone = Data1D(x, y, dx=dx, dy=dy)777 778 clone.title = self.title779 clone.run = self.run780 clone.filename = self.filename781 clone.instrument = self.instrument782 clone.notes = deepcopy(self.notes)783 clone.process = deepcopy(self.process)784 clone.detector = deepcopy(self.detector)785 clone.sample = deepcopy(self.sample)786 clone.source = deepcopy(self.source)787 clone.collimation = deepcopy(self.collimation)788 clone.trans_spectrum = deepcopy(self.trans_spectrum)789 clone.meta_data = deepcopy(self.meta_data)790 clone.errors = deepcopy(self.errors)791 792 return clone793 794 class Data1D(plottable_1D, DataInfo):795 """796 1D data class797 """798 x_unit = '1/A'799 y_unit = '1/cm'800 801 def __init__(self, x, y, dx=None, dy=None):802 DataInfo.__init__(self)803 plottable_1D.__init__(self, x, y, dx, dy)804 805 def __str__(self):806 """807 Nice printout808 """809 _str = "%s\n" % DataInfo.__str__(self)810 _str += "Data:\n"811 _str += " Type: %s\n" % self.__class__.__name__812 _str += " X-axis: %s\t[%s]\n" % (self._xaxis, self._xunit)813 _str += " Y-axis: %s\t[%s]\n" % (self._yaxis, self._yunit)814 _str += " Length: %g\n" % len(self.x)815 return _str816 817 730 def is_slit_smeared(self): 818 731 """ … … 843 756 y = numpy.zeros(length) 844 757 dy = numpy.zeros(length) 845 clone = Data1D(x, y, dx=dx, dy=dy) 758 lam = numpy.zeros(length) 759 dlam = numpy.zeros(length) 760 clone = Data1D(x, y, lam=lam, dx=dx, dy=dy, dlam=dlam) 846 761 847 762 clone.title = self.title … … 1018 933 ## Vector of Q-values at the center of each bin in y 1019 934 y_bins = None 935 ## No 2D SESANS data as of yet. Always set it to False 936 isSesans = False 1020 937 1021 938 def __init__(self, data=None, err_data=None, qx_data=None, 1022 939 qy_data=None, q_data=None, mask=None, 1023 940 dqx_data=None, dqy_data=None): 1024 self.y_bins = []1025 self.x_bins = []1026 941 DataInfo.__init__(self) 1027 942 plottable_2D.__init__(self, data, err_data, qx_data, 1028 943 qy_data, q_data, mask, dqx_data, dqy_data) 944 self.y_bins = [] 945 self.x_bins = [] 946 1029 947 if len(self.detector) > 0: 1030 948 raise RuntimeError, "Data2D: Detector bank already filled at init" … … 1265 1183 final_dataset.xmin = data.xmin 1266 1184 final_dataset.ymin = data.ymin 1185 final_dataset.isSesans = datainfo.isSesans 1267 1186 final_dataset.title = datainfo.title 1268 1187 final_dataset.run = datainfo.run -
src/sas/sascalc/dataloader/readers/cansas_constants.py
r250fec92 rad4632c 133 133 "variable" : None, 134 134 "children" : {"Idata" : SASDATA_IDATA, 135 "Sesans": {"storeas": "content"}, 136 "zacceptance": {"storeas": "float"}, 135 137 "<any>" : ANY 136 138 } -
src/sas/sascalc/dataloader/readers/cansas_reader.py
rbcabf4e rc221349 261 261 # I and Q - 1D data 262 262 elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 263 self.current_dataset.yaxis("Intensity", unit) 263 unit_list = unit.split("|") 264 if len(unit_list) > 1: 265 self.current_dataset.yaxis(unit_list[0].strip(), 266 unit_list[1].strip()) 267 else: 268 self.current_dataset.yaxis("Intensity", unit) 264 269 self.current_dataset.y = np.append(self.current_dataset.y, data_point) 265 270 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 266 271 self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 267 272 elif tagname == 'Q': 268 self.current_dataset.xaxis("Q", unit) 273 unit_list = unit.split("|") 274 if len(unit_list) > 1: 275 self.current_dataset.xaxis(unit_list[0].strip(), 276 unit_list[1].strip()) 277 else: 278 self.current_dataset.xaxis("Q", unit) 269 279 self.current_dataset.x = np.append(self.current_dataset.x, data_point) 270 280 elif tagname == 'Qdev': … … 278 288 elif tagname == 'Shadowfactor': 279 289 pass 290 elif tagname == 'Sesans': 291 self.current_datainfo.isSesans = bool(data_point) 292 elif tagname == 'zacceptance': 293 self.current_datainfo.sample.zacceptance = (data_point, unit) 280 294 281 295 # I and Qx, Qy - 2D data … … 1020 1034 node.append(point) 1021 1035 self.write_node(point, "Q", datainfo.x[i], 1022 {'unit': datainfo. x_unit})1036 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 1023 1037 if len(datainfo.y) >= i: 1024 1038 self.write_node(point, "I", datainfo.y[i], 1025 {'unit': datainfo. y_unit})1039 {'unit': datainfo._yaxis + " | " + datainfo._yunit}) 1026 1040 if datainfo.dy is not None and len(datainfo.dy) > i: 1027 1041 self.write_node(point, "Idev", datainfo.dy[i], 1028 {'unit': datainfo. y_unit})1042 {'unit': datainfo._yaxis + " | " + datainfo._yunit}) 1029 1043 if datainfo.dx is not None and len(datainfo.dx) > i: 1030 1044 self.write_node(point, "Qdev", datainfo.dx[i], 1031 {'unit': datainfo. x_unit})1045 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 1032 1046 if datainfo.dxw is not None and len(datainfo.dxw) > i: 1033 1047 self.write_node(point, "dQw", datainfo.dxw[i], 1034 {'unit': datainfo. x_unit})1048 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 1035 1049 if datainfo.dxl is not None and len(datainfo.dxl) > i: 1036 1050 self.write_node(point, "dQl", datainfo.dxl[i], 1037 {'unit': datainfo.x_unit}) 1051 {'unit': datainfo._xaxis + " | " + datainfo._xunit}) 1052 if datainfo.isSesans: 1053 sesans = self.create_element("Sesans") 1054 sesans.text = str(datainfo.isSesans) 1055 node.append(sesans) 1056 self.write_node(node, "zacceptance", datainfo.sample.zacceptance[0], 1057 {'unit': datainfo.sample.zacceptance[1]}) 1058 1038 1059 1039 1060 def _write_data_2d(self, datainfo, entry_node): -
src/sas/sascalc/dataloader/readers/sesans_reader.py
r9525358 r7caf3e5 8 8 import numpy 9 9 import os 10 from sas.sascalc.dataloader.data_info import SESANSData1D10 from sas.sascalc.dataloader.data_info import Data1D 11 11 12 12 # Check whether we have a converter available … … 59 59 raise RuntimeError, "sesans_reader: cannot open %s" % path 60 60 buff = input_f.read() 61 # print buff62 61 lines = buff.splitlines() 63 # print lines64 #Jae could not find python universal line spliter:65 #keep the below for now66 # some ascii data has \r line separator,67 # try it when the data is on only one long line68 # if len(lines) < 2 :69 # lines = buff.split('\r')70 71 62 x = numpy.zeros(0) 72 63 y = numpy.zeros(0) … … 83 74 tdlam = numpy.zeros(0) 84 75 tdx = numpy.zeros(0) 85 # print "all good" 86 output = SESANSData1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam) 87 # print output 76 output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, isSesans=True) 88 77 self.filename = output.filename = basename 89 78 90 # #Initialize counters for data lines and header lines.91 # is_data = False # Has more than 5 lines92 # # More than "5" lines of data is considered as actual93 # # data unless that is the only data94 # mum_data_lines = 595 # # To count # of current data candidate lines96 # i = -197 # # To count total # of previous data candidate lines98 # i1 = -199 # # To count # of header lines100 # j = -1101 # # Helps to count # of header lines102 # j1 = -1103 # #minimum required number of columns of data; ( <= 4).104 # lentoks = 2105 79 paramnames=[] 106 80 paramvals=[] … … 111 85 Pvals=[] 112 86 dPvals=[] 113 # print x 114 # print zvals 87 115 88 for line in lines: 116 89 # Initial try for CSV (split on ,) … … 122 95 if len(toks)>5: 123 96 zvals.append(toks[0]) 124 dzvals.append(toks[ 1])125 lamvals.append(toks[ 2])126 dlamvals.append(toks[ 3])127 Pvals.append(toks[ 4])128 dPvals.append(toks[ 5])97 dzvals.append(toks[3]) 98 lamvals.append(toks[4]) 99 dlamvals.append(toks[5]) 100 Pvals.append(toks[1]) 101 dPvals.append(toks[2]) 129 102 else: 130 103 continue … … 140 113 default_z_unit = "A" 141 114 data_conv_P = None 142 default_p_unit = " " 115 default_p_unit = " " # Adjust unit for axis (L^-3) 143 116 lam_unit = lam_header[1].replace("[","").replace("]","") 117 if lam_unit == 'AA': 118 lam_unit = 'A' 144 119 varheader=[zvals[0],dzvals[0],lamvals[0],dlamvals[0],Pvals[0],dPvals[0]] 145 120 valrange=range(1, len(zvals)) … … 161 136 output.x, output.x_unit = self._unit_conversion(x, lam_unit, default_z_unit) 162 137 output.y = y 138 output.y_unit = r'\AA^{-2} cm^{-1}' # output y_unit added 163 139 output.dx, output.dx_unit = self._unit_conversion(dx, lam_unit, default_z_unit) 164 140 output.dy = dy 165 141 output.lam, output.lam_unit = self._unit_conversion(lam, lam_unit, default_z_unit) 166 142 output.dlam, output.dlam_unit = self._unit_conversion(dlam, lam_unit, default_z_unit) 143 144 output.xaxis(r"\rm{z}", output.x_unit) 145 output.yaxis(r"\rm{ln(P)/(t \lambda^2)}", output.y_unit) # Adjust label to ln P/(lam^2 t), remove lam column refs 167 146 168 output.xaxis(r"\rm{z}", output.x_unit)169 output.yaxis(r"\rm{P/P0}", output.y_unit)170 147 # Store loading process information 171 148 output.meta_data['loader'] = self.type_name 172 output.sample.thickness = float(paramvals[6])149 #output.sample.thickness = float(paramvals[6]) 173 150 output.sample.name = paramvals[1] 174 151 output.sample.ID = paramvals[0] 175 152 zaccept_unit_split = paramnames[7].split("[") 176 153 zaccept_unit = zaccept_unit_split[1].replace("]","") 177 if zaccept_unit.strip() == r'\AA^-1' :154 if zaccept_unit.strip() == r'\AA^-1' or zaccept_unit.strip() == r'\A^-1': 178 155 zaccept_unit = "1/A" 179 156 output.sample.zacceptance=(float(paramvals[7]),zaccept_unit) 180 output.vars =varheader157 output.vars = varheader 181 158 182 159 if len(output.x) < 1: -
src/sas/sascalc/fit/AbstractFitEngine.py
rd3911e3 ra9f579c 131 131 a way to get residuals from data. 132 132 """ 133 def __init__(self, x, y, dx=None, dy=None, smearer=None, data=None ):133 def __init__(self, x, y, dx=None, dy=None, smearer=None, data=None, lam=None, dlam=None): 134 134 """ 135 135 :param smearer: is an object of class QSmearer or SlitSmearer … … 152 152 153 153 """ 154 Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy )154 Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy, lam=lam, dlam=dlam) 155 155 self.num_points = len(x) 156 156 self.sas_data = data -
src/sas/sasgui/guiframe/dataFitting.py
r345e7e4 r68adf86 17 17 """ 18 18 """ 19 def __init__(self, x=None, y=None, dx=None, dy=None): 19 20 def __init__(self, x=None, y=None, dx=None, dy=None, lam=None, dlam=None, isSesans=False): 20 21 """ 21 22 """ … … 24 25 if y is None: 25 26 y = [] 26 PlotData1D.__init__(self, x, y, dx, dy) 27 LoadData1D.__init__(self, x, y, dx, dy) 27 self.isSesans = isSesans 28 PlotData1D.__init__(self, x, y, dx, dy, lam, dlam) 29 LoadData1D.__init__(self, x, y, dx, dy, lam, dlam, isSesans) 30 28 31 self.id = None 29 32 self.list_group_id = [] … … 32 35 self.path = None 33 36 self.xtransform = None 37 if self.isSesans: 38 self.xtransform = "x" 34 39 self.ytransform = None 40 if self.isSesans: 41 self.ytransform = "y" 35 42 self.title = "" 36 43 self.scale = None … … 68 75 # First, check the data compatibility 69 76 dy, dy_other = self._validity_check(other) 70 result = Data1D(x=[], y=[], dx=None, dy=None)77 result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=None) 71 78 result.clone_without_data(length=len(self.x), clone=self) 72 79 result.copy_from_datainfo(data1d=self) … … 115 122 # First, check the data compatibility 116 123 self._validity_check_union(other) 117 result = Data1D(x=[], y=[], dx=None, dy=None)124 result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=None) 118 125 tot_length = len(self.x) + len(other.x) 119 126 result = self.clone_without_data(length=tot_length, clone=result) 127 if self.dlam == None or other.dlam is None: 128 result.dlam = None 129 else: 130 result.dlam = numpy.zeros(tot_length) 120 131 if self.dy == None or other.dy is None: 121 132 result.dy = None … … 141 152 result.y = numpy.append(self.y, other.y) 142 153 result.y = result.y[ind] 154 result.lam = numpy.append(self.lam, other.lam) 155 result.lam = result.lam[ind] 156 if result.dlam != None: 157 result.dlam = numpy.append(self.dlam, other.dlam) 158 result.dlam = result.dlam[ind] 143 159 if result.dy != None: 144 160 result.dy = numpy.append(self.dy, other.dy) … … 260 276 # First, check the data compatibility 261 277 self._validity_check_union(other) 262 result = Data1D(x=[], y=[], dx=None, dy=None)278 result = Data1D(x=[], y=[], lam=[], dx=None, dy=None, dlam=[]) 263 279 tot_length = len(self.x)+len(other.x) 264 280 result.clone_without_data(length=tot_length, clone=self) 281 if self.dlam == None or other.dlam is None: 282 result.dlam = None 283 else: 284 result.dlam = numpy.zeros(tot_length) 265 285 if self.dy == None or other.dy is None: 266 286 result.dy = None … … 285 305 result.y = numpy.append(self.y, other.y) 286 306 result.y = result.y[ind] 307 result.lam = numpy.append(self.lam, other.lam) 308 result.lam = result.lam[ind] 287 309 if result.dy != None: 288 310 result.dy = numpy.append(self.dy, other.dy) -
src/sas/sasgui/guiframe/data_manager.py
r345e7e4 r2ffe241 61 61 62 62 if issubclass(Data2D, data.__class__): 63 new_plot = Data2D(image=None, err_image=None) 64 else: 65 new_plot = Data1D(x=[], y=[], dx=None, dy=None) 66 63 new_plot = Data2D(image=None, err_image=None) # For now, isSesans for 2D data is always false 64 else: 65 new_plot = Data1D(x=[], y=[], dx=None, dy=None, lam=None, dlam=None, isSesans=data.isSesans) 66 67 68 #elif data.meta_data['loader'] == 'SESANS': 69 # new_plot = Data1D(x=[], y=[], dx=None, dy=None, lam=None, dlam=None, isSesans=True) 70 #else: 71 # new_plot = Data1D(x=[], y=[], dx=None, dy=None, lam=None, dlam=None) #SESANS check??? 72 67 73 new_plot.copy_from_datainfo(data) 68 74 data.clone_without_data(clone=new_plot) -
src/sas/sasgui/plottools/plottables.py
r345e7e4 ra9f579c 1023 1023 """ 1024 1024 1025 def __init__(self, x, y, dx=None, dy=None ):1025 def __init__(self, x, y, dx=None, dy=None, lam=None, dlam=None): 1026 1026 """ 1027 1027 Draw points specified by x[i],y[i] in the current color/symbol. … … 1037 1037 self.x = x 1038 1038 self.y = y 1039 self.lam = lam 1039 1040 self.dx = dx 1040 1041 self.dy = dy 1042 self.dlam = dlam 1041 1043 self.source = None 1042 1044 self.detector = None
Note: See TracChangeset
for help on using the changeset viewer.