Changeset b682c6a in sasview for src/sas/sascalc
- Timestamp:
- Aug 17, 2017 10:14:00 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c9ecd1b
- Parents:
- ce2819b (diff), a06ee7e (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. - Location:
- src/sas/sascalc
- 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/sascalc/dataloader/readers/cansas_reader.py
r7432acb r6a455cd3 158 158 # If the file does not match the schema, raise this error 159 159 invalid_xml = self.find_invalid_xml() 160 invalid_xml = INVALID_XML.format(basename + extension) + invalid_xml 161 self.errors.add(invalid_xml) 160 if invalid_xml != "": 161 invalid_xml = INVALID_XML.format(basename + extension) + invalid_xml 162 self.errors.add(invalid_xml) 162 163 # Try again with an invalid CanSAS schema, that requires only a data set in each 163 164 base_name = xml_reader.__file__ … … 263 264 # I and Q - 1D data 264 265 elif tagname == 'I' and isinstance(self.current_dataset, plottable_1D): 265 unit_list = unit.split("|") 266 if len(unit_list) > 1: 267 self.current_dataset.yaxis(unit_list[0].strip(), 268 unit_list[1].strip()) 269 else: 270 self.current_dataset.yaxis("Intensity", unit) 266 self.current_dataset.yaxis("Intensity", unit) 271 267 self.current_dataset.y = np.append(self.current_dataset.y, data_point) 272 268 elif tagname == 'Idev' and isinstance(self.current_dataset, plottable_1D): 273 269 self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 274 270 elif tagname == 'Q': 275 unit_list = unit.split("|") 276 if len(unit_list) > 1: 277 self.current_dataset.xaxis(unit_list[0].strip(), 278 unit_list[1].strip()) 279 else: 280 self.current_dataset.xaxis("Q", unit) 271 self.current_dataset.xaxis("Q", unit) 281 272 self.current_dataset.x = np.append(self.current_dataset.x, data_point) 282 273 elif tagname == 'Qdev': … … 292 283 elif tagname == 'Sesans': 293 284 self.current_datainfo.isSesans = bool(data_point) 285 self.current_dataset.xaxis(attr.get('x_axis'), 286 attr.get('x_unit')) 287 self.current_dataset.yaxis(attr.get('y_axis'), 288 attr.get('y_unit')) 294 289 elif tagname == 'yacceptance': 295 290 self.current_datainfo.sample.yacceptance = (data_point, unit) … … 785 780 value_unit = local_unit 786 781 except KeyError: 787 err_msg = "CanSAS reader: unexpected " 788 err_msg += "\"{0}\" unit [{1}]; " 789 err_msg = err_msg.format(tagname, local_unit) 790 err_msg += "expecting [{0}]".format(default_unit) 782 # Do not throw an error for loading Sesans data in cansas xml 783 # This is a temporary fix. 784 if local_unit != "A" and local_unit != 'pol': 785 err_msg = "CanSAS reader: unexpected " 786 err_msg += "\"{0}\" unit [{1}]; " 787 err_msg = err_msg.format(tagname, local_unit) 788 err_msg += "expecting [{0}]".format(default_unit) 791 789 value_unit = local_unit 792 790 except: … … 1039 1037 node.append(point) 1040 1038 self.write_node(point, "Q", datainfo.x[i], 1041 {'unit': datainfo. _xaxis + " | " + datainfo._xunit})1039 {'unit': datainfo.x_unit}) 1042 1040 if len(datainfo.y) >= i: 1043 1041 self.write_node(point, "I", datainfo.y[i], 1044 {'unit': datainfo. _yaxis + " | " + datainfo._yunit})1042 {'unit': datainfo.y_unit}) 1045 1043 if datainfo.dy is not None and len(datainfo.dy) > i: 1046 1044 self.write_node(point, "Idev", datainfo.dy[i], 1047 {'unit': datainfo. _yaxis + " | " + datainfo._yunit})1045 {'unit': datainfo.y_unit}) 1048 1046 if datainfo.dx is not None and len(datainfo.dx) > i: 1049 1047 self.write_node(point, "Qdev", datainfo.dx[i], 1050 {'unit': datainfo. _xaxis + " | " + datainfo._xunit})1048 {'unit': datainfo.x_unit}) 1051 1049 if datainfo.dxw is not None and len(datainfo.dxw) > i: 1052 1050 self.write_node(point, "dQw", datainfo.dxw[i], 1053 {'unit': datainfo. _xaxis + " | " + datainfo._xunit})1051 {'unit': datainfo.x_unit}) 1054 1052 if datainfo.dxl is not None and len(datainfo.dxl) > i: 1055 1053 self.write_node(point, "dQl", datainfo.dxl[i], 1056 {'unit': datainfo. _xaxis + " | " + datainfo._xunit})1054 {'unit': datainfo.x_unit}) 1057 1055 if datainfo.isSesans: 1058 sesans = self.create_element("Sesans") 1056 sesans_attrib = {'x_axis': datainfo._xaxis, 1057 'y_axis': datainfo._yaxis, 1058 'x_unit': datainfo.x_unit, 1059 'y_unit': datainfo.y_unit} 1060 sesans = self.create_element("Sesans", attrib=sesans_attrib) 1059 1061 sesans.text = str(datainfo.isSesans) 1060 node.append(sesans)1061 self.write_node( node, "yacceptance", datainfo.sample.yacceptance[0],1062 entry_node.append(sesans) 1063 self.write_node(entry_node, "yacceptance", datainfo.sample.yacceptance[0], 1062 1064 {'unit': datainfo.sample.yacceptance[1]}) 1063 self.write_node( node, "zacceptance", datainfo.sample.zacceptance[0],1065 self.write_node(entry_node, "zacceptance", datainfo.sample.zacceptance[0], 1064 1066 {'unit': datainfo.sample.zacceptance[1]}) 1065 1067 -
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
rc94280c r7c24685 126 126 127 127 if isinstance(value, h5py.Group): 128 parent_class = class_name 128 129 self.parent_class = class_name 129 130 parent_list.append(key) … … 136 137 # Recursion step to access data within the group 137 138 self.read_children(value, parent_list) 139 self.parent_class = parent_class 138 140 self.add_intermediate() 139 141 parent_list.remove(key) -
src/sas/sascalc/dataloader/readers/xml_reader.py
r235f514 r6a455cd3 130 130 first_error = schema.assertValid(self.xmldoc) 131 131 except etree.DocumentInvalid as err: 132 # Suppress errors for <'any'> elements 133 if "##other" in str(err): 134 return first_error 132 135 first_error = str(err) 133 136 return first_error
Note: See TracChangeset
for help on using the changeset viewer.