Skip to main content

A modern C++ header only cdf library

Project description

License: GPL v3 CPP17 PyPi Coverage Discover on MyBinder

Python packages

Linux x86_64 Windows x86_64 MacOs x86_64 MacOs ARM64
linux_x86_64 windows_x86_64 macos_x86_64 macos_arm64

Unit Tests

Linux x86_64 Windows x86_64 MacOs x86_64
linux_x86_64 windows_x86_64 macos_x86_64

CDFpp (CDF++)

A NASA's CDF modern C++ library. This is not a C++ wrapper but a full C++ implementation. Why? CDF files are still used for space physics missions but few implementations are available. The main one is NASA's C implementation available here but it lacks multi-threads support, has an old C interface and has a license which isn't compatible with most Linux distributions policy. There are also Java and Python implementations which are not usable in C++.

List of features and roadmap:

  • CDF reading
    • read uncompressed file headers
    • read uncompressed attributes
    • read uncompressed variables
    • read variable attributes
    • loads cdf files from memory (std::vector or char*)
    • handles both row and column major files
    • read variables with nested VXRs
    • read compressed file (GZip, RLE)
    • read compressed variables (GZip, RLE)
    • read UTF-8 encoded files
    • read ISO 8859-1(Latin-1) encoded files (converts to UTF-8 on the fly)
  • CDF writing
    • write uncompressed headers
    • write uncompressed attributes
    • write uncompressed variables
    • write compressed attributes
    • write compressed file variables
  • General features
    • handle leap seconds
    • Python wrappers
    • Documentation
    • Examples
    • Benchmarks

If you want to understand how it works, how to use the code or what works, you may have to read tests.

Installing

From PyPi

pip3 install --user pycdfpp

From sources

meson build
cd build
ninja
sudo ninja install

Basic usage

Python

Basic example from a local file:

import pycdfpp
cdf = pycdfpp.load("some_cdf.cdf")
cdf_var_data = cdf["var_name"].values #builds a numpy view or a list of strings
attribute_name_first_value = cdf.attributes['attribute_name'][0]

Note that you can also load in memory files:

import pycdfpp
import requests
import matplotlib.pyplot as plt
tha_l2_fgm = pycdfpp.load(requests.get("https://spdf.gsfc.nasa.gov/pub/data/themis/tha/l2/fgm/2016/tha_l2_fgm_20160101_v01.cdf").content)
plt.plot(tha_l2_fgm["tha_fgl_gsm"])
plt.show()

Buffer protocol support:

import pycdfpp
import requests
import xarray as xr
import matplotlib.pyplot as plt

tha_l2_fgm = pycdfpp.load(requests.get("https://spdf.gsfc.nasa.gov/pub/data/themis/tha/l2/fgm/2016/tha_l2_fgm_20160101_v01.cdf").content)
xr.DataArray(tha_l2_fgm['tha_fgl_gsm'], dims=['time', 'components'], coords={'time':tha_l2_fgm['tha_fgl_time'].values, 'components':['x', 'y', 'z']}).plot.line(x='time')
plt.show()

# Works with matplotlib directly too

plt.plot(tha_l2_fgm['tha_fgl_time'], tha_l2_fgm['tha_fgl_gsm'])
plt.show()

Datetimes handling:

import pycdfpp
import os
# Due to an issue with pybind11 you have to force your timezone to UTC for 
# datetime conversion (not necessary for numpy datetime64)
os.environ['TZ']='UTC'

mms2_fgm_srvy = pycdfpp.load("mms2_fgm_srvy_l2_20200201_v5.230.0.cdf")

# to convert any CDF variable holding any time type to python datetime:
epoch_dt = pycdfpp.to_datetime(mms2_fgm_srvy["Epoch"])

# same with numpy datetime64:
epoch_dt64 = pycdfpp.to_datetime64(mms2_fgm_srvy["Epoch"])

# note that using datetime64 is ~100x faster than datetime (~2ns/element on an average laptop)

C++

#include "cdf-io/cdf-io.hpp"
#include <iostream>

std::ostream& operator<<(std::ostream& os, const cdf::Variable::shape_t& shape)
{
    os << "(";
    for (auto i = 0; i < static_cast<int>(std::size(shape)) - 1; i++)
        os << shape[i] << ',';
    if (std::size(shape) >= 1)
        os << shape[std::size(shape) - 1];
    os << ")";
    return os;
}

