Changeset 535e181 in sasview
- Timestamp:
- Aug 5, 2016 11:48:33 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:
- 05595c4
- Parents:
- c3f0114
- Location:
- src/sas
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/file_converter/bsl_loader.py
rc3f0114 r535e181 8 8 # TODO: Change to __init__(self, filename, frame) 9 9 # and parse n_(pixels/rasters) from header file 10 def __init__(self, filename , frame):10 def __init__(self, filename): 11 11 header_file = open(filename, 'r') 12 12 data_info = {} … … 56 56 data_info['pixels'] = 1 57 57 58 CLoader.__init__(self, data_info['filename'], frame,58 CLoader.__init__(self, data_info['filename'], data_info['frames'], 59 59 data_info['pixels'], data_info['rasters'], data_info['swap_bytes']) 60 60 … … 62 62 if name == 'filename': 63 63 return self.set_filename(value) 64 elif name == 'n_frames': 65 return self.set_n_frames(value) 64 66 elif name == 'frame': 65 67 return self.set_frame(value) … … 75 77 if name == 'filename': 76 78 return self.get_filename() 79 elif name == 'n_frames': 80 return self.get_n_frames() 77 81 elif name == 'frame': 78 82 return self.get_frame() … … 84 88 return self.get_swap_bytes() 85 89 return CLoader.__getattr__(self, name) 86 87 def create_arr(self):88 return np.zeros((self.n_rasters, self.n_pixels)) -
src/sas/sascalc/file_converter/c_ext/bsl_loader.c
rc3f0114 r535e181 21 21 static PyObject *CLoader_init(CLoader *self, PyObject *args, PyObject *kwds) { 22 22 const char *filename; 23 const int frame;23 const int n_frames; 24 24 const int n_pixels; 25 25 const int n_rasters; … … 27 27 28 28 if (self != NULL) { 29 if (!PyArg_ParseTuple(args, "siiii", &filename, & frame, &n_pixels, &n_rasters, &swap_bytes))29 if (!PyArg_ParseTuple(args, "siiii", &filename, &n_frames, &n_pixels, &n_rasters, &swap_bytes)) 30 30 Py_RETURN_NONE; 31 31 if (!(self->params.filename = malloc(strlen(filename) + 1))) 32 32 Py_RETURN_NONE; 33 33 strcpy(self->params.filename, filename); 34 self->params. frame = frame;34 self->params.n_frames = n_frames; 35 35 self->params.n_pixels = n_pixels; 36 36 self->params.n_rasters = n_rasters; … … 49 49 char str[100]; 50 50 sprintf(str, 51 "Filename: %s\n frame: %d\nn_pixels: %d\nn_rasters: %d\nswap_bytes: %d",51 "Filename: %s\nn_frames: %d\nframe: %d\nn_pixels: %d\nn_rasters: %d\nswap_bytes: %d", 52 52 self->params.filename, 53 self->params.n_frames, 53 54 self->params.frame, 54 55 self->params.n_pixels, … … 73 74 } 74 75 76 static PyObject *get_n_frames(CLoader *self, PyObject *args) { 77 return Py_BuildValue("i", self->params.n_frames); 78 } 79 80 static PyObject *set_n_frames(CLoader *self, PyObject *args) { 81 int new_frames; 82 if (!PyArg_ParseTuple(args, "i", &new_frames)) 83 return NULL; 84 self->params.n_frames = new_frames; 85 86 return Py_BuildValue("i", self->params.n_frames); 87 } 88 75 89 static PyObject *get_frame(CLoader *self, PyObject *args) { 76 90 return Py_BuildValue("i", self->params.frame); … … 144 158 int pixel; 145 159 int frame_pos; 146 intsize[2] = {self->params.n_rasters, self->params.n_pixels};160 npy_intp size[2] = {self->params.n_rasters, self->params.n_pixels}; 147 161 float cur_val; 148 162 FILE *input_file; 149 163 PyArrayObject *data; 150 164 151 if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &data)) { 152 return NULL; 153 } 165 data = (PyArrayObject *)PyArray_SimpleNew(2, size, NPY_FLOAT); 154 166 155 167 input_file = fopen(self->params.filename, "rb"); … … 171 183 172 184 fclose(input_file); 173 Py_DECREF(data); 174 175 return Py_BuildValue("O", data); 185 186 return Py_BuildValue("N", data); 176 187 } 177 188 … … 182 193 { "get_filename", (PyCFunction)get_filename, METH_VARARGS, "Get the filename" }, 183 194 { "set_filename", (PyCFunction)set_filename, METH_VARARGS, "Set the filename" }, 195 { "get_n_frames", (PyCFunction)get_n_frames, METH_VARARGS, "Get n_frames" }, 196 { "set_n_frames", (PyCFunction)set_n_frames, METH_VARARGS, "Set n_frames" }, 184 197 { "get_frame", (PyCFunction)get_frame, METH_VARARGS, "Get the frame that will be loaded" }, 185 198 { "set_frame", (PyCFunction)set_frame, METH_VARARGS, "Set the frame that will be loaded" }, -
src/sas/sascalc/file_converter/c_ext/bsl_loader.h
r6eaf89ea r535e181 5 5 // File to load 6 6 char *filename; 7 // Number of frames in the file 8 int n_frames; 7 9 // Frame to load 8 10 int frame; -
src/sas/sasgui/perspectives/file_converter/converter_panel.py
ra3c538e1 r535e181 18 18 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 19 19 from sas.sasgui.guiframe.dataFitting import Data1D 20 from sas.sascalc.dataloader.data_info import Data2D 20 21 from sas.sasgui.guiframe.utils import check_float 21 22 from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter 22 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader 23 from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader as OTOKOLoader 24 from sas.sascalc.file_converter.bsl_loader import BSLLoader 23 25 from sas.sascalc.dataloader.data_info import Detector 24 26 from sas.sascalc.dataloader.data_info import Sample … … 90 92 sasentry_attrs=entry_attrs) 91 93 92 def extract_ data(self, filename):94 def extract_ascii_data(self, filename): 93 95 data = np.loadtxt(filename, dtype=str) 94 96 … … 114 116 115 117 return np.array(data, dtype=np.float32) 118 119 def extract_otoko_data(self, filename): 120 loader = OTOKOLoader(self.q_input.GetPath(), 121 self.iq_input.GetPath()) 122 bsl_data = loader.load_bsl_data() 123 qdata = bsl_data.q_axis.data 124 iqdata = bsl_data.data_axis.data 125 if len(qdata) > 1: 126 msg = ("Q-Axis file has multiple frames. Only 1 frame is " 127 "allowed for the Q-Axis") 128 wx.PostEvent(self.parent.manager.parent, 129 StatusEvent(status=msg, info="error")) 130 return 131 else: 132 qdata = qdata[0] 133 134 return qdata, iqdata 116 135 117 136 def ask_frame_range(self, n_frames): … … 160 179 try: 161 180 if self.data_type == 'ascii': 162 qdata = self.extract_data(self.q_input.GetPath()) 163 iqdata = self.extract_data(self.iq_input.GetPath()) 181 qdata = self.extract_ascii_data(self.q_input.GetPath()) 182 iqdata = np.array([self.extract_ascii_data(self.iq_input.GetPath())]) 183 elif self.data_type == 'otoko': 184 qdata, iqdata = self.extract_otoko_data(self.q_input.GetPath()) 164 185 else: # self.data_type == 'bsl' 165 loader = BSLLoader(self.q_input.GetPath(), 166 self.iq_input.GetPath()) 167 bsl_data = loader.load_bsl_data() 168 qdata = bsl_data.q_axis.data 169 iqdata = bsl_data.data_axis.data 170 if len(qdata) > 1: 171 msg = ("Q-Axis file has multiple frames. Only 1 frame is " 172 "allowed for the Q-Axis") 173 wx.PostEvent(self.parent.manager.parent, 174 StatusEvent(status=msg, info="error")) 175 return 176 else: 177 qdata = qdata[0] 178 frames = [iqdata.shape[0]] 179 increment = 1 180 single_file = True 181 # Standard file has 3 frames: SAS, calibration and WAS 182 if frames[0] > 3: 183 # File has multiple frames 184 params = self.ask_frame_range(frames[0]) 186 loader = BSLLoader(self.iq_input.GetPath()) 187 frames = [0] 188 if loader.n_frames > 1: 189 params = self.ask_frame_range(loader.n_frames) 185 190 frames = params['frames'] 186 increment = params['inc'] 187 single_file = params['file'] 188 if frames == []: return 189 else: # Only interested in SAS data 190 frames = [0] 191 data = [] 192 for frame in frames: 193 loader.frame = frame 194 data.append(loader.load_data()) 195 data = data[0] 196 data_x = [] 197 data_y = range(loader.n_pixels) * loader.n_rasters 198 data_i = data.reshape((loader.n_pixels*loader.n_rasters,1)) 199 for i in range(loader.n_rasters): 200 data_x += [i] * loader.n_pixels 201 import pdb; pdb.set_trace() 202 data_info = Data2D(data=data_i, qx_data=data_x, qy_data=data_y) 203 from sas.sascalc.dataloader.readers.red2d_reader import Reader as Writer2D 204 writer = Writer2D() 205 writer.write(self.output.GetPath(), data_info) 206 wx.PostEvent(self.parent.manager.parent, 207 StatusEvent(status="Conversion completed.")) 208 return 209 191 210 except Exception as ex: 192 211 msg = str(ex) … … 194 213 StatusEvent(status=msg, info='error')) 195 214 return 215 216 frames = [] 217 increment = 1 218 single_file = True 219 # Standard file has 3 frames: SAS, calibration and WAS 220 if iqdata.shape[0] > 3: 221 # File has multiple frames 222 params = self.ask_frame_range(frames[0]) 223 frames = params['frames'] 224 increment = params['inc'] 225 single_file = params['file'] 226 if frames == []: return 227 else: # Only interested in SAS data 228 frames = [0] 196 229 197 230 output_path = self.output.GetPath() … … 243 276 def validate_inputs(self): 244 277 msg = "You must select a" 245 if self.q_input.GetPath() == '' :278 if self.q_input.GetPath() == '' and self.data_type != 'bsl': 246 279 msg += " Q Axis input file." 247 280 elif self.iq_input.GetPath() == '': … … 299 332 dtype = event.GetEventObject().GetName() 300 333 self.data_type = dtype 334 if dtype == 'bsl': 335 self.q_input.Disable() 336 else: 337 self.q_input.Enable() 301 338 302 339 def radiationtype_changed(self, event): … … 363 400 ascii_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 364 401 radio_sizer.Add(ascii_btn) 365 bsl_btn = wx.RadioButton(self, -1, "BSL/OTOKO", name="bsl") 402 otoko_btn = wx.RadioButton(self, -1, "OTOKO 1D", name="otoko") 403 otoko_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 404 radio_sizer.Add(otoko_btn) 405 input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) 406 bsl_btn = wx.RadioButton(self, -1, "BSL 2D", name="bsl") 366 407 bsl_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) 367 408 radio_sizer.Add(bsl_btn) 368 input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5)369 409 y += 1 370 410
Note: See TracChangeset
for help on using the changeset viewer.