A Python wrapper for the FAPEC data compressor.
Project description
FaPyc
A Python wrapper for the FAPEC data compressor. (C) DAPCOM Data Services S.L. - https://www.dapcom.es
The free decompression-only library is included, which has some limitations such as the maximum number of threads and the recovery of corrupted files. Only a 'dummy' compression library is provided: You can get free evaluation licenses at https://www.dapcom.es/get-fapec/ to test the compressor. For full licenses, please contact us at fapec@dapcom.es
Usage
There are 3 main execution modes:
- File: When invoking Fapyc or Unfapyc on a filename, it will (de)compress it directly into another file.
- Buffer: You can load the whole file to (de)compress on e.g. a byte array, and then invoke Fapyc/Unfapyc which will leave the result in the output buffer. Obviously, you should be careful with large/huge files!
- File-to-buffer decompression: You can directly decompress a file (without having to load it beforehand) and leave its decompressed output in a buffer, which you can use afterwards.
- Chunk: FAPEC internally works in 'chunks' of data, of up to 384MB each, which allows to progressively (de)compress a huge file while keeping memory usage under control. For now, this feature is only available in the FAPEC CLI and C API, not in Fapyc/Unfapyc yet.
Examples
Compress and decompress a file
In this example we use the kmall
option of FAPEC, suitable for this kind of geomaritime data files from Kongsberg Maritime:
from fapyc import Fapyc, Unfapyc
filename = input("Path to KMALL file: ")
print("Preparing to compress %s" % (filename))
# Here we invoke FAPEC to directly run on files,
# so the memory usage will be small (just 10MB or so)
# although it won't allow us to directly access the
# (de)compressed buffers.
f = Fapyc(filename, chunksize = 2048576, blen = 512)
f.compress_kmall()
print("Preparing to decompress %s" % (filename + ".fapec"))
uf = Unfapyc(filename + ".fapec")
uf.decompress(output=filename+".dec")
Compress and decompress a buffer
In this example we use the tab
option of FAPEC, which typically outperforms gzip
and bzip2
on tabulated text data:
from fapyc import Fapyc, Unfapyc
filename = input("Path to file: ")
file = open(filename, "rb")
# Beware - Load the whole file to memory
data = file.read()
f = Fapyc(buffer = data)
# Invoke our tabulated-text compression algorithm
# indicating a comma separator
f.compress_tabtxt(sep1=',')
print("Ratio =", round(float(len(data))/len(f.outputBuffer), 4))
# Now we decompress the buffer
uf = Unfapyc(buffer = f.outputBuffer)
uf.decompress()
Decompress a file into a buffer, and do some operations on it
Here we provide a quite specific use case, based on ESA/DPAC Gaia (E)DR3 bulk catalogue (which is publicly available as FAPEC-compressed CSVs). In this example, we decompress one of the files, get its CSV-formatted contents with Pandas, apply some filtering conditions, and generate a histogram.
from fapyc import Unfapyc
from io import BytesIO
import pandas as pd
import matplotlib.pyplot as plt
filename = input("Path to CSV-FAPEC file: ")
### Option 1: open the file, load it to memory (beware!), and decompress the buffer:
#file = open(filename, "rb")
#data = file.read()
#uf = Unfapyc(buffer = data)
### Option 2: directly decompress from the file into a buffer:
uf = Unfapyc(filename = filename)
# Actual decompressor invocation - same for both options
uf.decompress()
# Regenerate the CSV from the bytes buffer
df = pd.read_csv(BytesIO(uf.outputBuffer), comment="#")
print("Info from the full CSV:")
print(df.info())
# Prepare some nice histograms for all data
plt.subplot(2,2,1)
plt.title("Full CSV: skymap (%d sources)" % df.shape[0])
plt.xlabel("RA")
plt.ylabel("DEC")
print("Getting 2D histogram...")
plt.hist2d(df.ra, df.dec, bins=(100, 100), cmap=plt.cm.jet)
plt.colorbar()
plt.subplot(2,2,2)
plt.title("Full CSV: G dist")
plt.xlabel("G magnitude")
plt.ylabel("Counts")
plt.yscale("log")
print("Getting histogram...")
plt.hist(df.phot_g_mean_mag, bins=(50))
# Now let's repeat, but doing the histogram from only the values that fulfil
# some conditions on some of the CSV fields
print("Loading+filtering CSV...")
iter_csv = pd.read_csv(BytesIO(uf.outputBuffer), comment="#", iterator=True, chunksize=1000)
df = pd.concat((x.query("ra_error < 0.1 & dec_error < 0.1 & ruwe > 0 & ruwe < 5") for x in iter_csv))
print("Info from the filtered CSV:")
print(df.info())
plt.subplot(2,2,3)
plt.title("Filtered CSV: skymap (%d sources)" % df.shape[0])
plt.xlabel("RA")
plt.ylabel("DEC")
print("Getting 2D histogram...")
plt.hist2d(df.ra, df.dec, bins=(100, 100), cmap=plt.cm.jet)
plt.colorbar()
plt.subplot(2,2,4)
plt.title("Filtered CSV: G dist")
plt.xlabel("G magnitude")
plt.ylabel("Counts")
plt.yscale("log")
print("Getting histogram...")
plt.hist(df.phot_g_mean_mag, bins=(50))
print("Plotting!")
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file fapyc-0.3.1-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 794.6 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce90f41f1a698793c2c4b08c202282cb98d5cbcb34951869aa9183ce45165500 |
|
MD5 | 20dd269ca928b149cef1204adef8bd91 |
|
BLAKE2b-256 | d2220daf576ae5eb2d71ab8a69c6fa7c2d63e03c822d514a30b69a65160a6f72 |
File details
Details for the file fapyc-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 908.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310667b67a1a50190082cd19719b5b10def194e6100cd1085b0d47bba086b59c |
|
MD5 | e2c5d43209f53bee35b5c2cb6c38362d |
|
BLAKE2b-256 | d01aa806c0b94b95e465dc48798dc7ea326ab4ab0a2f462551b777aeabb096e4 |
File details
Details for the file fapyc-0.3.1-cp312-cp312-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp312-cp312-macosx_13_0_arm64.whl
- Upload date:
- Size: 453.5 kB
- Tags: CPython 3.12, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ec1d76bee4584338ff49cea23a4f418e7675c084ac6bd6df5f43c2a18842e8b |
|
MD5 | 83a65f1b3a9387021e1988088a3d47ed |
|
BLAKE2b-256 | ceaf51d8c27e83b1806c5e4bdd840e666a52d1c508026442b0eefa408de7002a |
File details
Details for the file fapyc-0.3.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 794.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f10a8865e7d2e9691c38349976b684bdf566c2ac5a8462b67ceef5a96f28f1 |
|
MD5 | 1054126aff728439546d4161f940e468 |
|
BLAKE2b-256 | dcacfd5361cbc4f1263817f38667bf7321f573cfd566ee8822417dc18bea1e09 |
File details
Details for the file fapyc-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 904.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcca70746973de14adc4cf00394b1f6a8090bb1c81ae94b29558eb0230fea772 |
|
MD5 | d114d31f853f395b8bd4f02015953813 |
|
BLAKE2b-256 | 12bf652973c911a81cca90bdb9106a97a3addd2a44a092ffa6ad5f5156734f75 |
File details
Details for the file fapyc-0.3.1-cp311-cp311-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp311-cp311-macosx_13_0_arm64.whl
- Upload date:
- Size: 452.8 kB
- Tags: CPython 3.11, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d84f286e5d38ae4e0e96124ee1f9556dd328616522530efd48de0707faf65755 |
|
MD5 | 9d432eafc051ab2103b72ef8129af08b |
|
BLAKE2b-256 | 3a9aa9b52e0e67401616e77aabee10abfb94bb40a8455e3584c51c2c0cb64aa6 |
File details
Details for the file fapyc-0.3.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 794.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b85e36b6cf9eae7e96d623d2fc3025b64814d49100ea01d3094d8ccc0e7957f |
|
MD5 | 16cdab415202b5fccaf55f1b4972a708 |
|
BLAKE2b-256 | 383102d2a6288de989ed734591e1ab380ac15c6408f202172966d8a108e350f1 |
File details
Details for the file fapyc-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 872.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f6d1c1081adbcd6cde75ef6a2788fcf61db222a8c2db7eee1600cd2faddaf85 |
|
MD5 | e4acd6a709ec6a44b248fa6041e7af6c |
|
BLAKE2b-256 | 4dc328743a41e33fe557e04de842c27b26113cb4bbc5d6f62fb5e2c0d4669024 |
File details
Details for the file fapyc-0.3.1-cp310-cp310-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp310-cp310-macosx_13_0_arm64.whl
- Upload date:
- Size: 452.2 kB
- Tags: CPython 3.10, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c76dbb365a140148f840c258f16b30a8a465877ea33731df283875b01fe4bb92 |
|
MD5 | 7b37a34053e9adb2e59c5a16e7398c0c |
|
BLAKE2b-256 | d7a6eb7463bb6cbad0604197f6420f635da2ff3272afac056e476cb86687663e |
File details
Details for the file fapyc-0.3.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 802.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab16e1b7b7f3c2849273c990f58b1c24d586411d30796534f96a1e0c7aeff99 |
|
MD5 | b52b7eb934edad3aa4f7453c12f46328 |
|
BLAKE2b-256 | 027f64f9cbb128fd94c723bf6f9f74b6dd4f6ca8c668d1f2357ccf7d0b754c8c |
File details
Details for the file fapyc-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 875.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a12abf8d8bc992144ce878036c8cd36652841a4c3961d16d1182d4fba225354 |
|
MD5 | 04e1aa9dd1f2a0341c3cefa4ea295c14 |
|
BLAKE2b-256 | fa909c099d9a0883db1c1ea9dee6d967904798f619290142d1cf9072d0c41e01 |
File details
Details for the file fapyc-0.3.1-cp39-cp39-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp39-cp39-macosx_13_0_arm64.whl
- Upload date:
- Size: 452.8 kB
- Tags: CPython 3.9, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3095186354a4725984741e66f2ffe390c29df77cf2558d9e8f4168c7880b4414 |
|
MD5 | 00829b4adb8c58c8d8be3efb544abbe7 |
|
BLAKE2b-256 | 2053d24bba9e9ad87479421b5f6743d7bdf8ba85006ce86cfd32c7972673c743 |
File details
Details for the file fapyc-0.3.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 802.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18c7b3eda31c20972dd6cb7fc90094ba586b63e21c2b29f968d27e2836407d28 |
|
MD5 | f1dc6aacf43a11369cdcf4450146fe98 |
|
BLAKE2b-256 | 97457e53565783dd707ffbce3e272ff0ec61e3f54112cf511e04d4501910cc4c |
File details
Details for the file fapyc-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 880.0 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e356597c071f129af315434c8b81040221cc7472b2f1387abf03d48168a91b7 |
|
MD5 | 62ab84bbd4656bf3f87c34a06924c9bb |
|
BLAKE2b-256 | 1b242b2760df392d7db1a5e55ad1a0c1ba3c0add9b9d60aea6325d2834b50ec9 |
File details
Details for the file fapyc-0.3.1-cp38-cp38-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp38-cp38-macosx_13_0_arm64.whl
- Upload date:
- Size: 453.1 kB
- Tags: CPython 3.8, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04df436c10fc200a0378a4da66661d3d511da8fd28dd2c5f6ddb2c321271f04b |
|
MD5 | 68ac79a8bcfe1c1a3173dc7bc74bb6f9 |
|
BLAKE2b-256 | df772d3ff88cc6e95fca005720fda3d085af228327e360ba6de259cf8a2d686e |
File details
Details for the file fapyc-0.3.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 801.9 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b41073e4d654e2d3ecbb9bc93a6c825b5f496cb9eed6e2f624c79c555d9c918c |
|
MD5 | 6130f051a972556749f2b29ffb1a7891 |
|
BLAKE2b-256 | 88ffdaba797edc473a610850307dee64632574b726fe3f9a642ce14d5784ce8f |
File details
Details for the file fapyc-0.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 852.3 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5554f6daba1683137ffbd136723693f4c03d5db00cb99600b63c3e62f126885 |
|
MD5 | 263875a062128d31670c71cebf5b829a |
|
BLAKE2b-256 | 55ca5d7d5ac9697a260b9d34baf6abf18233205b433ba315b53dd8403efcbc17 |
File details
Details for the file fapyc-0.3.1-cp37-cp37m-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp37-cp37m-macosx_13_0_arm64.whl
- Upload date:
- Size: 452.4 kB
- Tags: CPython 3.7m, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0911e59411f2e03af7f6f5341aa158f9db77f10182971c0ffa0524cb20032549 |
|
MD5 | 8bbfccf520d371d2ca892cd04a1c638b |
|
BLAKE2b-256 | 319392b5ba5c6ec7f7eee0703b76f8b50455654f00ec9f6c317e0e4b6aab1b9a |
File details
Details for the file fapyc-0.3.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 806.1 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aeae0223492b452dab4f2a11660566acdcf9f27c523d77c8f3b6af8d24a2249 |
|
MD5 | 79abcb466cf1f47174d8f1bad0ed9788 |
|
BLAKE2b-256 | 80e5e0bad33d3145e71f1166da350e147aeef8991a3568069d1bcd1e5d1e4441 |
File details
Details for the file fapyc-0.3.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 838.0 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de7a1b21f515c1355f6d20e6275a859930f9a4205e5032af65e19bc7a96414e2 |
|
MD5 | 64e661aec19ad967d34bc339a1721f29 |
|
BLAKE2b-256 | 801451d925f59ea928746746e07f998b8d83b7ac4adabb0e47ed011b72dfc4f2 |
File details
Details for the file fapyc-0.3.1-cp36-cp36m-macosx_13_0_arm64.whl
.
File metadata
- Download URL: fapyc-0.3.1-cp36-cp36m-macosx_13_0_arm64.whl
- Upload date:
- Size: 449.3 kB
- Tags: CPython 3.6m, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0547f33542b52dacb2a010570fcef06fa423a714688821600d7fa454409337e5 |
|
MD5 | 11d73f2d0dd787d650a3e105d3ad0ba1 |
|
BLAKE2b-256 | db33ac2d06c437c481625fc809e3e914c7e7509ee3ac77655268793b4d15fd2c |