SuperDARN DMAP file format I/O
Project description
A library for SuperDARN DMAP file I/O
The SuperDARN DMAP file formats are all supported (IQDAT, RAWACF, FITACF, GRID, MAP, and SND) as well as a generic DMAP format that is unaware of any required fields or types (e.g. char, int32) for any fields. For more information on DMAP please see RST Documentation.
Installation
Package manager
This package is registered on PyPI as darn-dmap, you can install the package with your package manager, e.g. pip install darn-dmap.
From source
If you want to build from source, you first need to have Rust installed on your machine. Then:
- Clone the repository:
git clone https://github.com/SuperDARNCanada/dmap - Create a virtual environment and source it, then install
maturin - In the project directory, run
maturin developto build and install the Python bindings. This will make a wheel file based on your operating system and architecture that you can install directly on any compatible machine.
Usage
The basics
The basic code to read and write a DMAP file is:
import dmap
file = "path/to/rawacf_file"
data, _ = dmap.read_rawacf(file) # returns `tuple[list[dict], Optional[int]]`
outfile = "path/to/outfile.rawacf"
dmap.write_rawacf(data, outfile) # writes binary data to `outfile`
raw_bytes = dmap.write_rawacf(data) # returns a `bytes` object
dmap.read_rawacf(...) reads the file into a list of dictionaries, returning the list as well as the byte where any corrupted records start.
The supported reading functions are:
read_iqdat,read_rawacf,read_fitacf,read_grid,read_map,read_snd, andread_dmap.
The supported writing functions are:
write_iqdat,write_rawacf,write_fitacf,write_grid,write_map,write_snd, andwrite_dmap.
Accessing data fields
To see the names of the variables you've loaded in and now have access to, try using the keys() method:
print(data[0].keys())
which will tell you all the variables in the first (zeroth) record.
Let's say you loaded in a MAP file, and wanted to grab the cross polar-cap potentials for each record:
import dmap
file = "20150302.n.map"
map_data, _ = dmap.read_map(file)
cpcps=[rec['pot.drop'] for rec in map_data]
I/O on a bz2 compressed file
dmap will handle compressing and decompressing .bz2 files seamlessly, detecting the compression automatically. E.g.
import dmap
fitacf_file = "path/to/file.bz2"
data, _ = dmap.read_fitacf(fitacf_file)
dmap.write_fitacf(data, "temp.fitacf.bz2")
will read in the compressed file, then also write out a new compressed file. Note that compression on the writing side will only be done when writing to file, as the detection is done based on the file extension of the output file.
Generic I/O
dmap supports generic DMAP I/O, without verifying the field names and types. The file must still be properly formatted as a DMAP file, but otherwise no checks are conducted.
NOTE: When using the generic writing function write_dmap, scalar fields will possibly be resized; e.g., the stid
field may be stored as an 8-bit integer, as opposed to a 16-bit integer as usual. As such, reading with a specific method
(e.g. read_fitacf) on a file written using write_dmap will likely not pass the FITACF format checks.
import dmap
generic_file = "path/to/file" # can be iqdat, rawacf, fitacf, grid, map, snd, and optionally .bz2 compressed
data, _ = dmap.read_dmap(generic_file)
dmap.write_dmap(data, "temp.generic.fitacf") # fitacf as an example
data2, bad_byte = dmap.read_rawacf("temp.generic.fitacf") # This will fail due to different types for scalar fields
assert bad_byte == 0 # The first record should be corrupted, i.e. not be a valid FITACF record
assert len(data2) == 0 # No valid records encountered
Handling corrupted data files
The self-describing data format of DMAP files makes it susceptible to corruption. The metadata fields which describe
how to interpret the following bytes are very important, and so any corruption will lead to the remainder of the file being
effectively useless. dmap is able to handle corruption in two ways. The keyword argument mode of the read_rawacf, etc.
functions allows you to choose how to handle corrupt records.
In "lax" mode (the default), no error is raised if a corrupt file is read, and the byte where the corrupted records start is
returned along with the non-corrupted records.
In "strict" mode, the I/O functions will raise an error if a corrupted record is encountered.
import dmap
corrupted_file = "path/to/file"
data, bad_byte = dmap.read_dmap(corrupted_file, mode="lax")
assert bad_byte > 0
good_file = "path/to/file"
data, bad_byte = dmap.read_dmap(good_file, mode="lax")
assert bad_byte is None
In both uses of the above example, data will be a list of all records extracted from the file, but may be
considerably smaller than the file.
import dmap
corrupted_file = "path/to/file"
try:
data = dmap.read_dmap(corrupted_file, mode="strict")
had_error = False
except:
had_error = True
assert had_error
good_file = "path/to/file"
try:
data = dmap.read_dmap(good_file, mode="strict")
had_error = False
except:
had_error = True
assert had_error is False
Stream I/O
dmap also can conduct read/write operations from/to Python bytes objects directly. These bytes must be formatted in
accordance with the DMAP format. Simply pass in a bytes object to any of the read_[type] functions instead of a path
and the input will be parsed.
While not the recommended way to read data from a DMAP file, the following example shows the use of these byte I/O functions:
import dmap
file = "path/to/file.fitacf"
with open(file, 'rb') as f: # 'rb' specifies to open the binary (b) file as read-only (r)
raw_bytes = f.read() # reads the file in its entirety
data, _ = dmap.read_dmap(raw_bytes)
binary_data = dmap.write_fitacf(data)
assert binary_data == raw_bytes
As a note, this binary data can be compressed ~2x typically using zlib, or with another compression utility. This is quite
useful if sending data over a network where speed and bandwidth must be considered. Note that the binary writing functions
don't compress automatically, an external package like zlib or bzip2 must be used.
File "sniffing"
If you only want to inspect a file, without actually needing access to all of the data, you can use the read_[type]
functions in "sniff" mode. This will only read in the first record from a file, and works on both compressed and
non-compressed files. Note that this mode does not work with bytes objects directly.
import dmap
path = "path/to/file"
first_rec = dmap.read_dmap(path, mode="sniff")
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file darn_dmap-0.5.0.tar.gz.
File metadata
- Download URL: darn_dmap-0.5.0.tar.gz
- Upload date:
- Size: 465.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
302cc6b8919bf9d9d3aed222976f5013e3482469e3dbb3b7043989ccaa110bff
|
|
| MD5 |
72104b45b597be9cd79b5154cd7c75e6
|
|
| BLAKE2b-256 |
7c1d0f9d823b6f54b210e90ebfd1d2e87bb70a25825ad1fdafba80f7d2b9c2f9
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 541.4 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5101a36c7f764c3aa7b702dede34c0ddfd309b1ed09b79209eafc0fe7180a76
|
|
| MD5 |
cb178cff89e4625f93035424555e1616
|
|
| BLAKE2b-256 |
3e3bb5ec205efb860ca6239f769f9773882cb3ba412619edc0876b3ef84569fe
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-win32.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-win32.whl
- Upload date:
- Size: 491.5 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d0c34493170c8804061181e157ae08a3b8922c8ff66b810c917615385ccdb4
|
|
| MD5 |
813ee404cc9868ede06854011913c24a
|
|
| BLAKE2b-256 |
fdceefdf992ceb2f9e70b796854373f19d7041943b09eaac5fb9e37ee46e4ef6
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 826.0 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51cc5aef58852f55843a90bc5f01cb89544c2c83444df5b1385977b35e2aa904
|
|
| MD5 |
51c9adf747dd662298c2fa19b84f6a96
|
|
| BLAKE2b-256 |
acb252ca3a0cc3f2e2274789ac4b8c021c707089e7109de405c2fbb2268126cc
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_i686.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 846.3 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b218209022d5cea2001402e459a0bcc37b25053d2f20de8764754c9d6ff74aa5
|
|
| MD5 |
462e5bad7f7a37d3834c737fe2fcf97f
|
|
| BLAKE2b-256 |
64189e538a3f80ec238d452be09c11f4a9e5ed5886e0f21944cf0ff8df39b3f0
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_armv7l.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 868.5 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23f86dc5b3e4611323e95f571128bf386ceed8c1f7a6ec18341c570ea3bb5647
|
|
| MD5 |
61d6ef8948c1c815c8ca3a3f9787dd88
|
|
| BLAKE2b-256 |
82d97097914a5ccbfb022553f21dd804b20c8ad9b7e608991c884175a78ea3da
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 782.4 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a4cdb4745e7fd3de427d4be10f79c7437d2920f190630a72a6fb49bb78f99e0
|
|
| MD5 |
d2f387c26a8e7c7ffb044199505b70a5
|
|
| BLAKE2b-256 |
eb48d83afab29355435f8d4e73d2a8a362d1da0c56a88096c2dfff1b6d35cf4c
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 669.5 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8253383df9346cc9758b0ed7fca30b30e12da1f8c38898614acac8e93f165d17
|
|
| MD5 |
4a775a4c248a9a7dee2d9de44dbbea00
|
|
| BLAKE2b-256 |
7b6df735576d237dd4863920f19c46a23942ef442c9b870af92bc56bf712060e
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 672.1 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b33b4d93230e4c763ea15896a2c151b718ea8aee858be5857e39ea66fed093df
|
|
| MD5 |
db228cee8e4f9ee9b707746445628ff6
|
|
| BLAKE2b-256 |
094c56a29c0e17567749b9739a47fd8ea9c24c49cc71f4a1fcfba7374a63d9d9
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 713.0 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10c4fd522bd85dadab2fdb8fff8af4e1f928a51a1e01775e2f5fb540ca25a9f9
|
|
| MD5 |
4ff7f1d95219721218ad61b8a01581e7
|
|
| BLAKE2b-256 |
609978c630bac12d57cd9aff511791df14c3f2fa3e2abf17f802eee6a4196df2
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 600.4 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abfe1f45061b4c637e2c56155d1f5694c1cdecc72c6a5dba6cbd685e7a805c96
|
|
| MD5 |
95dfc723213fff008290e83bb3ce1c77
|
|
| BLAKE2b-256 |
3bc2a048824c08f9c59eba0f5e7fc515bbfb33c0753bd4645ab69d4d03ee58ed
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 611.8 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e00559b7b0b05d9a3a3f547e4f2ba2647e6153f51b4accfc0f7db13bc4a3d711
|
|
| MD5 |
871d06bdef5fe257ff323c5777ee168d
|
|
| BLAKE2b-256 |
1cfc9ff14601f9357706df81271d37b875f5f6cda6a92dfa048db600ff7a6a39
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 542.6 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e70e0dc7634c3ed6b18d2d70beb7f6d39c9df5b8141276c49115dd069a0dbe4
|
|
| MD5 |
49d7630a4e7e0ef991e69448c7de4632
|
|
| BLAKE2b-256 |
ef36b09f2951fc2c62e50a97b608238cfb022e324f42fde78425ee423852d0e9
|
File details
Details for the file darn_dmap-0.5.0-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: darn_dmap-0.5.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 586.5 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
388c52ce4ccedcda6b6f0e845951f85dc61e95b5610bac412a8fa8612ea72de2
|
|
| MD5 |
e5d4b4e9dab28619f90a7a31a1f27fc2
|
|
| BLAKE2b-256 |
19f279ef80ec5da2a2af35124b6051e9b5a960d6bd3dc0af4eff638a4598ceea
|