Changeset cb62bd5 in sasview
- Timestamp:
- Aug 4, 2017 4:22:51 AM (7 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 1abd19c
- Parents:
- a0e6b1b
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/pr/c_extensions/Cinvertor.c
r959eb01 rcb62bd5 294 294 } 295 295 296 const char set_ has_bck_doc[] =296 const char set_est_bck_doc[] = 297 297 "Sets background flag\n"; 298 298 … … 300 300 * Sets the maximum distance 301 301 */ 302 static PyObject * set_ has_bck(Cinvertor *self, PyObject *args) {303 int has_bck;304 305 if (!PyArg_ParseTuple(args, "i", & has_bck)) return NULL;306 self->params. has_bck = has_bck;307 return Py_BuildValue("i", self->params. has_bck);308 } 309 310 const char get_ has_bck_doc[] =302 static PyObject * set_est_bck(Cinvertor *self, PyObject *args) { 303 int est_bck; 304 305 if (!PyArg_ParseTuple(args, "i", &est_bck)) return NULL; 306 self->params.est_bck = est_bck; 307 return Py_BuildValue("i", self->params.est_bck); 308 } 309 310 const char get_est_bck_doc[] = 311 311 "Gets background flag\n"; 312 312 … … 314 314 * Gets the maximum distance 315 315 */ 316 static PyObject * get_ has_bck(Cinvertor *self, PyObject *args) {317 return Py_BuildValue("i", self->params. has_bck);316 static PyObject * get_est_bck(Cinvertor *self, PyObject *args) { 317 return Py_BuildValue("i", self->params.est_bck); 318 318 } 319 319 … … 882 882 sqrt_alpha = sqrt(self->params.alpha); 883 883 pi = acos(-1.0); 884 offset = (self->params. has_bck==1) ? 0 : 1;884 offset = (self->params.est_bck==1) ? 0 : 1; 885 885 886 886 for (j=0; j<nfunc; j++) { … … 892 892 } 893 893 if (accept_q(self, self->params.x[i])){ 894 if (self->params. has_bck==1 && j==0) {894 if (self->params.est_bck==1 && j==0) { 895 895 a[i*nfunc+j] = 1.0/self->params.err[i]; 896 896 } else { … … 906 906 } 907 907 for (i_r=0; i_r<nr; i_r++){ 908 if (self->params. has_bck==1 && j==0) {908 if (self->params.est_bck==1 && j==0) { 909 909 a[(i_r+self->params.npoints)*nfunc+j] = 0.0; 910 910 } else { … … 1029 1029 {"set_slit_height", (PyCFunction)set_slit_height, METH_VARARGS, set_slit_height_doc}, 1030 1030 {"get_slit_height", (PyCFunction)get_slit_height, METH_VARARGS, get_slit_height_doc}, 1031 {"set_ has_bck", (PyCFunction)set_has_bck, METH_VARARGS, set_has_bck_doc},1032 {"get_ has_bck", (PyCFunction)get_has_bck, METH_VARARGS, get_has_bck_doc},1031 {"set_est_bck", (PyCFunction)set_est_bck, METH_VARARGS, set_est_bck_doc}, 1032 {"get_est_bck", (PyCFunction)get_est_bck, METH_VARARGS, get_est_bck_doc}, 1033 1033 {"get_nx", (PyCFunction)get_nx, METH_VARARGS, get_nx_doc}, 1034 1034 {"get_ny", (PyCFunction)get_ny, METH_VARARGS, get_ny_doc}, -
src/sas/sascalc/pr/c_extensions/invertor.c
r959eb01 rcb62bd5 20 20 pars->q_min = -1.0; 21 21 pars->q_max = -1.0; 22 pars-> has_bck = 0;22 pars->est_bck = 0; 23 23 } 24 24 … … 313 313 return sqrt(sum_r2/(2.0*sum)); 314 314 } 315 -
src/sas/sascalc/pr/c_extensions/invertor.h
r959eb01 rcb62bd5 27 27 double q_max; 28 28 /// Flag for whether or not to evalute a constant background while inverting 29 int has_bck;29 int est_bck; 30 30 /// Slit height in units of q [A-1] 31 31 double slit_height; -
src/sas/sascalc/pr/invertor.py
r45dffa69 rcb62bd5 121 121 self.q_min, self.q_max, 122 122 self.x, self.y, 123 self.err, self. has_bck,123 self.err, self.est_bck, 124 124 self.slit_height, self.slit_width) = state 125 125 … … 133 133 self.q_min, self.q_max, 134 134 self.x, self.y, 135 self.err, self. has_bck,135 self.err, self.est_bck, 136 136 self.slit_height, self.slit_width, 137 137 ) … … 175 175 elif name == 'slit_width': 176 176 return self.set_slit_width(value) 177 elif name == ' has_bck':177 elif name == 'est_bck': 178 178 if value == True: 179 return self.set_ has_bck(1)179 return self.set_est_bck(1) 180 180 elif value == False: 181 return self.set_ has_bck(0)181 return self.set_est_bck(0) 182 182 else: 183 raise ValueError, "Invertor: has_bck can only be True or False"183 raise ValueError, "Invertor: est_bck can only be True or False" 184 184 185 185 return Cinvertor.__setattr__(self, name, value) … … 220 220 elif name == 'slit_width': 221 221 return self.get_slit_width() 222 elif name == ' has_bck':223 value = self.get_ has_bck()222 elif name == 'est_bck': 223 value = self.get_est_bck() 224 224 if value == 1: 225 225 return True … … 248 248 invertor.y = self.y 249 249 invertor.err = self.err 250 invertor.has_bck = self.has_bck 250 invertor.est_bck = self.est_bck 251 invertor.background = self.background 251 252 invertor.slit_height = self.slit_height 252 253 invertor.slit_width = self.slit_width … … 290 291 """ 291 292 # Reset the background value before proceeding 292 self.background = 0.0 293 return self.lstsq(nfunc, nr=nr) 293 # self.background = 0.0 294 if not self.est_bck: 295 self.y -= self.background 296 out, cov = self.lstsq(nfunc, nr=nr) 297 if not self.est_bck: 298 self.y += self.background 299 return out, cov 294 300 295 301 def iq(self, out, q): … … 454 460 455 461 # If we need to fit the background, add a term 456 if self. has_bck == True:462 if self.est_bck == True: 457 463 nfunc_0 = nfunc 458 464 nfunc += 1 … … 500 506 501 507 # Keep a copy of the last output 502 if self.has_bck == False: 503 self.background = 0 508 if self.est_bck == False: 504 509 self.out = c 505 510 self.cov = err … … 653 658 file.write("#slit_width=%g\n" % self.slit_width) 654 659 file.write("#background=%g\n" % self.background) 655 if self. has_bck == True:660 if self.est_bck == True: 656 661 file.write("#has_bck=1\n") 657 662 else: … … 734 739 toks = line.split('=') 735 740 if int(toks[1]) == 1: 736 self. has_bck = True741 self.est_bck = True 737 742 else: 738 self. has_bck = False743 self.est_bck = False 739 744 740 745 # Now read in the parameters -
src/sas/sasgui/perspectives/pr/inversion_panel.py
ra0e6b1b rcb62bd5 73 73 self.bck_est_ctl = None 74 74 self.bck_man_ctl = None 75 self. has_bck = True75 self.est_bck = True 76 76 self.bck_input = None 77 77 self.bck_ctl = None … … 330 330 331 331 # Background evaluation checkbox 332 state.estimate_bck = self. has_bck332 state.estimate_bck = self.est_bck 333 333 state.bck_value = bck 334 334 … … 382 382 self.bck_input.Enable() 383 383 self.bck_input.SetValue(str(state.bck_value)) 384 self. has_bck = state.estimate_bck384 self.est_bck = state.estimate_bck 385 385 self.bck_value = state.bck_value 386 386 … … 804 804 805 805 def _on_bck_changed(self, evt=None): 806 self. has_bck = self.bck_est_ctl.GetValue()807 if self. has_bck:806 self.est_bck = self.bck_est_ctl.GetValue() 807 if self.est_bck: 808 808 self.bck_input.Disable() 809 809 else: … … 828 828 d_max=dmax, 829 829 q_min=qmin, q_max=qmax, 830 bck=self.has_bck, 830 est_bck=self.est_bck, 831 bck_val=bck, 831 832 height=height, 832 833 width=width) … … 937 938 938 939 # Read background 939 if not self. has_bck:940 if not self.est_bck: 940 941 try: 941 942 bck_str = self.bck_input.GetValue() … … 987 988 d_max=dmax, 988 989 q_min=qmin, q_max=qmax, 989 bck=self.has_bck, 990 est_bck=self.est_bck, 991 bck_val = bck, 990 992 height=height, 991 993 width=width) -
src/sas/sasgui/perspectives/pr/pr.py
ra1b8fee rcb62bd5 68 68 self.q_min = None 69 69 self.q_max = None 70 self.has_bck = False 70 self.est_bck = False 71 self.bck_val = 0 71 72 self.slit_height = 0 72 73 self.slit_width = 0 … … 828 829 self.control_panel.iq0 = pr.iq0(out) 829 830 self.control_panel.bck = pr.background 831 self.control_panel.bck_input.SetValue("{:.2g}".format(pr.background)) 830 832 831 833 # Show I(q) fit … … 907 909 908 910 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 909 bck=False, height=0, width=0):911 est_bck=False, bck_val=0, height=0, width=0): 910 912 """ 911 913 Set up inversion from plotted data … … 916 918 self.q_min = q_min 917 919 self.q_max = q_max 918 self.has_bck = bck 920 self.est_bck = est_bck 921 self.bck_val = bck_val 919 922 self.slit_height = height 920 923 self.slit_width = width … … 930 933 def estimate_plot_inversion(self, alpha, nfunc, d_max, 931 934 q_min=None, q_max=None, 932 bck=False, height=0, width=0):935 est_bck=False, bck_val=0, height=0, width=0): 933 936 """ 934 937 Estimate parameters from plotted data … … 939 942 self.q_min = q_min 940 943 self.q_max = q_max 941 self.has_bck = bck 944 self.est_bck = est_bck 945 self.bck_val = bck_val 942 946 self.slit_height = height 943 947 self.slit_width = width … … 973 977 pr.x = self.current_plottable.x 974 978 pr.y = self.current_plottable.y 975 pr. has_bck = self.has_bck979 pr.est_bck = self.est_bck 976 980 pr.slit_height = self.slit_height 977 981 pr.slit_width = self.slit_width 982 pr.background = self.bck_val 978 983 979 984 # Keep track of the plot window title to ensure that … … 1019 1024 self.q_min = q_min 1020 1025 self.q_max = q_max 1021 self. has_bck = bck1026 self.est_bck = bck 1022 1027 self.slit_height = height 1023 1028 self.slit_width = width … … 1042 1047 self.q_min = q_min 1043 1048 self.q_max = q_max 1044 self. has_bck = bck1049 self.est_bck = bck 1045 1050 self.slit_height = height 1046 1051 self.slit_width = width … … 1115 1120 pr.y = y 1116 1121 pr.err = err 1117 pr. has_bck = self.has_bck1122 pr.est_bck = self.est_bck 1118 1123 pr.slit_height = self.slit_height 1119 1124 pr.slit_width = self.slit_width -
test/pr_inversion/test/utest_invertor.py
raaf5e49 rcb62bd5 68 68 self.x_in[i] = 1.0*(i+1) 69 69 70 def test_ has_bck_flag(self):71 """ 72 Tests the has_bck flag operations73 """ 74 self.assertEqual(self.invertor. has_bck, False)75 self.invertor. has_bck=True76 self.assertEqual(self.invertor. has_bck, True)70 def test_est_bck_flag(self): 71 """ 72 Tests the est_bck flag operations 73 """ 74 self.assertEqual(self.invertor.est_bck, False) 75 self.invertor.est_bck=True 76 self.assertEqual(self.invertor.est_bck, True) 77 77 def doit_float(): 78 self.invertor. has_bck = 2.078 self.invertor.est_bck = 2.0 79 79 def doit_str(): 80 self.invertor. has_bck = 'a'80 self.invertor.est_bck = 'a' 81 81 82 82 self.assertRaises(ValueError, doit_float)
Note: See TracChangeset
for help on using the changeset viewer.