diff --git a/pyschism/forcing/nws/best_track.py b/pyschism/forcing/nws/best_track.py index 466dab19..0b179144 100644 --- a/pyschism/forcing/nws/best_track.py +++ b/pyschism/forcing/nws/best_track.py @@ -18,6 +18,7 @@ from pyschism.enums import NWSType from pyschism.forcing.nws.base import NWS +from pyschism.mesh import gridgr3 class HurricaneModel(IntEnum): @@ -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, @@ -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""" @@ -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 diff --git a/tests/test_paramwind.py b/tests/test_paramwind.py index 462e1269..c868f0c7 100644 --- a/tests/test_paramwind.py +++ b/tests/test_paramwind.py @@ -69,5 +69,3 @@ def test_paramwind_from_file(): driver.write(tmpdir / 'paramwind', overwrite=True) -if __name__ == '__main__': - test_paramwind()