All Projects → ywangd → pybufrkit

ywangd / pybufrkit

Licence: MIT license
Pure Python toolkit to work with WMO BUFR messages

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pybufrkit

A
A graphical text editor
Stars: ✭ 280 (+374.58%)
Mutual labels:  pure
Dive into haskell
Dive into Haskell: Examples of all features of this Pure Functional programing language
Stars: ✭ 64 (+8.47%)
Mutual labels:  pure
Vanilla Back To Top
Simple and smooth Back To Top button
Stars: ✭ 179 (+203.39%)
Mutual labels:  pure
Pure
A set of small, responsive CSS modules that you can use in every web project.
Stars: ✭ 22,090 (+37340.68%)
Mutual labels:  pure
Blink Java
Simplified pure Java http server
Stars: ✭ 10 (-83.05%)
Mutual labels:  pure
Awa Ssh
Purely functional SSH library in ocaml.
Stars: ✭ 80 (+35.59%)
Mutual labels:  pure
indent.js
Pure code indentation for jsx, tsx, ts, js, html, css, less, scss.
Stars: ✭ 55 (-6.78%)
Mutual labels:  pure
freedsl
Practical effect composition library based on abstract wrapping type and the free monad
Stars: ✭ 37 (-37.29%)
Mutual labels:  pure
Icmplib
Easily forge ICMP packets and make your own ping and traceroute.
Stars: ✭ 58 (-1.69%)
Mutual labels:  pure
Pure
♾ PTS: Pure Type System for Erlang
Stars: ✭ 135 (+128.81%)
Mutual labels:  pure
Turbine
Purely functional frontend framework for building web applications
Stars: ✭ 651 (+1003.39%)
Mutual labels:  pure
Anybar.nim
Nim client for Anybar
Stars: ✭ 5 (-91.53%)
Mutual labels:  pure
Pure
Pretty, minimal and fast ZSH prompt
Stars: ✭ 10,891 (+18359.32%)
Mutual labels:  pure
Aecor
Pure functional event sourcing runtime
Stars: ✭ 299 (+406.78%)
Mutual labels:  pure
Webgradients
A curated collection of splendid gradients made in CSS3, .sketch and .PSD formats.
Stars: ✭ 2,197 (+3623.73%)
Mutual labels:  pure
tweakflow
Safe embeddable scripting for the JVM
Stars: ✭ 21 (-64.41%)
Mutual labels:  pure
Ui Challenges
UI challenges by Semicolon, we accept challenges on twitter on #SemicolonChallenge
Stars: ✭ 69 (+16.95%)
Mutual labels:  pure
pure
🌱 elegant and lovely components
Stars: ✭ 27 (-54.24%)
Mutual labels:  pure
Vps
A handy bash script to setup crypto masternodes in no time. Initially developed for $PIVX. Now many more ;-)
Stars: ✭ 220 (+272.88%)
Mutual labels:  pure
Purewebappsample
Minimal http4s + Doobie + ZIO + Circe Scala application to show how to build a purely functional web application in Scala.
Stars: ✭ 123 (+108.47%)
Mutual labels:  pure

Python Toolkit for WMO BUFR Messages

https://travis-ci.org/ywangd/pybufrkit.svg?branch=master

PyBufrKit is a pure Python package to work with WMO BUFR (FM-94) messages. It can be used as both a command line tool or library to decode and encode BUFR messages. Here is a brief list of some of the features:

  • Pure Python
  • Handles both compressed and un-compressed messages
  • Handles all practical operator descriptors, including data quality info, stats, bitmaps, etc.
  • Option to construct hierarchial structure of a message, e.g. associate first order stats data to their owners.
  • Convenient subsetting support for BUFR messages
  • Comprehensive query support for BUFR messages
  • Script support enables flexible extensions, e.g. filtering through large number of files.
  • Tested with the same set of BUFR files used by ecCodes and BUFRDC.

More documentation at http://pybufrkit.readthedocs.io/

An online BUFR decoder powered by PyBufrKit, Serverless and AWS Lambda.

Installation

PyBufrKit is compatible with Python 2.7, 3.5+, and PyPy. To install from PyPi:

pip install pybufrkit

Or from source:

python setup.py install

Command Line Usage

The command line usage of the toolkit takes the following form:

pybufrkit [OPTIONS] command ...

