Changeset 1d014cb in sasview for src/sas/sascalc


Ignore:
Timestamp:
Sep 23, 2017 12:08:08 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
a50da82
Parents:
9e308a3
Message:

sas_gen tests now pass cleanly

Location:
src/sas/sascalc/calculator
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/calculator/c_extensions/sld2i_module.cpp

    rd04ac05 r1d014cb  
    158158#define MODULE_NAME "sld2i" 
    159159#define MODULE_INIT2 initsld2i 
    160 #define MODULE_INIT3 PyInit_reflmodule 
     160#define MODULE_INIT3 PyInit_sld2i 
    161161#define MODULE_METHODS module_methods 
    162162 
  • src/sas/sascalc/calculator/sas_gen.py

    r574adc7 r1d014cb  
    55from __future__ import print_function 
    66 
    7 import sas.sascalc.calculator.core.sld2i as mod 
    8 from sas.sascalc.calculator.BaseComponent import BaseComponent 
     7import os 
     8import sys 
     9import copy 
     10import logging 
     11 
    912from periodictable import formula 
    1013from periodictable import nsf 
    1114import numpy as np 
    12 import os 
    13 import copy 
    14 import sys 
    15 import logging 
     15 
     16from .core import sld2i as mod 
     17from .BaseComponent import BaseComponent 
    1618 
    1719logger = logging.getLogger(__name__) 
     20 
     21if sys.version_info[0] < 3: 
     22    def decode(s): 
     23        return s 
     24else: 
     25    def decode(s): 
     26        return s.decode() if isinstance(s, bytes) else s 
    1827 
    1928MFACTOR_AM = 2.853E-12 
     
    288297                z_dir2 *= z_dir2 
    289298                mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0 
    290             except: 
     299            except Exception: 
    291300                logger.error(sys.exc_value) 
    292301        self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 
     
    368377        try: 
    369378            input_f = open(path, 'rb') 
    370             buff = input_f.read() 
     379            buff = decode(input_f.read()) 
    371380            lines = buff.split('\n') 
    372381            input_f.close() 
     
    374383            valueunit = None 
    375384            for line in lines: 
    376                 toks = line.split() 
     385                line = line.strip() 
    377386                # Read data 
    378                 try: 
    379                     _mx = float(toks[0]) 
    380                     _my = float(toks[1]) 
    381                     _mz = float(toks[2]) 
    382                     _mx = mag2sld(_mx, valueunit) 
    383                     _my = mag2sld(_my, valueunit) 
    384                     _mz = mag2sld(_mz, valueunit) 
    385                     mx = np.append(mx, _mx) 
    386                     my = np.append(my, _my) 
    387                     mz = np.append(mz, _mz) 
    388                 except: 
    389                     # Skip non-data lines 
    390                     logger.error(sys.exc_value) 
     387                if line and not line.startswith('#'): 
     388                    try: 
     389                        toks = line.split() 
     390                        _mx = float(toks[0]) 
     391                        _my = float(toks[1]) 
     392                        _mz = float(toks[2]) 
     393                        _mx = mag2sld(_mx, valueunit) 
     394                        _my = mag2sld(_my, valueunit) 
     395                        _mz = mag2sld(_mz, valueunit) 
     396                        mx = np.append(mx, _mx) 
     397                        my = np.append(my, _my) 
     398                        mz = np.append(mz, _mz) 
     399                    except Exception as exc: 
     400                        # Skip non-data lines 
     401                        logger.error(str(exc)+" when processing %r"%line) 
    391402                #Reading Header; Segment count ignored 
    392403                s_line = line.split(":", 1) 
     
    472483            output.set_m(mx, my, mz) 
    473484            return output 
    474         except: 
     485        except Exception: 
    475486            msg = "%s is not supported: \n" % path 
    476487            msg += "We accept only Text format OMF file." 
     
    512523        try: 
    513524            input_f = open(path, 'rb') 
    514             buff = input_f.read() 
     525            buff = decode(input_f.read()) 
    515526            lines = buff.split('\n') 
    516527            input_f.close() 
     
    526537                            float(line[12]) 
    527538                            atom_name = atom_name[1].upper() 
    528                         except: 
     539                        except Exception: 
    529540                            if len(atom_name) == 4: 
    530541                                atom_name = atom_name[0].upper() 
     
    549560                            vol = 1.0e+24 * atom.mass / atom.density / NA 
    550561                            vol_pix = np.append(vol_pix, vol) 
    551                         except: 
     562                        except Exception: 
    552563                            print("Error: set the sld of %s to zero"% atom_name) 
    553564                            sld_n = np.append(sld_n, 0.0) 
     
    563574                            try: 
    564575                                int_val = int(val) 
    565                             except: 
     576                            except Exception: 
    566577                                break 
    567578                            if int_val == 0: 
     
    582593                        y_lines.append(y_line) 
    583594                        z_lines.append(z_line) 
    584                 except: 
     595                except Exception: 
    585596                    logger.error(sys.exc_value) 
    586597 
     
    594605            output.sld_unit = '1/A^(2)' 
    595606            return output 
    596         except: 
     607        except Exception: 
    597608            raise RuntimeError("%s is not a sld file" % path) 
    598609 
     
    647658                elif ncols == 7: 
    648659                    vol_pix = None 
    649             except: 
     660            except Exception: 
    650661                # For older version of numpy 
    651662                input_f = open(path, 'rb') 
    652                 buff = input_f.read() 
     663                buff = decode(input_f.read()) 
    653664                lines = buff.split('\n') 
    654665                input_f.close() 
     
    673684                            _vol_pix = float(toks[7]) 
    674685                            vol_pix = np.append(vol_pix, _vol_pix) 
    675                         except: 
     686                        except Exception: 
    676687                            vol_pix = None 
    677                     except: 
     688                    except Exception: 
    678689                        # Skip non-data lines 
    679690                        logger.error(sys.exc_value) 
     
    686697                output.set_pixel_volumes(vol_pix) 
    687698            return output 
    688         except: 
     699        except Exception: 
    689700            raise RuntimeError("%s is not a sld file" % path) 
    690701 
     
    967978                self.ynodes = int(ydist) + 1 
    968979                self.znodes = int(zdist) + 1 
    969             except: 
     980            except Exception: 
    970981                self.xnodes = None 
    971982                self.ynodes = None 
     
    10021013                self.set_pixel_volumes(vol) 
    10031014                self.has_stepsize = True 
    1004             except: 
     1015            except Exception: 
    10051016                self.xstepsize = None 
    10061017                self.ystepsize = None 
     
    10471058    reader = SLDReader() 
    10481059    oreader = OMFReader() 
    1049     output = reader.read(tfpath) 
    1050     ooutput = oreader.read(ofpath) 
     1060    output = decode(reader.read(tfpath)) 
     1061    ooutput = decode(oreader.read(ofpath)) 
    10511062    foutput = OMF2SLD() 
    10521063    foutput.set_data(ooutput) 
     
    10891100            break 
    10901101    oreader = OMFReader() 
    1091     ooutput = oreader.read(ofpath) 
     1102    ooutput = decode(oreader.read(ofpath)) 
    10921103    foutput = OMF2SLD() 
    10931104    foutput.set_data(ooutput) 
Note: See TracChangeset for help on using the changeset viewer.