Skip to main content

SuperDARN DMAP file format I/O

Project description

A library for SuperDARN DMAP file I/O

github

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:

  1. Clone the repository: git clone https://github.com/SuperDARNCanada/dmap
  2. Create a virtual environment and source it, then install maturin
  3. In the project directory, run maturin develop to 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, and
  • read_dmap.

The supported writing functions are:

  • write_iqdat,
  • write_rawacf,
  • write_fitacf,
  • write_grid,
  • write_map,
  • write_snd, and
  • write_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

darn_dmap-0.6.0.tar.gz (39.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

darn_dmap-0.6.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (708.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ s390x

darn_dmap-0.6.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (711.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ s390x

darn_dmap-0.6.0-cp38-abi3-win_amd64.whl (598.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

darn_dmap-0.6.0-cp38-abi3-win32.whl (538.7 kB view details)

Uploaded CPython 3.8+Windows x86

darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_x86_64.whl (873.5 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_i686.whl (894.0 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ i686

darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_armv7l.whl (918.6 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARMv7l

darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_aarch64.whl (831.9 kB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (713.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (710.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (765.5 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (651.9 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (663.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

darn_dmap-0.6.0-cp38-abi3-macosx_11_0_arm64.whl (590.9 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

darn_dmap-0.6.0-cp38-abi3-macosx_10_12_x86_64.whl (623.0 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file darn_dmap-0.6.0.tar.gz.

File metadata

  • Download URL: darn_dmap-0.6.0.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for darn_dmap-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d2efa2bc3315ab71fd04d42b049b9d76aa33f56e5640a9eaa017280089616395
MD5 a2d94c48ce5badf4b2fe5749163996b6
BLAKE2b-256 7ccf1b89bfabbac9b624d0df61bd28a6aa6324389b786a0fc7d4e115b60f057d

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 0b4a709e9f78f77f11f997a41ef21e757be4248783d4107b5192ce8768e15f2a
MD5 3986a971371bbd3c80318b0869943880
BLAKE2b-256 cbf7c00fc9555d183b3929d784f2d44be046d0f2a8b4d6c3731226efded0a2f7

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 4e843fa5e33ec9fbaefb1a01709d1802b0398660ea4c2315b7c84306a6774582
MD5 a47b872d2dc8ad80ca14dfcc9230d4e6
BLAKE2b-256 3a99bf0cfe3f67cf2ab68d96bfe22beae71226d9287f2b9063b35cdd0ecbf3cc

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: darn_dmap-0.6.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 598.0 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cd0562a984fb67cdb5fa4f1d7c16ff55f451ccda729687a17922a604a8afd626
MD5 effd4c9ef55244f5b5f7fd0a0a221a62
BLAKE2b-256 16c01ddfb9785857caa505b05d1fe026e8c526f68901c62d861c7c1d999d88c3

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-win32.whl.

File metadata

  • Download URL: darn_dmap-0.6.0-cp38-abi3-win32.whl
  • Upload date:
  • Size: 538.7 kB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 8b4488fdaa51beaa0291986827e36711e27a344c04e10b7a4f506daf95c781aa
MD5 5104fba8fe1acf7a1b090ec5fb652d48
BLAKE2b-256 260d46686ee928a84187ec8356124c8524978488f7b9ce8a1e9f7ba3cf0d7f98

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cf68e361b38b1a9bddb02f8bb0e2009b0f4164a16c7e5994d6f6c31a3cf0ef7b
MD5 6eb3c6b14ddd27f98fadd9fb95f180e3
BLAKE2b-256 7be81249ee33574e8d0dda731a14299b91bbeceb634652b033487608caa4c907

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d6119ba08350eafb698276d2ddd197b60560faf91b48beaf62c93265e3e74e79
MD5 01eae7d775ba9aa505af8e01383b9ffa
BLAKE2b-256 41f94914024820b3ac271c82ac46df94d3a08e17125ab0c0ed1b940e19433c8b

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 7dc1d00094c73a0ba5d1878f7a14a2dc8354f3ee7a9b7c5918d20684c3a3f833
MD5 04ed4629b13a55005b8e9058f2ec409a
BLAKE2b-256 808e1381ac627c6380c8ea1ae61635f643c255b35b6b02e42f58916ca964ec21

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0251afea55a280a7234b5109e9aa1404cf00853734e0b2dd8f30e4aacd895689
MD5 d9bfa34b1625298648bd373bd12f295d
BLAKE2b-256 f2373eefe47de990619604bb5dd3b836ba63d596224c202c2db1820eb73ed749

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 61cbb0425bade97a29b6c390182cf8356803bd8f2cd44a6f4124e784347ef237
MD5 6370761b91a8580de5389873f2250f37
BLAKE2b-256 1709a25e8958b03b5c0529c386c46770e2a97d9b8bd124dee2c7cba36f7a3a9c

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 21c68ea243c76d4036005d350afd311bd715b2be9b31522a2522c9c2e7892557
MD5 ec9bd6fc2d7f1f02141932d31d44f6a5
BLAKE2b-256 c8964ad55aff5c819dc6b8984063368f879f58ab78edf991d0625058bef4c1a0

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7ebf0fd5c5c68ac973ea7695c169ce238a78bb0f6c4e2a49f4d211e5af3eba85
MD5 8b3bf316577ebd9660bce4d93507dda5
BLAKE2b-256 c8626e5905cd464d3c22c0ed30aee284e01c2dd65b8299e57d59b206738bfa22

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 e4cb018c180d1ed3580e289eab381dbab2e5860871bac2e17bffbf2daa4a35a3
MD5 ed824aea2c13aaa04a587cc718adb492
BLAKE2b-256 4f49fa947fd5fe7ee18d3b0ac9aea76f4ca020576ca102bf6c9c6c701fa187d7

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 aa15194f6633bbf9b9bdebddff12c6c463d9cedafb77c1d1c9302c22cb9fb90c
MD5 307021c6aa025b6ee231f1994b1e2fbf
BLAKE2b-256 db957f41136351c6bd207dfea6aa0d0cda3108974450f6e65683431be38af8ba

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0398f81aa41f982f0126d30a4035163f4c6e87f638765031118e106a6aba8896
MD5 d5f696ba017bea8218fdce42baeb2ac8
BLAKE2b-256 62a06bca56688156b8a124cc02887f749d8b659446a8c1da18040101cf7a0a91

See more details on using hashes here.

File details

Details for the file darn_dmap-0.6.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for darn_dmap-0.6.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cc12c296b4d25d0b3b8b1ab0b6b0bde0dc7f152fd181ef1db74f34ef81b5e708
MD5 28b0347703e9e1a86bb90b6a8fa80c23
BLAKE2b-256 0017ec61a6f02357aa5ccb2b09c0f0d14d0e8eab7ec495160e11e098f793d165

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page