where the command is one of following actions that can be performed by the tool:

  • decode - Decode a BUFR file to outputs of various format, e.g. JSON
  • encode - Encode a BUFR file from a JSON input
  • info - Decode only the metadata sections (i.e. section 0, 1, 2, 3) of given BUFR files
  • split - Split given BUFR files into one message per file
  • subset - Subset the given BUFR file and save as new file
  • query - Query metadata or data of given BUFR files
  • script - Embed BUFR query expressions into normal Python script
  • lookup - Look up information about the given list of comma separated BUFR descriptors
  • compile - Compile the given comma separated BUFR descriptors

Here are a few examples using the tool from command line. For more details, please refer to the help option, e.g. pybufrkit decode -h. Also checkout the documentation.

# Decode a BUFR file and output in the default flat text format
pybufrkit decode BUFR_FILE

# Decode a file that is a concatenation of multiple BUFR messages,
# skipping any erroneous messages and continue on next one
pybufrkit decode -m --continue-on-error FILE

# Filter through a multi-message file and only decode messages
# that have data_category equals to 2. See below for details
# about usable filter expressions.
pybufrkit decode -m --filter '${%data_category} == 2' FILE

# Decode a BUFR file and display it in a hierarchical structure
# corresponding to the BUFR Descriptors. In addition, the attribute
# descriptors are associated to their (bitmap) corresponding descriptors.
pybufrkit decode -a BUFR_FILE

# Decode a BUFR file and output in the flat JSON format
pybufrkit decode -j BUFR_FILE

# Encode from a flat JSON file to BUFR
pybufrkit encode -j JSON_FILE BUFR_FILE

# Decode a BUFR file, pipe it to the encoder to encode it back to BUFR
pybufrkit decode BUFR_FILE | pybufrkit encode -

# Decode only the metadata sections of a BUFR file
pybufrkit info BUFR_FILE

# Split a BUFR file into one message per file
pybufrkit split BUFR_FILE

# Subset from a given BUFR file
pybufrkit subset 0,3,6,9 BUFR_FILE

# Query values from the metadata sections (section 0, 1, 2, 3):
pybufrkit query %n_subsets BUFR_FILE

# Query all values for descriptor 001002 of the data section
pybufrkit query 001002 BUFR_FILE

# Query for those root level 001002 of the BUFR Template
pybufrkit query /001002 BUFR_FILE

# Query for 001002 that is a direct child of 301001
pybufrkit query /301001/001002 BUFR_FILE

# Query for all 001002 of the first subset
pybufrkit query '@[0] > 001002' BUFR_FILE

# Query for associated field of 021062
pybufrkit query 021062.A21062 BUFR_FILE

# Filtering through a number of BUFR files with Script support
# (find files that have multiple subsets):
pybufrkit script 'if ${%n_subsets} > 1: print(PBK_FILENAME)' DIRECTORY/*.bufr

# Lookup information for a Element Descriptor (along with its code table)
pybufrkit lookup -l 020003

# Compile a BUFR Template composed as a comma separated list of descriptors
pybufrkit compile 309052,205060

Library Usage

The following code shows an example of basic library usage

# Decode a BUFR file
from pybufrkit.decoder import Decoder
decoder = Decoder()
with open(SOME_BUFR_FILE, 'rb') as ins:
    bufr_message = decoder.process(ins.read())

# Convert the BUFR message to JSON
from pybufrkit.renderer import FlatJsonRenderer
json_data = FlatJsonRenderer().render(bufr_message)

# Encode the JSON back to BUFR file
from pybufrkit.encoder import Encoder
encoder = Encoder()
bufr_message_new = encoder.process(json_data)
with open(BUFR_OUTPUT_FILE, 'wb') as outs:
    outs.write(bufr_message_new.serialized_bytes)

# Decode for multiple messages from a single file
from pybufrkit.decoder import generate_bufr_message
with open(SOME_FILE, 'rb') as ins:
    for bufr_message in generate_bufr_message(decoder, ins.read()):
        pass  # do something with the decoded message object

# Query the metadata
from pybufrkit.mdquery import MetadataExprParser, MetadataQuerent
n_subsets = MetadataQuerent(MetadataExprParser()).query(bufr_message, '%n_subsets')

# Query the data
from pybufrkit.dataquery import NodePathParser, DataQuerent
query_result = DataQuerent(NodePathParser()).query(bufr_message, '001002')

# Script
from pybufrkit.script import ScriptRunner
# NOTE: must use the function version of print (Python 3), NOT the statement version
code = """print('Multiple' if ${%n_subsets} > 1 else 'Single')"""
runner = ScriptRunner(code)
runner.run(bufr_message)

For more help, please check the documentation site at http://pybufrkit.readthedocs.io/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].