Commits

Georg Brandl  committed d827d80

data: add read_numors() script function

  • Participants
  • Parent commits 0f483c8

Comments (0)

Files changed (3)

File docs/script.rst

 
 .. autofunction:: read_data
 
+.. autofunction:: read_numors
+
 .. autofunction:: as_data
 
 .. class:: Dataset

File ufit/data/__init__.py

 }
 
 __all__ = ['Dataset', 'sets', 'set_datatemplate', 'set_dataformat',
-           'read_data', 'as_data']
+           'read_data', 'as_data', 'read_numors']
 
 
 # simplified interface for usage in noninteractive scripts
 def as_data(x, y, dy, name=''):
     """Quickly construct a :class:`Dataset` object from three numpy arrays."""
     return Dataset.from_arrays(name or 'data', x, y, dy)
+
+def read_numors(nstring, binsize, xcol, ycol, dycol=None, ncol=None, nscale=1):
+    """Read a number of data files.  Returns a list of :class:`Dataset`\s.
+
+    :param nstring: A string that gives file numbers, with the operators given
+        below.
+    :param binsize: Bin size when files need to be merged according to
+        *nstring*.
+
+    Other parameters as in :func:`read_data`.
+
+    *nstring* can contain these operators:
+
+    * ``,`` -- loads multiple files
+    * ``-`` -- loads multiple sequential files
+    * ``+`` -- merges multiple files
+    * ``>`` -- merges multiple sequential files
+
+    For example:
+
+    * ``'10-15,23'`` loads files 10 through 15 and 23 in 7 separate datasets.
+    * ``'10+11,23+24'`` loads two datasets consisting of files 10 and 11 merged
+      into one set, as well as files 23 and 24.
+    * ``'10>15+23'`` merges files 10 through 15 and 23 into one single dataset.
+    * ``'10,11,12+13,14'`` loads four sets.
+    """
+    return global_loader.load_numors(nstring, binsize, xcol, ycol,
+                                     dycol, ncol, nscale)

File ufit/data/dataset.py

                  name='', sources=None):
         self.meta = attrdict(meta)
         self.name = name or str(self.meta.filenumber)
-        self.sources = sources or [self.filedesc]
+        self.sources = sources or [getattr(self, 'filedesc', '')]
         self._data = data
 
         self.xcol = self.xaxis = xcol
     def __getattr__(self, key):
         if key == '__setstate__':
             # pickling support
-            raise AttributeError
+            raise AttributeError(key)
         elif key in self.meta:
             return self.meta[key]
         raise AttributeError('no such data column: %s' % key)
             return self.__class__(self.meta, self._data[key],
                                   self.xcol, self.ycol, self.ncol, self.nscale,
                                   name=self.name, sources=self.sources)
-        raise KeyError
+        raise KeyError(key)
 
     def __or__(self, other):
         return self.__class__(self.meta, concatenate((self._data, other._data)),