Previous topic

Post-processing filter example

Next topic

Plot canvas example

This Page

File format filter example¶

from terapy.files.base import FileFilter

class FileFilterExample(FileFilter):
   """
       File filter class example

   """
   def __init__(self):
       FileFilter.__init__(self)
       self.ext = ["*.*"] # list of file extensions handled by this filter (list of str)
       self.desc = "Example files" # name of file type (str)
       self.can_save = True # if True, this filter can be used to save data
       self.can_read = True # if True, this filter can be used to load data
       self.multi_data = False # if True, this filter can save multiple datasets in one file

   def read(self,fname):
       """
           Read given file name.
           Parameters:
               fname    -    file name (str)
           Output:
               list of data (list of DataArray)
       """
       # Insert here what the filter should do to read a file
       return []

   def save(self, fname, data):
       """
           Save data to given file name.
           Parameters:
               fname    -    file name (str)
               data     -    data (DataArray)
       """
       # Insert here what the filter should do to save some data to a file
       return True