Skip to content

Commit

Permalink
Small tweaks (#51)
Browse files Browse the repository at this point in the history
* Update tests.yml

* Truncation of station name to 20 chars + updated version no

* Removed redundant Docker image test files

* Added name length check
  • Loading branch information
RoryPTB authored Mar 14, 2024
1 parent 865348a commit 5fedefe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 126 deletions.
68 changes: 0 additions & 68 deletions .github/workflows/dhcr.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/ghcr.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
python3 -m pip install --upgrade pip
pip3 install https://github.com/wmo-im/csv2bufr/archive/master.zip
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.1.zip
pip3 install -r requirements-dev.txt
python3 setup.py install
- name: run tests ⚙️
run: |
Expand Down
22 changes: 20 additions & 2 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pymetdecoder import synop
from csv2bufr import BUFRMessage

__version__ = '0.6.2'
__version__ = '0.7.0_dev'

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -1485,12 +1485,30 @@ def transform(data: str, metadata: str, year: int,
error_msgs = []
continue

def truncate_to_twenty(name: str) -> str:
"""
Ensures the string is no longer than 20 characters,
which is the maximum length allowed for the station name
in the BUFR template.
Args:
name (str): The station or site name.
Returns:
str: This name truncated to 20 characters.
"""
if len(name) <= 20:
return name
LOGGER.info(f"Truncating station name {name} to 20 characters")
return name[:20]

# parse WSI to get sections
try:
wsi_series, wsi_issuer, wsi_issue_number, wsi_local = wsi.split("-") # noqa

# get other required metadata
station_name = metadata_dict[wsi]["station_name"]
station_name = truncate_to_twenty(
metadata_dict[wsi]["station_name"])
latitude = metadata_dict[wsi]["latitude"]
longitude = metadata_dict[wsi]["longitude"]
station_height = metadata_dict[wsi]["elevation"]
Expand Down

0 comments on commit 5fedefe

Please sign in to comment.