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

WIP: ssebop #262

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions recipes/us-ssebop/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
title: 'US SSEBop Evapotranspiration'
description: >
Actual Evapotranspiration (ETa) produced using MODIS and the operational Simplified Surface Energy Balance (SSEBop) model
for the period 2000 to 2022 at 1-kilometer (km) spatial resolution for the contiguous United States.
pangeo_forge_version: '0.10.3'
pangeo_notebook_version: '2022.07.13'
recipes:
- id: us-ssebop
object: 'recipe:recipe'
provenance:
providers:
- name: 'USGS'
description: 'US Geological Survey'
roles:
- host
- provider
- name: 'Gabriel Senay'
description: 'Gabriel Senay, Research Physical Scientist, US Geological Survey'
orcid: '0000-0002-8810-8539'
roles:
- producer
url: 'https://www.usgs.gov/staff-profiles/gabriel-b-senay'
license: 'CC0'
maintainers:
- name: 'Timothy Hodson'
orcid: '0000-0003-0962-5130'
github: thodson-usgs
bakery:
id: 'pangeo-ldeo-nsf-earthcube'
63 changes: 63 additions & 0 deletions recipes/us-ssebop/recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from datetime import date

import apache_beam as beam
import pandas as pd
import xarray as xr

from pangeo_forge_recipes.patterns import ConcatDim, FilePattern
from pangeo_forge_recipes.transforms import Indexed, StoreToZarr, T

input_url_pattern = (
'zip+'
'https://edcintl.cr.usgs.gov/downloads/sciweb1/shared/uswem/web/'
'conus/eta/modis_eta/daily/downloads/'
'det{yyyyjjj}.modisSSEBopETactual.zip'
'!/det{yyyyjjj}.modisSSEBopETactual.tif'
)

start = date(2001, 1, 1)
end = date(2022, 10, 7)
dates = pd.date_range(start, end, freq='1D')


def make_url(time: pd.Timestamp) -> str:
return input_url_pattern.format(yyyyjjj=time.strftime('%Y%j'))


pattern = FilePattern(make_url, ConcatDim(name='time', keys=dates, nitems_per_file=1))


class Preprocess(beam.PTransform):
"""Preprocessor transform."""

@staticmethod
def _preproc(item: Indexed[T]) -> Indexed[xr.Dataset]:
import numpy as np
import rioxarray

index, url = item
time_dim = index.find_concat_dim('time')
time_index = index[time_dim].value
time = dates[time_index]

da = rioxarray.open_rasterio(url).drop('band')
da = da.rename({'x': 'lon', 'y': 'lat'})
ds = da.to_dataset(name='aet')
ds = ds['aet'].where(ds['aet'] != 9999)
ds = ds.expand_dims(time=np.array([time]))

return index, ds

def expand(self, pcoll: beam.PCollection) -> beam.PCollection:
return pcoll | beam.Map(self._preproc)


recipe = (
beam.Create(pattern.items())
| Preprocess()
| StoreToZarr(
store_name='us-ssebop.zarr',
combine_dims=pattern.combine_dim_keys,
target_chunks={'time': 1, 'lat': int(2834 / 2), 'lon': int(6612 / 6)},
)
)
1 change: 1 addition & 0 deletions recipes/us-ssebop/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rioxarray