Skip to content
Merged
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
44 changes: 22 additions & 22 deletions NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import math
from pathlib import Path

import numpy as np

Expand All @@ -15,11 +14,13 @@
except ImportError:
import ESMF

import logging
from functools import cached_property, wraps
from typing import Any
import logging

import xarray as xr

from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core import err_handler
from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import (
ConfigOptions,
)
Expand All @@ -28,6 +29,10 @@
log_critical,
)
from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig
from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.esmf_utils import (
esmf_grid_retry,
esmf_mesh_retry,
)

LOG = logging.getLogger("FORCING")

Expand Down Expand Up @@ -352,16 +357,14 @@ def dx_meters(self) -> float:
@cached_property
def esmf_grid(self) -> ESMF.Grid:
"""Create the ESMF grid object for the gridded domain."""
try:
return ESMF.Grid(
np.array([self.ny_global, self.nx_global]),
staggerloc=ESMF.StaggerLoc.CENTER,
coord_sys=ESMF.CoordSys.SPH_DEG,
)
except Exception as e:
self.config_options.errMsg = f"Unable to create ESMF grid for WRF-Hydro geogrid: {self.config_options.geogrid}"
log_critical(self.config_options, self.mpi_config)
raise e
return esmf_grid_retry(
self.mpi_config,
self.config_options,
err_handler,
np.array([self.ny_global, self.nx_global]),
staggerloc=ESMF.StaggerLoc.CENTER,
coord_sys=ESMF.CoordSys.SPH_DEG,
)

@cached_property
def esmf_lat(self) -> np.ndarray:
Expand Down Expand Up @@ -865,16 +868,13 @@ def ny_global(self) -> int:
@cached_property
def esmf_grid(self) -> ESMF.Mesh:
"""Create the ESMF Mesh object for the hydrofabric domain."""
try:
return ESMF.Mesh(
filename=self.config_options.geogrid, filetype=ESMF.FileFormat.ESMFMESH
)
except Exception as e:
LOG.critical(
f"Unable to create ESMF Mesh: {self.config_options.geogrid} "
f"due to {str(e)}"
)
raise e
return esmf_mesh_retry(
self.mpi_config,
self.config_options,
err_handler,
filename=self.config_options.geogrid,
filetype=ESMF.FileFormat.ESMFMESH,
)

@cached_property
def latitude_grid(self) -> np.ndarray:
Expand Down