Changeset 8475d16 in sasview for src


Ignore:
Timestamp:
Dec 22, 2017 11:37:19 AM (6 years ago)
Author:
krzywon
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
cc62607
Parents:
0a88623
Message:

Coerce all nan values to 0 when loading data files. refs #1037

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    r3053a4a r8475d16  
    77import os 
    88import sys 
    9 import re 
     9import math 
    1010import logging 
    1111from abc import abstractmethod 
     
    102102        self.current_dataset = None 
    103103        self.filepath = None 
     104        self.ind = None 
    104105        self.output = [] 
    105106 
     
    158159                data.y_unit = self.format_unit(data.y_unit) 
    159160                # Sort data by increasing x and remove 1st point 
    160                 ind = np.lexsort((data.y, data.x)) 
    161                 data.x = np.asarray([data.x[i] for i in ind]).astype(np.float64) 
    162                 data.y = np.asarray([data.y[i] for i in ind]).astype(np.float64) 
     161                self.ind = np.lexsort((data.y, data.x)) 
     162                data.x = self.sort_1d_array(data.x) 
     163                data.y = self.sort_1d_array(data.y) 
    163164                if data.dx is not None: 
    164165                    if len(data.dx) == 0: 
    165166                        data.dx = None 
    166167                        continue 
    167                     data.dx = np.asarray([data.dx[i] for i in ind]).astype(np.float64) 
     168                    data.dx = self.sort_1d_array(data.dx) 
    168169                if data.dxl is not None: 
    169                     data.dxl = np.asarray([data.dxl[i] for i in ind]).astype(np.float64) 
     170                    data.dxl = self.sort_1d_array(data.dxl) 
    170171                if data.dxw is not None: 
    171                     data.dxw = np.asarray([data.dxw[i] for i in ind]).astype(np.float64) 
     172                    data.dxw = self.sort_1d_array(data.dxw) 
    172173                if data.dy is not None: 
    173174                    if len(data.dy) == 0: 
    174175                        data.dy = None 
    175176                        continue 
    176                     data.dy = np.asarray([data.dy[i] for i in ind]).astype(np.float64) 
     177                    data.dy = self.sort_1d_array(data.dy) 
    177178                if data.lam is not None: 
    178                     data.lam = np.asarray([data.lam[i] for i in ind]).astype(np.float64) 
     179                    data.lam = self.sort_1d_array(data.lam) 
    179180                if data.dlam is not None: 
    180                     data.dlam = np.asarray([data.dlam[i] for i in ind]).astype(np.float64) 
     181                    data.dlam = self.sort_1d_array(data.dlam) 
    181182                if len(data.x) > 0: 
    182183                    data.xmin = np.min(data.x) 
     
    184185                    data.ymin = np.min(data.y) 
    185186                    data.ymax = np.max(data.y) 
     187 
     188    def sort_1d_array(self, array=[]): 
     189        if array.any(): 
     190            for i in self.ind: 
     191                if math.isnan(array[i]): 
     192                    array[i] = 0 
     193            array = np.asarray([array[i] for i in self.ind]).astype(np.float64) 
     194        return array 
    186195 
    187196    def sort_two_d_data(self): 
Note: See TracChangeset for help on using the changeset viewer.