Changeset 2760662 in sasview


Ignore:
Timestamp:
Aug 4, 2016 12:11:45 PM (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:
cc03f59
Parents:
18e7309
Message:

Implement getters in python class

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

Legend:

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

    r18e7309 r2760662  
    11from sas.sascalc.file_converter.core.bsl_loader import CLoader 
     2import numpy as np 
    23 
    34class BSLLoader(CLoader): 
    45 
     6    # TODO: Change to __init__(self, filename, frame) 
     7    # and parse n_(pixels/rasters) from header file 
     8    def __init__(self, filename, frame, n_pixels, n_rasters): 
     9        CLoader.__init__(self, filename, frame, n_pixels, n_rasters) 
     10 
    511    # See invertor.py for implementation of pickling and setters/getters 
    6  
    712 
    813    # def __setattr__(self, name, value): 
     
    1015    #     #     return self.set_param(value) 
    1116    #     return CBSLLoader.__set_attr__(self, name, value) 
    12     # 
    13     # def __getattr__(self, name): 
    14     #     if name == 'val': 
    15     #         return self.get_val() 
    16     #     return CBSLLoader.__getattr__(self, name) 
     17 
     18    def __getattr__(self, name): 
     19        if name == 'filename': 
     20            return self.get_filename() 
     21        elif name == 'frame': 
     22            return self.get_frame() 
     23        elif name == 'n_pixels': 
     24            return self.get_n_pixels() 
     25        elif name == 'n_rasters': 
     26            return self.get_n_rasters() 
     27        return CBSLLoader.__getattr__(self, name) 
     28 
     29    def create_arr(self): 
     30        return np.zeros((self.n_rasters, self.n_pixels)) 
  • src/sas/sascalc/file_converter/c_ext/bsl_loader.c

    r18e7309 r2760662  
    5353} 
    5454 
     55static PyObject *get_filename(CLoader *self, PyObject *args) { 
     56    return Py_BuildValue("s", self->params.filename); 
     57} 
     58 
     59static PyObject *get_frame(CLoader *self, PyObject *args) { 
     60    return Py_BuildValue("i", self->params.frame); 
     61} 
     62 
     63static PyObject *get_n_pixels(CLoader *self, PyObject *args) { 
     64    return Py_BuildValue("i", self->params.n_pixels); 
     65} 
     66 
     67static PyObject *get_n_rasters(CLoader *self, PyObject *args) { 
     68    return Py_BuildValue("i", self->params.n_rasters); 
     69} 
     70 
    5571static PyObject *load_data(CLoader *self, PyObject *args) { 
    5672    int raster; 
     
    100116static PyMethodDef CLoader_methods[] = { 
    101117    { "to_string", (PyCFunction)to_string, METH_VARARGS, "Print the objects params" }, 
    102     {"load_data", (PyCFunction)load_data, METH_VARARGS, "Load the data into a numpy array"}, 
     118    { "get_filename", (PyCFunction)get_filename, METH_VARARGS, "Get the filename" }, 
     119    { "get_frame", (PyCFunction)get_frame, METH_VARARGS, "Get the frame that will be loaded" }, 
     120    { "get_n_pixels", (PyCFunction)get_n_pixels, METH_VARARGS, "Get n_pixels" }, 
     121    { "get_n_rasters", (PyCFunction)get_n_rasters, METH_VARARGS, "Get n_rasters" }, 
     122    { "load_data", (PyCFunction)load_data, METH_VARARGS, "Load the data into a numpy array" }, 
    103123    {NULL} 
    104124}; 
Note: See TracChangeset for help on using the changeset viewer.