Code Monkey home page Code Monkey logo

dvidutils's Introduction

Travis CI Status

dvidutils

A collection of utility functions for dealing with dvid data

Installation

conda install -c flyem-forge dvidutils

Usage

In [1]: import numpy as np

In [2]: from dvidutils import LabelMapper, downsample_labels

In [3]: labels = np.random.randint(0, 3, (9,9), dtype=np.uint64)

In [4]: labels
Out[4]:
array([[2, 0, 0, 0, 1, 0, 1, 0, 1],
       [1, 1, 1, 2, 1, 0, 2, 2, 2],
       [1, 2, 2, 1, 1, 2, 1, 1, 2],
       [0, 2, 1, 0, 1, 0, 2, 0, 2],
       [2, 2, 1, 0, 0, 0, 1, 2, 1],
       [0, 1, 0, 1, 2, 2, 2, 2, 0],
       [0, 0, 2, 2, 1, 2, 1, 0, 2],
       [2, 0, 2, 1, 2, 2, 2, 2, 1],
       [1, 1, 1, 1, 2, 0, 2, 0, 1]], dtype=uint64)

In [5]: mapping = {1:10, 2:20}

In [6]: mapping_keys = np.array( list(mapping.keys()), np.uint64 )

In [7]: mapping_values = np.array( list(mapping.values()), np.uint64 )

In [8]: mapper = LabelMapper(mapping_keys, mapping_values)

In [9]: remapped = mapper.apply( labels, allow_unmapped=True )

In [10]: remapped
Out[10]:
array([[20,  0,  0,  0, 10,  0, 10,  0, 10],
       [10, 10, 10, 20, 10,  0, 20, 20, 20],
       [10, 20, 20, 10, 10, 20, 10, 10, 20],
       [ 0, 20, 10,  0, 10,  0, 20,  0, 20],
       [20, 20, 10,  0,  0,  0, 10, 20, 10],
       [ 0, 10,  0, 10, 20, 20, 20, 20,  0],
       [ 0,  0, 20, 20, 10, 20, 10,  0, 20],
       [20,  0, 20, 10, 20, 20, 20, 20, 10],
       [10, 10, 10, 10, 20,  0, 20,  0, 10]], dtype=uint64)

In [11]: downsample_labels(remapped, factor=3, suppress_zero=True)
Out[11]:
array([[10, 10, 10],
       [10, 10, 20],
       [10, 20, 20]], dtype=uint64)

Developer Instructions

Linux (or Mac)

Here's how to make an ordinary Makefile-based build:

conda install -c conda-forge python=3.6 cmake xtensor-python

mkdir build
cd build

# Makefiles
cmake .. \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CXX_FLAGS_DEBUG="-g -O0 -DXTENSOR_ENABLE_ASSERT=ON" \
    -DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
##

make
make install

Note: Requires gcc >=4.9 or a recent version of clang. On CentOS, the easiesst way to get gcc-4.9 is with these commands:

# Install devtoolset-3
yum install -y centos-release-scl yum-utils devtoolset-3-binutils devtoolset-3-gcc devtoolset-3-gcc-c++

# Activate it (preferably in your .bashrc)
source /opt/rh/devtoolset-3/enable

Xcode

On Mac, your best option for C++14 development is to use Xcode. (On Linux, your best option is to switch to Mac.)

To use Xcode and its debugger, add -G Xcode to the cmake command:

cmake .. \
    -G Xcode \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CXX_FLAGS_DEBUG="-g -O0 -DXTENSOR_ENABLE_ASSERT=ON" \
    -DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \

open dvidutils.xcodeproj

Xcode is finicky about which executables it likes. Install this special build of Python:

conda install -c conda-forge python.app

Within Xcode, Opt+click the 'Run' button to edit your executable settings:

  • Under "Info":
    • Select ${CONDA_PREFIX}/python.app as the Executable (NOT ${CONDA_PREFIX}/bin/python.app).
  • Under "Arguments":
    • Add an Environment Variable for PYTHONPATH: /path/to/my-dvidutils-repo/build-for-xcode/Debug
    • Add an item to "Arguments Passed on Launch": -m pytest --color=no /path/to/my-dvidutils-repo/tests

dvidutils's People

Contributors

stuarteberg avatar

Watchers

James Cloos avatar  avatar

Forkers

davidackerman

dvidutils's Issues

conda installation in mac OS

Hi, I am trying to install this package in mac OS, but got an error of loading draco.

I used the following command to install it.

mamba install -c conda-forge -c flyem-forge dvidutils

The errors are as follows:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/jwu/code/pydvid/dvid/__init__.py", line 11, in <module>
    from .annotation import *
  File "/Users/jwu/code/pydvid/dvid/annotation.py", line 14, in <module>
    from dvidutils import LabelMapper
  File "/Users/jwu/opt/anaconda3/envs/cf/lib/python3.10/site-packages/dvidutils/__init__.py", line
 2, in <module>
    from . import _dvidutils as _dvidutils
ImportError: dlopen(/Users/jwu/opt/anaconda3/envs/cf/lib/python3.10/site-packages/dvidutils/_dvidu
tils.so, 0x0002): Library not loaded: @rpath/libdraco.1.dylib
  Referenced from: <E437E875-1F66-3445-AEC9-1C13F9011BE6> /Users/jwu/opt/anaconda3/envs/cf/lib/pyt
hon3.10/site-packages/dvidutils/_dvidutils.so
  Reason: tried: '/Users/jwu/opt/anaconda3/envs/cf/lib/python3.10/site-packages/dvidutils/../../..
/libdraco.1.dylib' (no such file), '/Users/jwu/opt/anaconda3/envs/cf/lib/python3.10/site-packages/
dvidutils/../../../libdraco.1.dylib' (no such file), '/Users/jwu/opt/anaconda3/envs/cf/bin/../lib/
libdraco.1.dylib' (no such file), '/Users/jwu/opt/anaconda3/envs/cf/bin/../lib/libdraco.1.dylib' (
no such file), '/usr/local/lib/libdraco.1.dylib' (no such file), '/usr/lib/libdraco.1.dylib' (no s
uch file, not in dyld cache)

any idea to fix it?

LabelMapper dtype woes

LabelMapper currently supports unsigned types only. If you pass signed types, you get incorrect behavior without any errors or warnings. This is terrible.

One option is to fix the python/xtensor bindings so that there's an overload for every possible dtype. Another option is to add a wrapper on the python side to assert when the dtype isn't supported, or to auto-convert the array in such cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.