Skip to content

Commit

Permalink
bugfix: bad logger init
Browse files Browse the repository at this point in the history
  • Loading branch information
jreniel committed Feb 28, 2021
1 parent 01fdcc7 commit 47d70cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion pyschism/cmd/bctides.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ def add_bctides(subparsers):
help="Allow overwrite of output file.")
bctides.add_argument(
"--log-level",
choices=[name.lower() for name in logging._nameToLevel])
choices=[name.lower() for name in logging._nameToLevel],
default='warning')
44 changes: 24 additions & 20 deletions pyschism/io/bctides.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import pytz

from pyschism.forcing.tides.tides import Tides
from pyschism.mesh import Hgrid, hgrid
from pyschism.mesh import Hgrid


def datetime_is_naive(d) -> bool:
return d.tzinfo is None or d.tzinfo.utcoffset(d) is None


def datetime_is_aware(d) -> bool:
return d.tzinfo is not None and d.tzinfo.utcoffset(d) is not None

Expand All @@ -25,6 +27,7 @@ def __set__(self, obj, val: Hgrid):
def __get__(self, obj, val):
return obj.__dict__['hgrid']


class StartDateDescriptor:

def __set__(self, obj, val: datetime):
Expand All @@ -38,7 +41,8 @@ def __set__(self, obj, val: datetime):

def __get__(self, obj, val):
return obj.__dict__['start_date']



class RndayDescriptor:

def __set__(self, obj, val: Union[int, float, timedelta]):
Expand All @@ -48,11 +52,12 @@ def __set__(self, obj, val: Union[int, float, timedelta]):
f'{timedelta}, not type {type(val)}.')
if not isinstance(val, timedelta):
val = timedelta(days=val)
obj.__dict__['rnday'] = val
obj.__dict__['rnday'] = val

def __get__(self, obj, val) -> timedelta:
return obj.__dict__['rnday']


class Bctides:

_hgrid = HgridDescriptor()
Expand Down Expand Up @@ -119,7 +124,7 @@ def write(self, path, overwrite: bool = False):
path = pathlib.Path(path)
if path.exists() and not overwrite:
raise IOError('path exists and overwrite is False')
open(path, 'w').write(str(self))
open(path.resolve(), 'w').write(str(self))

def get_forcing(self, boundary):

Expand Down Expand Up @@ -161,12 +166,14 @@ def forcing_digit(pos):

else:
raise ValueError(f'Unhandled argument pos={pos}.')

def get_forcing(pos, digit):
f =[]
if pos == 1: # elevation
if digit == 3: # tides
if self.elevation is True: # default tidal elevation

f = []

if pos == 1: # elevation
if digit == 3: # tides
if self.elevation is True: # default tidal elevation
for constituent in \
self.tides.get_active_forcing_constituents():
f.append(f'{constituent}')
Expand All @@ -183,8 +190,8 @@ def get_forcing(pos, digit):
else:
raise ValueError(
f'Unhandled elevation forcing digit={digit}')
elif pos == 2: # velocity
if self.velocity is True: # default tidal velocity
elif pos == 2: # velocity
if self.velocity is True: # default tidal velocity
for constituent in \
self.tides.get_active_forcing_constituents():
f.append(f'{constituent}')
Expand All @@ -193,29 +200,26 @@ def get_forcing(pos, digit):
uamp, uphase, vamp, vphase = self.tides.get_velocity(
constituent, vertices)
for i in range(len(vertices)):
f.append(f'{uamp[i]:.8e} {uphase[i]:.8e} ' \
f'{vamp[i]:.8e} {vphase[i]:.8e}')
f.append(f'{uamp[i]:.8e} {uphase[i]:.8e} '
f'{vamp[i]:.8e} {vphase[i]:.8e}')
return '\n'.join(f)
else:
raise TypeError(
f'Unhandled velocity type {type(self.velocity)}')
else:
raise TypeError('Unhandled forcing at pos={pos}.')


f = [' '.join(list(map(forcing_digit, range(5 + len(self._tracers)))))]

for i in range(1, 5 + len(self._tracers)):
if int(forcing_digit(i)) > 0:
f.append(get_forcing(i, int(forcing_digit(i))))
return '\n'.join(f)




@property
def hgrid(self):
return self._hgrid

@property
def tides(self):
return self._tides
Expand All @@ -235,11 +239,11 @@ def elevation(self):
@property
def velocity(self):
return self._velocity

@property
def temperature(self):
return self._temperature

@property
def salinity(self):
return self._salinity
return self._salinity

0 comments on commit 47d70cc

Please sign in to comment.