Skip to main content

A modern C++ header only cdf library

Project description

License: GPL v3 CPP17 PyPi Windows(x86_64) test matrix Linux test matrix MacOs(x86_64) test matrix MacOs(ARM64) test matrix Coverage Discover on MyBinder

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.2.tar.gz (493.9 kB view details)

Uploaded Source

Built Distributions

pycdfpp-0.4.2-cp311-cp311-win_amd64.whl (966.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

pycdfpp-0.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (438.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.2-cp311-cp311-macosx_10_15_x86_64.whl (821.0 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

pycdfpp-0.4.2-cp310-cp310-win_amd64.whl (966.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

pycdfpp-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (437.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.2-cp310-cp310-macosx_12_0_arm64.whl (796.2 kB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

pycdfpp-0.4.2-cp310-cp310-macosx_10_15_x86_64.whl (822.8 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pycdfpp-0.4.2-cp39-cp39-win_amd64.whl (966.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

pycdfpp-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (438.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.2-cp39-cp39-macosx_12_0_arm64.whl (797.8 kB view details)

Uploaded CPython 3.9 macOS 12.0+ ARM64

pycdfpp-0.4.2-cp39-cp39-macosx_10_15_x86_64.whl (821.5 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pycdfpp-0.4.2-cp38-cp38-win_amd64.whl (965.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

pycdfpp-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (476.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pycdfpp-0.4.2-cp38-cp38-macosx_12_0_arm64.whl (837.5 kB view details)

Uploaded CPython 3.8 macOS 12.0+ ARM64

pycdfpp-0.4.2-cp38-cp38-macosx_10_15_x86_64.whl (856.0 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pycdfpp-0.4.2-cp37-cp37m-win_amd64.whl (967.3 kB view details)

Uploaded CPython 3.7m Windows x86-64

pycdfpp-0.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (476.4 kB view details)

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

pycdfpp-0.4.2-cp37-cp37m-macosx_10_15_x86_64.whl (852.8 kB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pycdfpp-0.4.2.tar.gz
Algorithm Hash digest
SHA256 f0e7fda584a22ccbbae2e1899bf2827d486a78c93626f548f42b4401f2f5e72e
MD5 25a9d4f9c4e69277cb03115d1bd49a31
BLAKE2b-256 f4dfc61bc219ede253872573313cffde901b26fbcc5f53914083cbe04e7c8deb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 966.3 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.4.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0e731628b999cd8ed2834c5ccd5305d05ba8f1e0128fcf41527a2704c0d865ef
MD5 bbde4f5db4477e03e13c9b735017d59d
BLAKE2b-256 2aba781697f4d83074ef0ec32906426bd2666c112231961c264bb0d62274e766

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 672580a5a2a9d92ad357b12b67e465a41630162e796d33932fe4d40227e612ec
MD5 6decead6d6c91a838bc8f2787e83b03c
BLAKE2b-256 8e87924a5b4c6ac6b72393cffcbaab044e69adf6efe0407fb6e945123d664da9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0323fc4fed303df1f969739e7890ea7a4ac414f59b0a870671ae3b6d8fcbbf9b
MD5 8d071844edd231d744eeca2255f37744
BLAKE2b-256 876c7dfca514f8068afd123ff10a8f0e2fb99544baa285664450cd78384c401b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 966.3 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.4.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 35da7437aace827821f4a6c35a1df2004bf750857a75ba4d345f28121ec3142a
MD5 f7d43bd9012b24e4cd220cea3120c426
BLAKE2b-256 b82c3186855de5e295c9276917a1f6ec8a20ade7ab3c3d418ccc1e1095ad041a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 98cbb099b169863cbb78e9834a125d9da07032e69b91fa7678b3561b02806739
MD5 437295b33ff87a726655c20711a8e409
BLAKE2b-256 b56f69294bd414609a33dac8c9f325ec7d2852c4c2ef5efac343399cf7b5e1c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 7ea6803faae0840ee970994098b54cc0d18aeef53001114527d0f966c6fe4e5e
MD5 398ad58bfd76c532a29140a99f621f9a
BLAKE2b-256 4ce8432dd5e283b4cbb044415c69566e79cda76530c70ed4b7eee090fdd005ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ccf48a78644f3aeaf51d339e51d8980bcdc65bf120225d2de476e9c1ea7ed7bd
MD5 2418d79bde32f55beda280fc0540b719
BLAKE2b-256 26fcb826b65abb08ca09e6d8f9df1370765213504f83c509bb3a99a689769c80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 966.4 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.4.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e321eff692de54654ada8318075e63aeb439c10082ff0130bbfaba78fc3ad3b1
MD5 58a416b95791c4fe9b551b381fbc119e
BLAKE2b-256 dd9937c58e8832c9dfe2f74f4935b69fec6f80070d663a39b2723aa4d2e7ee8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b2ddd30877262ee0cfede9092e1ce14ebafd9c82e8f3a36c246d66afa5c96ba
MD5 904c65304f59b290eb380dffd8cbbdf2
BLAKE2b-256 483f1334582133911d69005ec4c3204c5421cad3159b4027c8b39d08ea533a53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 d1977f9e6e712ea7ac6bc1e2c04fde7c2591ef5b9afd93a79a2121df4794a211
MD5 54df130ddd77a3972fd0978a1edf33c2
BLAKE2b-256 ce1d33975acd0a58ed8e377945b5f066bac1e03e85e0579b2e627e7eafa83aed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 32f272ac981adff06c4f46af3c3bd6c633ef708159d4cbe57e966bd90fca9ca7
MD5 d01a5120e2867e2120a33603107c1d8b
BLAKE2b-256 73044143f0f5e6ae885f68aeadb8060e569a2a8ec85acbf71fe2a70fa2310649

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 965.4 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.4.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8558d76f1e17562111ead3232de55571b1cb2a4a94d79629874b1af7e9c21b19
MD5 50fd2bc6b00ca2bbe95c191efdd70616
BLAKE2b-256 a5cf484031a3b26062af60c26384147a75fbd01afb7e1996dd569eee42b192cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eadddb98865728389b3adb02dec83d7ab056ab2e70f08f51ebd2e6078e271810
MD5 218d91ec4ff927a61cdd81a75906d35f
BLAKE2b-256 6a29c58697f7b58b92728813d70774b4220eaa6ab60450c976e0e698577ef650

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp38-cp38-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 e89bacfc91f6f9f3300b2952795d409b4e1485765a2321b7176f23e1dd1a0e62
MD5 46b7455300087a5ee64323457ec44265
BLAKE2b-256 44e10e523d899a8c0f183f5851795d27afef288c183c3f793d2a103db17c6390

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ce89e39749af58c58c353a5a1d2f720d696b0f1d26c25e4ffa930c4b01c8f2f0
MD5 4aee5eb18e4b8551bd92db156ffac7e5
BLAKE2b-256 b7740e8050b11140d591521eb27205c083dc46f7f30030eb5f5e5a941e3b31ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 967.3 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.4.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 656ac287c74ee6a7550a419eacc87e09d05fb8541c5336ca16a4432e5d7545af
MD5 bfdabc89de882046906819e5e783b31a
BLAKE2b-256 a44e2a4717154d3de909b748f72fd12b8936c4cce82da6b9f4182ef4171c9400

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d609196a562d226155e16b353be9411ca96474eaf23424b1bf63881c636db0dc
MD5 c2426096c02296544b9c50b125f1bf67
BLAKE2b-256 dfdfef3627e69adde4b36ba0ae630b455818ae3d1e3bd3d39294e14c1520915f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8e8bbafb8f6bafbe325a8ac27fbc344e6e1a1796816068d4de43c7cf32b506fc
MD5 9438e15351ba998609bac154907e2b51
BLAKE2b-256 50f75c2b15ed9f5f09dd4ef94b1c3f2cd96e0ee81b023a69865227e7d3669eab

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