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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.11 Windows x86-64

pycdfpp-0.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

pycdfpp-0.4.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

pycdfpp-0.4.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8 Windows x86-64

pycdfpp-0.4.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (541.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.7m Windows x86-64

pycdfpp-0.4.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (542.0 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for pycdfpp-0.4.4.tar.gz
Algorithm Hash digest
SHA256 50bcb6db61ab14863d98eb67e08e08865865de412fb2a1c77800b49144c73367
MD5 3df182684f616cd88ec0c0c98085f39c
BLAKE2b-256 45af97b597d024117822578af162def9b1b4db760e9c8f1fe245df392b710483

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.4-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.2 CPython/3.11.4

File hashes

Hashes for pycdfpp-0.4.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6866f3fc9fb54fd847ae34fd6f0a7c4f35acc52f9ef8bb495180b854eb0787ab
MD5 e9cc7692eacfea3162290c2af26045a6
BLAKE2b-256 19867fe91b7719cd6b2bc699e4551778bffd3273cf5287dba46e6017e117cc56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c167fd266dfccce86e083408bd12e4414999a3f3a221a64d82b4ffe32415bef8
MD5 e26bb292ae7c94e2906b1539dde2c971
BLAKE2b-256 8a60f6b1ddd8be1e288186c2442c8c7b13bd9c9a5355e4a75f3890e0bd90825e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.4-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.2 CPython/3.10.11

File hashes

Hashes for pycdfpp-0.4.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fbd91b0bd90cc78fbe872b54a9a4424038dcea11c72b646977a822141984d298
MD5 3ddf5b544573f1216edf39c2c6ac487d
BLAKE2b-256 cee88770c1cd5d1b319aa11a73ea4ee53d989412933f30851d551bc4426454a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93f195e75b5a6db5757933e74d4e8c9788308bcd7595494fdf3c45bfb9c2bb9e
MD5 8ec2525731fd3de4d7931eb0acd5fc35
BLAKE2b-256 4f98df1c0eb97cc5f7a32c225710bf7c8e0cc8a07fd457c732b177b3d27d91ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.4-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.2 CPython/3.9.13

File hashes

Hashes for pycdfpp-0.4.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ce25496a946ff5cb70bcf98ab5bfd0cfcfb882a74ae5488847429d332b64a06c
MD5 af1539a951e1c1c363077db83be0b976
BLAKE2b-256 ce352f21a00d69c2f03afc22c3e9f90dda7fb1ffe5217885284741d7eb5c62cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15eb75067265df0611cb0421f04399da2b97ebf94d0fccaec3ca3e3eca50f855
MD5 b3f1662bf3fad313999704069326c8d6
BLAKE2b-256 18d371e818b991bba510c601922dbc7ed8cc00cfc5d5c8ef95c476cdd2939d66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.4-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.2 CPython/3.8.10

File hashes

Hashes for pycdfpp-0.4.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 57c939fb2dd9e058aa06c1f74c5218ff8102e4a829aabb3755d39f53f2fe290c
MD5 05f3993e861b571dfec4eddd99fbfe3f
BLAKE2b-256 ccbd78a1c7ecb9ea28e3db3690eaf8e37481868632a6563e182f0ddef255d5ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 683b9c17677d4661a4237dcac271ffdef29dd4cef952267b0263ed56df95deff
MD5 d23e77bf544f9a33d50aab9557ad88ce
BLAKE2b-256 45c4627945f8c741ec1a984ba6de5526f658b133e152ab518590dd8e991e69b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycdfpp-0.4.4-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.2 CPython/3.7.9

File hashes

Hashes for pycdfpp-0.4.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b1252ae37cd9031019a68984fe15f1a5f8cbd22a11f7c02eabece116023025ec
MD5 640a3a1c96c68eb7d28959f4ce016518
BLAKE2b-256 e67d4ba4bb1f2d42b6ad5a46cc3b03894e117787c4bdff0d9414801dce1852fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pycdfpp-0.4.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 653853c046a8cb8a297d5899179c4d6c0c701c4c96de86514d9cdfc22d43191c
MD5 ab1c4bb4cb415eaba79048c7bb6a1d89
BLAKE2b-256 07228f9cac435687af081d20d650444dc435b80294364417227945fa84ec7842

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