diff options
author | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2018-07-31 16:22:25 +0200 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2018-07-31 16:22:25 +0200 |
commit | 159ef14fb9e198bb0066ea14e6b980f065de63dd (patch) | |
tree | bc37c7d4ba09ee59deb708897fa0571709aec293 /silx/io/specfile.pyx | |
parent | 270d5ddc31c26b62379e3caa9044dd75ccc71847 (diff) |
New upstream version 0.8.0+dfsg
Diffstat (limited to 'silx/io/specfile.pyx')
-rw-r--r-- | silx/io/specfile.pyx | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/silx/io/specfile.pyx b/silx/io/specfile.pyx index 39e8816..38101b7 100644 --- a/silx/io/specfile.pyx +++ b/silx/io/specfile.pyx @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2017 European Synchrotron Radiation Facility +# Copyright (C) 2016-2018 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -115,25 +115,11 @@ import sys _logger = logging.getLogger(__name__) -cimport numpy cimport cython from libc.stdlib cimport free cimport specfile_wrapper -# hack to avoid C compiler warnings about unused functions in the NumPy header files -# Sources: Cython test suite. -cdef extern from *: - bint FALSE "0" - void import_array() - void import_umath() - -if FALSE: - import_array() - import_umath() - -numpy.import_array() - SF_ERR_NO_ERRORS = 0 SF_ERR_FILE_OPEN = 2 @@ -654,7 +640,7 @@ cdef class SpecFile(object): str filename def __cinit__(self, filename): - cdef int error = SF_ERR_NO_ERRORS + cdef int error = 0 self.handle = NULL if is_specfile(filename): @@ -890,12 +876,18 @@ cdef class SpecFile(object): int i, j int error = SF_ERR_NO_ERRORS long nlines, ncolumns, regular + double[:, :] ret_array sfdata_error = specfile_wrapper.SfData(self.handle, scan_index + 1, &mydata, &data_info, &error) + if sfdata_error == -1 and not error: + # this has happened in some situations with empty scans (#1759) + _logger.warning("SfData returned -1 without an error." + " Assuming aborted scan.") + self._handle_error(error) if <long>data_info != 0: @@ -907,15 +899,15 @@ cdef class SpecFile(object): ncolumns = 0 regular = 0 - cdef numpy.ndarray ret_array = numpy.empty((nlines, ncolumns), - dtype=numpy.double) + ret_array = numpy.empty((nlines, ncolumns), dtype=numpy.double) + for i in range(nlines): for j in range(ncolumns): ret_array[i, j] = mydata[i][j] specfile_wrapper.freeArrNZ(<void ***>&mydata, nlines) free(data_info) - return ret_array + return numpy.asarray(ret_array) def data_column_by_name(self, scan_index, label): """Returns data column for the specified scan index and column label. @@ -934,6 +926,7 @@ cdef class SpecFile(object): double* data_column long i, nlines int error = SF_ERR_NO_ERRORS + double[:] ret_array label = _string_to_char_star(label) @@ -944,13 +937,19 @@ cdef class SpecFile(object): &error) self._handle_error(error) - cdef numpy.ndarray ret_array = numpy.empty((nlines,), - dtype=numpy.double) + if nlines == -1: + # this can happen on empty scans in some situations (see #1759) + _logger.warning("SfDataColByName returned -1 without an error." + " Assuming aborted scan.") + nlines = 0 + + ret_array = numpy.empty((nlines,), dtype=numpy.double) + for i in range(nlines): ret_array[i] = data_column[i] free(data_column) - return ret_array + return numpy.asarray(ret_array) def scan_header(self, scan_index): """Return list of scan header lines. @@ -1255,6 +1254,7 @@ cdef class SpecFile(object): int error = SF_ERR_NO_ERRORS double* mca_data long len_mca + double[:] ret_array len_mca = specfile_wrapper.SfGetMca(self.handle, scan_index + 1, @@ -1263,10 +1263,10 @@ cdef class SpecFile(object): &error) self._handle_error(error) - cdef numpy.ndarray ret_array = numpy.empty((len_mca,), - dtype=numpy.double) + ret_array = numpy.empty((len_mca,), dtype=numpy.double) + for i in range(len_mca): ret_array[i] = mca_data[i] free(mca_data) - return ret_array + return numpy.asarray(ret_array) |