Coverage for /home/kale/research/software/projects/bio96/bio96/verify.py : 98%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python3
Usage: bio96 <toml> [<attr>...] [options]
Arguments: <toml> TOML file describing the plate layout to display. For a complete description of the file format, refer to:
https://github.com/kalekundert/bio96/
<attr> The name(s) of one or more attributes from the above TOML file to project onto the plate. For example, if the TOML file contains something equivalent to `well.A1.conc = 1`, then "conc" would be a valid attribute.
Options: -o --output PATH Output an image of the layout to the given path. The file type is inferred from the file extension.
-c --color NAME [default: rainbow] Use the given color scheme to illustrate which wells have which properties. The given NAME must be one of the color scheme names understood by either `matplotlib` or `colorcet`. See the links below for the full list of supported colors, but some common choices are:
rainbow: blue, green, yellow, red viridis: purple, green, yellow plasma: purple, red, yellow coolwarm: blue, red
Matplotlib colors: https://matplotlib.org/examples/color/colormaps_reference.html
Colorcet colors: http://colorcet.pyviz.org/
-f --foreground Don't attempt to return the terminal to the user while the GUI runs. This is meant to be used on systems where the program crashes if run in the background. """
# TODO: # - General renaming/refactoring # - Object for num plates/attrs/rows/cols # - Tests?
if os.fork() != 0: sys.exit()
else: plt.show()
# The whole architecture of this program is dictated by a small and obscure # bug in matplotlib. (Well, I think it's a bug.) That bug is: if you are # displaying a figure in the GUI and you use `set_size_inches()`, the whole # GUI will have the given height, but the figure itself will be too short # by the height of the GUI control panel. That control panel has different # heights with different backends (and no way that I know of to query what # it's height will be), so `set_size_inches()` is not reliable. # # The only way to reliably control the height of the figure is to provide a # size when constructing it. But that requires knowing the size of the # figure in advance. I would've preferred to set the size at the end, # because by then I know everything that will be in the figure. Instead, I # have to basically work out some things twice (once to figure out how big # they will be, then a second time to actually put them in the figure). # # In particular, I have to work out the colorbar labels twice. These are # the most complicated part of the figure layout, because they come from # the TOML file and could be either very narrow or very wide. So I need to # do a first pass where I plot all the labels on a dummy figure, get their # widths, then allocate enough room for them in the main figure. I also # need to work out the dimensions of the plates twice, but that's a simpler # calculation.
# Complain if the user specified any columns that don't exist.
# Using lists (slower) instead of sets (faster) to maintain the order # of the attributes in case we want to print an error message. x for x in user_attrs if x not in user_cols ]
# If the user didn't specify any columns, show any that have more than one # unique value. else: x for x in user_cols if df[x].nunique() == 1 ] x for x in user_cols if x not in degenerate_cols ] else:
ax, norm=norm.norm, cmap=cmap, boundaries=norm.boundaries, )
# These assumptions let us simplify some code, and should always be true.
# Determine how much data will be shown in the figure:
# Define the grid on which the axes will live: LEFT_MARGIN, ] CELL_SIZE * num_cols, PAD_WIDTH, ] BAR_PAD_WIDTH, BAR_WIDTH, RIGHT_MARGIN + bar_label_width, ]
TOP_MARGIN, ] CELL_SIZE * num_rows, PAD_HEIGHT, ] BOTTOM_MARGIN, ]
# Add up all the divisions to get the width and height of the figure:
# Make the figure: num_attrs, num_plates + 1, # +1 for the colorbar axes. figsize=figsize, squeeze=False, )
# Position the axes:
# I've seen some posts suggesting that this might not work on Macs. I # can't test that, but if this ends up being a problem, I probably need to # wrap this is a try/except block and fall back to guessing a width based # on the number of characters in the string representation of each label.
# With some backends, getting the renderer like this may trigger a warning # and cause matplotlib to drop down to the Agg backend.
artist.get_window_extent(renderer).width for artist in ax.get_yticklabels() )
# Bad name...
return np.nan
#from matplotlib.cbook import iterable #values = value if iterable(value) else [value] #return np.array([self.map[x] for x in values])
def isnan(x):
|