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

Redeveloped MRF 10-day SWE Change Forecast service #787

Open
wants to merge 11 commits into
base: ti
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
sys.path.append("../utils")
from lambda_function import create_raster, upload_raster, open_raster

def main(product_name, data_bucket, input_files, reference_time, output_bucket, output_workspace):
reversed_input_files = sorted(input_files, reverse=True)

print(reversed_input_files)

### 10-DAY SNOW WATER EQUIVALENT CHANGE
all_uploaded_rasters = []

variable = "SNEQV"
days = [1, 2, 3] # defining loop for input files
change = {1:3,2:5,3:10} # defining dictionary for naming purposes
swe_present, crs = open_raster(data_bucket, reversed_input_files[0], variable)
swe_present = swe_present.sel(time = swe_present.time[0])
for day in days:

swe_past, crs = open_raster(data_bucket, reversed_input_files[day], variable)
# get the land files from past 10 days in reverse order
swe_past = swe_past.sel(time = swe_past.time[0])
swe_present_nan = swe_present.where(swe_present != -99990)
swe_present_nan = swe_present_nan / 254 # convert kg/m2 to inches, should be 25.4
# but there's an extra order of mag
swe_past_nan = swe_past.where(swe_past != -99990)
swe_past_nan = swe_past_nan /254 #convert kg/m2 to inches

swe_difference = swe_present_nan - swe_past_nan
data = swe_difference.round(2)

print("Creating raster...")
local_raster = create_raster(data, crs, f"mrf_gfs_{change[day]}day_snow_water_equivalent_change")

print(f"Uploading raster to {output_bucket}/{output_workspace}...")
uploaded_raster = upload_raster(local_raster, output_bucket, output_workspace)
all_uploaded_rasters.append(uploaded_raster)

return all_uploaded_rasters
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DROP TABLE IF EXISTS publish.mrf_gfs_10day_snow_water_equivalent_change;
CREATE TABLE publish.mrf_gfs_10day_snow_water_equivalent_change (
reference_time TEXT,
update_time TEXT
);
INSERT INTO publish.mrf_gfs_10day_snow_water_equivalent_change
VALUES (
to_char('1900-01-01 00:00:00'::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC'),
to_char(now()::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC')
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DROP TABLE IF EXISTS publish.mrf_gfs_10day_snow_water_equivalent_change;
CREATE TABLE publish.mrf_gfs_10day_snow_water_equivalent_change (
reference_time TEXT,
valid_time TEXT,
update_time TEXT
);
INSERT INTO publish.mrf_gfs_10day_snow_water_equivalent_change
VALUES (
to_char('1900-01-01 00:00:00'::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC'),
to_char('1900-01-01 00:00:00'::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC'),
to_char(now()::timestamp without time zone, 'YYYY-MM-DD HH24:MI:SS UTC')
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
product: mrf_gfs_10day_snow_water_equivalent_change
configuration: medium_range_mem1
product_type: "raster"
run: true

raster_input_files:
product_file: mrf_gfs_10day_snow_water_equivalent_change
file_format: common/data/model/com/nwm/{{variable:NWM_DATAFLOW_VERSION}}/nwm.{{datetime:%Y%m%d}}/medium_range_mem1/nwm.t{{datetime:%H}}z.medium_range.land_1.f003.conus.nc
file_step: 1D
file_window: P10D

postprocess_sql:
- sql_file: mrf_gfs_10day_snow_water_equivalent_change
target_table: publish.mrf_gfs_10day_snow_water_equivalent_change

services:
- mrf_gfs_10day_snow_water_equivalent_change_noaa
Loading
Loading