Skip to main content

Module to extract data from SHEF formated files with ability to save output as flat file, HEC-DSS file, or directly into Corps water management systems (CWMS) database

Project description

Package SHEF Parser

A python based package to parse SHEF files and optionally load them into various data stores. It also provides functionality for generating SHEF text from various data stores.

Parsing and loading can be performed by using module in python or through command line. Generating SHEF text from a data store is currenly limited to using the module in python.

See User Guide at https://shef-processing.readthedocs.io/en/latest/

See API Documentation at https://hydrologicengineeringcenter.github.io/shef-parser/index.html

Install

pip install shef-parser

Loading via command line

#CWMS CDA loader
shefParser -i input_filename --loader cda[$API_ROOT][$API_KEY]
#HEC-DSS loader
shefParser -i input_filename --loader dss[<dss_file>][<sensors_file>][<parameters_file>]

Loading via module

#CWMS CDA loader
import os
from shef import shef_parser

cda_url: str = os.getenv("CDA_API_ROOT")
cda_api_key: str = os.getenv("CDA_API_KEY")

shef_parser.parse(
    input_name=input_filename,
    loader_spec=f"cda[{cda_url}][{cda_api_key}]",
)
#HEC-DSS loader
from shef import shef_parser

dss_filename: str = "/path/to/dss_file"
sensors_filename: str = "/path/to/sensors_file"
parameters_filename: str = "/path/to/parameters_file"

shef_parser.parse(
    input_name=input_filename,
    loader_spec=f"dss[{dss_filename}][{sensors_filename}][{parameters_filename}]",
)

Generating SHEF Text

#CWMS CDA loader
import os
from datetime import datetime, timedelta
from shef.exporters import cda_exporter

cda_url: str = os.getenv("CDA_API_ROOT")
office_id: str = os.getenv("CDA_OFFICE_ID")
tsids: list[str] = [
    ...
]

exporter = cda_exporter.CdaExporter(cda_url, office_id)
exporter.start_time = datetime.now() - timedelta(days=1)
exporter.end_time = datetime.now()
with open("/path/to/output_file", "w") as f:
    exporter.set_output(f)
    for (tsid in tsids):
        exporter.export(tsid)
#HEC-DSS loader
from datetime import datetime, timedelta
from shef.exporters import dss_exporter

dss_filename: str = "/path_to_dss_file"
sensors_filename: str = "/path/to/sensors_file"
parameters_filename: str = "/path/to/parameters_file"
pathnames: list[str] = [
    ...
]

exporter = dss_exporter.DssExporter(
    dss_filename,
    sensors_filename,
    parameters_filename
)
exporter.start_time = datetime.now() - timedelta(days=1)
exporter.end_time = datetime.now()
with open("/path/to/output_file", "w") as f:
    exporter.set_output(f)
    for (pathname in pathnames):
        exporter.export(pathname)

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

shef_parser-1.6.1.tar.gz (72.6 kB view details)

Uploaded Source

Built Distribution

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

shef_parser-1.6.1-py3-none-any.whl (80.2 kB view details)

Uploaded Python 3

File details

Details for the file shef_parser-1.6.1.tar.gz.

File metadata

  • Download URL: shef_parser-1.6.1.tar.gz
  • Upload date:
  • Size: 72.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shef_parser-1.6.1.tar.gz
Algorithm Hash digest
SHA256 b5fa96620c314a0d59855c73dce362f1a0296f1ce7d48c166c4fad36a9eedeba
MD5 22eae7d59a8d65b162cb6b4bdc579f4a
BLAKE2b-256 47d634c87aad7f0f4b71a565f475a697705274829e67c2820d9581b5871dafbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for shef_parser-1.6.1.tar.gz:

Publisher: pypi-deploy.yml on HydrologicEngineeringCenter/SHEF_processing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shef_parser-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: shef_parser-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 80.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shef_parser-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80488fd4ab34c4354331cd0643c851639364a15367d51bdc1ff3ed9e30e2598a
MD5 67a18c046a90a9bf4cdf049544f22e74
BLAKE2b-256 085ec65d85d5c1f752590f494e439b2f2645a768ca235e65c9b51e992cc518d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for shef_parser-1.6.1-py3-none-any.whl:

Publisher: pypi-deploy.yml on HydrologicEngineeringCenter/SHEF_processing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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