Changeset 0997158f in sasview for DataLoader
- Timestamp:
- Jun 1, 2010 3:20:09 PM (15 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, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- a45622a
- Parents:
- 54180f9
- Location:
- DataLoader
- Files:
-
- 83 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/data_info.py
r3cd95c8 r0997158f 9 9 """ 10 10 11 """ 12 This software was developed by the University of Tennessee as part of the 13 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 14 project funded by the US National Science Foundation. 15 16 If you use DANSE applications to do scientific research that leads to 17 publication, we ask that you acknowledge the use of the software with the 18 following sentence: 19 20 "This work benefited from DANSE software developed under NSF award DMR-0520547." 21 22 copyright 2008, University of Tennessee 23 """ 11 12 #This software was developed by the University of Tennessee as part of the 13 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 14 #project funded by the US National Science Foundation. 15 #If you use DANSE applications to do scientific research that leads to 16 #publication, we ask that you acknowledge the use of the software with the 17 #following sentence: 18 #This work benefited from DANSE software developed under NSF award DMR-0520547. 19 #copyright 2008, University of Tennessee 20 24 21 25 22 #TODO: Keep track of data manipulation in the 'process' data structure. … … 34 31 class plottable_1D: 35 32 """ 36 33 Data1D is a place holder for 1D plottables. 37 34 """ 38 35 # The presence of these should be mutually exclusive with the presence of Qdev (dx) … … 70 67 class plottable_2D: 71 68 """ 72 69 Data2D is a place holder for 2D plottables. 73 70 """ 74 71 xmin = None … … 118 115 class Vector: 119 116 """ 120 117 Vector class to hold multi-dimensional objects 121 118 """ 122 119 ## x component … … 129 126 def __init__(self, x=None, y=None, z=None): 130 127 """ 131 Initialization. Components that are not 132 set a set to None by default. 133 134 @param x: x component 135 @param y: y component 136 @param z: z component 128 Initialization. Components that are not 129 set a set to None by default. 130 131 :param x: x component 132 :param y: y component 133 :param z: z component 134 137 135 """ 138 136 self.x = x … … 146 144 class Detector: 147 145 """ 148 146 Class to hold detector information 149 147 """ 150 148 ## Name of the instrument [string] … … 171 169 def __init__(self): 172 170 """ 173 Initialize class attribute that are objects... 171 172 Initialize class attribute that are objects... 173 174 174 """ 175 175 self.offset = Vector() … … 215 215 class Collimation: 216 216 """ 217 217 Class to hold collimation information 218 218 """ 219 219 ## Name … … 241 241 class Source: 242 242 """ 243 243 Class to hold source information 244 244 """ 245 245 ## Name … … 289 289 290 290 """ 291 291 Definitions of radiation types 292 292 """ 293 293 NEUTRON = 'neutron' … … 298 298 class Sample: 299 299 """ 300 300 Class to hold the sample description 301 301 """ 302 302 ## Short name for sample … … 347 347 class Process: 348 348 """ 349 350 349 Class that holds information about the processes 350 performed on the data. 351 351 """ 352 352 name = '' … … 374 374 class DataInfo: 375 375 """ 376 377 378 379 376 Class to hold the data read from a file. 377 It includes four blocks of data for the 378 instrument description, the sample description, 379 the data itself and any other meta data. 380 380 """ 381 381 ## Title … … 408 408 def __init__(self): 409 409 """ 410 410 Initialization 411 411 """ 412 412 ## Title … … 438 438 def __str__(self): 439 439 """ 440 440 Nice printout 441 441 """ 442 442 _str = "File: %s\n" % self.filename … … 464 464 def __add__(self, other): 465 465 """ 466 467 468 @param other: data set to add to the current one469 @return: new data set470 @raise ValueError: raised when two data sets are incompatible466 Add two data sets 467 468 :param other: data set to add to the current one 469 :return: new data set 470 :raise ValueError: raised when two data sets are incompatible 471 471 """ 472 472 def operation(a, b): return a+b … … 475 475 def __radd__(self, other): 476 476 """ 477 Add two data sets 478 479 @param other: data set to add to the current one 480 @return: new data set 481 @raise ValueError: raised when two data sets are incompatible 477 Add two data sets 478 479 :param other: data set to add to the current one 480 481 :return: new data set 482 483 :raise ValueError: raised when two data sets are incompatible 484 482 485 """ 483 486 def operation(a, b): return b+a … … 486 489 def __sub__(self, other): 487 490 """ 488 Subtract two data sets 489 490 @param other: data set to subtract from the current one 491 @return: new data set 492 @raise ValueError: raised when two data sets are incompatible 491 Subtract two data sets 492 493 :param other: data set to subtract from the current one 494 495 :return: new data set 496 497 :raise ValueError: raised when two data sets are incompatible 498 493 499 """ 494 500 def operation(a, b): return a-b … … 497 503 def __rsub__(self, other): 498 504 """ 499 Subtract two data sets 500 501 @param other: data set to subtract from the current one 502 @return: new data set 503 @raise ValueError: raised when two data sets are incompatible 505 Subtract two data sets 506 507 :param other: data set to subtract from the current one 508 509 :return: new data set 510 511 :raise ValueError: raised when two data sets are incompatible 512 504 513 """ 505 514 def operation(a, b): return b-a … … 508 517 def __mul__(self, other): 509 518 """ 510 Multiply two data sets 511 512 @param other: data set to subtract from the current one 513 @return: new data set 514 @raise ValueError: raised when two data sets are incompatible 519 Multiply two data sets 520 521 :param other: data set to subtract from the current one 522 523 :return: new data set 524 525 :raise ValueError: raised when two data sets are incompatible 526 515 527 """ 516 528 def operation(a, b): return a*b … … 519 531 def __rmul__(self, other): 520 532 """ 521 Multiply two data sets 522 523 @param other: data set to subtract from the current one 524 @return: new data set 525 @raise ValueError: raised when two data sets are incompatible 533 Multiply two data sets 534 535 :param other: data set to subtract from the current one 536 537 :return: new data set 538 539 :raise ValueError: raised when two data sets are incompatible 526 540 """ 527 541 def operation(a, b): return b*a … … 530 544 def __div__(self, other): 531 545 """ 532 Divided a data set by another 533 534 @param other: data set that the current one is divided by 535 @return: new data set 536 @raise ValueError: raised when two data sets are incompatible 546 Divided a data set by another 547 548 :param other: data set that the current one is divided by 549 550 :return: new data set 551 552 :raise ValueError: raised when two data sets are incompatible 553 537 554 """ 538 555 def operation(a, b): return a/b … … 541 558 def __rdiv__(self, other): 542 559 """ 543 Divided a data set by another 544 545 @param other: data set that the current one is divided by 546 @return: new data set 547 @raise ValueError: raised when two data sets are incompatible 560 Divided a data set by another 561 562 :param other: data set that the current one is divided by 563 564 :return: new data set 565 566 :raise ValueError: raised when two data sets are incompatible 567 548 568 """ 549 569 def operation(a, b): return b/a … … 552 572 class Data1D(plottable_1D, DataInfo): 553 573 """ 554 574 1D data class 555 575 """ 556 576 x_unit = '1/A' … … 564 584 def __str__(self): 565 585 """ 566 586 Nice printout 567 587 """ 568 588 _str = "%s\n" % DataInfo.__str__(self) … … 578 598 def is_slit_smeared(self): 579 599 """ 580 Check whether the data has slit smearing information 581 582 @return: True is slit smearing info is present, False otherwise 600 Check whether the data has slit smearing information 601 602 :return: True is slit smearing info is present, False otherwise 603 583 604 """ 584 605 def _check(v): … … 593 614 def clone_without_data(self, length=0, clone=None): 594 615 """ 595 596 597 598 599 @param length: length of the data array to be initialized600 @param clone: if provided, the data will be copied to clone616 Clone the current object, without copying the data (which 617 will be filled out by a subsequent operation). 618 The data arrays will be initialized to zero. 619 620 :param length: length of the data array to be initialized 621 :param clone: if provided, the data will be copied to clone 601 622 """ 602 623 from copy import deepcopy … … 625 646 def _validity_check(self, other): 626 647 """ 627 Checks that the data lengths are compatible. 628 Checks that the x vectors are compatible. 629 Returns errors vectors equal to original 630 errors vectors if they were present or vectors 631 of zeros when none was found. 632 633 @param other: other data set for operation 634 @return: dy for self, dy for other [numpy arrays] 635 @raise ValueError: when lengths are not compatible 648 Checks that the data lengths are compatible. 649 Checks that the x vectors are compatible. 650 Returns errors vectors equal to original 651 errors vectors if they were present or vectors 652 of zeros when none was found. 653 654 :param other: other data set for operation 655 656 :return: dy for self, dy for other [numpy arrays] 657 658 :raise ValueError: when lengths are not compatible 659 636 660 """ 637 661 dy_other = None … … 685 709 class Data2D(plottable_2D, DataInfo): 686 710 """ 687 711 2D data class 688 712 """ 689 713 ## Units for Q-values … … 724 748 def clone_without_data(self, length=0, clone=None): 725 749 """ 726 727 728 729 730 @param length: length of the data array to be initialized731 @param clone: if provided, the data will be copied to clone750 Clone the current object, without copying the data (which 751 will be filled out by a subsequent operation). 752 The data arrays will be initialized to zero. 753 754 :param length: length of the data array to be initialized 755 :param clone: if provided, the data will be copied to clone 732 756 """ 733 757 from copy import deepcopy … … 761 785 def _validity_check(self, other): 762 786 """ 763 Checks that the data lengths are compatible. 764 Checks that the x vectors are compatible. 765 Returns errors vectors equal to original 766 errors vectors if they were present or vectors 767 of zeros when none was found. 768 769 @param other: other data set for operation 770 @return: dy for self, dy for other [numpy arrays] 771 @raise ValueError: when lengths are not compatible 787 Checks that the data lengths are compatible. 788 Checks that the x vectors are compatible. 789 Returns errors vectors equal to original 790 errors vectors if they were present or vectors 791 of zeros when none was found. 792 793 :param other: other data set for operation 794 795 :return: dy for self, dy for other [numpy arrays] 796 797 :raise ValueError: when lengths are not compatible 798 772 799 """ 773 800 err_other = None … … 797 824 def _perform_operation(self, other, operation): 798 825 """ 799 Perform 2D operations between data sets 800 801 @param other: other data set 802 @param operation: function defining the operation 826 Perform 2D operations between data sets 827 828 :param other: other data set 829 :param operation: function defining the operation 830 803 831 """ 804 832 # First, check the data compatibility -
DataLoader/loader.py
rfd4b6f8 r0997158f 1 2 ##################################################################### 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 #See the license text in license.txt 7 #copyright 2008, University of Tennessee 8 ###################################################################### 9 1 10 """ 2 11 File handler to support different file extensions. … … 12 21 a directory (for instance, a user plug-in directory) and 13 22 look for new readers/writers. 14 """15 16 """17 This software was developed by the University of Tennessee as part of the18 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)19 project funded by the US National Science Foundation.20 21 See the license text in license.txt22 23 copyright 2008, University of Tennessee24 23 """ 25 24 … … 37 36 class Registry(ExtensionRegistry): 38 37 """ 39 40 38 Registry class for file format extensions. 39 Readers and writers are supported. 41 40 """ 42 41 … … 65 64 def load(self, path, format=None): 66 65 """ 67 68 69 @param path: file path70 @param format: explicit extension, to force the use of a particular reader71 72 73 74 66 Call the loader for the file type of path. 67 68 :param path: file path 69 :param format: explicit extension, to force the use of a particular reader 70 71 Defaults to the ascii (multi-column) reader 72 if no reader was registered for the file's 73 extension. 75 74 """ 76 75 try: … … 83 82 def find_plugins(self, dir): 84 83 """ 85 Find readers in a given directory. This method 86 can be used to inspect user plug-in directories to 87 find new readers/writers. 88 89 @param dir: directory to search into 90 @return: number of readers found 84 Find readers in a given directory. This method 85 can be used to inspect user plug-in directories to 86 find new readers/writers. 87 88 :param dir: directory to search into 89 90 :return: number of readers found 91 91 """ 92 92 readers_found = 0 … … 138 138 def associate_file_type(self, ext, module): 139 139 """ 140 141 142 143 144 @param ext: file extension [string]145 @param module: module object140 Look into a module to find whether it contains a 141 Reader class. If so, APPEND it to readers and (potentially) 142 to the list of writers for the given extension 143 144 :param ext: file extension [string] 145 :param module: module object 146 146 """ 147 147 reader_found = False … … 180 180 def associate_file_reader(self, ext, loader): 181 181 """ 182 183 184 @param ext: file extension [string]185 @param module: reader object182 Append a reader object to readers 183 184 :param ext: file extension [string] 185 :param module: reader object 186 186 """ 187 187 reader_found = False … … 211 211 def _identify_plugin(self, module): 212 212 """ 213 Look into a module to find whether it contains a 214 Reader class. If so, add it to readers and (potentially) 215 to the list of writers. 216 @param module: module object 213 Look into a module to find whether it contains a 214 Reader class. If so, add it to readers and (potentially) 215 to the list of writers. 216 :param module: module object 217 217 218 """ 218 219 reader_found = False … … 252 253 def lookup_writers(self, path): 253 254 """ 254 Returnthe loader associated with the file type of path.255 256 Raises ValueErrorif file type is not known.255 :return: the loader associated with the file type of path. 256 257 :Raises ValueError: if file type is not known. 257 258 """ 258 259 # Find matching extensions … … 282 283 Raises ValueError if no writer is available. 283 284 Raises KeyError if format is not available. 285 284 286 May raise a writer-defined exception if writer fails. 285 287 """ … … 299 301 class Loader(object): 300 302 """ 301 303 Utility class to use the Registry as a singleton. 302 304 """ 303 305 ## Registry instance … … 306 308 def associate_file_type(self, ext, module): 307 309 """ 308 309 310 311 312 @param ext: file extension [string]313 @param module: module object310 Look into a module to find whether it contains a 311 Reader class. If so, append it to readers and (potentially) 312 to the list of writers for the given extension 313 314 :param ext: file extension [string] 315 :param module: module object 314 316 """ 315 317 return self.__registry.associate_file_type(ext, module) … … 317 319 def associate_file_reader(self, ext, loader): 318 320 """ 319 320 321 @param ext: file extension [string]322 @param module: reader object321 Append a reader object to readers 322 323 :param ext: file extension [string] 324 :param module: reader object 323 325 """ 324 326 return self.__registry.associate_file_reader(ext, loader) … … 326 328 def load(self, file, format=None): 327 329 """ 328 329 330 @param file: file name (path)331 @param format: specified format to use (optional)332 @return: DataInfo object330 Load a file 331 332 :param file: file name (path) 333 :param format: specified format to use (optional) 334 :return: DataInfo object 333 335 """ 334 336 return self.__registry.load(file, format) … … 336 338 def save(self, file, data, format): 337 339 """ 338 339 @param file: file name (path)340 @param data: DataInfo object341 @param format: format to write the data in340 Save a DataInfo object to file 341 :param file: file name (path) 342 :param data: DataInfo object 343 :param format: format to write the data in 342 344 """ 343 345 return self.__registry.save(file, data, format) … … 345 347 def _get_registry_creation_time(self): 346 348 """ 347 348 349 Internal method used to test the uniqueness 350 of the registry object 349 351 """ 350 352 return self.__registry._created … … 352 354 def find_plugins(self, dir): 353 355 """ 354 Find plugins in a given directory 355 @param dir: directory to look into to find new readers/writers 356 Find plugins in a given directory 357 358 :param dir: directory to look into to find new readers/writers 356 359 """ 357 360 return self.__registry.find_plugins(dir) -
DataLoader/manipulations.py
rf265927 r0997158f 1 2 ##################################################################### 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 #See the license text in license.txt 7 #copyright 2008, University of Tennessee 8 ###################################################################### 9 1 10 """ 2 11 Data manipulations for 2D data sets. … … 5 14 """ 6 15 7 """ 8 This software was developed by the University of Tennessee as part of the 9 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 10 project funded by the US National Science Foundation. 11 12 See the license text in license.txt 13 14 copyright 2008, University of Tennessee 15 """ 16 16 17 #TODO: copy the meta data from the 2D object to the resulting 1D object 17 18 … … 22 23 def get_q(dx, dy, det_dist, wavelength): 23 24 """ 24 @param dx: x-distance from beam center [mm] 25 @param dy: y-distance from beam center [mm] 26 @return: q-value at the given position 25 :param dx: x-distance from beam center [mm] 26 :param dy: y-distance from beam center [mm] 27 28 :return: q-value at the given position 27 29 """ 28 30 # Distance from beam center in the plane of detector … … 33 35 34 36 def get_q_compo(dx, dy, det_dist, wavelength,compo=None): 35 #This reduces tiny error at very large q. 36 #Implementation of this func is not started yet.<--ToDo 37 """ 38 This reduces tiny error at very large q. 39 Implementation of this func is not started yet.<--ToDo 40 """ 37 41 if dy==0: 38 42 if dx>=0: … … 53 57 def flip_phi(phi): 54 58 """ 55 Correct phi to within the 0 <= to <= 2pi range 56 @return: phi in >=0 and <=2Pi 59 Correct phi to within the 0 <= to <= 2pi range 60 61 :return: phi in >=0 and <=2Pi 57 62 """ 58 63 Pi = math.pi … … 67 72 def reader2D_converter(data2d=None): 68 73 """ 69 convert old 2d format opened by IhorReader or danse_reader to new Data2D format 70 @param data2d: 2d array of Data2D object 71 @return: 1d arrays of Data2D object 74 convert old 2d format opened by IhorReader or danse_reader to new Data2D format 75 76 :param data2d: 2d array of Data2D object 77 78 :return: 1d arrays of Data2D object 79 72 80 """ 73 81 if data2d.data==None or data2d.x_bins==None or data2d.y_bins==None: … … 103 111 class _Slab(object): 104 112 """ 105 113 Compute average I(Q) for a region of interest 106 114 """ 107 115 def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0, bin_width=0.001): … … 123 131 def _avg(self, data2D, maj): 124 132 """ 125 Compute average I(Q_maj) for a region of interest. 126 The major axis is defined as the axis of Q_maj. 127 The minor axis is the axis that we average over. 128 129 @param data2D: Data2D object 130 @param maj_min: min value on the major axis 131 @return: Data1D object 133 Compute average I(Q_maj) for a region of interest. 134 The major axis is defined as the axis of Q_maj. 135 The minor axis is the axis that we average over. 136 137 :param data2D: Data2D object 138 :param maj_min: min value on the major axis 139 140 :return: Data1D object 132 141 """ 133 142 if len(data2D.detector) != 1: … … 221 230 class SlabY(_Slab): 222 231 """ 232 Compute average I(Qy) for a region of interest 233 """ 234 def __call__(self, data2D): 235 """ 223 236 Compute average I(Qy) for a region of interest 237 238 :param data2D: Data2D object 239 240 :return: Data1D object 241 """ 242 return self._avg(data2D, 'y') 243 244 class SlabX(_Slab): 245 """ 246 Compute average I(Qx) for a region of interest 224 247 """ 225 248 def __call__(self, data2D): 226 249 """ 227 Compute average I(Qy) for a region of interest228 229 @param data2D: Data2D object230 @return: Data1D object231 """232 return self._avg(data2D, 'y')233 234 class SlabX(_Slab):235 """236 250 Compute average I(Qx) for a region of interest 237 """ 238 def __call__(self, data2D): 239 """ 240 Compute average I(Qx) for a region of interest 241 242 @param data2D: Data2D object 243 @return: Data1D object 251 252 :param data2D: Data2D object 253 254 :return: Data1D object 255 244 256 """ 245 257 return self._avg(data2D, 'x') … … 247 259 class Boxsum(object): 248 260 """ 249 261 Perform the sum of counts in a 2D region of interest. 250 262 """ 251 263 def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): … … 261 273 def __call__(self, data2D): 262 274 """ 263 Perform the sum in the region of interest 264 265 @param data2D: Data2D object 266 @return: number of counts, error on number of counts 275 Perform the sum in the region of interest 276 277 :param data2D: Data2D object 278 279 :return: number of counts, error on number of counts 280 267 281 """ 268 282 y, err_y, y_counts = self._sum(data2D) … … 276 290 def _sum(self, data2D): 277 291 """ 278 Perform the sum in the region of interest 279 @param data2D: Data2D object 280 @return: number of counts, error on number of counts, number of entries summed 292 Perform the sum in the region of interest 293 294 :param data2D: Data2D object 295 296 :return: number of counts, error on number of counts, number of entries summed 297 281 298 """ 282 299 if len(data2D.detector) != 1: … … 328 345 class Boxavg(Boxsum): 329 346 """ 330 347 Perform the average of counts in a 2D region of interest. 331 348 """ 332 349 def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): … … 335 352 def __call__(self, data2D): 336 353 """ 337 Perform the sum in the region of interest 338 339 @param data2D: Data2D object 340 @return: average counts, error on average counts 354 Perform the sum in the region of interest 355 356 :param data2D: Data2D object 357 358 :return: average counts, error on average counts 359 341 360 """ 342 361 y, err_y, y_counts = self._sum(data2D) … … 350 369 def get_pixel_fraction_square(x, xmin, xmax): 351 370 """ 352 Return the fraction of the length 353 from xmin to x. 354 355 A B 356 +-----------+---------+ 357 xmin x xmax 358 359 @param x: x-value 360 @param xmin: minimum x for the length considered 361 @param xmax: minimum x for the length considered 362 @return: (x-xmin)/(xmax-xmin) when xmin < x < xmax 363 371 Return the fraction of the length 372 from xmin to x.:: 373 374 375 A B 376 +-----------+---------+ 377 xmin x xmax 378 379 :param x: x-value 380 :param xmin: minimum x for the length considered 381 :param xmax: minimum x for the length considered 382 383 :return: (x-xmin)/(xmax-xmin) when xmin < x < xmax 384 364 385 """ 365 386 if x<=xmin: … … 373 394 class CircularAverage(object): 374 395 """ 375 376 377 378 396 Perform circular averaging on 2D data 397 398 The data returned is the distribution of counts 399 as a function of Q 379 400 """ 380 401 def __init__(self, r_min=0.0, r_max=0.0, bin_width=0.0005): … … 388 409 def __call__(self, data2D): 389 410 """ 390 Perform circular averaging on the data 391 392 @param data2D: Data2D object 393 @return: Data1D object 411 Perform circular averaging on the data 412 413 :param data2D: Data2D object 414 415 :return: Data1D object 394 416 """ 395 417 # Get data … … 465 487 class Ring(object): 466 488 """ 467 468 469 470 471 472 473 474 475 489 Defines a ring on a 2D data set. 490 The ring is defined by r_min, r_max, and 491 the position of the center of the ring. 492 493 The data returned is the distribution of counts 494 around the ring as a function of phi. 495 496 Phi_min and phi_max should be defined between 0 and 2*pi 497 in anti-clockwise starting from the x- axis on the left-hand side 476 498 """ 477 499 #Todo: remove center. … … 490 512 def __call__(self, data2D): 491 513 """ 492 Apply the ring to the data set. 493 Returns the angular distribution for a given q range 494 495 @param data2D: Data2D object 496 @return: Data1D object 514 Apply the ring to the data set. 515 Returns the angular distribution for a given q range 516 517 :param data2D: Data2D object 518 519 :return: Data1D object 497 520 """ 498 521 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: … … 562 585 def get_pixel_fraction(qmax, q_00, q_01, q_10, q_11): 563 586 """ 564 565 566 has q < qmax.567 587 Returns the fraction of the pixel defined by 588 the four corners (q_00, q_01, q_10, q_11) that 589 has q < qmax.:: 590 568 591 q_01 q_11 569 592 y=1 +--------------+ … … 575 598 576 599 x=0 x=1 577 600 578 601 """ 579 602 … … 631 654 def get_intercept(q, q_0, q_1): 632 655 """ 633 Returns the fraction of the side at which the 634 q-value intercept the pixel, None otherwise. 635 The values returned is the fraction ON THE SIDE 636 OF THE LOWEST Q. 637 638 639 640 A B 641 +-----------+--------+ 642 0 1 <--- pixel size 643 644 Q_0 -------- Q ----- Q_1 <--- equivalent Q range 645 646 656 Returns the fraction of the side at which the 657 q-value intercept the pixel, None otherwise. 658 The values returned is the fraction ON THE SIDE 659 OF THE LOWEST Q. :: 660 661 662 A B 663 +-----------+--------+ <--- pixel size 664 0 1 665 Q_0 -------- Q ----- Q_1 <--- equivalent Q range 647 666 if Q_1 > Q_0, A is returned 648 667 if Q_1 < Q_0, B is returned 649 650 668 if Q is outside the range of [Q_0, Q_1], None is returned 651 669 … … 661 679 class _Sector: 662 680 """ 663 664 665 666 667 668 669 681 Defines a sector region on a 2D data set. 682 The sector is defined by r_min, r_max, phi_min, phi_max, 683 and the position of the center of the ring 684 where phi_min and phi_max are defined by the right and left lines wrt central line 685 and phi_max could be less than phi_min. 686 687 Phi is defined between 0 and 2*pi in anti-clockwise starting from the x- axis on the left-hand side 670 688 """ 671 689 def __init__(self, r_min, r_max, phi_min=0, phi_max=2*math.pi,nbins=20): … … 679 697 def _agv(self, data2D, run='phi'): 680 698 """ 681 Perform sector averaging. 682 683 @param data2D: Data2D object 684 @param run: define the varying parameter ('phi' , 'q' , or 'q2') 685 @return: Data1D object 699 Perform sector averaging. 700 701 :param data2D: Data2D object 702 :param run: define the varying parameter ('phi' , 'q' , or 'q2') 703 704 :return: Data1D object 686 705 """ 687 706 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: … … 793 812 class SectorPhi(_Sector): 794 813 """ 795 796 797 798 799 814 Sector average as a function of phi. 815 I(phi) is return and the data is averaged over Q. 816 817 A sector is defined by r_min, r_max, phi_min, phi_max. 818 The number of bin in phi also has to be defined. 800 819 """ 801 820 def __call__(self, data2D): 802 821 """ 803 804 805 @param data2D: Data2D object806 @return: Data1D object822 Perform sector average and return I(phi). 823 824 :param data2D: Data2D object 825 :return: Data1D object 807 826 """ 808 827 … … 811 830 class SectorQ(_Sector): 812 831 """ 813 814 815 816 817 818 832 Sector average as a function of Q for both symatric wings. 833 I(Q) is return and the data is averaged over phi. 834 835 A sector is defined by r_min, r_max, phi_min, phi_max. 836 r_min, r_max, phi_min, phi_max >0. 837 The number of bin in Q also has to be defined. 819 838 """ 820 839 def __call__(self, data2D): 821 840 """ 822 Perform sector average and return I(Q). 823 824 @param data2D: Data2D object 825 @return: Data1D object 841 Perform sector average and return I(Q). 842 843 :param data2D: Data2D object 844 845 :return: Data1D object 826 846 """ 827 847 return self._agv(data2D, 'q2') … … 829 849 class Ringcut(object): 830 850 """ 831 832 833 834 835 836 837 838 851 Defines a ring on a 2D data set. 852 The ring is defined by r_min, r_max, and 853 the position of the center of the ring. 854 855 The data returned is the region inside the ring 856 857 Phi_min and phi_max should be defined between 0 and 2*pi 858 in anti-clockwise starting from the x- axis on the left-hand side 839 859 """ 840 860 def __init__(self, r_min=0, r_max=0, center_x=0, center_y=0 ): … … 851 871 def __call__(self, data2D): 852 872 """ 853 Apply the ring to the data set. 854 Returns the angular distribution for a given q range 855 856 @param data2D: Data2D object 857 @return: index array in the range 873 Apply the ring to the data set. 874 Returns the angular distribution for a given q range 875 876 :param data2D: Data2D object 877 878 :return: index array in the range 858 879 """ 859 880 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: … … 875 896 class Boxcut(object): 876 897 """ 877 898 Find a rectangular 2D region of interest. 878 899 """ 879 900 def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): … … 889 910 def __call__(self, data2D): 890 911 """ 891 892 893 @param data2D: Data2D object894 @return: mask, 1d array (len = len(data))895 912 Find a rectangular 2D region of interest. 913 914 :param data2D: Data2D object 915 :return: mask, 1d array (len = len(data)) 916 with Trues where the data points are inside ROI, otherwise False 896 917 """ 897 918 mask = self._find(data2D) … … 901 922 def _find(self, data2D): 902 923 """ 903 Find a rectangular 2D region of interest. 904 @param data2D: Data2D object 905 @return: out, 1d array (length = len(data)) 906 with Trues where the data points are inside ROI, otherwise Falses 924 Find a rectangular 2D region of interest. 925 926 :param data2D: Data2D object 927 928 :return: out, 1d array (length = len(data)) 929 with Trues where the data points are inside ROI, otherwise Falses 907 930 """ 908 931 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: … … 921 944 class Sectorcut(object): 922 945 """ 923 924 925 926 927 928 946 Defines a sector (major + minor) region on a 2D data set. 947 The sector is defined by phi_min, phi_max, 948 where phi_min and phi_max are defined by the right and left lines wrt central line. 949 950 Phi_min and phi_max are given in units of radian 951 and (phi_max-phi_min) should not be larger than pi 929 952 """ 930 953 def __init__(self,phi_min=0, phi_max=math.pi): … … 934 957 def __call__(self, data2D): 935 958 """ 936 Find a rectangular 2D region of interest. 937 938 @param data2D: Data2D object 939 @return: mask, 1d array (len = len(data)) 940 with Trues where the data points are inside ROI, otherwise False 959 Find a rectangular 2D region of interest. 960 961 :param data2D: Data2D object 962 963 :return: mask, 1d array (len = len(data)) 964 965 with Trues where the data points are inside ROI, otherwise False 941 966 """ 942 967 mask = self._find(data2D) … … 946 971 def _find(self, data2D): 947 972 """ 948 Find a rectangular 2D region of interest. 949 @param data2D: Data2D object 950 @return: out, 1d array (length = len(data)) 951 with Trues where the data points are inside ROI, otherwise Falses 973 Find a rectangular 2D region of interest. 974 975 :param data2D: Data2D object 976 977 :return: out, 1d array (length = len(data)) 978 979 with Trues where the data points are inside ROI, otherwise Falses 952 980 """ 953 981 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: -
DataLoader/qsmearing.py
rf72333f r0997158f 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 1 2 ##################################################################### 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 #See the license text in license.txt 7 #copyright 2008, University of Tennessee 8 ###################################################################### 10 9 11 10 import DataLoader.extensions.smearer as smearer … … 17 16 def smear_selection(data1D): 18 17 """ 19 20 21 22 23 24 25 26 27 28 29 30 31 32 @param data1D: Data1D object18 Creates the right type of smearer according 19 to the data. 20 21 The canSAS format has a rule that either 22 slit smearing data OR resolution smearing data 23 is available. 24 25 For the present purpose, we choose the one that 26 has none-zero data. If both slit and resolution 27 smearing arrays are filled with good data 28 (which should not happen), then we choose the 29 resolution smearing data. 30 31 :param data1D: Data1D object 33 32 """ 34 33 # Sanity check. If we are not dealing with a SANS Data1D … … 94 93 def __deepcopy__(self, memo={}): 95 94 """ 96 97 98 95 Return a valid copy of self. 96 Avoid copying the _smearer C object and force a matrix recompute 97 when the copy is used. 99 98 """ 100 99 result = _BaseSmearer() … … 107 106 def get_bin_range(self, q_min=None, q_max=None): 108 107 """ 109 @param q_min: minimum q-value to smear 110 @param q_max: maximum q-value to smear 108 109 :param q_min: minimum q-value to smear 110 :param q_max: maximum q-value to smear 111 111 112 """ 112 113 # If this is the first time we call for smearing, … … 143 144 def __call__(self, iq_in, first_bin=0, last_bin=None): 144 145 """ 145 146 Perform smearing 146 147 """ 147 148 # If this is the first time we call for smearing, … … 170 171 class _SlitSmearer(_BaseSmearer): 171 172 """ 172 173 Slit smearing for I(q) array 173 174 """ 174 175 175 176 def __init__(self, nbins=None, width=None, height=None, min=None, max=None): 176 177 """ 177 Initialization 178 179 @param iq: I(q) array [cm-1] 180 @param width: slit width [A-1] 181 @param height: slit height [A-1] 182 @param min: Q_min [A-1] 183 @param max: Q_max [A-1] 178 Initialization 179 180 :param iq: I(q) array [cm-1] 181 :param width: slit width [A-1] 182 :param height: slit height [A-1] 183 :param min: Q_min [A-1] 184 :param max: Q_max [A-1] 185 184 186 """ 185 187 _BaseSmearer.__init__(self) … … 202 204 def _initialize_smearer(self): 203 205 """ 204 205 206 Initialize the C++ smearer object. 207 This method HAS to be called before smearing 206 208 """ 207 209 #self._smearer = smearer.new_slit_smearer(self.width, self.height, self.min, self.max, self.nbins) … … 211 213 def get_unsmeared_range(self, q_min, q_max): 212 214 """ 213 214 215 Determine the range needed in unsmeared-Q to cover 216 the smeared Q range 215 217 """ 216 218 # Range used for input to smearing … … 226 228 class SlitSmearer(_SlitSmearer): 227 229 """ 228 230 Adaptor for slit smearing class and SANS data 229 231 """ 230 232 def __init__(self, data1D): 231 233 """ 232 233 234 @param data1D: data used to set the smearing parameters234 Assumption: equally spaced bins of increasing q-values. 235 236 :param data1D: data used to set the smearing parameters 235 237 """ 236 238 # Initialization from parent class … … 267 269 class _QSmearer(_BaseSmearer): 268 270 """ 269 271 Perform Gaussian Q smearing 270 272 """ 271 273 272 274 def __init__(self, nbins=None, width=None, min=None, max=None): 273 275 """ 274 275 276 @param nbins: number of Q bins277 @param width: array standard deviation in Q [A-1]278 @param min: Q_min [A-1]279 @param max: Q_max [A-1]276 Initialization 277 278 :param nbins: number of Q bins 279 :param width: array standard deviation in Q [A-1] 280 :param min: Q_min [A-1] 281 :param max: Q_max [A-1] 280 282 """ 281 283 _BaseSmearer.__init__(self) … … 294 296 def _initialize_smearer(self): 295 297 """ 296 297 298 Initialize the C++ smearer object. 299 This method HAS to be called before smearing 298 300 """ 299 301 #self._smearer = smearer.new_q_smearer(numpy.asarray(self.width), self.min, self.max, self.nbins) … … 303 305 def get_unsmeared_range(self, q_min, q_max): 304 306 """ 305 306 307 307 Determine the range needed in unsmeared-Q to cover 308 the smeared Q range 309 Take 3 sigmas as the offset between smeared and unsmeared space 308 310 """ 309 311 # Range used for input to smearing … … 318 320 return _qmin_unsmeared, _qmax_unsmeared 319 321 320 321 322 322 323 class QSmearer(_QSmearer): 323 324 """ 324 325 Adaptor for Gaussian Q smearing class and SANS data 325 326 """ 326 327 def __init__(self, data1D): 327 328 """ 328 329 330 @param data1D: data used to set the smearing parameters329 Assumption: equally spaced bins of increasing q-values. 330 331 :param data1D: data used to set the smearing parameters 331 332 """ 332 333 # Initialization from parent class -
DataLoader/readers/IgorReader.py
readf1f9 r0997158f 1 2 ############################################################################ 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 #If you use DANSE applications to do scientific research that leads to 7 #publication, we ask that you acknowledge the use of the software with the 8 #following sentence: 9 #This work benefited from DANSE software developed under NSF award DMR-0520547. 10 #copyright 2008, University of Tennessee 11 ############################################################################# 12 1 13 """ 2 14 IGOR 2D reduced file reader 3 """4 5 """6 This software was developed by the University of Tennessee as part of the7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)8 project funded by the US National Science Foundation.9 10 If you use DANSE applications to do scientific research that leads to11 publication, we ask that you acknowledge the use of the software with the12 following sentence:13 14 "This work benefited from DANSE software developed under NSF award DMR-0520547."15 16 copyright 2008, University of Tennessee17 15 """ 18 16 -
DataLoader/readers/abs_reader.py
rfe78c7b r0997158f 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2008, University of Tennessee 9 """ 1 ##################################################################### 2 #This software was developed by the University of Tennessee as part of the 3 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 #project funded by the US National Science Foundation. 5 #See the license text in license.txt 6 #copyright 2008, University of Tennessee 7 ###################################################################### 10 8 11 9 import numpy … … 21 19 class Reader: 22 20 """ 23 21 Class to load IGOR reduced .ABS files 24 22 """ 25 23 ## File type … … 32 30 def read(self, path): 33 31 """ 34 Load data file 35 36 @param path: file path 37 @return: Data1D object, or None 38 @raise RuntimeError: when the file can't be opened 39 @raise ValueError: when the length of the data vectors are inconsistent 32 Load data file. 33 34 :param path: file path 35 36 :return: Data1D object, or None 37 38 :raise RuntimeError: when the file can't be opened 39 :raise ValueError: when the length of the data vectors are inconsistent 40 40 """ 41 41 if os.path.isfile(path): -
DataLoader/readers/ascii_reader.py
rc7c5ef8 r0997158f 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2008, University of Tennessee 9 """ 1 2 3 ############################################################################ 4 #This software was developed by the University of Tennessee as part of the 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 #If you use DANSE applications to do scientific research that leads to 8 #publication, we ask that you acknowledge the use of the software with the 9 #following sentence: 10 #This work benefited from DANSE software developed under NSF award DMR-0520547. 11 #copyright 2008, University of Tennessee 12 ############################################################################# 13 10 14 11 15 import numpy … … 22 26 class Reader: 23 27 """ 24 Class to load ascii files (2, 3 or 4 columns)28 Class to load ascii files (2, 3 or 4 columns). 25 29 """ 26 30 ## File type … … 39 43 def read(self, path): 40 44 """ 41 Load data file 42 43 @param path: file path 44 @return: Data1D object, or None 45 @raise RuntimeError: when the file can't be opened 46 @raise ValueError: when the length of the data vectors are inconsistent 45 Load data file 46 47 :param path: file path 48 49 :return: Data1D object, or None 50 51 :raise RuntimeError: when the file can't be opened 52 :raise ValueError: when the length of the data vectors are inconsistent 47 53 """ 48 54 if os.path.isfile(path): -
DataLoader/readers/associations.py
rded62ce r0997158f 1 """2 This software was developed by the University of Tennessee as part of the3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)4 project funded by the US National Science Foundation.5 1 6 See the license text in license.txt7 2 8 copyright 2009, University of Tennessee 9 """ 3 ############################################################################ 4 #This software was developed by the University of Tennessee as part of the 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 #If you use DANSE applications to do scientific research that leads to 8 #publication, we ask that you acknowledge the use of the software with the 9 #following sentence: 10 #This work benefited from DANSE software developed under NSF award DMR-0520547. 11 #copyright 2009, University of Tennessee 12 ############################################################################# 13 10 14 11 15 """ 12 13 14 16 Module to associate default readers to file extensions. 17 The module reads an xml file to get the readers for each file extension. 18 The readers are tried in order they appear when reading a file. 15 19 """ 16 20 … … 26 30 def read_associations(loader, settings='defaults.xml'): 27 31 """ 28 29 30 31 @param loader: Loader object32 @param settings: path to the XML settings file [string]32 Read the specified settings file to associate 33 default readers to file extension. 34 35 :param loader: Loader object 36 :param settings: path to the XML settings file [string] 33 37 """ 34 38 reader_dir = os.path.dirname(__file__) … … 69 73 def register_readers(registry_function): 70 74 """ 71 Function called by the registry/loader object to register 72 all default readers using a call back function. 73 74 WARNING: this method is now obsolete 75 Function called by the registry/loader object to register 76 all default readers using a call back function. 75 77 76 @param registry_function: function to be called to register each reader 78 :WARNING: this method is now obsolete 79 80 :param registry_function: function to be called to register each reader 77 81 """ 78 82 logging.info("register_readers is now obsolete: use read_associations()") -
DataLoader/readers/cansas_reader.py
rfe78c7b r0997158f 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2008, 2009, University of Tennessee 9 """ 1 2 3 ############################################################################ 4 #This software was developed by the University of Tennessee as part of the 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 #If you use DANSE applications to do scientific research that leads to 8 #publication, we ask that you acknowledge the use of the software with the 9 #following sentence: 10 #This work benefited from DANSE software developed under NSF award DMR-0520547. 11 #copyright 2008,2009 University of Tennessee 12 ############################################################################# 13 10 14 # Known issue: reader not compatible with multiple SASdata entries 11 15 # within a single SASentry. Will raise a runtime error. … … 37 41 def write_node(doc, parent, name, value, attr={}): 38 42 """ 39 @param doc: document DOM 40 @param parent: parent node 41 @param name: tag of the element 42 @param value: value of the child text node 43 @param attr: attribute dictionary 44 @return: True if something was appended, otherwise False 43 :param doc: document DOM 44 :param parent: parent node 45 :param name: tag of the element 46 :param value: value of the child text node 47 :param attr: attribute dictionary 48 49 :return: True if something was appended, otherwise False 45 50 """ 46 51 if value is not None: … … 55 60 def get_content(location, node): 56 61 """ 57 Get the first instance of the content of a xpath location 58 59 @param location: xpath location 60 @param node: node to start at 61 @return: Element, or None 62 Get the first instance of the content of a xpath location. 63 64 :param location: xpath location 65 :param node: node to start at 66 67 :return: Element, or None 62 68 """ 63 69 nodes = node.xpath(location, namespaces={'ns': CANSAS_NS}) … … 70 76 def get_float(location, node): 71 77 """ 72 73 74 @param location: xpath location75 @param node: node to start at78 Get the content of a node as a float 79 80 :param location: xpath location 81 :param node: node to start at 76 82 """ 77 83 nodes = node.xpath(location, namespaces={'ns': CANSAS_NS}) … … 96 102 class Reader: 97 103 """ 98 99 100 101 104 Class to load cansas 1D XML files 105 106 :Dependencies: 107 The CanSas reader requires PyXML 0.8.4 or later. 102 108 """ 103 109 ## CanSAS version … … 116 122 def read(self, path): 117 123 """ 118 Load data file 119 120 @param path: file path 121 @return: Data1D object if a single SASentry was found, 122 or a list of Data1D objects if multiple entries were found, 123 or None of nothing was found 124 @raise RuntimeError: when the file can't be opened 125 @raise ValueError: when the length of the data vectors are inconsistent 124 Load data file 125 126 :param path: file path 127 128 :return: Data1D object if a single SASentry was found, 129 or a list of Data1D objects if multiple entries were found, 130 or None of nothing was found 131 132 :raise RuntimeError: when the file can't be opened 133 :raise ValueError: when the length of the data vectors are inconsistent 126 134 """ 127 135 output = [] … … 162 170 def _parse_entry(self, dom): 163 171 """ 164 Parse a SASentry 165 166 @param node: SASentry node 167 @return: Data1D object 172 Parse a SASentry 173 174 :param node: SASentry node 175 176 :return: Data1D object 168 177 """ 169 178 x = numpy.zeros(0) … … 510 519 def _to_xml_doc(self, datainfo): 511 520 """ 512 513 514 @param datainfo: Data1D object521 Create an XML document to contain the content of a Data1D 522 523 :param datainfo: Data1D object 515 524 """ 516 525 … … 696 705 def write(self, filename, datainfo): 697 706 """ 698 699 700 @param filename: name of the file to write701 @param datainfo: Data1D object707 Write the content of a Data1D as a CanSAS XML file 708 709 :param filename: name of the file to write 710 :param datainfo: Data1D object 702 711 """ 703 712 # Create XML document … … 710 719 def _store_float(self, location, node, variable, storage, optional=True): 711 720 """ 712 713 714 715 716 717 718 719 720 @param location: xpath location to fetch721 @param node: node to read the data from722 @param variable: name of the data member to store it in [string]723 @param storage: data object that has the 'variable' data member724 @param optional: if True, no exception will be raised if unit conversion can't be done725 726 @raise ValueError: raised when the units are not recognized721 Get the content of a xpath location and store 722 the result. Check that the units are compatible 723 with the destination. The value is expected to 724 be a float. 725 726 The xpath location might or might not exist. 727 If it does not exist, nothing is done 728 729 :param location: xpath location to fetch 730 :param node: node to read the data from 731 :param variable: name of the data member to store it in [string] 732 :param storage: data object that has the 'variable' data member 733 :param optional: if True, no exception will be raised if unit conversion can't be done 734 735 :raise ValueError: raised when the units are not recognized 727 736 """ 728 737 entry = get_content(location, node) … … 767 776 def _store_content(self, location, node, variable, storage): 768 777 """ 769 Get the content of a xpath location and store 770 the result. The value is treated as a string. 771 772 The xpath location might or might not exist. 773 If it does not exist, nothing is done 774 775 @param location: xpath location to fetch 776 @param node: node to read the data from 777 @param variable: name of the data member to store it in [string] 778 @param storage: data object that has the 'variable' data member 779 @return: return a list of errors 778 Get the content of a xpath location and store 779 the result. The value is treated as a string. 780 781 The xpath location might or might not exist. 782 If it does not exist, nothing is done 783 784 :param location: xpath location to fetch 785 :param node: node to read the data from 786 :param variable: name of the data member to store it in [string] 787 :param storage: data object that has the 'variable' data member 788 789 :return: return a list of errors 780 790 """ 781 791 entry = get_content(location, node) -
DataLoader/readers/danse_reader.py
readf1f9 r0997158f 1 2 3 ############################################################################ 4 #This software was developed by the University of Tennessee as part of the 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 #If you use DANSE applications to do scientific research that leads to 8 #publication, we ask that you acknowledge the use of the software with the 9 #following sentence: 10 #This work benefited from DANSE software developed under NSF award DMR-0520547. 11 #copyright 2008, University of Tennessee 12 ############################################################################# 13 1 14 """ 2 15 DANSE/SANS file reader 3 """4 5 """6 This software was developed by the University of Tennessee as part of the7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)8 project funded by the US National Science Foundation.9 10 If you use DANSE applications to do scientific research that leads to11 publication, we ask that you acknowledge the use of the software with the12 following sentence:13 14 "This work benefited from DANSE software developed under NSF award DMR-0520547."15 16 copyright 2008, University of Tennessee17 16 """ 18 17 … … 34 33 class Reader: 35 34 """ 36 35 Example data manipulation 37 36 """ 38 37 ## File type … … 45 44 def read(self, filename=None): 46 45 """ 47 48 46 Open and read the data in a file 47 @param file: path of the file 49 48 """ 50 49 … … 215 214 216 215 217 # Store all data ######################################216 # Store all data 218 217 # Store wavelength 219 218 if has_converter==True and output.source.wavelength_unit != 'A': -
DataLoader/readers/hfir1d_reader.py
rfe78c7b r0997158f 1 """2 This software was developed by the University of Tennessee as part of the3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)4 project funded by the US National Science Foundation.5 1 6 See the license text in license.txt 7 8 copyright 2008, University of Tennessee 9 """ 2 ##################################################################### 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 #See the license text in license.txt 7 #copyright 2008, University of Tennessee 8 ###################################################################### 10 9 11 10 import numpy … … 22 21 class Reader(object): 23 22 """ 24 23 Class to load HFIR 1D 4-column files 25 24 """ 26 25 ## File type … … 33 32 def read(self, path): 34 33 """ 35 Load data file 36 37 @param path: file path 38 @return: Data1D object, or None 39 @raise RuntimeError: when the file can't be opened 40 @raise ValueError: when the length of the data vectors are inconsistent 34 Load data file 35 36 :param path: file path 37 38 :return: Data1D object, or None 39 40 :raise RuntimeError: when the file can't be opened 41 :raise ValueError: when the length of the data vectors are inconsistent 41 42 """ 42 43 if os.path.isfile(path): -
DataLoader/readers/red2d_reader.py
r59a2dab r0997158f 1 2 ##################################################################### 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 #See the license text in license.txt 7 #copyright 2008, University of Tennessee 8 ###################################################################### 9 1 10 """ 2 11 TXT/IGOR 2D Q Map file reader 3 12 """ 4 13 5 """6 This software was developed by the University of Tennessee as part of the7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)8 project funded by the US National Science Foundation.9 10 If you use DANSE applications to do scientific research that leads to11 publication, we ask that you acknowledge the use of the software with the12 following sentence:13 14 "This work benefited from DANSE software developed under NSF award DMR-0520547."15 16 copyright 2008, University of Tennessee17 """18 14 19 15 import os, sys -
DataLoader/readers/tiff_reader.py
rfe78c7b r0997158f 1 2 3 ##################################################################### 4 #This software was developed by the University of Tennessee as part of the 5 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 6 #project funded by the US National Science Foundation. 7 #See the license text in license.txt 8 #copyright 2008, University of Tennessee 9 ###################################################################### 1 10 """ 2 11 Image reader. Untested. 3 12 """ 4 13 5 """6 This software was developed by the University of Tennessee as part of the7 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)8 project funded by the US National Science Foundation.9 14 10 See the license text in license.txt11 12 copyright 2008, University of Tennessee13 """14 15 #TODO: load and check data and orientation of the image (needs rendering) 15 16 … … 20 21 class Reader: 21 22 """ 22 23 Example data manipulation 23 24 """ 24 25 ## File type … … 33 34 def read(self, filename=None): 34 35 """ 35 Open and read the data in a file 36 @param file: path of the file 36 Open and read the data in a file 37 38 :param file: path of the file 37 39 """ 38 40 try: -
DataLoader/smearing_2d.py
rc6a48c27 r0997158f 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 1 ##################################################################### 2 #This software was developed by the University of Tennessee as part of the 3 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 #project funded by the US National Science Foundation. 5 #See the license text in license.txt 6 #copyright 2008, University of Tennessee 7 ###################################################################### 8 10 9 ## TODO: Need test,and check Gaussian averaging 11 10 import numpy, math,time … … 21 20 class Smearer2D: 22 21 """ 23 22 Gaussian Q smearing class for SANS 2d data 24 23 """ 25 24 26 def __init__(self, data=None,model=None,index=None,limit=LIMIT,accuracy='Low'): 27 """ 28 Assumption: equally spaced bins in dq_r, dq_phi space. 29 30 @param data: 2d data used to set the smearing parameters 31 @param model: model function 32 @param index: 1d array with len(data) to define the range of the calculation: elements are given as True or False 33 @param nr: number of bins in dq_r-axis 34 @param nphi: number of bins in dq_phi-axis 25 def __init__(self, data=None, model=None, index=None, 26 limit=LIMIT, accuracy='Low'): 27 """ 28 Assumption: equally spaced bins in dq_r, dq_phi space. 29 30 :param data: 2d data used to set the smearing parameters 31 :param model: model function 32 :param index: 1d array with len(data) to define the range of the calculation: elements are given as True or False 33 :param nr: number of bins in dq_r-axis 34 :param nphi: number of bins in dq_phi-axis 35 35 """ 36 36 ## data … … 52 52 def get_data(self): 53 53 """ 54 54 get qx_data, qy_data, dqx_data,dqy_data,and calculate phi_data=arctan(qx_data/qy_data) 55 55 """ 56 56 if self.data == None or self.data.__class__.__name__ == 'Data1D': … … 68 68 return True 69 69 70 def set_accuracy(self,accuracy='Low'): 71 """ 72 Set accuracy: string 70 def set_accuracy(self, accuracy='Low'): 71 """ 72 Set accuracy. 73 74 :param accuracy: string 73 75 """ 74 76 self.accuracy = accuracy 75 77 76 def set_smearer(self,smearer = True): 77 """ 78 Set whether or not smearer will be used 78 def set_smearer(self, smearer=True): 79 """ 80 Set whether or not smearer will be used 81 82 :param smearer: smear object 83 79 84 """ 80 85 self.smearer = smearer 81 86 82 def set_data(self,data=None): 83 """ 84 Set data: 1d arrays 87 def set_data(self, data=None): 88 """ 89 Set data. 90 91 :param data: DataLoader.Data_info type 85 92 """ 86 93 self.data = data 87 94 88 95 89 def set_model(self,model=None): 90 """ 91 Set model 96 def set_model(self, model=None): 97 """ 98 Set model. 99 100 :param model: sans.models instance 92 101 """ 93 102 self.model = model 94 103 95 def set_index(self,index=None): 96 """ 97 Set index: 1d arrays 98 """ 99 104 def set_index(self, index=None): 105 """ 106 Set index. 107 108 :param index: 1d arrays 109 """ 100 110 self.index = index 101 111 102 112 def get_value(self): 103 113 """ 104 Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, then find smeared intensity 105 # For the default values, this is equivalent (but by using numpy array 106 # the speed optimized by a factor of ten)to the following: 107 ===================================================================================== 108 ## Remove the singular points if exists 114 Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, then find smeared intensity 115 For the default values, this is equivalent (but by using numpy array 116 the speed optimized by a factor of ten)to the following: :: 117 118 119 Remove the singular points if exists 109 120 self.dqx_data[self.dqx_data==0]=SIGMA_ZERO 110 121 self.dqy_data[self.dqy_data==0]=SIGMA_ZERO 122 111 123 for phi in range(0,4): 112 124 for r in range(0,5): … … 114 126 r = r+0.25 115 127 dphi = phi*2.0*math.pi/4.0 + numpy.arctan(self.qy_data[index_model]/self.dqy_data[index_model]/self.qx_data[index_model]*/self.dqx_data[index_model]) 116 dq = r* numpy.sqrt( self.dqx_data[index_model]*self.dqx_data[index_model] \128 dq = r*sqrt( self.dqx_data[index_model]*self.dqx_data[index_model] \ 117 129 + self.dqy_data[index_model]*self.dqy_data[index_model] ) 118 #integrant of math.exp(-0.5*r*r) r dr at each bins : The integration may not need. 119 weight_res[n] = math.exp(-0.5*((r-0.25)*(r-0.25)))-math.exp(-0.5*((r-0.25)*(r-0.25))) 120 #if phi !=0 and r != 0: 121 qx_res=numpy.append(qx_res,self.qx_data[index_model]+ dq*math.cos(dphi)) 122 qy_res=numpy.append(qy_res,self.qy_data[index_model]+ dq*math.sin(dphi)) 123 ## Then compute I(qx_res,qy_res) and do weighted averaging. 124 ===================================================================================== 130 #integrant of exp(-0.5*r*r) r dr at each bins : The integration may not need. 131 weight_res[n] = e^{(-0.5*((r-0.25)*(r-0.25)))}- e^{(-0.5*((r-0.25)*(r-0.25)))} 132 #if phi != 0 and r != 0: 133 qx_res = numpy.append(qx_res,self.qx_data[index_model]+ dq * cos(dphi)) 134 qy_res = numpy.append(qy_res,self.qy_data[index_model]+ dq * sin(dphi)) 135 136 Then compute I(qx_res,qy_res) and do weighted averaging. 137 125 138 """ 126 139 valid = self.get_data()
Note: See TracChangeset
for help on using the changeset viewer.