CS 251: Lab #4

Lab 4: Integrating Data and View

Project due Monday night Mar 10, 2014

The purpose of this assignment 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 lab, your goal should be to get data onto the screen. The bells and whistles will come in the project portion.

  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 the last project, you should be able to read one or more CSV data files in the proper format and manage them in a listbox on the GUI.
  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 hold the file's data. You will need to keep this around for plotting, so it needs to get into a field. If you are going to support more than one open file at a time, then you might want to add it to a list.
    4. Next you will want to update any widgets that manage open data objects (i.e. you might want to make a listbox with one entry for each open file.)
    5. Assuming you are going to draw the data right away, you will need to reset the view. The easiest way to do that is to make a new View object and store it in the application's view data field.
    6. Finally, you will need to develop a method that will allow the user to choose which features (columns) to display, and display them. The user interaction will be added during the project. In the lab, we will just assume the first three features will be displayed on the x, y, and z axes, respectively.
  3. Write a method named handleChooseAxes. It will eventually pop up a dialog box. But right now, it should call self.data.get_headers() and use the first three headers as the x, y, and z data axes. You may want to store an list of DataColIds in a field (this is more forward looking), but at a minimum, store these headers in a list so that othe drawing functions can access the information. Then, handleChooseAxes should call buildPoints (which you are about to write and which will access the field you just set).
  4. Write a method named buildPoints. It should get rid of any data points currently displayed, then it should get the data points for the selected columns, build a matrix using the view, and create points at the appropriate locations.
    • Delete any existing canvas objects used for plotting data.
    • 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.
    • 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]. (i.e call normalize_columns_separately).
    • Calculate the VTM from the current view object.
    • Transform the data using the VTM.

      pts = (vtm * data.T).T

    • Create the canvas graphics objects, ovals/squares/crosses/points, for each data point. (In the project, you will use the color and size data, if any, to adjust the visual attributes, but for now, just color and size them all identically). Letting the user specify the type of graphics object to use in the plot is a nice extension.

When you are done with the lab exercises, you may start on the rest of the project.