A modern C++ header only cdf library
Project description
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
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 Distribution
Built Distributions
File details
Details for the file pycdfpp-0.4.0.tar.gz
.
File metadata
- Download URL: pycdfpp-0.4.0.tar.gz
- Upload date:
- Size: 493.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2b6bf83868a560c36ff97d0843c0fcb4e76f773d80094c1f4528801e2d39bf0 |
|
MD5 | ea07da66640349fee80a07799381559a |
|
BLAKE2b-256 | bc976137bfb9917d9609e402b8c3ccfa992a4087d82e21b0f98c8ca955d6bc1f |
File details
Details for the file pycdfpp-0.4.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9fe20cd0ae98a8189f2875ad42d7cc29af3e19c70b5c2f36300d80c43228545 |
|
MD5 | fdc40510fe1299da5d1e40e60797aad3 |
|
BLAKE2b-256 | 9d6bce07893950b9b19555fdec3cd542a3d392a283632ba7de935870a7dd5789 |
File details
Details for the file pycdfpp-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 438.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a614b04504971839937a5116f6ab0c1fcc1c16d54fd89be4edbc177679311521 |
|
MD5 | d1b54ef951a84dac5b0b6eb2e7b21acf |
|
BLAKE2b-256 | 1eb4cfd9cfa885a6be9606da0e35b0b4ade6234e71d2a18b2f14f77285ff46f7 |
File details
Details for the file pycdfpp-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp311-cp311-macosx_10_15_x86_64.whl
- Upload date:
- Size: 821.0 kB
- Tags: CPython 3.11, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d782d94a5e73fc6416573dc806047be608f0e52c77e5bcc997b44cd6e576bc5 |
|
MD5 | 1f61579927847cc9bc8026bd5ea483be |
|
BLAKE2b-256 | f808919b181be0a609d8b8c1993977ad9557d9bc9bfb378c6105435b2cfd22d6 |
File details
Details for the file pycdfpp-0.4.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 966.2 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | e31d3455419730fee88ab07033762a6a520f98beee7c87a2d061cdef57e7e2f6 |
|
MD5 | e1f485da922a1ed200db4908090902f8 |
|
BLAKE2b-256 | 093604d97cefd7ac1858baaf1e8021a0cfda9d73145fdfd1e730184692c2bef2 |
File details
Details for the file pycdfpp-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 437.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1000b04d887115b8a7d9f3e75445a37cf6a90d2d930321108482672578901b21 |
|
MD5 | 1728e8e3abd152e1087b3ae86e3f73f7 |
|
BLAKE2b-256 | 497e3f00c6106fcdc995b23d0078f4dbf994db9fbc1a85fa4536fcef267c5f15 |
File details
Details for the file pycdfpp-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 822.8 kB
- Tags: CPython 3.10, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f9a3f109e1cdd50cfb2977eab3185ef1237ef0b4862efdaebdda1fb4ced04d7 |
|
MD5 | fc5aa14b0ceb765fc2a27ca66093a9cb |
|
BLAKE2b-256 | 7ad58d26ddaece062bf9561b44d65eb9d3a84ac6558bde4ca9b75744a32d8a40 |
File details
Details for the file pycdfpp-0.4.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50b0110a2ee44e1bbe2603cabde6f0299a7e62daa127a73ef4d49bc00305e17 |
|
MD5 | 226b08bc2278e9d7d825219b95765441 |
|
BLAKE2b-256 | 83ab5c066273930c43de89a97390081f7602a87d2165fb25c2b0b9952e664541 |
File details
Details for the file pycdfpp-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 438.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd28e432ec2d7eb27bbf2f0d39d21d0d3d928bb3aa4cb4ca9a3b7563b5e824f7 |
|
MD5 | 5ff0d99c7ca1a3d3b5b1532b4f18918a |
|
BLAKE2b-256 | 9023356665eb07ae534290b9ad52cc32007ed4189f4908e8c0ef005bcf428e6c |
File details
Details for the file pycdfpp-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 821.4 kB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6a5d38801a7c6caaf7210614e51d6da50078654f3bfb696d0c0fdf89daa1bd9 |
|
MD5 | 38c35a79f610aee57ad0b97f19d1277c |
|
BLAKE2b-256 | 4c93e9949aaaae97a8f0286bdc27036b6847440ca503b26efd5a8210ca83f0bb |
File details
Details for the file pycdfpp-0.4.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c4511994ff7330a61ef6d6beff578446a0c60a311909442567b7eeeb973803d |
|
MD5 | fbe60c81d8429632a9256c3f58bc23b5 |
|
BLAKE2b-256 | 53c4f217129ed447c119d90eb79863c54be7295a27ba4a3c4afaed86675d09b7 |
File details
Details for the file pycdfpp-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 476.6 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36e95f3f91b7181aa7c49a3b935313bf559124f79be4a3c1a7e961e655275a8c |
|
MD5 | 41cd3492dd83f601584129a5f8eeddd0 |
|
BLAKE2b-256 | 07fb0b82869fbbb5fafbfd0b9158f22b5c8795f5943af5566728348f4c0d64de |
File details
Details for the file pycdfpp-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 856.0 kB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef99ca2b08541486855f4c99414e352908d48185e9a5ffd74555f00af0e167f |
|
MD5 | 307e916dc47b18821b0c3d6adaabafd2 |
|
BLAKE2b-256 | 9e7ffaf7fa0d4ddadf794225059737ef3cec9aea596860acffb6f9bf0fbdc4a1 |
File details
Details for the file pycdfpp-0.4.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83eeb337360600633778774e7fe1218aa929589a4c063d895687b273cca3df84 |
|
MD5 | a37985dc98feca8d914921dcd92252df |
|
BLAKE2b-256 | 51575ef3fbca1001cef1e59564dd4ffefcfbdb65f72d7f9af42b79661777e044 |
File details
Details for the file pycdfpp-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 476.4 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5db296886c72df18fb88c1ad90fe7e14db9b763edd86684016cc963b510b45c |
|
MD5 | 2db7c2b31d258bc3ef858f2b829caa05 |
|
BLAKE2b-256 | ae86f9108bc5a242b20a0d57ee9ccf810c063b1fd12a58d996ef44758d1da7ce |
File details
Details for the file pycdfpp-0.4.0-cp37-cp37m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: pycdfpp-0.4.0-cp37-cp37m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 852.7 kB
- Tags: CPython 3.7m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86ae20c75626a51d7300c64883d44975cfe4761cc9307d2d2e8793c1566cf25d |
|
MD5 | 0b4d1e3bcc0d3f5d491b3d0a60999c9f |
|
BLAKE2b-256 | 197703bc96632ad0888be85c7a8471259bb8b0937253b9bc5f771da097ab0bf5 |