Skip to main content

A modern C++ header only cdf library

Project description

License: GPL v3 CPP17 All OS test matrix Discover on MyBinder Coverage

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:

  • 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)
  • write uncompressed headers
  • write uncompressed attributes
  • write uncompressed variables
  • write compressed attributes
  • write compressed file variables
  • 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()

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 Distributions

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

Built Distributions

pycdfpp-0.3.4-cp311-cp311-win_amd64.whl (999.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

pycdfpp-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (452.7 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pycdfpp-0.3.4-cp311-cp311-macosx_10_15_x86_64.whl (386.9 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

pycdfpp-0.3.4-cp310-cp310-win_amd64.whl (998.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

pycdfpp-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (450.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pycdfpp-0.3.4-cp310-cp310-macosx_10_15_x86_64.whl (387.3 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pycdfpp-0.3.4-cp39-cp39-win_amd64.whl (997.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

pycdfpp-0.3.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (452.3 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pycdfpp-0.3.4-cp39-cp39-macosx_10_15_x86_64.whl (387.6 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pycdfpp-0.3.4-cp38-cp38-win_amd64.whl (996.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

pycdfpp-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (487.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pycdfpp-0.3.4-cp38-cp38-macosx_10_15_x86_64.whl (424.4 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pycdfpp-0.3.4-cp37-cp37m-win_amd64.whl (994.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

pycdfpp-0.3.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (486.6 kB view details)

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

pycdfpp-0.3.4-cp37-cp37m-macosx_10_15_x86_64.whl (421.0 kB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: pycdfpp-0.3.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 999.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0rc1

File hashes

Hashes for pycdfpp-0.3.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e1a6381aaef4592ea5f9732b79e7dd5e894132ac2e6a2cd17584e877eaadb630
MD5 523a000714773228fdd4ac74c34e5996
BLAKE2b-256 6fd0e1027290a7358a7dddd7abc24995d46daa66b17023cbdca7e806e2194425

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 771d3afa6a466665d9ece128d635b9efad3b09a83c213f578f396262b79638ac
MD5 5f19e8e697ee66ff018d8caa9acba8c1
BLAKE2b-256 8a8a39b60294a66fbe5658b5809dd9718b3710c039dc5ec4ddd1f4bdac7759a0

See more details on using hashes here.

File details

Details for the file pycdfpp-0.3.4-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5e2f78902feffa739d24231c5635e01c6597c47d1ff1b9ced6e84aeb6bcd92a5
MD5 2ce8dd563055568cc00c9907ec0406e5
BLAKE2b-256 79f5a46b36b75b8d8d849791350ac78dd38d0f53c6bbbbad328fdec4f15c36f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.3.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 998.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pycdfpp-0.3.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dd468bd714299df963262416394a11cec0a58cd1f4414d537ec4c3837cbc41d5
MD5 751831c1950a8985aa0285b028fabd02
BLAKE2b-256 0e1f90348400304f78293ce937d726f76e2ea0cb121febf5b7910e44d7a691b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8efe9e82a3cc45b5cf85303db420a43690626a2abb8fa2a23f910caef1b86df
MD5 7f852d3b86c1edd0503fef896dacb168
BLAKE2b-256 dbcb407c0a8fe0692b88eb428e0be31f0d92dcd6c9e62336339123bdae5d366d

See more details on using hashes here.

File details

Details for the file pycdfpp-0.3.4-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 21acf1e0e8b4d60c9e9aceabc7cb0dcef0a827f9ba4fd4babf06d379e6901877
MD5 78c4e8b6c1900893f27a20e7cd90526f
BLAKE2b-256 1b9d6a2ea12324122f4658b8a2532020659d4acf260e77244d374c037f58884b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.3.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 997.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pycdfpp-0.3.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 cb98faa7e4d279e46d635a65145558490dd5e603df968f169876bce8fdfeca1b
MD5 5c1dba551b18a877e4d0c7a84ea14049
BLAKE2b-256 e2cf26bb45d6ab28c35d61f0187822f4b22ce6b43d9bf877ce36acdff15c1dfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4479e6d6d3fc105e078b85fe764da088c1fdb31713430ad0b8c2e710ec396c99
MD5 3e1f2a55e20ccc5d60d6765ee780a17b
BLAKE2b-256 f069a806dec4f6d4eb33f64d7339c44bbe2614b03f6fd2926133280b8fef6d47

See more details on using hashes here.

File details

Details for the file pycdfpp-0.3.4-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b5fc7bd77c267c52ab23e00d26dfe31254edfe847dd7b8f191e77ceb8be52e8f
MD5 48c44aed21a207a6e753f2e6d2aa9114
BLAKE2b-256 63cd6eaac7b4112179805ec835e77dca944257e1df6b5cbe00a44e6c0491cd04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.3.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 996.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for pycdfpp-0.3.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9ab551a75851d63775c2d2cd7500e5d2b3a3fcc0baabb075404f901ad973a862
MD5 33643922732b57fb5fe5dfca8daff52d
BLAKE2b-256 d4ec2a90ce6e809a616abe2e9834bcebd313422b560aaf5a3c844f20f9fddd07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 262aed970fb1b5d22ee4a9d3b09f89d4733811d59a98cb248066b9ed529150ff
MD5 8d9ffa6b539d584ffc9cdb59fb3a3788
BLAKE2b-256 ba39d92d66bcb3e9e018a0039a1f6b6b1b70b5f71166969be682004166ac2643

See more details on using hashes here.

File details

Details for the file pycdfpp-0.3.4-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 aeeedf403ffc4d7c60da1b3c616cd9584768b127450057881c1b37b4da1aac1a
MD5 75ac4e0a3aa503e993cab79cd2bf8b80
BLAKE2b-256 2bf2fe8c3f7e512e87309c4699d5be33aaaea4cbda18e55b66ae6b38f7cee3dc

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pycdfpp-0.3.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 84d74dde6938109fe832fad09ddc2b16783600c41fc9b33bd24300442408847d
MD5 a21691c538c121f2d3cf7326fb823de8
BLAKE2b-256 462f50304848e1ce6b2be683f586e987be29d15a7c8f78b4c16fc86a2b50c5f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3732bbdcd57ec97f27deb647f2305b9d51b1735e2b9cb75b1ac525dbf5684b99
MD5 ee4ccc6ef5e64b24664a2e2e000bec26
BLAKE2b-256 dc0dfeeb7f24ad189eef6eda0749b50ca9ec3e2aab8fa98da5288fa94f70dcac

See more details on using hashes here.

File details

Details for the file pycdfpp-0.3.4-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pycdfpp-0.3.4-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 dac1396fcfd74e8099273c8277f5fa61a73d88fa4e05b06f0d14b0deca635916
MD5 394471d3ca67bccedce98f226d78629c
BLAKE2b-256 2a97b24b04fa4cdf6ba210c3437e58c6548da54fafef0b3c236a86227b6d50c2

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