Skip to content

Instantly share code, notes, and snippets.

@BhavyaC16
Last active May 17, 2020 10:13
Show Gist options
  • Save BhavyaC16/e6d1c02feed2ad15ffc81e871f1a83e5 to your computer and use it in GitHub Desktop.
Save BhavyaC16/e6d1c02feed2ad15ffc81e871f1a83e5 to your computer and use it in GitHub Desktop.
[RGSoC 2020] Contributions made to napari and LatexGo by Team Programaholics

Contributing to napari and LatexGo

RGSoC helped us explore the diverse world of open-source. Here is a blog sharing our experience!

Following is a detailed description of the contributions made to napari and LatexGo by Team Programaholics!

Members:

Contributions to napari

Tutorial for parameter sweep with napari

We worked on understanding how to perform parameter sweep with napari, and attempted to write a tutorial with examples for using dask and magicgui to perform parameter sweep, as suggested in issue #43

We opened pull request #67 for this tutorial for the applications section for napari.

A parametric sweep allows for a parameter to be swept through a range of user-defined values. Using napari to perform parameter sweep, allows the user to call a method with different parameter values, by moving the slider across the axis.

The tutorial is designed to help users visualise parameter sweep using napari, dask and magicgui.

We added three examples for the same:

  1. Lazy parameter sweep for a 2D periodic function using dask
  2. Parameter sweep using napari to visualize thresholding of an image
  3. Adding apply_threshold method as a magicgui widget to napari for visualizing the thresholded image

Lazy parameter sweep using dask and napari

We defined a 2D periodic function and visualized the output for different values of the x and y parameters. We defined a function that lazily shifts an array using the delayed method from Dask. Rather than shifting the array immediately, delayed will defer execution, and compute the result when required. It places the function and its arguments into a task graph similar to the one here:

Task graph generated using dask

We visualized these lazy shifts using napari as follows:

Lazy parameter sweep with napari and Dask

Using parameter sweep with napari to find the best thresholding technique

Making use of parameter sweep in napari, we can simplify many tasks, such as manually finding the best thresholding technique, or deciding the desired block_size or window_size to be passed as parameters for thresholding:

Parameter sweep for thresholding using napari

Parameter Sweep with napari using the magicgui widget

We then used the magicgui widget along with napari to better visualize the different thresholding techniques. The thresholded image is computed only for the layer and thresholding technique selected from the drop-down menus, for the value of block_size or window_size passed via the slider to the widget.

We used the magicgui decorator for the method apply_threshold to turn it into a magicgui. Further, a callback function was fefined to update the resultant layer whenever the magicgui is called.

Parameter sweep with magicgui and napari

Documentation for scale in image layer tutorial

We opened pull request #66 for adding documentation to napari's image layer tutorial, for scaling an image layer, while giving an example of scaling the Z-axis for the data-set of a retina's data-set. While documenting, we elaborated how scaling can be performed while adding an image layer to the viewer, or for an existing image layer as follows:

# scaling while creating the image layer, uses scale as keyword argument
napari.view_image(retina, name='retina', scale=[1,10,1,1])

# scaling an existing layer, uses scale as a property of the layer
viewer.layers['retina'].scale = [1,10,1,1]

Following is a demo of scaling the image layer:

scaling

Added documentation for label painting

We worked on solving issue #1041: Label painting modifies the input array in-place, by providing documentation for the methods view_labels and add_labels about modification of input-array in-place, when the developer uses label modification tools such as label painting and erasing.

We added this documentation to the docstrings of the methods, and also provided examples on passing a copy of the input-array to add_labels and view_labels, and also obtaining the modified/resultant array after performing label modification:

Documentation added for add_labels:

Using the viewer's label editing tools (painting, erasing) will
modify the input-array in-place.

    To avoid this, pass a copy as follows:
        layer = viewer.add_labels(data.copy())
        # do some painting/editing

    Get the modified labels as follows:
        result = layer.data

Documentation added for view_labels:

Using the viewer's label editing tools (painting, erasing) will
modify the input-array in-place.

    To avoid this, pass a copy as follows:
        viewer = napari.view_labels(data.copy(), name="sample")
        # do some painting/editing

    Get the painted labels as follows:
        result = viewer.layers["sample"].data

Our pull request #1094 was successfully merged as a documentation change to napari.

Importing 4D data-set of a retina into napari

To understand how to visualize with napari, we tried importing a 3-dimensional data-set of a retina.

First, we import napari and io from skimage, and we read the input tiff file for the data-set into a numpy-array using io.imread. Then we add the image to the viewer as follows:

import napari
from skimage import io

retina = io.imread("path_to_file.tiff")
viewer.add_image(retina, name="retina")

4D data-set of retina

To experiment with the channel layers, we created overlaid layers of the two channels, as suggested by the mentor:

viewer.add_image(retina, channel_axis=0)

Overlaid layers for channels


Contributions to LatexGo

Both of us started with understanding the structure of directories and codebase of LatexGo. After having set up the environment in our systems and installing emscripten, we started understanding the issues and working on them.

Adding config file for firebase paramaters

Our pull request #15 that fixes issue #9 has been merged into the LatexGo codebase. Here, we shifted the firebase config paramaters to a separate config file: js/config.js and included this file as a script in index.html for it to be loaded.

Creating a CI file to automate the build of texlivejs

Currently we are working on writing a CI file for linux configuration to build texlivejs automatically whenever the Makefile is updated for master or develop branches, or a commit message has build-tex in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment