Skip to content

Commit

Permalink
Merge pull request #199 from blaylockbk/blaylockbk/issue198-add-CFS-m…
Browse files Browse the repository at this point in the history
…odel

Add discovery and access of CFS model
  • Loading branch information
blaylockbk authored Jan 16, 2025
2 parents f356123 + 707f878 commit 8980367
Show file tree
Hide file tree
Showing 18 changed files with 3,727 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: true
matrix:
os: ["windows-latest"]
python-version: ["3.11"]
python-version: ["3.12"]

env:
OS: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
# In order to save resources, only run particular
# matrix slots on other OS than Linux.
include:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ herbie/_version.py

*.pkl
.coverage

.ruff_cache/
2 changes: 1 addition & 1 deletion ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- metpy
- numpy>=1.26.2
- pandas>=2.1.4
- pygrib
- pygrib>=2.1.6
- pytest
- requests>=2.31.0
- scikit-learn
Expand Down
9 changes: 5 additions & 4 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cfgrib>=0.9.9.1
cfgrib>=0.9.15
metpy>=1.3.0
numpy>=1.22.3
pandas>=1.4.1
requests>=2.27.1
pandas>=2.2.3
pygrib>=2.1.6
requests>=2.32.3
toml>=0.10.2
xarray>=2022.3.0
xarray>=2025.1.1
2,780 changes: 2,780 additions & 0 deletions docs/gallery/noaa_models/cfs.ipynb

Large diffs are not rendered by default.

60 changes: 22 additions & 38 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,73 @@ name: herbie-dev
channels:
- conda-forge
dependencies:
- python>=3.11
- pip
- git
- curl
- rclone # Not required, but is an awesome alternative (https://rclone.org/)
- wgrib2 # ONLY AVAILABLE ON LINUX. Comment if not using Linux.
- eccodes>=2.31
- git
- pip
- python>=3.13
- rclone
- uv
- wgrib2 # Linux only

# ===========
# Handy Tools
# ===========
# ============
# Dependencies
# ============
- cartopy>=0.22
- cfgrib>=0.9.10.4
- eccodes>=2.31
- geopandas
- h5py
- jupyter
- jupyterlab
- matplotlib>=3.4.3
- metpy
- netcdf4
- numpy>=1.25
- pandas>=2.0
- polars>=1.0
- polars>=1.17.1
- pygrib>=2.1.4
- pylint
- pyproj>=3.6
- requests>=2.31
- s3fs
- scipy
- scipy>=1.15.1
- scikit-learn
- toml
- xarray>=2023.7
- zarr

# ===================
# Formatter & Testing
# ===================
# ===========
# Development
# ===========
- ruff
- black
- black-jupyter
- isort
- pylint
- pytest
- pytest-cov
- line_profiler

# =============
# Documentation
# =============
- sphinx>=4.4.0
- nbsphinx
- nbconvert>=6.5
- pydata-sphinx-theme # PyData Sphinx Theme (i.e, Numpy, Pandas, MetPy)
- pydata-sphinx-theme
- sphinx-design
- recommonmark
- sphinx-markdown-tables
- sphinxcontrib-mermaid # For mermaid diagram support
- sphinxcontrib-mermaid
- autodocsumm
- sphinx-autosummary-accessors # pandas and xarray accessor docs
- sphinx-autosummary-accessors
- latexmk
- myst-parser
- linkify-it-py

#- pip:
#- cartopy>=0.22
# Herbie: Development version from GitHub
#- git+https://github.com/blaylockbk/Herbie.git

# Install a specific branch
#- git+https://github.com/blaylockbk/Herbie.git@blaylockbk/issue98

# Borrow some tools from my garage
#- git+https://github.com/blaylockbk/Carpenter_Workshop.git

# Create idx files on the fly!! -- Waiting for package maturity
#- git+https://github.com/joxtoby/beltzer.git
# =============================================================================
# Extra Setup Steps
# Setup Steps
# =============================================================================
# conda activate herbie-dev
# mamba activate herbie-dev
# git clone https://github.com/blaylockbk/Herbie.git
# cd Herbie
# pip install -e .
#
# cd ~
# git clone https://github.com/blaylockbk/Carpenter_Workshop.git
# cd Carpenter_Workshop
# pi install -e .
Expand Down
38 changes: 24 additions & 14 deletions herbie/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ def _validate(self) -> None:
_models = {m for m in dir(model_templates) if not m.startswith("__")}
_products = set(self.PRODUCTS)

assert self.date < pd.Timestamp.utcnow().tz_localize(
None
), "🔮 `date` cannot be in the future."
assert self.date < pd.Timestamp.utcnow().tz_localize(None), (
"🔮 `date` cannot be in the future."
)
assert self.model in _models, f"`model` must be one of {_models}"
assert self.product in _products, f"`product` must be one of {_products}"

Expand Down Expand Up @@ -910,7 +910,7 @@ def subset(search, outFile):
grib_source = f"file://{str(self.grib)}"
if verbose:
print(
f'📇 Download subset: {self.__repr__()}{" ":60s}\n cURL from {grib_source}'
f"📇 Download subset: {self.__repr__()}{' ':60s}\n cURL from {grib_source}"
)

# -----------------------------------------------------
Expand Down Expand Up @@ -1142,16 +1142,26 @@ def xarray(
# Get CF grid projection information with pygrib and pyproj because
# this is something cfgrib doesn't do (https://github.com/ecmwf/cfgrib/issues/251)
# NOTE: Assumes the projection is the same for all variables
with pygrib.open(str(local_file)) as grb:
msg = grb.message(1)
cf_params = CRS(msg.projparams).to_cf()

# Funny stuff with polar stereographic (https://github.com/pyproj4/pyproj/issues/856)
# TODO: Is there a better way to handle this? What about south pole?
if cf_params["grid_mapping_name"] == "polar_stereographic":
cf_params["latitude_of_projection_origin"] = cf_params.get(
"latitude_of_projection_origin", 90
)
# TODO: Issues with pygrib in tests. Segmentation Fault. Is it Numpy 2???
use_pygrib = False
if use_pygrib:
with pygrib.open(str(local_file)) as grb:
msg = grb.message(1)
cf_params = CRS(msg.projparams).to_cf()

#grb = pygrib.open(str(local_file))
#msg = grb.message(1)
#cf_params = CRS(msg.projparams).to_cf()
#grb.close()

# Funny stuff with polar stereographic (https://github.com/pyproj4/pyproj/issues/856)
# TODO: Is there a better way to handle this? What about south pole?
if cf_params["grid_mapping_name"] == "polar_stereographic":
cf_params["latitude_of_projection_origin"] = cf_params.get(
"latitude_of_projection_origin", 90
)
else:
cf_params = {}

# Here I'm looping over each dataset in the list returned by cfgrib
for ds in Hxr:
Expand Down
1 change: 1 addition & 0 deletions herbie/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .rtma import *
from .usnavy import *
from .urma import *
from .cfs import *

# ======================================================================
# Import Private Model Templates
Expand Down
Loading

0 comments on commit 8980367

Please sign in to comment.