pysarpro.data#

Test images and datasets.

A curated set of general purpose and scientific images used in tests, examples, and documentation.

Newer datasets are no longer included as part of the package, but are downloaded on demand. To make data available offline, use download_all().

pysarpro.data.astronaut

Color image of the astronaut Eileen Collins.

pysarpro.data.binary_blobs

Generate synthetic binary image with several rounded blob-like objects.

pysarpro.data.download_all

Download all datasets for use with pysarpro offline.

pysarpro.data.file_hash

Calculate the hash of a given file.


pysarpro.data.astronaut()[source]#

Color image of the astronaut Eileen Collins.

Photograph of Eileen Collins, an American astronaut. She was selected as an astronaut in 1992 and first piloted the space shuttle STS-63 in 1995. She retired in 2006 after spending a total of 38 days, 8 hours and 10 minutes in outer space.

This image was downloaded from the NASA Great Images database <https://flic.kr/p/r9qvLn>`__.

No known copyright restrictions, released into the public domain.

Returns:
astronaut(512, 512, 3) uint8 ndarray

Astronaut image.


pysarpro.data.binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2, volume_fraction=0.5, rng=None)[source]#

Generate synthetic binary image with several rounded blob-like objects.

Parameters:
lengthint, optional

Linear size of output image.

blob_size_fractionfloat, optional

Typical linear size of blob, as a fraction of length, should be smaller than 1.

n_dimint, optional

Number of dimensions of output image.

volume_fractionfloat, default 0.5

Fraction of image pixels covered by the blobs (where the output is 1). Should be in [0, 1].

rng{numpy.random.Generator, int}, optional

Pseudo-random number generator. By default, a PCG64 generator is used (see numpy.random.default_rng()). If rng is an int, it is used to seed the generator.

Returns:
blobsndarray of bools

Output binary image

Other Parameters:
seedDEPRECATED

Deprecated in favor of rng.

Deprecated since version 0.21.

Examples

>>> from pysarpro import data
>>> data.binary_blobs(length=5, blob_size_fraction=0.2)  
array([[ True, False,  True,  True,  True],
       [ True,  True,  True, False,  True],
       [False,  True, False,  True,  True],
       [ True, False, False,  True,  True],
       [ True, False, False, False,  True]])
>>> blobs = data.binary_blobs(length=256, blob_size_fraction=0.1)
>>> # Finer structures
>>> blobs = data.binary_blobs(length=256, blob_size_fraction=0.05)
>>> # Blobs cover a smaller volume fraction of the image
>>> blobs = data.binary_blobs(length=256, volume_fraction=0.3)

pysarpro.data.download_all(directory=None, pattern=None)[source]#

Download all datasets for use with pysarpro offline.

pysarpro datasets are no longer shipped with the library by default. This allows us to use higher quality datasets, while keeping the library download size small.

This function requires the installation of an optional dependency, pooch, to download the full dataset. Follow installation instruction found at

Call this function to download all sample images making them available offline on your machine.

Parameters:
directory: path-like, optional

The directory where the dataset should be stored.

pattern: str, optional

A regex pattern to filter the datasets to be downloaded.

Raises:
ModuleNotFoundError:

If pooch is not install, this error will be raised.

Notes

pysarpro will only search for images stored in the default directory. Only specify the directory if you wish to download the images to your own folder for a particular reason. You can access the location of the default data directory by inspecting the variable pysarpro.data.data_dir.


pysarpro.data.file_hash(fname, alg='sha256')[source]#

Calculate the hash of a given file.

Useful for checking if a file has changed or been corrupted.

Parameters:
fnamestr

The name of the file.

algstr

The type of the hashing algorithm

Returns:
hashstr

The hash of the file.

Examples

>>> fname = "test-file-for-hash.txt"
>>> with open(fname, "w") as f:
...     __ = f.write("content of the file")
>>> print(file_hash(fname))
0fc74468e6a9a829f103d069aeb2bb4f8646bad58bf146bb0e3379b759ec4a00
>>> import os
>>> os.remove(fname)