int main(int argc, char** argv)
{
    auto path = std::string(DATA_PATH) + "/a_cdf.cdf";
    // cdf::io::load returns a optional<CDF>
    if (const auto my_cdf = cdf::io::load(path); my_cdf)
    {
        std::cout << "Attribute list:" << std::endl;
        for (const auto& [name, attribute] : my_cdf->attributes)
        {
            std::cout << "\t" << name << std::endl;
        }
        std::cout << "Variable list:" << std::endl;
        for (const auto& [name, variable] : my_cdf->variables)
        {
            std::cout << "\t" << name << " shape:" << variable.shape() << std::endl;
        }
        return 0;
    }
    return -1;
}

Project details


Download files

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

Source Distribution

pycdfpp-0.4.6.tar.gz (495.1 kB view details)

Uploaded Source

Built Distributions

pycdfpp-0.4.6-cp311-cp311-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

pycdfpp-0.4.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.6-cp311-cp311-macosx_12_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11 macOS 12.0+ ARM64

pycdfpp-0.4.6-cp311-cp311-macosx_10_9_universal2.whl (4.0 MB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

pycdfpp-0.4.6-cp310-cp310-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

pycdfpp-0.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.6-cp310-cp310-macosx_12_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pycdfpp-0.4.6-cp310-cp310-macosx_11_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

pycdfpp-0.4.6-cp39-cp39-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

pycdfpp-0.4.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.6-cp39-cp39-macosx_12_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pycdfpp-0.4.6-cp39-cp39-macosx_11_0_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

pycdfpp-0.4.6-cp38-cp38-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

pycdfpp-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (543.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.6-cp38-cp38-macosx_12_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.8 macOS 12.0+ ARM64

pycdfpp-0.4.6-cp38-cp38-macosx_11_0_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8 macOS 11.0+ x86-64

pycdfpp-0.4.6-cp37-cp37m-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.7m Windows x86-64

pycdfpp-0.4.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (542.3 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.6-cp37-cp37m-macosx_11_0_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.7m macOS 11.0+ x86-64

File details

Details for the file pycdfpp-0.4.6.tar.gz.

File metadata

  • Download URL: pycdfpp-0.4.6.tar.gz
  • Upload date:
  • Size: 495.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.6.tar.gz
Algorithm Hash digest
SHA256 da7aee0c0f97962a1acc907503f12898eab8ec7a09c63269906d7610a62d31de
MD5 93b52ca301125a83e372e325120f0f8f
BLAKE2b-256 70fa2ad8d0d40426b7f189ab5a46a3b70b59381471d7c3e2daf9796d9dc495f2

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pycdfpp-0.4.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 247ed6ac9a34fdcd41f878bf9ff91e3255d4288ad3b313380e1bd59650686bb9
MD5 2fb09b37d48525845efd2adba9ad6fe3
BLAKE2b-256 06d2b904a21d5ffce5bfac0b5025b739353aa2caa5e63b51b473cd245392dd85

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03d775e4f4f0a155a75f1a44fe20d234a47cf13c04a713cfcde5a15490ce5b0e
MD5 6089a0eb36e9075f079a56c0792b7668
BLAKE2b-256 467c2f26b679619d5d78f22ade982f609febffefdd28761f2e508bf3f3943f9d

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 5f556bebd03efe43431152e32e9e0fabaceda5336ff5a5d7f9da86040679025e
MD5 bfe83db4cd1ca440801f33d65a1661cf
BLAKE2b-256 8fe057af2f847765d813a69e53ab80aa159e231f6bbac7ff03664cbecd2e3d94

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 93121a9b29c2ff90d15d71ccc91c4114a5a96015c8274b8464891cad942eb12c
MD5 47248271799ec278c302d049dfe9dafa
BLAKE2b-256 16cc163f429b55bd539fdf04d93f17292c06fbe820b3ad782e4513807015556f

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pycdfpp-0.4.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 aa51b610bb66e33a96a5d0bd066fc5fe3ee22ba425412dac90b09c8e98be40b4
MD5 3f9777d930bfce7d3b7942ccc2d6020f
BLAKE2b-256 0c38397933120e909d51f842773e5dcb5c36f40fbe4ffa9f21264ebae1f9ffc8

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55b9e55bf6a04de25d28ee66b693b01930b9931ed320b7066ae1b5fa3dd04815
MD5 bc4c4497f19f4a3ccddab9e3d6c6b90f
BLAKE2b-256 48b0f77211b01d115f01366e68d9510d4892f82551e1054d8d9c9770a797cc13

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 0687e7145dbdb56aeaaac93c972671ab06df48d540b8b60fe082538553341580
MD5 c2b6c426dc775860a1aaa722e9a16a8a
BLAKE2b-256 f1f43c55878ded6475c32ad146d108cb10d29c322eacd10bb4fd72f20ef79561

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 082f4333ac58f7a11d28ccdd6728609ab9ca1299dae35c65f4e42881cdce85c4
MD5 35a8272d70fbe39caade84a8aab8aa9c
BLAKE2b-256 1886296dcd41a3d1b5e8569073d36aaaeb403e076b6545b09e1e00669fc85ced

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pycdfpp-0.4.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 879b6ca522cb7d0a010545146d9ddb425a39bb5e6d5f1084f8634c993047189b
MD5 f1ddd8d0bb0f2d356e822d1fe12ad260
BLAKE2b-256 a87a56a516c654ab84cd320b00d5525b022307c8eb8d722319d1fe61be7013c8

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6576029c5199dd2269c7fd3e2479ecb8aac96fbef77463dc594ff53cea54a2e4
MD5 1511cea071d9677a1b1792c802f95914
BLAKE2b-256 e29d3358daee9896c733a89b7b7779e36a57f9d9c29ce49de7ac3b41fff8f2bf

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 f74f2a040988699f66ecd91dcb629be3f18778a5e47d5d11896867ceb7667da3
MD5 d811ddf1a34a2061b6fc56f25013a927
BLAKE2b-256 c9fe8378b009177ee674898b750565583c59e8fba5f1353a98eda1e778d063de

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ae0f36bae93dea5f59efb6a6e7990829ec9c48d4eabfb23afade04bef3d3e9d1
MD5 82750ecbf38b8a9c0161fb690585d159
BLAKE2b-256 e2a662743c9625825f14c56caa6c66d4a51ea7cfb708897567c62c93a669b28b

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pycdfpp-0.4.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3c84ba1b559d7a8ad62f5dfe056b5023da23bc658d8c2248f69911ee30f78b5a
MD5 53ca1c957cfd7e96ee64f84164366dcb
BLAKE2b-256 f58d16de44576478d2b8422dd4a5672fe39af0ad9adbe4783e21ab5593f61642

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 266a1dd475e447dc51bce7084b37f7026916e4684bbcc6094fb243760d6d3c95
MD5 2a1df1fdfbcdcc61711323fadfe74c76
BLAKE2b-256 e8d347a764194c7f4b68d1873dc1fc1a765c1c96a0808b62a61b32fd260219fd

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp38-cp38-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp38-cp38-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 22c3ab4f8b00c3500b461118c1f2a1ac812a143680611a40a88a92d8c13e6a07
MD5 256deb57353a1be935d2ca4d6fe698b3
BLAKE2b-256 a54445d0be9b4f7c903d83016883e2ef9b1d1811012b95c898830693b211d856

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 d31ace6aa009aefcdb11649d545121ca9b9034b4138c5650ca19baeb335ee991
MD5 3d4cc22538c8a937e614dd9d5fe1d716
BLAKE2b-256 210689e0edd383649eb91a10b1d186ad6cf8b3f07845f61e650d290fe2b3d477

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pycdfpp-0.4.6-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.6-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5fdee2c20989e70c62f80fc4593f50405e25a3481029f7aae713290e5fae9342
MD5 3602d0c72872b7f1c3cc0203b406f7c3
BLAKE2b-256 dd41d6b27715482e71eb92f0dd6f171efaf2e919b1233309e0832c394c1ada0d

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc5fa992392e37617caa040cc2ff2e59f3ec20cfc57b6239d03d1cd77281198a
MD5 0373d4240231c8811b5e11f5d6fe1d72
BLAKE2b-256 09724c6065b583ad66846feef839913e9b0c3b319396fc759272320488046a60

See more details on using hashes here.

File details

Details for the file pycdfpp-0.4.6-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.4.6-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 efc9a7c9702f82ed92e4cb55b946d7d7d35d64a3c8f5735f836b8f5ee4990b29
MD5 8b7fcadd85a509e2982cba6405f91544
BLAKE2b-256 53f42b298d013c8967634c8057882b988d8b092d74eb28666c1cbc7f3c68b46d

See more details on using hashes here.

Supported by

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