mitmedialab / Vida_Modeling

User Interface and Simulation Platform for a System Dynamics Model
MIT License
6 stars 2 forks source link

Adding configuration parameters for plotting SD_objects #34

Closed jackreid closed 3 years ago

jackreid commented 3 years ago

I realized that two separate issues, #33 and #24 , could perhaps be solved with the same method. The proposal is as follows:

  1. Add one or more new attributes to SD_object, something along the lines of visualization_config. This would be a list of parameters that can be called to determine how to visualize that object. For the temporal graphs, we could include default minimum and maximum y-axis values (the make_fig function would then override these if the data exceeded these values). In the future we may even include other plot types beyond scatterplots. For the geographic maps, we could use it to set various color choices and the range for defining the color bar over.
  2. Edit the respective visualization functions in both SD_UI and MapWindow to accept these parameters. If they are not defined for a particular SD_object, they should default to their current behavior.

Does this sound reasonable?

seamuslo commented 3 years ago

I had a lot of trouble implementing these in the ways that we had discussed. I think for both the y-axis limits and the map legends, I was unable to pass things through the entire flow in order to get them to work correctly.

As a quick fix for now, I implemented conditional statements to address both of these issues. For the y-axis limit, I used the following statement which determines whether or not to use the lower bound of zero based on the difference between the max and min values of the historical data. This seemed to work well for all the data in the Indonesia context, but let me know if it breaks for other contexts. if (np.nanmax(histval) - np.nanmin(histval)) < 0.5(np.nanmin(histval)): ax1.set_ylim(min(0.8np.nanmin(plotval), 0.8np.nanmin(histval)), 1.2max(np.nanmax(plotval), np.nanmax(histval))) else: ax1.set_ylim(min(0, np.nanmin(plotval), np.nanmin(histval)), 1.2*max(np.nanmax(plotval), np.nanmax(histval)))

For the map legends, I used the following statement: if minim < 0 and smallpos == []: colormap = cm.get_cmap('autumn', 48) elif minim < 0 and smallpos != []: colormap = cm.get_cmap('RdYlGn', 48) else: colormap = cm.get_cmap('YlOrRd', 48)

This seems to change the direction of the legend appropriately for the Indonesia cases, but let me know if it doesn't work for other contexts.

These changes are currently pushed to Shealombardo

jackreid commented 3 years ago

I like these changes. They significantly improve readability for the graphs and the maps, for all the contexts as far as I can tell. I still want to have functionality of manually setting visualization parameters, but your changes will be the default in absence of such parameters. This is based not so much out of a desire to set visualization parameters at the moment, but I think that we may be making changes in the future of various kinds, I want to have the groundwork laid for that.

To this end I have added such functionality, and it can be seen in the graph_bounds branch.

For the temporal graphs, SD_object has a new keyword 'visualization' which is used to define two attributes 'vismin' and 'vismax' which are checked for in make_fig. You can see an example of how it looks by looking at the 'Brazil Unemployment Rate' in the Rio de Janeiro context.

For the geographic data, each shp_fields object now has three additional columns: VisMin, VisMax, and VisColor, which set the minimum, maximum, and colormap for the map, respectively. You can see an example of it in action for the 'Relative Humidity' field in the Rio de Janeiro context.

If this looks good to you, we can merge this into SheaLombardo and master.

seamuslo commented 3 years ago

These changes sound sane to me, but I have a very novice question: How do I pull branches that I didn't create? Currently on my machine I only have the SheaLombardo and Master branches, and I can't figure out how to pull down a branch that you made?

jackreid commented 3 years ago

I think the below should get your computer to get all of the branches that are on the github repository. Then you can checkout and pull them as normal.

git fetch --all