Skip to main content

Limited Error Raster Compression

Project description

pylerc is the LERC Python package

LERC is an open-source raster format which supports rapid encoding and decoding for any pixel type, with user-set maximum compression error per pixel.

What's new in Lerc 4.0?

Option 1, uses numpy masked array

An encoded image tile (2D, 3D, or 4D), of data type byte to double, can have any value set to invalid. There are new and hopefully easy to use numpy functions to decode from or encode to Lerc. They make use of the numpy masked array.

(result, npmaArr, nDepth, npmaNoData) = decode_ma(lercBlob)

  • lercBlob is the compressed Lerc blob as a string buffer or byte array as read in from disk or passed in memory.
  • result is 0 for success or an error code for failure.
  • npmaArr is the masked numpy array with the data and mask of the same shape.
  • nDepth == nValuesPerPixel. E.g., 3 for RGB, or 2 for complex numbers.
  • npmaNoData is a 1D masked array of size nBands. It can hold one noData value per band. The caller can usually ignore it as npmaArr has all mask info. It may be useful if the data needs to be Lerc encoded again.

(result, nBytesWritten, lercBlob) = encode_ma(npmaArr, nDepth, maxZErr, nBytesHint, npmaNoData = None)

  • npmaArr is the image tile (2D, 3D, or 4D) to be encoded, as a numpy masked array.

  • nDepth == nValuesPerPixel. E.g., 3 for RGB, or 2 for complex numbers.

  • maxZErr is the max encoding error allowed per value. 0 means lossless.

  • nBytesHint can be

    • 0 - compute num bytes needed for output buffer, but do not encode it (faster than encode)
    • 1 - do both, compute exact buffer size needed and encode (slower than encode alone)
    • N - create buffer of size N and encode, if buffer too small encode will fail.
  • npmaNoData is a 1D masked array of size nBands. It can hold one noData value per band. It can be used as an alternative to masks. It must be used for the so called mixed case of valid and invalid values at the same pixel, only possible for nDepth > 1. In most cases None can be passed. Note Lerc does not take NaN as a noData value here. It is enough to set the data values to NaN and not specify a noData value.

Option 2, uses regular numpy arrays for data and mask

As an alternative to the numpy masked array above, there is also the option to have data and masked as separate numpy arrays.

(result, npArr, npValidMask, npmaNoData) = decode_4D(lercBlob)

Here, npArr can be of the same shapes as npmaArr above, but it is a regular numpy array, not a masked array. The mask is passed separately as a regular numpy array of type bool. Note that in contrast to the masked array above, True means now valid and False means invalid. The npValidMask can have the following shapes:

  • None, all pixels are valid or are marked invalid using noData value or NaN.
  • 2D or (nRows, nCols), same mask for all bands.
  • 3D or (nBands, nRows, nCols), one mask per band.

The _4D() functions may work well if all pixels are valid, or nDepth == 1, and the shape of the mask here matches the shape of the data anyway. In such cases the use of a numpy masked array might not be needed or considered an overkill.

Similar for encode:

(result, nBytesWritten, lercBlob) = encode_4D(npArr, nDepth, npValidMask, maxZErr, nBytesHint, npmaNoData = None)

General remarks

Note that for all encode functions, you can set values to invalid using a mask, or using a noData value, or using NaN (for data types float or double). Or any combination which is then merged using AND for valid (same as OR for invalid) by the Lerc API.

The decode functions, however, return this info as a mask, wherever possible. Only for nDepth > 1 and the mixed case of valid and invalid values at the same pixel, a noData value is used internally. NaN is never returned by decode.

The existing Lerc 3.0 encode and decode functions can still be used. Only for nDepth > 1 the mixed case cannot be encoded. If the decoder should encounter a Lerc blob with such a mixed case, it will fail with the error code LercNS::ErrCode::HasNoData == 5.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pylerc-4.1.1-py3-none-win_amd64.whl (179.2 kB view details)

Uploaded Python 3Windows x86-64

pylerc-4.1.1-py3-none-manylinux_2_31_x86_64.whl (318.1 kB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

pylerc-4.1.1-py3-none-macosx_15_0_universal2.whl (224.7 kB view details)

Uploaded Python 3macOS 15.0+ universal2 (ARM64, x86-64)

File details

Details for the file pylerc-4.1.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: pylerc-4.1.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 179.2 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pylerc-4.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8aa86728a77f0a132d2ec549a17ca007cc4011304616f36e2337a072b077d7a0
MD5 a3765c9cc98a29c5e2a3c1bff005c975
BLAKE2b-256 31b958bec26d86ce5e9cddc4797780fd9229d8364b914258c7080f21448a8bdf

See more details on using hashes here.

File details

Details for the file pylerc-4.1.1-py3-none-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for pylerc-4.1.1-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 6d0d58e77786815d6eef841a2577927edb329d01ae445ed227aaa215c5227d28
MD5 02c1ab95343c6d5c2718263b2cf94a9f
BLAKE2b-256 ab96c90aa5b50a144b1b7e14a3c9527804a4963ab564006a7d029a6f9bd40d27

See more details on using hashes here.

File details

Details for the file pylerc-4.1.1-py3-none-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for pylerc-4.1.1-py3-none-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 af6a709d31051643f35fed40c0d49dfc46e2456f1e78ae649ffeb3f3f2b5e20c
MD5 b42e3fd505a299eaa9869b2ad61df274
BLAKE2b-256 c2bc8a3dc0386f3d75345aaf04af36051cfc71d76ba50657814a61bda75b4795

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page