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
Hashes for pycdfpp-0.4.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5321253d66bdd5751257f1f9c0309b6f702d8eb7cd56f49871e4804c4007958d |
|
MD5 | d6149c7f2038c334721049d399e2a072 |
|
BLAKE2b-256 | b60152ef804b3fa6da53e5e211053a58bd8a113bdb51b784e6c4f2937c31e7a3 |
Hashes for pycdfpp-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a46bb15628682b3e894d0710a88df7e325ed8291ba19c1806aa3d10062154c82 |
|
MD5 | 51e04c9cbf2a4b862d2386d72cf6139a |
|
BLAKE2b-256 | 8656029a066b97f91bea82f6c217a7ac8dce69d08ba50c31760a7c0d0129425b |
Hashes for pycdfpp-0.4.1-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65ebcd8fd3fbda9f3529767ad981872162e6d6d72ea629dcc71aba7051fecf4f |
|
MD5 | 71824d53d4cec219f3a36a36e6d5cfc6 |
|
BLAKE2b-256 | 1203cc7998770b1db01e714de01fae5e408f10b7bb1f489bc912fa4d92b59fc2 |
Hashes for pycdfpp-0.4.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f20133abacd1ece720e98e51dfe16d59b42799b1dfd6d5bfc1b855bfbed07f60 |
|
MD5 | cc9b62613e4bec762f426e039594249e |
|
BLAKE2b-256 | e6dcf637d770b331d7bfcff655e0d2e68018b536e34d861831173fa630b3b0df |
Hashes for pycdfpp-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a75c41dc03ebc3cde0aabee89d6f340418d321adbd752d2b063d550b17b8ae36 |
|
MD5 | cfdaf66711a7e5b39a420110084c869b |
|
BLAKE2b-256 | 8c640cce29a95d9bcf33d021f0edabf29a41ca3b444fa7bef8ad9222caaa70ac |
Hashes for pycdfpp-0.4.1-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f215040ea1147691e34abfb0c769a54588627d0e8aec55961eb9ea0c04195b8 |
|
MD5 | 0703bfd5d0590750f85da7c64a8a16d0 |
|
BLAKE2b-256 | 78fcc1e3524ed678c14035e10b1451e048b5443ffa90c4de7f914d88d28a34d7 |
Hashes for pycdfpp-0.4.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5243f78978825a863203b0acba3802e70f4c44216e1cc69d3346e74d4437dd75 |
|
MD5 | 1f703dda8bd2393e24da6a3b90e5f9a1 |
|
BLAKE2b-256 | aadffaf65f52e7c74ae7c9b2ca7981834ecad35f9aa23f475b0516c33c065817 |
Hashes for pycdfpp-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d8a3a52efd9e61f1c644204f9eb6aaa57394a1c599748d5ccbe8d52d2e3f104 |
|
MD5 | 3767a04dfd056f6a139e49789cb5b657 |
|
BLAKE2b-256 | f6e3e4e9f9a1b1255f67501cc3233300aebff352283e906631ae8be38c885b55 |
Hashes for pycdfpp-0.4.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ed407723c30062fbd335ff533348288265a5b86eef9948467836105e2c230b |
|
MD5 | a9fae6c7ac225aeefb392c7b700f4fb1 |
|
BLAKE2b-256 | b7e031cfcbe4dffa89588ea87eb58cd5b965cbe50c281877c17d2c4311a8a50f |
Hashes for pycdfpp-0.4.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fbd0f6e90dc6fee33ea8fda76e4b079e7a81236aeac4d834b58cabb58b9f889 |
|
MD5 | 3d750fc13d053369739d05ee56a344cc |
|
BLAKE2b-256 | 96b79afc234c6902109873b231f6c58a56e4eaaad417fcc743d6c6d6b85d67d1 |
Hashes for pycdfpp-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbef971fe60ce54286896e8d39e4a88557c40d89a18683675c8729a38e944bed |
|
MD5 | f35ea821cdd86db8302e8d3651cd8811 |
|
BLAKE2b-256 | 425b10ac42ca4d8a4c1e11a8ed915a2f974c541cf612bede3a7b560991855d05 |
Hashes for pycdfpp-0.4.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 081b89a656ef0515cf1b6a2a33d20f985cfb8cc958d286e3bced7f2b12fb8e65 |
|
MD5 | 3bb2a7ee7430806a3d3cd006d64ec813 |
|
BLAKE2b-256 | c142982719c0191cfe943a7692ef3aaa64c3fdeeae442af81c7408dc1fcd880a |
Hashes for pycdfpp-0.4.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ecaf79d5737d27eb2f843fe161edd4fe6a086d76b58e3f5c3e3e7d70e3bd60e |
|
MD5 | df4c2ea037e29395671aeabdf358e765 |
|
BLAKE2b-256 | 4f815ed4014ac179d72b5f81637b8791cd8e4613f8a3753ddef87a4069f8514a |
Hashes for pycdfpp-0.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 578edd3e336de1d16ea81b45bf71d0f7f93d98735c908e93f149c6624ce51485 |
|
MD5 | 584bc4728815e6c4a252001eef0b5579 |
|
BLAKE2b-256 | bdcc58c408507a438f29379b3b1ec5522424bff8735e2895002cd95a2c5c71d5 |
Hashes for pycdfpp-0.4.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33236706b3ddd9a35f7ca77d56624bd4bafeeb30ce0bdb182a6bb15d8ee87532 |
|
MD5 | f0dc35056e5a63ac05844840f3bd602a |
|
BLAKE2b-256 | 0f128b0f43c19e6ad669b1f1d042514e5be634005925fdaa415cf38ed478e822 |