Skip to content

Commit

Permalink
added basic tests & updated readmes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmejia committed Nov 27, 2024
1 parent 73d7635 commit a07f032
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 143 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,7 @@ To install the DRP along with its dependencies, you need to run the following st
cd lvmdrp
```

3. Optional, but recommended: compile c-code for better performance

```bash
pushd lvmdrp/python/cextern/fast_median/src
make
popd
```
This should have created a fast_median.so (Linux) or fast_median.dylib (MacOS) in the src directory.
Set environment variable `LVMDRP_LIB_DIR` if you move the shared library. If you leave it in src/, no need to set this.
We will automate this step eventually ;-)

4. Install the DRP package in the current python environment (see [contributing](#contributing-to-lvm-drp-development) section below for a replacement of this step). Make sure you're back in the lvmdrp directory.
3. Install the DRP package in the current python environment (see [contributing](#contributing-to-lvm-drp-development) section below for a replacement of this step). Make sure you're back in the lvmdrp directory.

```bash
cd lvmdrp
Expand Down
9 changes: 4 additions & 5 deletions cextern/README.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
C code to be compiled on setup goes here.
C++ code to generate fast_median extension goes here.

fast_median.cpp is a very fast median filter for 1d and 2d ndarrays
with float or double data. The glue code is in fast_median.py

compile using the Makefile in src/
fast_median.cpp, fast_median.hpp: a very fast median filter for 1d and 2d ndarrays
with float or double data.
python/lvmdrp/external/fast_median.py: python interface for fast_median extension


14 changes: 0 additions & 14 deletions cextern/fast_median/src/Makefile

This file was deleted.

15 changes: 0 additions & 15 deletions cextern/fast_median/test/testfilter.py

This file was deleted.

46 changes: 0 additions & 46 deletions cextern/fast_median/test/testfilter2.py

This file was deleted.

51 changes: 0 additions & 51 deletions cextern/fast_median/test/testfilter3.py

This file was deleted.

40 changes: 40 additions & 0 deletions tests/external/test_fast_median.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import numpy as np
from lvmdrp.external.fast_median import fast_median_filter_2d, fast_median_filter_1d
from scipy.ndimage import median_filter
import time
import pytest


def test_median_filter_1d_speed():
np.random.seed(123)
img = np.random.random(size=100)*3 + 1000
img = img.astype(np.float32)

t = time.time()
img_fm = fast_median_filter_1d(img, size=5)
dt_fm = time.time()-t

t = time.time()
img_om = median_filter(img, size=5)
dt_om = time.time()-t

assert dt_om > dt_fm
assert img_om == pytest.approx(img_fm, rel=0.01)


def test_median_filter_2d_speed():
np.random.seed(456)
img = np.random.random(size=[100,100])*3 + 1000
img = img.astype(np.float32)

t = time.time()
img_fm = fast_median_filter_2d(img, size=(5,5))
dt_fm = time.time()-t

t = time.time()
img_om = median_filter(img, size=(5,5))
dt_om = time.time()-t

assert dt_om > dt_fm
assert img_om == pytest.approx(img_fm, rel=0.01)

0 comments on commit a07f032

Please sign in to comment.