Skip to content

Commit

Permalink
reslove conflicts in bctides
Browse files Browse the repository at this point in the history
  • Loading branch information
cuill committed Apr 17, 2023
2 parents 744502d + 820d93c commit b6f2a24
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 43 deletions.
14 changes: 14 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cff-version: 1.2.0
message: "If you used this software as part of your work, please use the following citation format."
authors:
- family-names: Calzada
given-names: Jaime R
orcid: https://orcid.org/0000-0002-3172-1906
- family-names: Cui
given-names: Linlin
- family-names: Zhang
given-names: Joseph
title: "PySCHISM"
version: v0.1.5
doi: 10.5281/zenodo.7623122
date-released: 2023-02-08
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# PySCHISM
[![codecov](https://codecov.io/gh/schism-dev/pyschism/branch/main/graph/badge.svg?token=VE9PHEACBZ)](https://codecov.io/gh/schism-dev/pyschism)
[![DOI](https://zenodo.org/badge/233075737.svg)](https://zenodo.org/badge/latestdoi/233075737)

## A Python interface for SCHISM model runs.

Expand Down Expand Up @@ -58,11 +59,22 @@ hgrid = Hgrid.open('hgrid.gr3')
hgrid.write("/path/to/output/file.2dm", fmt='2dm')
```
---
## References

If you used this software as part of your work, please use the following citation format.

Jaime R Calzada, Linlin Cui, & Joseph Zhang. (2023). schism-dev/pyschism: v0.1.5 (v0.1.5). Zenodo. https://doi.org/10.5281/zenodo.7623122

---



Questions, comments and suggestions are welcome. Please follow the instructions on the `CONTRIBUTING.md` file for contributions. For bug reports and feature requests, please open an issue using the issue tracker.
Author contact: [email protected]
Main author name: Jaime R Calzada
Author contact: [email protected]


---
“Marconi is a good fellow. Let him continue. He is using seventeen of my patents.”
Nikola Tesla
---
---
1 change: 1 addition & 0 deletions pyschism/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def __init__(
self.config.forcings.nws.windrot = gridgr3.Windrot.default(
self.config.hgrid
)
self.param.opt.model_type_pahm = self.config.forcings.nws.model.value

self.param.opt.wtiminc = self.param.core.dt
self.param.opt.nws = self.config.forcings.nws.dtype.value
Expand Down
25 changes: 12 additions & 13 deletions pyschism/forcing/bctides/bctides.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import datetime, timedelta
from functools import cached_property
from functools import cached_property, lru_cache
import pathlib
from typing import Dict, Union
import logging

from ordered_set import OrderedSet
import numpy as np

from pyschism import dates
Expand Down Expand Up @@ -310,7 +311,7 @@ def __init__(self, gdf):
)

def get_active_forcing_constituents(self):
active_constituents = set()
active_constituents = OrderedSet()
for row in self.gdf.itertuples():
if row.iettype is not None:
if row.iettype.iettype in [3, 5]:
Expand All @@ -328,7 +329,7 @@ def get_active_forcing_constituents(self):
return list(active_constituents)

def get_active_potential_constituents(self):
active_constituents = set()
active_constituents = OrderedSet()
for row in self.gdf.itertuples():
if row.iettype is not None:
if row.iettype.iettype in [3, 5]:
Expand All @@ -345,16 +346,14 @@ def get_active_potential_constituents(self):

return list(active_constituents)

@cached_property
def constituents(self):
return sorted(
list(
set(
[
*self.get_active_potential_constituents(),
*self.get_active_forcing_constituents(),
]
)
@lru_cache
def get_active_constituents(self):
return list(
OrderedSet(
[
*self.get_active_potential_constituents(),
*self.get_active_forcing_constituents(),
]
)
)

Expand Down
42 changes: 33 additions & 9 deletions pyschism/forcing/nws/best_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
import io
import logging
import os
from os import PathLike
import pathlib
from enum import IntEnum
from os import PathLike
from typing import Union

from matplotlib import pyplot
from matplotlib.axis import Axis
from matplotlib.transforms import Bbox
import numpy as numpy
from pandas import DataFrame
from pyproj import CRS, Transformer
from shapely import ops
from shapely.geometry import Point, Polygon
from stormevents.nhc import VortexTrack
from stormevents.nhc.atcf import ATCF_Mode
import utm

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


class HurricaneModel(IntEnum):
SYMMETRIC = 1
GAHM = 10

@classmethod
def _missing_(cls, value):
raise ValueError(f"Invalid hurricane model specified: {value}, choose from: {cls.__members__}")


class BestTrackForcing(VortexTrack, NWS):
Expand All @@ -31,9 +36,10 @@ def __init__(
storm: Union[str, PathLike, DataFrame, io.BytesIO],
start_date: datetime = None,
end_date: datetime = None,
mode: ATCF_Mode = None,
hurricane_model: Union[str, HurricaneModel] = 'gahm'
):

self.model = hurricane_model

VortexTrack.__init__(
self,
Expand All @@ -44,12 +50,10 @@ def __init__(
advisories=['BEST'],
)


def __str__(self):
"""Returns string used in param.nml"""
return f"{self.dtype.value}"


@classmethod
def from_nhc_bdeck(
cls,
Expand Down Expand Up @@ -99,6 +103,26 @@ def dtype(self) -> NWSType:
"""Returns the datatype of the object"""
return NWSType(-1)

@property
def model(self) -> HurricaneModel:
"""Return hurricane model used for this best track forcing"""
return self._model

@model.setter
def model(self, value: Union[str, HurricaneModel]):
"""Set hurricane model used for this best track forcing"""
if isinstance(value, str):
if value.upper() not in HurricaneModel.__members__:
raise ValueError(f"Invalid hurricane model specified: {value}, choose from: {HurricaneModel.__members__}")
value = HurricaneModel[value.upper()]
elif isinstance(value, int):
value = HurricaneModel(value)
elif isinstance(value, HurricaneModel):
pass
else:
raise ValueError(f"Invalid hurricane model specified: {value}")
self._model = value

def clip_to_bbox(self, bbox, bbox_crs):
msg = f'bbox must be a {Bbox} instance.'
assert isinstance(bbox, Bbox), msg
Expand Down
2 changes: 1 addition & 1 deletion pyschism/forcing/source_sink/nwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")

tar.extractall(path, members, numeric_owner)
tar.extractall(path, members, numeric_owner=numeric_owner)


safe_extract(src, DATADIR)
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ url = https://github.com/schism-dev/pyschism.git
exe = True
tests = tests/

[flake8]
max-line-length = 130

[mypy]
plugins = sqlmypy
36 changes: 18 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,33 @@ def run(self):
"build_schism": BuildSchism
},
install_requires=[
'pygeos',
'boto3',
'cdsapi',
'cf-python',
'cfgrib',
'f90nml',
'fsspec',
'geopandas',
'netcdf-flattener>=1.2.0',
'metpy',
'netCDF4',
'f90nml',
'netcdf-flattener>=1.2.0',
'numba',
'ordered-set',
'psutil',
'scipy',
'wget',
'cf-python',
'metpy',
'sqlalchemy',
'pygeos',
'pyugrid',
'boto3',
'rtree',
'numba',
'scipy',
'seawater',
'sqlalchemy',
'stormevents',
'tqdm',
'tqdm-logging-wrapper',
'xmltodict',
'cdsapi',
'seawater',
'utm',
'wget',
'xarray',
'cfgrib',
'xmltodict',
'zarr',
'fsspec',
'stormevents',
'utm',
# 'dask_geopandas @ git+git://github.com/geopandas/dask-geopandas.git@master',
],
entry_points={'console_scripts': ['pyschism = pyschism.__main__:main']},
tests_require=['nose'],
Expand Down

0 comments on commit b6f2a24

Please sign in to comment.