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:
- 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
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
Hashes for pycdfpp-0.3.9-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a49eb49f3f0c944318cac93a6728d23ba839874a856a611c78334e42fbe252c6 |
|
MD5 | d0f1321ff1506f639a358f4b255d576d |
|
BLAKE2b-256 | 14d588644a9b13fd826ed58872c3dd50e5ba643e7c39779e3f45a07b8135b54e |
Hashes for pycdfpp-0.3.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5638774f01856e6515f492140698d9d9f41ec7437329a7ce360e5b7dd819d93 |
|
MD5 | 9269adb0845e22c69c8f067e974b55e0 |
|
BLAKE2b-256 | eb835a2abe7f34e085ad5ae7a245d934c16deb3238bf3666ab1384cb5a90938f |
Hashes for pycdfpp-0.3.9-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9a4a0bdbeef9f8244ab264a49e4361ee622fdff41c1d94fcee9712770e8882c |
|
MD5 | 380bfe90ed9d0c41a3ddf2117ecf1f51 |
|
BLAKE2b-256 | 6a5c85d4c77d44e9f1f5efdcb4a589aaea72efa757f8d15db5571dc9ba43ba4b |
Hashes for pycdfpp-0.3.9-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9337dce0358b9ff82b99fee8509ba6fe5539ae515e338318f54d31f2d1e36679 |
|
MD5 | c2fc0655c2e4e38dc8f85fb81f565a61 |
|
BLAKE2b-256 | 62c0f430b2a82412e34efea1c8cf976b04bcffe1ea9d05c01e7ce1648ef1b550 |
Hashes for pycdfpp-0.3.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5ebe2f62d14d1ccaf1e537c5753db723da22f38d1d870584049efdf9b60d140 |
|
MD5 | 6026accf617268594c87e97577198333 |
|
BLAKE2b-256 | 1556e65d72192423bb9751a51be892931dd03046b29cf23e808990f75be6ed25 |
Hashes for pycdfpp-0.3.9-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff68839a2acb5d1ffa8bfcbadf1180b50b6a1e68b8be08f5d071b31c9aa33411 |
|
MD5 | a0e8c8f0c6cbe8d748a616eb5e38e93d |
|
BLAKE2b-256 | 4d0b6919eb9e04d49492559e2aac9d0b1254f578805810d1ef6d05dda8645a57 |
Hashes for pycdfpp-0.3.9-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dc78770b3f27a8e7b622828714783666e18f35f5012a942fc0fcd3da8c74071 |
|
MD5 | be5bebc065c2c30f5b35176c87a34827 |
|
BLAKE2b-256 | c44ccca9da83b057def3c12c9461eb0af868ea290395e6be14aedc0f30441484 |
Hashes for pycdfpp-0.3.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eaf54cc66016409f74972993457848ed09edee19cf44daa7d97188b736595cd |
|
MD5 | 0fc55eb8e14232c8c5883093b9012f54 |
|
BLAKE2b-256 | b6e4d1bf04fb1cce9521085378bdb3b603692b8c55f05051d8dbbdfa53c9127a |
Hashes for pycdfpp-0.3.9-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72182df6ca5e0edbaf3a278ae3e9003eb6d1b4b410a88fd45f6da847d9452048 |
|
MD5 | 0274b3372c918ed356209707009d3093 |
|
BLAKE2b-256 | 629fe7fe2e5fe58ba9eea7837a5cecd689614d2b881ddabc506058a2783b9d99 |
Hashes for pycdfpp-0.3.9-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace0c8cc0830b8c280bb4c42f7c9f51f0c88af1f5649a85c596ae298f43cd99f |
|
MD5 | 1762156f94059cbdc5cd2db6f99366e7 |
|
BLAKE2b-256 | 5e3d7fb0798e9f09eb3019c7070d03b05ec6147b5f4428793046e31203466067 |
Hashes for pycdfpp-0.3.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207eeceaca8eabc536d3a4f59c6ff1ba6e12fb6ec02b2d51ad7240a1aa787910 |
|
MD5 | 92f937c55beffa9be3a39de85e4784af |
|
BLAKE2b-256 | 2c6f054ed413a71febdad2d98b2442844008a0238a7f4ef7ce2b102662d3c095 |
Hashes for pycdfpp-0.3.9-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7612ae0263528abc5dc74821a45ee39fdda3eb966a5236d345da55810ff554e9 |
|
MD5 | f68888e024ce11244cfd776fb0be1055 |
|
BLAKE2b-256 | 0e0f7b35740877dc8a002ac77879164b105bc6e2486656af712bdf46baca6d89 |
Hashes for pycdfpp-0.3.9-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccbd5dbff15bd9ec9ad818f655b402a5a41d974a91206587a1c3f24b929fae99 |
|
MD5 | 4aa1bb1c6d16fc8d3b88af1c40d6b96f |
|
BLAKE2b-256 | c44a606c543ac99ac68ba392c33672da4011f99854bc82d61c27ab2d005648f1 |
Hashes for pycdfpp-0.3.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9992a1b1b0147da55e181986c362c491d6377a429e9c7bc99679428af9dd172d |
|
MD5 | 071709c33c6fcbb32d62237603463eb3 |
|
BLAKE2b-256 | f2cb4ad1a34c9725c735ecac38cb31e2c5bfd67c7a187c406e2bdc86a4eb7471 |
Hashes for pycdfpp-0.3.9-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d22fe22d03faff654f63416f5f41bbb72a64643de633ebae6501519ed0188aae |
|
MD5 | 49a87fa5f7850eb5c320c34de0d2f8cf |
|
BLAKE2b-256 | c206b76d70c273502c7ce6ef12d0bacda87f76ab07c14dd9d5b3d308f5a84d1d |