Skip to content

Commit

Permalink
Truncation of station name to 20 chars + updated version no
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Mar 14, 2024
1 parent 3270c80 commit cd8ede6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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.11.zip
pip3 install -r requirements-dev.txt
python3 setup.py install
- name: run tests ⚙️
run: |
Expand Down
19 changes: 17 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 @@ -1484,13 +1484,28 @@ def transform(data: str, metadata: str, year: int,
warning_msgs = []
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.
"""
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 cd8ede6

Please sign in to comment.