Skip to content

Commit

Permalink
Fix windrot file for best track
Browse files Browse the repository at this point in the history
  • Loading branch information
SorooshMani-NOAA committed Jun 2, 2023
1 parent a1339f9 commit f056672
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 27 additions & 1 deletion pyschism/forcing/nws/best_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from pyschism.enums import NWSType
from pyschism.forcing.nws.base import NWS
from pyschism.mesh import gridgr3


class HurricaneModel(IntEnum):
Expand All @@ -37,11 +38,13 @@ def __init__(
start_date: datetime = None,
end_date: datetime = None,
hurricane_model: Union[str, HurricaneModel] = 'gahm',
windrot: gridgr3.Windrot = None,
*args,
**kwargs
):

self.model = hurricane_model
self.windrot = windrot

VortexTrack.__init__(
self,
Expand Down Expand Up @@ -96,10 +99,20 @@ def summary(
logging.debug(f'skipping existing file "{output}"')
return summary

def write(self, path: PathLike, overwrite: bool = False):
def write(
self,
path: PathLike,
overwrite: bool = False,
windrot: bool = True,
):
VortexTrack.to_file(
self, path=path/'hurricane-track.dat', overwrite=overwrite)

# write windrot data
if windrot is not False and self.windrot is not None:
windrot = "windrot_geo2proj.gr3" if windrot is True else windrot
self.windrot.write(path / "windrot_geo2proj.gr3", overwrite)

@property
def dtype(self) -> NWSType:
"""Returns the datatype of the object"""
Expand Down Expand Up @@ -172,3 +185,16 @@ def clip_to_bbox(self, bbox, bbox_crs):

if _found_start_date is False:
raise Exception(f'No data within mesh bounding box for storm {self.storm_id}.')

@property
def windrot(self):
return self._windrot

@windrot.setter
def windrot(self, windrot: Union[gridgr3.Windrot, None]):
if not isinstance(windrot, (gridgr3.Windrot, type(None))):
raise TypeError(
f"Argument windrot must be of type {gridgr3.Windrot} or None, "
f"not type {type(windrot)}."
)
self._windrot = windrot
2 changes: 0 additions & 2 deletions tests/test_paramwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,3 @@ def test_paramwind_from_file():
driver.write(tmpdir / 'paramwind', overwrite=True)


if __name__ == '__main__':
test_paramwind()

0 comments on commit f056672

Please sign in to comment.