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

380 product aprfc data products #50

Merged
merged 10 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENV PYTHONUNBUFFERED=1
ENV PYTEST_ADDOPTS="--color=yes"

# env var for test data version to use, which should always be the most up to date
ENV TEST_DATA_TAG=2023-11-08
ENV TEST_DATA_TAG=2024-12-13

RUN apt-get update -y \
&& apt-get install -y python3-pip python3-venv curl \
Expand Down
98 changes: 98 additions & 0 deletions src/cumulus_geoproc/processors/aprfc-qte-01h.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
# Alaska Pacific River Forecast Center

## QTE 01 hour total precipitation
"""


import os
import sys
import pyplugs

from cumulus_geoproc import logger
from cumulus_geoproc.utils import cgdal


@pyplugs.register
def process(*, src: str, dst: str = None, acquirable: str = None):
"""
# Grid processor

__Requires keyword only arguments (*)__

Parameters
----------
src : str
path to input file for processing
dst : str, optional
path to temporary directory
acquirable: str, optional
acquirable slug

Returns
-------
List[dict]
```
{
"filetype": str, Matching database acquirable
"file": str, Converted file
"datetime": str, Valid Time, ISO format with timezone
"version": str Reference Time (forecast), ISO format with timezone
}
```
"""

try:
attr = {"GRIB_COMMENT":"Temperature [C]"}
# determine the path and open the file in gdal
ds, src_path, dst_path = cgdal.openfileGDAL(src, dst, GDALAccess="read_only")

# Grad the grid from the band
if (band_number := cgdal.find_band(ds, attr)) is None:
raise Exception("Band number not found for attributes: {attr}")

logger.debug(f"Band number '{band_number}' found for attributes {attr}")

raster = ds.GetRasterBand(band_number)

# Get Datetime from String Like "1599008400 sec UTC"
dt_valid = cgdal.getDate(raster, src_path, "GRIB_VALID_TIME", None, None)

cgdal.gdal_translate_w_options(
tif := os.path.join(
dst, f'{acquirable}.{dt_valid.strftime("%Y%m%d_%H%M")}.tif'
),
ds,
bandList=[band_number],
)

# validate COG
if (validate := cgdal.validate_cog("-q", tif)) == 0:
logger.debug(f"Validate COG = {validate}\t{tif} is a COG")

outfile_list = [
{
"filetype": acquirable,
"file": tif,
"datetime": dt_valid.isoformat(),
"version": None,
},
]

except (RuntimeError, KeyError, Exception) as ex:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback_details = {
"filename": os.path.basename(exc_traceback.tb_frame.f_code.co_filename),
"line number": exc_traceback.tb_lineno,
"method": exc_traceback.tb_frame.f_code.co_name,
"type": exc_type.__name__,
"message": exc_value,
}
for k, v in traceback_details.items():
logger.error(f"{k}: {v}")

finally:
ds = None
raster = None

return outfile_list
7 changes: 7 additions & 0 deletions src/tests/integration/fixtures/test_products.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
"versioned": true,
"name_pattern": "qpf06f_has_96f_%Y%m%d_%H_awips_%Y%m%d%H%M.grb.gz"
},
{
"plugin": "aprfc-qte-01h",
"url": "",
"local_source": "cumulus-geoproc-test-data/fixtures/aprfc-qte-06h/20240731_akurma.t11z.2dvaranl_ndfd_3p0.grb2.gz",
"versioned": false,
"name_pattern": "%Y%m%d_akurma.t%Hz.2dvaranl_ndfd_3p0.grb2"
},
{
"plugin": "cbrfc-mpe",
"url": "",
Expand Down
Loading