CS 251: Lab #4

Integrating Data and Viewing

The goal of this lab is to bring together all of the elements--data, GUI, and viewing--into a single application that enables interactive visualization of data sets in the proper format. The result of this project should be an application that can read in a data set, enable the user to interactively view it in up to 5 user-selected dimensions (3 spatial, color, and size).


Tasks

In the lab, your goal should be to get data onto the screen and moving around correctly.

  1. Give yourself a new working directory and copy your display, viewing, and data python files into it. It's best to start with copies and modify them from there. Integration often involves re-writing parts of your code to make the process cleaner. From project 2, you should be able to read one or more CSV data files in the proper format, and from project 1 you should know how to create a dialog box.
  2. In your display class, create a method (e.g. handleOpen that will use the tkFileDialog module to let the user select the csv file they want to open.
    1. Use the file dialog to get a filename, e.g.
            fn = tkFileDialog.askopenfilename( parent=self.root,
            title='Choose a data file', initialdir='.' )
        
    2. Bind your method to both a menu option (e.g. File/Open), and to Command-O (or Control-O).
    3. Make a Data object to read and hold the file's data. You will need to keep this around for plotting, so it needs to get into a field of your Display class. For now, your program needs to support having only one data file open at a time.
    4. Your handleOpen function should not plot data.
  3. Create a button and/or menu item on your main window that begins the process of plotting data. The button should call a function (e.g. handlePlotData) that will enable the user to select which columns of data to plot on which axes and then builds the data.
  4. Eventually, in this project you will need to design a dialog box that lets the user select which columns of the data to plot, along with other parameters. You may want to make that process a function, like handleChooseAxes. For the lab, however, your handleChooseAxes function should return the headers of the first three columns as the x, y, and z axes (if they exist).

    After determining which columns to plot, your handlePlotData function should pass those headers to the function buildPoints.

  5. Create a buildPoints function in your display class that is analagous to your buildAxes function. The buildPoints should take in a list of headers, delete any existing canvas objects representing data, and then create a new set for the current plot.

    You probably want to follow the steps below in your buildPoints method.

    • Delete any existing canvas objects used for plotting data.
    • Get the spatial columns specified by the argument headers to plot. If you are selecting only 2 columns to plot, add a column of 0's (z-value) and a column of 1's (homogeneous coordinate) to the data. If you are selecting 3 columns to plot, add a column of 1's (homogeneous coordinate). Each data point is now represented as a 4-column row in the spatial data matrix. Make sure this data is stored in a field of the display class. Do not change it until the user clicks on plotData again.
    • At this point you have to make a decision about how to normalize the data. A simple approach is to use the max and min value of each data column to normalize it to the range [0, 1], which you have already implemented in your analysis class.

      x' = float(x - xmin) / float(xmax - xmin)

    • Calculate the VTM from the current view object.
    • Transform the data using the VTM (the following assumes the data is in rows).

      pts = (vtm * data.T).T

    • Create the canvas graphics objects, ovals/squares/crosses/points, for each data point using the X and Y (first two columns) of your transformed points. Be sure to save a reference to each data point object drawn on the screen (e.g. in self.objects). Letting the user specify the type of graphics object to use in the plot is a nice extension.
  6. Make sure your program can read in test data case 1 and display 3 spatial dimensions. Then try test data case 2, which has 5 dimensions, the first two of which are correlated.

When you are finished with the lab, go ahead and continue with the project.