Changeset 535e181 in sasview for src/sas/sascalc/file_converter


Ignore:
Timestamp:
Aug 5, 2016 11:48:33 AM (8 years ago)
Author:
lewis
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
Message:

Begin implementing 2D BSL loader into GUI

Location:
src/sas/sascalc/file_converter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/bsl_loader.py

    rc3f0114 r535e181  
    88    # TODO: Change to __init__(self, filename, frame) 
    99    # and parse n_(pixels/rasters) from header file 
    10     def __init__(self, filename, frame): 
     10    def __init__(self, filename): 
    1111        header_file = open(filename, 'r') 
    1212        data_info = {} 
     
    5656            data_info['pixels'] = 1 
    5757 
    58         CLoader.__init__(self, data_info['filename'], frame, 
     58        CLoader.__init__(self, data_info['filename'], data_info['frames'], 
    5959            data_info['pixels'], data_info['rasters'], data_info['swap_bytes']) 
    6060 
     
    6262        if name == 'filename': 
    6363            return self.set_filename(value) 
     64        elif name == 'n_frames': 
     65            return self.set_n_frames(value) 
    6466        elif name == 'frame': 
    6567            return self.set_frame(value) 
     
    7577        if name == 'filename': 
    7678            return self.get_filename() 
     79        elif name == 'n_frames': 
     80            return self.get_n_frames() 
    7781        elif name == 'frame': 
    7882            return self.get_frame() 
     
    8488            return self.get_swap_bytes() 
    8589        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  
    2121static PyObject *CLoader_init(CLoader *self, PyObject *args, PyObject *kwds) { 
    2222    const char *filename; 
    23     const int frame; 
     23    const int n_frames; 
    2424    const int n_pixels; 
    2525    const int n_rasters; 
     
    2727 
    2828    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)) 
    3030            Py_RETURN_NONE; 
    3131        if (!(self->params.filename = malloc(strlen(filename) + 1))) 
    3232            Py_RETURN_NONE; 
    3333        strcpy(self->params.filename, filename); 
    34         self->params.frame = frame; 
     34        self->params.n_frames = n_frames; 
    3535        self->params.n_pixels = n_pixels; 
    3636        self->params.n_rasters = n_rasters; 
     
    4949    char str[100]; 
    5050    sprintf(str, 
    51         "Filename: %s\nframe: %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", 
    5252        self->params.filename, 
     53        self->params.n_frames, 
    5354        self->params.frame, 
    5455        self->params.n_pixels, 
     
    7374} 
    7475 
     76static PyObject *get_n_frames(CLoader *self, PyObject *args) { 
     77    return Py_BuildValue("i", self->params.n_frames); 
     78} 
     79 
     80static 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 
    7589static PyObject *get_frame(CLoader *self, PyObject *args) { 
    7690    return Py_BuildValue("i", self->params.frame); 
     
    144158    int pixel; 
    145159    int frame_pos; 
    146     int size[2] = {self->params.n_rasters, self->params.n_pixels}; 
     160    npy_intp size[2] = {self->params.n_rasters, self->params.n_pixels}; 
    147161    float cur_val; 
    148162    FILE *input_file; 
    149163    PyArrayObject *data; 
    150164 
    151     if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &data)) { 
    152         return NULL; 
    153     } 
     165    data = (PyArrayObject *)PyArray_SimpleNew(2, size, NPY_FLOAT); 
    154166 
    155167    input_file = fopen(self->params.filename, "rb"); 
     
    171183 
    172184    fclose(input_file); 
    173     Py_DECREF(data); 
    174  
    175     return Py_BuildValue("O", data); 
     185 
     186    return Py_BuildValue("N", data); 
    176187} 
    177188 
     
    182193    { "get_filename", (PyCFunction)get_filename, METH_VARARGS, "Get the filename" }, 
    183194    { "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" }, 
    184197    { "get_frame", (PyCFunction)get_frame, METH_VARARGS, "Get the frame that will be loaded" }, 
    185198    { "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  
    55    // File to load 
    66    char *filename; 
     7    // Number of frames in the file 
     8    int n_frames; 
    79    // Frame to load 
    810    int frame; 
Note: See TracChangeset for help on using the changeset viewer.