Small visualization example¶
Import required packages¶
In [3]:
Copied!
from unsat.io import tif_to_numpy
from unsat.plot import plot_slice, slicer
from unsat.Sampler import RectangularSampler
import matplotlib.pyplot as plt
import os
from unsat.io import tif_to_numpy
from unsat.plot import plot_slice, slicer
from unsat.Sampler import RectangularSampler
import matplotlib.pyplot as plt
import os
Set-up variables¶
In [4]:
Copied!
PATH = "../data/"
EXAMPLE = os.path.join(PATH, "exp", "CoarseSand_Day2Growth.tif")
PATH = "../data/"
EXAMPLE = os.path.join(PATH, "exp", "CoarseSand_Day2Growth.tif")
Store as numpy
array¶
And explore some slices.
In [5]:
Copied!
example_np = tif_to_numpy(EXAMPLE)
example_np = tif_to_numpy(EXAMPLE)
In [6]:
Copied!
plot_slice(example_np, 300, 0)
plot_slice(example_np, 300, 0)
Out[6]:
<matplotlib.image.AxesImage at 0x7f7df86d09a0>
Use slicer and samplers¶
slicer
is just a wrapper for easy slicingSampler
class and subclasses contain functions for easy sampling
In [7]:
Copied!
slice2d = slicer(example_np, 300, 1) # Create a 2D array by sampling the 3D one
sam = RectangularSampler(slice2d, loc=[100, 200], size=[300, 400])
sam.plot()
slice2d = slicer(example_np, 300, 1) # Create a 2D array by sampling the 3D one
sam = RectangularSampler(slice2d, loc=[100, 200], size=[300, 400])
sam.plot()
Extract the sampling area:
In [8]:
Copied!
snap = sam.sample()
plt.imshow(snap)
snap = sam.sample()
plt.imshow(snap)
Out[8]:
<matplotlib.image.AxesImage at 0x7f7df4a311b0>
Check if the sampling area is out of bounds:
In [9]:
Copied!
sam.is_out()
sam.is_out()
Out[9]:
False