A modern C++ header only cdf library
Project description
Python packages
Linux x86_64 | Windows x86_64 | MacOs x86_64 | MacOs ARM64 |
---|---|---|---|
Unit Tests
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
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.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e34809ece4b9e638bf3f17ac7237b5d4207bd44ab76e6ed82ddd494814209d07 |
|
MD5 | 482394deeb5986db1a6ab25572ea00c7 |
|
BLAKE2b-256 | b242ace77de60e84aa67f514af9ea763db3efca656e88c08d43cd3d1ffe48fd8 |
Hashes for pycdfpp-0.4.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5ff6e1f21d8ad856adaadd3ab8fd76669cbffb4f5fa586d95bec861297ef384 |
|
MD5 | 01a08ce6925ed03dfe9cbc7ca23bab81 |
|
BLAKE2b-256 | 9ed3988b9ac0963e91cb9cbdedb4138ee5e3603a79ba469e17e49c7ffb4a677e |
Hashes for pycdfpp-0.4.5-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d363411241e3e3b49f80bb4a9d74d2fcd7f580a5a6dc826b154e99e71e24f698 |
|
MD5 | 4905c4d2c17adcbe72aeabc93b0e8bd7 |
|
BLAKE2b-256 | 8fef4f899a7a9b12a2eb6817e6077573f58e3b922c97959c0faa6ee068672f39 |
Hashes for pycdfpp-0.4.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6699252b481d418a73a28e6cc0649f42e36968d9c25843b938b99eed2a6d1b24 |
|
MD5 | 31b515945ad173babeec234f0b29e8bd |
|
BLAKE2b-256 | 1ab54c31d161321d228e94b09ee7b01a17656b410be3d0a187d05bbba3604a52 |
Hashes for pycdfpp-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d40f7c7842b96ccb5ab77b7238262c2bc0e477c46a2cb181a86212c07a364a2 |
|
MD5 | 74950b1885c01df0fbe73a37941df872 |
|
BLAKE2b-256 | bcfaa6e94b753648663ce394bdd0c3aaac780dabcf30b5b2bebc301b7712d89c |
Hashes for pycdfpp-0.4.5-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23206c9d8561719d5c3f9ce65d32ab0c24a2e09ebd0d3af063f5e84ef9f8154d |
|
MD5 | 3132b520938d0caecdefeadadebbae4a |
|
BLAKE2b-256 | eb8398e70af65dece9fa92f7448e9238a9c138fa765a6616d3085ef741d550a6 |
Hashes for pycdfpp-0.4.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6050fac5bab5bf9a5960f6efd6f5d38234a8ccb3ebc781f60ca46631401993 |
|
MD5 | 3f3a6be922bfd8f56e57c82764db1dd4 |
|
BLAKE2b-256 | 312705b077d4c41a0950cc3cfc11226eda807e66016ae4b8bb0edbebfc0340d4 |
Hashes for pycdfpp-0.4.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 349cb8cb406a6718330f71cb0fdf7aa6a8ea08066f0a8b2f2deb047d9e31788b |
|
MD5 | 2ca4d1aa2ef315af9e827cdd9dad47cd |
|
BLAKE2b-256 | db4b60d1e487f1cd33e451e9b304cda34c110a625b5374dc1b4ca386668c936e |
Hashes for pycdfpp-0.4.5-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 767e89a05066a83b56c28a655cd62695847cbd2bf1f1c2e88113db8a27b786d1 |
|
MD5 | 6151a0f0aede87f7c16e7c7b447800db |
|
BLAKE2b-256 | e8a5f9d47c4c4bd769f276efc70263545ae5d44aba06e68c16297e80f500186b |
Hashes for pycdfpp-0.4.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fce4321b437d3d81abdeee0eedf652a23b9ee33feb22ddac2819487e173b1177 |
|
MD5 | b02e007c11bff68242336d33c4a1c7fe |
|
BLAKE2b-256 | 243c5f6034ec212d4f220fed4d390260229ae36ff27c4c915ca48a4f03b15c99 |
Hashes for pycdfpp-0.4.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97995ae9819cd8f1b442778c117db79bd059376f8874545c40716f77ba24ceed |
|
MD5 | 6c4fd407610a2365f578ec51de379cdf |
|
BLAKE2b-256 | d0f0bde775e9cf8d3aadf692335416d3e5b11f14c4e8a587f29597684deda98c |
Hashes for pycdfpp-0.4.5-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eab06e6d86f1840b1471b1c4081990aeab309a495cdfb4e4abe9484adf1fd05a |
|
MD5 | 41a39c0e15e22a20388d4b9d5dec8009 |
|
BLAKE2b-256 | fc44321e08892ddc1dddbd8f862e61780f186b4f10ec84ce5e670ce82b11d10c |
Hashes for pycdfpp-0.4.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1013ce0e7f14f2e68a0c886a9a4f178d40fcfb2b240458e9db18393b29d8e113 |
|
MD5 | 2110b01e0687ba4f918fcd645b6fc8fe |
|
BLAKE2b-256 | 7ca238d339fbc647ce5c2b08ebd75630774942b88fde95050f5cb264baf1d3c5 |
Hashes for pycdfpp-0.4.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afe1e78721336820081676e7967776de99cc913f0624ba943dca20fc36212d91 |
|
MD5 | 557bd74396d49600feb74c61cfecf7b8 |
|
BLAKE2b-256 | 61670788f439153ad4c40368513fc7935d8860544cab5c8dd471183485c65887 |
Hashes for pycdfpp-0.4.5-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d42adba861928998565d9ecb0ce7d4a3f2e521b32b78ed0dc1b9965f7764472a |
|
MD5 | 5f0808a17b42a8937571a23dd89fe847 |
|
BLAKE2b-256 | 97cd0f4b02d68c5608edfc524c2b42e164fdbf468089a0e68f68382c3d28e738 |