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.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6866f3fc9fb54fd847ae34fd6f0a7c4f35acc52f9ef8bb495180b854eb0787ab |
|
MD5 | e9cc7692eacfea3162290c2af26045a6 |
|
BLAKE2b-256 | 19867fe91b7719cd6b2bc699e4551778bffd3273cf5287dba46e6017e117cc56 |
Hashes for pycdfpp-0.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c167fd266dfccce86e083408bd12e4414999a3f3a221a64d82b4ffe32415bef8 |
|
MD5 | e26bb292ae7c94e2906b1539dde2c971 |
|
BLAKE2b-256 | 8a60f6b1ddd8be1e288186c2442c8c7b13bd9c9a5355e4a75f3890e0bd90825e |
Hashes for pycdfpp-0.4.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbd91b0bd90cc78fbe872b54a9a4424038dcea11c72b646977a822141984d298 |
|
MD5 | 3ddf5b544573f1216edf39c2c6ac487d |
|
BLAKE2b-256 | cee88770c1cd5d1b319aa11a73ea4ee53d989412933f30851d551bc4426454a9 |
Hashes for pycdfpp-0.4.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93f195e75b5a6db5757933e74d4e8c9788308bcd7595494fdf3c45bfb9c2bb9e |
|
MD5 | 8ec2525731fd3de4d7931eb0acd5fc35 |
|
BLAKE2b-256 | 4f98df1c0eb97cc5f7a32c225710bf7c8e0cc8a07fd457c732b177b3d27d91ff |
Hashes for pycdfpp-0.4.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce25496a946ff5cb70bcf98ab5bfd0cfcfb882a74ae5488847429d332b64a06c |
|
MD5 | af1539a951e1c1c363077db83be0b976 |
|
BLAKE2b-256 | ce352f21a00d69c2f03afc22c3e9f90dda7fb1ffe5217885284741d7eb5c62cc |
Hashes for pycdfpp-0.4.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15eb75067265df0611cb0421f04399da2b97ebf94d0fccaec3ca3e3eca50f855 |
|
MD5 | b3f1662bf3fad313999704069326c8d6 |
|
BLAKE2b-256 | 18d371e818b991bba510c601922dbc7ed8cc00cfc5d5c8ef95c476cdd2939d66 |
Hashes for pycdfpp-0.4.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c939fb2dd9e058aa06c1f74c5218ff8102e4a829aabb3755d39f53f2fe290c |
|
MD5 | 05f3993e861b571dfec4eddd99fbfe3f |
|
BLAKE2b-256 | ccbd78a1c7ecb9ea28e3db3690eaf8e37481868632a6563e182f0ddef255d5ab |
Hashes for pycdfpp-0.4.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 683b9c17677d4661a4237dcac271ffdef29dd4cef952267b0263ed56df95deff |
|
MD5 | d23e77bf544f9a33d50aab9557ad88ce |
|
BLAKE2b-256 | 45c4627945f8c741ec1a984ba6de5526f658b133e152ab518590dd8e991e69b9 |
Hashes for pycdfpp-0.4.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1252ae37cd9031019a68984fe15f1a5f8cbd22a11f7c02eabece116023025ec |
|
MD5 | 640a3a1c96c68eb7d28959f4ce016518 |
|
BLAKE2b-256 | e67d4ba4bb1f2d42b6ad5a46cc3b03894e117787c4bdff0d9414801dce1852fd |
Hashes for pycdfpp-0.4.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 653853c046a8cb8a297d5899179c4d6c0c701c4c96de86514d9cdfc22d43191c |
|
MD5 | ab1c4bb4cb415eaba79048c7bb6a1d89 |
|
BLAKE2b-256 | 07228f9cac435687af081d20d650444dc435b80294364417227945fa84ec7842 |