- Timestamp:
- Apr 8, 2017 7:54:23 AM (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:
- c0ca2e3d
- Parents:
- fa4af76
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
rfa4af76 r168d359 4 4 Using the meta data information, various types of averaging 5 5 are performed in Q-space 6 7 To test this module use: 8 ``` 9 cd test 10 PYTHONPATH=../src/ python2 -m sasdataloader.test.utest_averaging DataInfoTests.test_sectorphi_quarter 11 ``` 6 12 """ 7 13 ##################################################################### … … 13 19 ###################################################################### 14 20 15 # If you want to run just a single test from this file: 16 # PYTHONPATH=../src/ python2 -m sasdataloader.test.utest_averaging data_info_tests.test_sectorq_full 21 17 22 # TODO: copy the meta data from the 2D object to the resulting 1D object 18 23 import math 19 24 import numpy as np 20 25 import sys 26 21 27 #from data_info import plottable_2D 22 28 from data_info import Data1D … … 266 272 ################################################################################ 267 273 274 class Binning(object): 275 ''' 276 This class just creates a binning object 277 either linear or log 278 ''' 279 280 def __init__(self, min_value, max_value, n_bins, base=None): 281 ''' 282 if base is None: Linear binning 283 ''' 284 self.min = min_value if min_value > 0 else 0.0001 285 self.max = max_value 286 self.n_bins = n_bins 287 self.base = base 288 289 def get_bin_index(self, value): 290 ''' 291 The general formula logarithm binning is: 292 bin = floor(N * (log(x) - log(min)) / (log(max) - log(min))) 293 ''' 294 if self.base: 295 temp_x = self.n_bins * (math.log(value, self.base) - math.log(self.min, self.base)) 296 temp_y = math.log(self.max, self.base) - math.log(self.min, self.base) 297 else: 298 temp_x = self.n_bins * (value - self.min) 299 temp_y = self.max - self.min 300 # Bin index calulation 301 return int(math.floor(temp_x / temp_y)) 302 303 304 ################################################################################ 305 268 306 class _Slab(object): 269 307 """ … … 765 803 """ 766 804 767 def __init__(self, r_min, r_max, phi_min=0, phi_max=2 * math.pi, nbins=20 ):805 def __init__(self, r_min, r_max, phi_min=0, phi_max=2 * math.pi, nbins=20, base = None): 768 806 self.r_min = r_min 769 807 self.r_max = r_max … … 771 809 self.phi_max = phi_max 772 810 self.nbins = nbins 811 self.base = base 773 812 774 813 def _agv(self, data2D, run='phi'): … … 805 844 phi_min = flip_phi(self.phi_min) 806 845 phi_max = flip_phi(self.phi_max) 807 846 847 # binning object 848 if run.lower() == 'phi': 849 binning = Binning(self.phi_min, self.phi_max, self.nbins, self.base) 850 else: 851 binning = Binning(self.r_min, self.r_max, self.nbins, self.base) 852 808 853 for n in range(len(data)): 809 854 … … 848 893 if not is_in: 849 894 continue 850 851 # Check which type of averaging we need895 896 # Get the binning index 852 897 if run.lower() == 'phi': 853 temp_x = (self.nbins) * (phi_value - self.phi_min) 854 temp_y = (self.phi_max - self.phi_min) 898 i_bin = binning.get_bin_index(phi_value) 855 899 else: 856 temp_x = (self.nbins) * (q_value - self.r_min) 857 temp_y = (self.r_max - self.r_min) 858 # Bin index calulation 859 i_bin = int(math.floor(temp_x / temp_y)) 900 i_bin = binning.get_bin_index(q_value) 860 901 861 902 # Take care of the edge case at phi = 2pi.
Note: See TracChangeset
for help on using the changeset viewer.