Changeset f2940c4 in sasview for src/sas/sascalc
- Timestamp:
- Apr 4, 2017 1:10:30 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 01febaf
- Parents:
- 9c0f3c17 (diff), dd11014 (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:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
red2276f rdd11014 14 14 #TODO: copy the meta data from the 2D object to the resulting 1D object 15 15 import math 16 import numpy as np16 import numpy 17 17 18 18 #from data_info import plottable_2D … … 82 82 if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None: 83 83 raise ValueError, "Can't convert this data: data=None..." 84 new_x = n p.tile(data2d.x_bins, (len(data2d.y_bins), 1))85 new_y = n p.tile(data2d.y_bins, (len(data2d.x_bins), 1))84 new_x = numpy.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 85 new_y = numpy.tile(data2d.y_bins, (len(data2d.x_bins), 1)) 86 86 new_y = new_y.swapaxes(0, 1) 87 87 … … 89 89 qx_data = new_x.flatten() 90 90 qy_data = new_y.flatten() 91 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 92 if data2d.err_data == None or np.any(data2d.err_data <= 0): 93 new_err_data = np.sqrt(np.abs(new_data)) 94 91 q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 92 if data2d.err_data is None or numpy.any(data2d.err_data <= 0): 93 new_err_data = numpy.sqrt(numpy.abs(new_data)) 95 94 else: 96 95 new_err_data = data2d.err_data.flatten() 97 mask = n p.ones(len(new_data), dtype=bool)96 mask = numpy.ones(len(new_data), dtype=bool) 98 97 99 98 #TODO: make sense of the following two lines... … … 150 149 151 150 # Get data 152 data = data2D.data[n p.isfinite(data2D.data)]153 err_data = data2D.err_data[n p.isfinite(data2D.data)]154 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]155 qy_data = data2D.qy_data[n p.isfinite(data2D.data)]151 data = data2D.data[numpy.isfinite(data2D.data)] 152 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 153 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 154 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 156 155 157 156 # Build array of Q intervals … … 171 170 raise RuntimeError, "_Slab._avg: unrecognized axis %s" % str(maj) 172 171 173 x = n p.zeros(nbins)174 y = n p.zeros(nbins)175 err_y = n p.zeros(nbins)176 y_counts = n p.zeros(nbins)172 x = numpy.zeros(nbins) 173 y = numpy.zeros(nbins) 174 err_y = numpy.zeros(nbins) 175 y_counts = numpy.zeros(nbins) 177 176 178 177 # Average pixelsize in q space … … 226 225 y = y / y_counts 227 226 x = x / y_counts 228 idx = (n p.isfinite(y) & np.isfinite(x))227 idx = (numpy.isfinite(y) & numpy.isfinite(x)) 229 228 230 229 if not idx.any(): … … 305 304 raise RuntimeError, msg 306 305 # Get data 307 data = data2D.data[n p.isfinite(data2D.data)]308 err_data = data2D.err_data[n p.isfinite(data2D.data)]309 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]310 qy_data = data2D.qy_data[n p.isfinite(data2D.data)]306 data = data2D.data[numpy.isfinite(data2D.data)] 307 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 308 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 309 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 311 310 312 311 y = 0.0 … … 415 414 """ 416 415 # Get data W/ finite values 417 data = data2D.data[n p.isfinite(data2D.data)]418 q_data = data2D.q_data[n p.isfinite(data2D.data)]419 err_data = data2D.err_data[n p.isfinite(data2D.data)]420 mask_data = data2D.mask[n p.isfinite(data2D.data)]416 data = data2D.data[numpy.isfinite(data2D.data)] 417 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 418 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 419 mask_data = data2D.mask[numpy.isfinite(data2D.data)] 421 420 422 421 dq_data = None … … 449 448 dq_overlap_y *= dq_overlap_y 450 449 451 dq_overlap = n p.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)450 dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 452 451 # Final protection of dq 453 452 if dq_overlap < 0: 454 453 dq_overlap = y_min 455 dqx_data = data2D.dqx_data[n p.isfinite(data2D.data)]456 dqy_data = data2D.dqy_data[n p.isfinite(data2D.data)] - dq_overlap454 dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] 455 dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap 457 456 # def; dqx_data = dq_r dqy_data = dq_phi 458 457 # Convert dq 2D to 1D here 459 458 dqx = dqx_data * dqx_data 460 459 dqy = dqy_data * dqy_data 461 dq_data = n p.add(dqx, dqy)462 dq_data = n p.sqrt(dq_data)463 464 #q_data_max = n p.max(q_data)460 dq_data = numpy.add(dqx, dqy) 461 dq_data = numpy.sqrt(dq_data) 462 463 #q_data_max = numpy.max(q_data) 465 464 if len(data2D.q_data) == None: 466 465 msg = "Circular averaging: invalid q_data: %g" % data2D.q_data … … 470 469 nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 471 470 472 x = n p.zeros(nbins)473 y = n p.zeros(nbins)474 err_y = n p.zeros(nbins)475 err_x = n p.zeros(nbins)476 y_counts = n p.zeros(nbins)471 x = numpy.zeros(nbins) 472 y = numpy.zeros(nbins) 473 err_y = numpy.zeros(nbins) 474 err_x = numpy.zeros(nbins) 475 y_counts = numpy.zeros(nbins) 477 476 478 477 for npt in range(len(data)): … … 528 527 529 528 err_y = err_y / y_counts 530 err_y[err_y == 0] = n p.average(err_y)529 err_y[err_y == 0] = numpy.average(err_y) 531 530 y = y / y_counts 532 531 x = x / y_counts 533 idx = (n p.isfinite(y)) & (np.isfinite(x))532 idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) 534 533 535 534 if err_x != None: … … 586 585 587 586 # Get data 588 data = data2D.data[n p.isfinite(data2D.data)]589 q_data = data2D.q_data[n p.isfinite(data2D.data)]590 err_data = data2D.err_data[n p.isfinite(data2D.data)]591 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]592 qy_data = data2D.qy_data[n p.isfinite(data2D.data)]587 data = data2D.data[numpy.isfinite(data2D.data)] 588 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 589 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 590 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 591 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 593 592 594 593 # Set space for 1d outputs 595 phi_bins = n p.zeros(self.nbins_phi)596 phi_counts = n p.zeros(self.nbins_phi)597 phi_values = n p.zeros(self.nbins_phi)598 phi_err = n p.zeros(self.nbins_phi)594 phi_bins = numpy.zeros(self.nbins_phi) 595 phi_counts = numpy.zeros(self.nbins_phi) 596 phi_values = numpy.zeros(self.nbins_phi) 597 phi_err = numpy.zeros(self.nbins_phi) 599 598 600 599 # Shift to apply to calculated phi values in order … … 637 636 phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 638 637 639 idx = (n p.isfinite(phi_bins))638 idx = (numpy.isfinite(phi_bins)) 640 639 641 640 if not idx.any(): … … 770 769 771 770 # Get the all data & info 772 data = data2D.data[n p.isfinite(data2D.data)]773 q_data = data2D.q_data[n p.isfinite(data2D.data)]774 err_data = data2D.err_data[n p.isfinite(data2D.data)]775 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]776 qy_data = data2D.qy_data[n p.isfinite(data2D.data)]771 data = data2D.data[numpy.isfinite(data2D.data)] 772 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 773 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 774 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 775 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 777 776 dq_data = None 778 777 … … 804 803 dq_overlap_y *= dq_overlap_y 805 804 806 dq_overlap = n p.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)805 dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 807 806 if dq_overlap < 0: 808 807 dq_overlap = y_min 809 dqx_data = data2D.dqx_data[n p.isfinite(data2D.data)]810 dqy_data = data2D.dqy_data[n p.isfinite(data2D.data)] - dq_overlap808 dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] 809 dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap 811 810 # def; dqx_data = dq_r dqy_data = dq_phi 812 811 # Convert dq 2D to 1D here 813 812 dqx = dqx_data * dqx_data 814 813 dqy = dqy_data * dqy_data 815 dq_data = n p.add(dqx, dqy)816 dq_data = n p.sqrt(dq_data)814 dq_data = numpy.add(dqx, dqy) 815 dq_data = numpy.sqrt(dq_data) 817 816 818 817 #set space for 1d outputs 819 x = n p.zeros(self.nbins)820 y = n p.zeros(self.nbins)821 y_err = n p.zeros(self.nbins)822 x_err = n p.zeros(self.nbins)823 y_counts = n p.zeros(self.nbins)818 x = numpy.zeros(self.nbins) 819 y = numpy.zeros(self.nbins) 820 y_err = numpy.zeros(self.nbins) 821 x_err = numpy.zeros(self.nbins) 822 y_counts = numpy.zeros(self.nbins) 824 823 825 824 # Get the min and max into the region: 0 <= phi < 2Pi … … 924 923 #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 925 924 x[i] = x[i] / y_counts[i] 926 y_err[y_err == 0] = n p.average(y_err)927 idx = (n p.isfinite(y) & np.isfinite(y_err))925 y_err[y_err == 0] = numpy.average(y_err) 926 idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) 928 927 if x_err != None: 929 928 d_x = x_err[idx] / y_counts[idx] … … 1013 1012 qx_data = data2D.qx_data 1014 1013 qy_data = data2D.qy_data 1015 q_data = n p.sqrt(qx_data * qx_data + qy_data * qy_data)1014 q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 1016 1015 1017 1016 # check whether or not the data point is inside ROI … … 1114 1113 1115 1114 # get phi from data 1116 phi_data = n p.arctan2(qy_data, qx_data)1115 phi_data = numpy.arctan2(qy_data, qx_data) 1117 1116 1118 1117 # Get the min and max into the region: -pi <= phi < Pi -
src/sas/sascalc/dataloader/readers/IgorReader.py
red2276f rdd11014 14 14 import os 15 15 16 import numpy as np17 import math18 #import logging19 20 16 from sas.sascalc.dataloader.data_info import Data2D 21 17 from sas.sascalc.dataloader.data_info import Detector 22 18 from sas.sascalc.dataloader.manipulations import reader2D_converter 19 import numpy as np 23 20 24 21 # Look for unit converter … … 65 62 data_conv_i(1.0, output.I_unit) 66 63 67 for line in lines:68 69 # Find setup info line70 if isInfo:71 isInfo = False72 line_toks = line.split()73 # Wavelength in Angstrom74 try:75 wavelength = float(line_toks[1])76 except:77 msg = "IgorReader: can't read this file, missing wavelength"78 raise ValueError, msg79 80 #Find # of bins in a row assuming the detector is square.81 if dataStarted == True:82 try:83 value = float(line)84 except:85 # Found a non-float entry, skip it86 continue87 88 # Get total bin number89 90 i_tot_row += 191 i_tot_row = math.ceil(math.sqrt(i_tot_row)) - 192 #print "i_tot", i_tot_row93 size_x = i_tot_row # 192#12894 size_y = i_tot_row # 192#12895 output.data = np.zeros([size_x, size_y])96 output.err_data = np.zeros([size_x, size_y])97 98 64 data_row = 0 99 65 wavelength = distance = center_x = center_y = None -
src/sas/sascalc/calculator/resolution_calculator.py
r9a5097c r9c0f3c17 15 15 import sys 16 16 import logging 17 18 logger = logging.getLogger(__name__) 17 19 18 20 #Plank's constant in cgs unit … … 1006 1008 detector_offset = self.sample2detector_distance[1] 1007 1009 except: 1008 logg ing.error(sys.exc_value)1010 logger.error(sys.exc_value) 1009 1011 1010 1012 # detector size in [no of pix_x,no of pix_y] … … 1093 1095 output.qy_data = qy_value 1094 1096 except: 1095 logg ing.error(sys.exc_value)1097 logger.error(sys.exc_value) 1096 1098 1097 1099 return output -
src/sas/sascalc/calculator/sas_gen.py
r9a5097c r9c0f3c17 12 12 import sys 13 13 import logging 14 15 logger = logging.getLogger(__name__) 14 16 15 17 MFACTOR_AM = 2.853E-12 … … 285 287 mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0 286 288 except: 287 logg ing.error(sys.exc_value)289 logger.error(sys.exc_value) 288 290 self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 289 291 self.pos_z[mask], self.sld_n[mask], … … 394 396 except: 395 397 # Skip non-data lines 396 logg ing.error(sys.exc_value)398 logger.error(sys.exc_value) 397 399 #Reading Header; Segment count ignored 398 400 s_line = line.split(":", 1) … … 589 591 z_lines.append(z_line) 590 592 except: 591 logg ing.error(sys.exc_value)593 logger.error(sys.exc_value) 592 594 593 595 output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) … … 683 685 except: 684 686 # Skip non-data lines 685 logg ing.error(sys.exc_value)687 logger.error(sys.exc_value) 686 688 output = MagSLD(pos_x, pos_y, pos_z, sld_n, 687 689 sld_mx, sld_my, sld_mz) -
src/sas/sascalc/data_util/calcthread.py
r934ce649 r463e7ffc 8 8 import traceback 9 9 import sys 10 import logging 10 11 11 12 if sys.platform.count("darwin") > 0: … … 21 22 from time import clock 22 23 from time import sleep 24 25 logger = logging.getLogger(__name__) 23 26 24 27 … … 244 247 pass 245 248 import logging 246 logg ing.error(traceback.format_exc())249 logger.error(traceback.format_exc()) 247 250 #print 'CalcThread exception', 248 251 -
src/sas/sascalc/dataloader/loader.py
rb699768 r463e7ffc 32 32 from readers import cansas_reader 33 33 34 logger = logging.getLogger(__name__) 35 34 36 class Registry(ExtensionRegistry): 35 37 """ … … 99 101 msg = "DataLoader couldn't locate DataLoader plugin folder." 100 102 msg += """ "%s" does not exist""" % dir 101 logg ing.warning(msg)103 logger.warning(msg) 102 104 return readers_found 103 105 … … 117 119 msg = "Loader: Error importing " 118 120 msg += "%s\n %s" % (item, sys.exc_value) 119 logg ing.error(msg)121 logger.error(msg) 120 122 121 123 # Process zip files … … 139 141 msg = "Loader: Error importing" 140 142 msg += " %s\n %s" % (mfile, sys.exc_value) 141 logg ing.error(msg)143 logger.error(msg) 142 144 143 145 except: 144 146 msg = "Loader: Error importing " 145 147 msg += " %s\n %s" % (item, sys.exc_value) 146 logg ing.error(msg)148 logger.error(msg) 147 149 148 150 return readers_found … … 190 192 msg = "Loader: Error accessing" 191 193 msg += " Reader in %s\n %s" % (module.__name__, sys.exc_value) 192 logg ing.error(msg)194 logger.error(msg) 193 195 return reader_found 194 196 … … 223 225 msg = "Loader: Error accessing Reader " 224 226 msg += "in %s\n %s" % (loader.__name__, sys.exc_value) 225 logg ing.error(msg)227 logger.error(msg) 226 228 return reader_found 227 229 … … 268 270 msg = "Loader: Error accessing Reader" 269 271 msg += " in %s\n %s" % (module.__name__, sys.exc_value) 270 logg ing.error(msg)272 logger.error(msg) 271 273 return reader_found 272 274 -
src/sas/sascalc/dataloader/readers/associations.py
re5c09cf r463e7ffc 18 18 import logging 19 19 import json 20 21 logger = logging.getLogger(__name__) 20 22 21 23 FILE_NAME = 'defaults.json' … … 67 69 msg = "read_associations: skipping association" 68 70 msg += " for %s\n %s" % (ext.lower(), sys.exc_value) 69 logg ing.error(msg)71 logger.error(msg) 70 72 else: 71 73 print "Could not find reader association settings\n %s [%s]" % (__file__, os.getcwd()) … … 81 83 :param registry_function: function to be called to register each reader 82 84 """ 83 logg ing.info("register_readers is now obsolete: use read_associations()")85 logger.info("register_readers is now obsolete: use read_associations()") 84 86 import abs_reader 85 87 import ascii_reader -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r8434365 r463e7ffc 33 33 import xml.dom.minidom 34 34 from xml.dom.minidom import parseString 35 36 logger = logging.getLogger(__name__) 35 37 36 38 PREPROCESS = "xmlpreprocess" … … 1471 1473 self.errors.add(err_mess) 1472 1474 if optional: 1473 logg ing.info(err_mess)1475 logger.info(err_mess) 1474 1476 else: 1475 1477 raise ValueError, err_mess … … 1480 1482 self.errors.add(err_mess) 1481 1483 if optional: 1482 logg ing.info(err_mess)1484 logger.info(err_mess) 1483 1485 else: 1484 1486 raise ValueError, err_mess -
src/sas/sascalc/dataloader/readers/danse_reader.py
r9a5097c r9c0f3c17 19 19 from sas.sascalc.dataloader.data_info import Data2D, Detector 20 20 from sas.sascalc.dataloader.manipulations import reader2D_converter 21 22 logger = logging.getLogger(__name__) 21 23 22 24 # Look for unit converter … … 142 144 error.append(err) 143 145 except: 144 logg ing.info("Skipping line:%s,%s" %(data_str,146 logger.info("Skipping line:%s,%s" %(data_str, 145 147 sys.exc_value)) 146 148 … … 196 198 msg = "Skipping entry (v1.0):%s,%s" % (str(data[i_pt]), 197 199 sys.exc_value) 198 logg ing.info(msg)200 logger.info(msg) 199 201 200 202 # Get bin number … … 271 273 raise ValueError, msg 272 274 else: 273 logg ing.info("Danse_reader Reading %s \n" % filename)275 logger.info("Danse_reader Reading %s \n" % filename) 274 276 275 277 # Store loading process information -
src/sas/sascalc/dataloader/readers/tiff_reader.py
r9a5097c r9c0f3c17 16 16 from sas.sascalc.dataloader.data_info import Data2D 17 17 from sas.sascalc.dataloader.manipulations import reader2D_converter 18 18 19 logger = logging.getLogger(__name__) 20 19 21 class Reader: 20 22 """ … … 76 78 value = float(val) 77 79 except: 78 logg ing.error("tiff_reader: had to skip a non-float point")80 logger.error("tiff_reader: had to skip a non-float point") 79 81 continue 80 82 -
src/sas/sascalc/dataloader/readers/xml_reader.py
ra235f715 r463e7ffc 18 18 from lxml import etree 19 19 from lxml.builder import E 20 21 logger = logging.getLogger(__name__) 20 22 21 23 PARSER = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False) … … 71 73 self.xmlroot = self.xmldoc.getroot() 72 74 except etree.XMLSyntaxError as xml_error: 73 logg ing.info(xml_error)75 logger.info(xml_error) 74 76 except Exception: 75 77 self.xml = None … … 88 90 self.xmlroot = etree.fromstring(tag_soup) 89 91 except etree.XMLSyntaxError as xml_error: 90 logg ing.info(xml_error)92 logger.info(xml_error) 91 93 except Exception: 92 94 self.xml = None … … 102 104 self.schemadoc = etree.parse(self.schema, parser=PARSER) 103 105 except etree.XMLSyntaxError as xml_error: 104 logg ing.info(xml_error)106 logger.info(xml_error) 105 107 except Exception: 106 108 self.schema = None -
src/sas/sascalc/pr/invertor.py
r9a5097c r9c0f3c17 18 18 from scipy import optimize 19 19 from sas.sascalc.pr.core.pr_inversion import Cinvertor 20 21 logger = logging.getLogger(__name__) 20 22 21 23 def help(): … … 495 497 # We were not able to estimate the errors 496 498 # Return an empty error matrix 497 logg ing.error(sys.exc_value)499 logger.error(sys.exc_value) 498 500 499 501 # Keep a copy of the last output … … 541 543 # number of terms 542 544 best_alpha, _, _ = self.estimate_alpha(self.nfunc) 543 logg ing.warning("Invertor.estimate_numterms: %s" % sys.exc_value)545 logger.warning("Invertor.estimate_numterms: %s" % sys.exc_value) 544 546 return self.nfunc, best_alpha, "Could not estimate number of terms" 545 547 -
src/sas/sascalc/pr/num_term.py
r9a5097c r9c0f3c17 5 5 import logging 6 6 from sas.sascalc.pr.invertor import Invertor 7 8 logger = logging.getLogger(__name__) 7 9 8 10 class NTermEstimator(object): … … 180 182 data_err = np.append(data_err, err) 181 183 except: 182 logg ing.error(sys.exc_value)184 logger.error(sys.exc_value) 183 185 184 186 return data_x, data_y, data_err
Note: See TracChangeset
for help on using the changeset viewer.