No project description provided
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 Distributions
Built Distributions
Hashes for pycdfpp-0.3.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2589ec8beaf8e56cb43c423e1d7a6072468cf9c6ad41cca4a3f94215b11980 |
|
MD5 | 6d6cb9472497f9e5a044a2e3c0062a87 |
|
BLAKE2b-256 | d42b90fd6781dcdea93be2f43b973f4a267bda4f3925bd412e8ba02afdc969e0 |
Hashes for pycdfpp-0.3.2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef48b5c11bcf0cac05bfe6cca4cafbb19389b34ece81c039262d682e960def6f |
|
MD5 | 250f06bfdaecd5d15b9a93099b897864 |
|
BLAKE2b-256 | 7731102624aa1fe2921a5dabcfd798253bddfa58d3a0594a5c52e0fae970e786 |
Hashes for pycdfpp-0.3.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 420872b8ba5d0ae6821fa2bd52481a0d28d04645c7b26dd7452d6d899e02b259 |
|
MD5 | e0cc9f98b7b1b715dfeb302c3dcf9049 |
|
BLAKE2b-256 | c429f3162f3a552822b7955cc1e6daf6fa11dd978ece4dc4b20dcf16845428c2 |
Hashes for pycdfpp-0.3.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 362e5c89fed340782eb32f1e1e67d1351fd23856de55d87612e38d75ef199e3d |
|
MD5 | c2b0ef125d394d0591ec6ff846df890b |
|
BLAKE2b-256 | f2bbb81fb035e7b1d2a4697e9331999e4cfe23fe837d1941403abc438b747abf |
Hashes for pycdfpp-0.3.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a124b131c406024d79adff29a8c49d6d7ce7d6994d7059056acc1d1fe0688f84 |
|
MD5 | aa81c16f110e52b65f62b86b18872349 |
|
BLAKE2b-256 | 06776765a7dd4eb51fa604771e3329bb523e36897eb30407228ec065794b5e63 |
Hashes for pycdfpp-0.3.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9303bdadda44b9b81bf266bc168dab0f2cc048c212f020e5e19ce11555724be |
|
MD5 | 75dfb6bfc0624f40b5995b8b1ae18b9f |
|
BLAKE2b-256 | 9ec5fb736ebc4a38a71f7e631474bb8805005e4b34d085f9506f031aaefde7d6 |
Hashes for pycdfpp-0.3.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54fd6259e74d56a6da17ebb740e37ff3e457fdfae5a9d712f5bdde510e94105f |
|
MD5 | ea04a6c610d3021a177cd08f7e9af98b |
|
BLAKE2b-256 | db4d8a8f32baf8b24cc6303f8a4f423108309dfa4f29fb9ba9e2104b5aaf2acf |
Hashes for pycdfpp-0.3.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02ad06649722786753b013c33b93744a8fca721c25e1de85c4b354db74dd3f44 |
|
MD5 | fbd6ad73e32b98fe2aa3c9f278b0f29a |
|
BLAKE2b-256 | a0a18ddf32c39dac95ab595eea43a2597c60f99c7b3fc21240659fbadb63637e |