Changeset 1d014cb in sasview
- Timestamp:
- Sep 23, 2017 2:08:08 AM (7 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, 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
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/calculator/c_extensions/sld2i_module.cpp
rd04ac05 r1d014cb 158 158 #define MODULE_NAME "sld2i" 159 159 #define MODULE_INIT2 initsld2i 160 #define MODULE_INIT3 PyInit_ reflmodule160 #define MODULE_INIT3 PyInit_sld2i 161 161 #define MODULE_METHODS module_methods 162 162 -
src/sas/sascalc/calculator/sas_gen.py
r574adc7 r1d014cb 5 5 from __future__ import print_function 6 6 7 import sas.sascalc.calculator.core.sld2i as mod 8 from sas.sascalc.calculator.BaseComponent import BaseComponent 7 import os 8 import sys 9 import copy 10 import logging 11 9 12 from periodictable import formula 10 13 from periodictable import nsf 11 14 import numpy as np 12 import os 13 import copy 14 import sys 15 import logging 15 16 from .core import sld2i as mod 17 from .BaseComponent import BaseComponent 16 18 17 19 logger = logging.getLogger(__name__) 20 21 if sys.version_info[0] < 3: 22 def decode(s): 23 return s 24 else: 25 def decode(s): 26 return s.decode() if isinstance(s, bytes) else s 18 27 19 28 MFACTOR_AM = 2.853E-12 … … 288 297 z_dir2 *= z_dir2 289 298 mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0 290 except :299 except Exception: 291 300 logger.error(sys.exc_value) 292 301 self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], … … 368 377 try: 369 378 input_f = open(path, 'rb') 370 buff = input_f.read()379 buff = decode(input_f.read()) 371 380 lines = buff.split('\n') 372 381 input_f.close() … … 374 383 valueunit = None 375 384 for line in lines: 376 toks = line.split()385 line = line.strip() 377 386 # 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) 391 402 #Reading Header; Segment count ignored 392 403 s_line = line.split(":", 1) … … 472 483 output.set_m(mx, my, mz) 473 484 return output 474 except :485 except Exception: 475 486 msg = "%s is not supported: \n" % path 476 487 msg += "We accept only Text format OMF file." … … 512 523 try: 513 524 input_f = open(path, 'rb') 514 buff = input_f.read()525 buff = decode(input_f.read()) 515 526 lines = buff.split('\n') 516 527 input_f.close() … … 526 537 float(line[12]) 527 538 atom_name = atom_name[1].upper() 528 except :539 except Exception: 529 540 if len(atom_name) == 4: 530 541 atom_name = atom_name[0].upper() … … 549 560 vol = 1.0e+24 * atom.mass / atom.density / NA 550 561 vol_pix = np.append(vol_pix, vol) 551 except :562 except Exception: 552 563 print("Error: set the sld of %s to zero"% atom_name) 553 564 sld_n = np.append(sld_n, 0.0) … … 563 574 try: 564 575 int_val = int(val) 565 except :576 except Exception: 566 577 break 567 578 if int_val == 0: … … 582 593 y_lines.append(y_line) 583 594 z_lines.append(z_line) 584 except :595 except Exception: 585 596 logger.error(sys.exc_value) 586 597 … … 594 605 output.sld_unit = '1/A^(2)' 595 606 return output 596 except :607 except Exception: 597 608 raise RuntimeError("%s is not a sld file" % path) 598 609 … … 647 658 elif ncols == 7: 648 659 vol_pix = None 649 except :660 except Exception: 650 661 # For older version of numpy 651 662 input_f = open(path, 'rb') 652 buff = input_f.read()663 buff = decode(input_f.read()) 653 664 lines = buff.split('\n') 654 665 input_f.close() … … 673 684 _vol_pix = float(toks[7]) 674 685 vol_pix = np.append(vol_pix, _vol_pix) 675 except :686 except Exception: 676 687 vol_pix = None 677 except :688 except Exception: 678 689 # Skip non-data lines 679 690 logger.error(sys.exc_value) … … 686 697 output.set_pixel_volumes(vol_pix) 687 698 return output 688 except :699 except Exception: 689 700 raise RuntimeError("%s is not a sld file" % path) 690 701 … … 967 978 self.ynodes = int(ydist) + 1 968 979 self.znodes = int(zdist) + 1 969 except :980 except Exception: 970 981 self.xnodes = None 971 982 self.ynodes = None … … 1002 1013 self.set_pixel_volumes(vol) 1003 1014 self.has_stepsize = True 1004 except :1015 except Exception: 1005 1016 self.xstepsize = None 1006 1017 self.ystepsize = None … … 1047 1058 reader = SLDReader() 1048 1059 oreader = OMFReader() 1049 output = reader.read(tfpath)1050 ooutput = oreader.read(ofpath)1060 output = decode(reader.read(tfpath)) 1061 ooutput = decode(oreader.read(ofpath)) 1051 1062 foutput = OMF2SLD() 1052 1063 foutput.set_data(ooutput) … … 1089 1100 break 1090 1101 oreader = OMFReader() 1091 ooutput = oreader.read(ofpath)1102 ooutput = decode(oreader.read(ofpath)) 1092 1103 foutput = OMF2SLD() 1093 1104 foutput.set_data(ooutput) -
test/sascalculator/test/utest_sas_gen.py
r959eb01 r1d014cb 10 10 11 11 class sas_gen_test(unittest.TestCase): 12 12 13 13 def setUp(self): 14 14 self.sldloader = sas_gen.SLDReader() 15 15 self.pdbloader = sas_gen.PDBReader() 16 16 self.omfloader = sas_gen.OMFReader() 17 17 18 18 def test_sldreader(self): 19 19 """ 20 Test .sld file loaded 20 Test .sld file loaded 21 21 """ 22 22 f = self.sldloader.read("sld_file.sld") … … 24 24 self.assertEqual(f.pos_y[0], -13.5) 25 25 self.assertEqual(f.pos_z[0], -13.5) 26 26 27 27 def test_pdbreader(self): 28 28 """ 29 Test .pdb file loaded 29 Test .pdb file loaded 30 30 """ 31 31 f = self.pdbloader.read("c60.pdb") … … 33 33 self.assertEqual(f.pos_y[0], -1.008) 34 34 self.assertEqual(f.pos_z[0], 3.326) 35 35 36 36 def test_omfreader(self): 37 37 """ 38 Test .omf file loaded 38 Test .omf file loaded 39 39 """ 40 40 f = self.omfloader.read("A_Raw_Example-1.omf")
Note: See TracChangeset
for help on using the changeset viewer.