Changeset 9c500ab in sasview for src/sas/sascalc/file_converter
- Timestamp:
- Aug 9, 2016 6:23:08 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.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- dc8a553
- Parents:
- b7c21a7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/file_converter/bsl_loader.py
r535e181 r9c500ab 4 4 import numpy as np 5 5 6 class BSLParsingError(Exception): 7 pass 8 6 9 class BSLLoader(CLoader): 10 """ 11 Loads 2D SAS data from a BSL file. 12 CLoader is a C extension (found in c_ext/bsl_loader.c) 7 13 8 # TODO: Change to __init__(self, filename, frame) 9 # and parse n_(pixels/rasters) from header file 14 See http://www.diamond.ac.uk/Beamlines/Soft-Condensed-Matter/small-angle/SAXS-Software/CCP13/BSL.html 15 for more info on the BSL file format. 16 """ 17 10 18 def __init__(self, filename): 19 """ 20 Parses the BSL header file and sets instance variables apropriately 21 22 :param filename: Path to the BSL header file 23 """ 11 24 header_file = open(filename, 'r') 12 25 data_info = {} … … 15 28 16 29 [folder, filename] = os.path.split(filename) 30 # SAS data will be in file Xnn001.mdd 31 sasdata_filename = filename.replace('000.', '001.') 32 if sasdata_filename == filename: 33 err_msg = ("Invalid header filename {}.\n Should be of the format " 34 "Xnn000.XXX where X is any alphanumeric character and n is any" 35 " digit.").format(filename) 36 raise BSLParsingError(err_msg) 17 37 18 38 # First 2 lines are headers … … 29 49 err_msg = "Invalid header file: {}".format(filename) 30 50 break 31 # SAS data will be in file Xnn001.mdd 32 if data_filename != filename.replace('0.', '1.'): 51 52 if data_filename != sasdata_filename: 53 last_file = (metadata[9] == '0') 54 if last_file: # Reached last file we have metadata for 55 is_valid = False 56 err_msg = "No metadata for {} found in header file: {}" 57 err_msg = err_msg.format(sasdata_filename, filename) 58 break 33 59 continue 34 60 try: … … 43 69 is_valid = False 44 70 err_msg = "Invalid metadata in header file for {}" 45 err_msg = err_msg.format( filename.replace('0.', '1.'))71 err_msg = err_msg.format(sasdata_filename) 46 72 break 47 73 48 74 if not is_valid: 49 raise Exception(err_msg) 50 51 if data_info['frames'] == 1: 52 # File is actually in OTOKO (1D) format 53 # Number of frames is 2nd indicator, 54 data_info['frames'] = data_info['rasters'] 55 data_info['rasters'] = data_info['pixels'] 56 data_info['pixels'] = 1 75 raise BSLParsingError(err_msg) 57 76 58 77 CLoader.__init__(self, data_info['filename'], data_info['frames'],
Note: See TracChangeset
for help on using the changeset viewer.