Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

607 review request to integrate universal pipeline #611

Merged
merged 18 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/data/data-mappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ data:
buckets:
- ${WIS2BOX_STORAGE_PUBLIC}
file-pattern: '^WIGOS_(\d-\d+-\d+-\w+)_.*\.bufr4$'
chn.babj.data.core.weather.prediction.forecast.shortrange.probabilistic.global.CMA_GEPS:
plugins:
grib2:
- plugin: wis2box.data.universal.UniversalData
notify: true
buckets:
- ${WIS2BOX_STORAGE_INCOMING}
file-pattern: '^.*_(\d{8})\d{2}.*\.grib2$'
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions wis2box-management/wis2box/data/universal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from datetime import datetime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add source code header (see example)

import logging
from pathlib import Path
import re
from typing import Union

from dateutil.parser import parse

from wis2box.data.base import BaseAbstractData

LOGGER = logging.getLogger(__name__)


class UniversalData(BaseAbstractData):
"""Universal data"""

def __init__(self, defs: dict) -> None:
super().__init__(defs)

def transform(self, input_data: Union[Path, bytes],
filename: str = '') -> bool:

filename2 = Path(filename)
LOGGER.debug('Procesing data')
input_bytes = self.as_bytes(input_data)

LOGGER.debug('Deriving datetime')

match = re.search(self.file_filter, filename2.name)
if match:
date_time = match.group(1)
else:
LOGGER.debug('Could not derive date/time: using today\'s date')
date_time = datetime.now()

if date_time:
date_time = parse(date_time)

rmk = filename2.stem
suffix = filename2.suffix.replace('.', '')

self.output_data[rmk] = {
suffix: input_bytes,
'_meta': {
'identifier': rmk,
'relative_filepath': self.get_local_filepath(date_time),
'data_date': date_time
}
}

return True

def get_local_filepath(self, date_):
yyyymmdd = date_.strftime('%Y-%m-%d')
return Path(yyyymmdd) / 'wis' / self.topic_hierarchy.dirpath
Loading