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.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 385c1fb00192cad7c8c337ed0541efb6156684408dbf6f1681c1534861ba078c |
|
MD5 | 1f880a7309010f36bed776089a3e6d83 |
|
BLAKE2b-256 | 30d3f20ba87243e573717cec2456fbd19d78bd27d1ef3a4b50f5aff87694ec01 |
Hashes for pycdfpp-0.3.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7836a9d4f866761666e0ff6482f4ff938114111e19b11b8b283c07a5c8054364 |
|
MD5 | 3dd21cb36921d23f77045a20a63902ef |
|
BLAKE2b-256 | 4ff04c53cd9730e5ca1ad9655e2318a12f1c9c32f5e5d3601a2c2663812d8fac |
Hashes for pycdfpp-0.3.7-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207b4cf099755f591c45f18cfcee318a23d93263ebae44cfd769fe1e64754c9f |
|
MD5 | 2f00cf14ed0018fce9098b8b2fb375ca |
|
BLAKE2b-256 | be7256ea701f445ab69a0219f033d4e52d9432771c46554c18e15dbd1844b121 |
Hashes for pycdfpp-0.3.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8037144d4c7233a1d371d45586a14ebc35d544a0263ea8c07228ab7a67fc238d |
|
MD5 | fcfc79b74a54681e6caf8744411546c5 |
|
BLAKE2b-256 | 3d399d83c89c67c49c873beea7d2d8af619ecb6b73a85d6eb9444de9559a12b3 |
Hashes for pycdfpp-0.3.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ecaa53d1193161505a705d488404749956bf32d30b076c4ff21d10dc30937d8 |
|
MD5 | 88d43950dae19b1ccd3bbcabe8765a3a |
|
BLAKE2b-256 | 1490595a0b580e72f6d4033cfd638c9b7f515769021a7987e5a341074a7eab46 |
Hashes for pycdfpp-0.3.7-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d44619c64028bbc8f3e887d990af91cc3280f810b7cbc83b69ba88b6a13a067 |
|
MD5 | 9bfd5f9a3f554fef8521bf79b2386fb9 |
|
BLAKE2b-256 | f01baef190142b26bd30118c7cfcd9597cfc0d477f37fee775eacbe15fd23e70 |
Hashes for pycdfpp-0.3.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4506c1294f53e80bb8b9be317e84707c270a5b6a1a2f54bd5c3082736fc85626 |
|
MD5 | fb6b9614977dd9d91abb02ab13cbc979 |
|
BLAKE2b-256 | 8d7a7312d424c3f32c792f0c2a6f816e7d7fcbf1d55d1c90c20d333c66e7f0e2 |
Hashes for pycdfpp-0.3.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 712f335378d49217188deca8e2344fb8d812e134367192d29b0a067a2c1de41c |
|
MD5 | b4d6832bd363c07a1748789409cb0774 |
|
BLAKE2b-256 | 5a1ef76e2fd9b6b921c259769f3a83a60c6acd73e1152bafc7f224133d7d82e5 |
Hashes for pycdfpp-0.3.7-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e38ffed6522534c591ba71a18f36cb2918ba1bfcf38864d285aa240da8d30166 |
|
MD5 | 850784b05e8bb25d0b314e10dff261b9 |
|
BLAKE2b-256 | 4b0e8f8729c81a91ef8ddac1620c8f2a79efe35c458e09286f0b60986b824ea4 |
Hashes for pycdfpp-0.3.7-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1a0406dd5a7b8c583a9d1691b8e1ccc1b382b938c57f93cf9f7daf37c9ed123 |
|
MD5 | 44d63e7f9994a77756e9dcc124f88841 |
|
BLAKE2b-256 | 868383832ba1962c1e31e5c7a1f1438318a8e9e7406ca8253277d68cfbeb71fb |
Hashes for pycdfpp-0.3.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c756149ceb7d500de6b2dda767b03b002c8ab5f72bae329da23e87c3207d17 |
|
MD5 | 95b6dd2c2f36f1b2a0a7d54ee2d9e165 |
|
BLAKE2b-256 | f74d1ff643aae9e4a04efca64b2be352d59b8faabc526577501483812f1aed29 |
Hashes for pycdfpp-0.3.7-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0884e39b9d15e2500d5385b075c0fa643031601f932c47325e1837ac72bb90ba |
|
MD5 | ba4864889af3941d48538ba1cb6a7cac |
|
BLAKE2b-256 | 886adf86a87d50b7fa41ec977bcb185bffb48ddbc386ac486f226ac05d6b5940 |
Hashes for pycdfpp-0.3.7-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed5e6b7ce97c8c1a92a7dda583aff2f7e47e9154ca6b2cd605b30471ae4aea85 |
|
MD5 | 71b1f31fab9fb8e416473924f2c35b3b |
|
BLAKE2b-256 | c82a7c423313ecbf3e3e5e95b55d9f220da4d20e0f5f1d4f2c37fe8ac8ab1e59 |
Hashes for pycdfpp-0.3.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85e2737b66126ab38ed6f9aec3b49f82368fa9544954ffbd2a735d3c1ae944b3 |
|
MD5 | a19f419adf110ccc0339aa95503da70e |
|
BLAKE2b-256 | cbf21d824142b5cf0a0e2c2133365b5f3df4a8918a097364bd9fea01e596f7e2 |
Hashes for pycdfpp-0.3.7-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b58c47a4aab20355dfcfaa90d8d6002c545a353aa537b4b36b7c1b9a5a86e853 |
|
MD5 | 288729063e1feca1a9e3d9a505322320 |
|
BLAKE2b-256 | c94ce046982e366d547ea0f7f6e9f6da141c48303a6455b473a621e2ed44b479 |