Skip to content

Commit

Permalink
bug fix for RTOFS profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed May 15, 2021
1 parent 0fd351a commit 94d503b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion hyo2/soundspeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed"
__version__ = '2021.1.6'
__version__ = '2021.1.7'
__copyright__ = 'Copyright 2021 University of New Hampshire, Center for Coastal and Ocean Mapping'

lib_info = LibInfo()
Expand Down
13 changes: 5 additions & 8 deletions hyo2/soundspeed/atlas/rtofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def download_db(self, dtstamp: Union[dt, None] = None, server_mode: bool = False
self._lat_step = self._lat[1] - self._lat_0
self._lon_0 = self._lon[0]
self._lon_step = self._lon[1] - self._lon_0
# logger.debug("0(%.3f, %.3f); step(%.3f, %.3f)" % (self._lat_0, self._lon_0, self._lat_step, self._lon_step))

# logger.debug("0(%.3f, %.3f); step(%.3f, %.3f)" % (self.lat_0, self.lon_0, self.lat_step, self.lon_step))
return True

def query(self, lat: Optional[float], lon: Optional[float], dtstamp: Union[dt, None] = None,
def query(self, lat: Optional[float], lon: Optional[float], dtstamp: Optional[dt] = None,
server_mode: bool = False):
"""Query RTOFS for passed location and timestamp"""
if dtstamp is None:
Expand All @@ -92,7 +92,7 @@ def query(self, lat: Optional[float], lon: Optional[float], dtstamp: Union[dt, N
logger.debug("query: %s @ (%.6f, %.6f)" % (dtstamp, lon, lat))

# check the inputs
if (lat is None) or (lon is None) or (dtstamp is None):
if (lat is None) or (lon is None):
logger.error("invalid query: %s @ (%s, %s)" % (dtstamp.strftime("%Y/%m/%d %H:%M:%S"), lon, lat))
return None

Expand All @@ -101,8 +101,8 @@ def query(self, lat: Optional[float], lon: Optional[float], dtstamp: Union[dt, N
except TypeError as e:
logger.critical("while converting location to grid coords, %s" % e)
return None

# logger.debug("idx > lat: %s, lon: %s" % (lat_idx, lon_idx))

lat_s_idx = lat_idx - self._search_half_window
lat_n_idx = lat_idx + self._search_half_window
lon_w_idx = lon_idx - self._search_half_window
Expand Down Expand Up @@ -364,9 +364,6 @@ def _download_files(self, datestamp: dt, server_mode: bool = False):
"""
progress = CliProgress()

if not isinstance(datestamp, dt):
raise RuntimeError("invalid datetime passed: %s" % type(datestamp))

# check if the files are loaded and that the date matches
if self._has_data_loaded:
# logger.info("%s" % self.last_loaded_day)
Expand Down Expand Up @@ -402,7 +399,7 @@ def _download_files(self, datestamp: dt, server_mode: bool = False):
progress.update(60)
self._file_sal = Dataset(url_sal)
progress.update(80)
self._day_idx = 2 # usually 3 1-day steps
self._day_idx = 1 # it was 3 1-day steps, now only 2 steps

except (RuntimeError, IOError) as e:
logger.warning("unable to access data: %s -> %s" % (datestamp.strftime("%Y%m%d"), e))
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeedmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Manager"
__version__ = "2021.1.6"
__version__ = "2021.1.7"
__copyright__ = "Copyright 2021 University of New Hampshire, Center for Coastal and Ocean Mapping"

app_info = AppInfo()
Expand Down
40 changes: 20 additions & 20 deletions hyo2/soundspeedmanager/qt_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def interpret_latitude(cls, str_value: str) -> Optional[float]:
try:
# this regex split the string if not a number, not a letter ,not . or -
lat_tokens = re.split(r'[^\d\w.-]+', str_value)
logger.debug("lat tokens: %s" % (lat_tokens,))
# logger.debug("lat tokens: %s" % (lat_tokens,))

# manage the different kind of input by nr. of tokens
nr_lat_tokens = len(lat_tokens)
Expand All @@ -121,20 +121,20 @@ def interpret_latitude(cls, str_value: str) -> Optional[float]:

if lat_tokens[0][-1] in ["N", "S"]: # DDH

logger.debug("DDH")
# logger.debug("DDH")
lat = float(lat_tokens[0][0:-1])
if lat_tokens[0][-1].strip() == "S":
lat *= -1

else: # DD
logger.debug("DD")
# logger.debug("DD")
lat = float(lat_tokens[0])

elif nr_lat_tokens == 2:

if lat_tokens[1].strip() in ["N", "S"]: # DD H

logger.debug("DD H")
# logger.debug("DD H")
lat = float(lat_tokens[0])
if lat_tokens[1].strip() == "S":
lat *= -1
Expand All @@ -143,37 +143,37 @@ def interpret_latitude(cls, str_value: str) -> Optional[float]:

if lat_tokens[1][-1] in ["N", "S"]: # DMH

logger.debug("DMH")
# logger.debug("DMH")
lat = cls.dm2dd(lat_tokens[0], lat_tokens[1][0:-1], lat_tokens[1][-1])

else: # DM
logger.debug("DM")
# logger.debug("DM")
lat = cls.dm2dd(lat_tokens[0], lat_tokens[1])

elif nr_lat_tokens == 3:

if lat_tokens[2].strip() in ["N", "S"]: # DM H

logger.debug("DM H")
# logger.debug("DM H")
lat = cls.dm2dd(lat_tokens[0], lat_tokens[1], lat_tokens[2])

else:

if lat_tokens[2][-1] in ["N", "S"]: # DMSH

logger.debug("DMSH")
# logger.debug("DMSH")
lat = cls.dms2dd(lat_tokens[0], lat_tokens[1], lat_tokens[2][0:-1], lat_tokens[2][-1])

else: # DMS

logger.debug("DMS")
# logger.debug("DMS")
lat = cls.dms2dd(lat_tokens[0], lat_tokens[1], lat_tokens[2])

elif nr_lat_tokens == 4:

if lat_tokens[3].strip() in ["N", "S"]: # DMS H

logger.debug("DMS H")
# logger.debug("DMS H")
lat = cls.dms2dd(lat_tokens[0], lat_tokens[1], lat_tokens[2], lat_tokens[3])

else:
Expand Down Expand Up @@ -205,7 +205,7 @@ def interpret_longitude(cls, str_value: str) -> Optional[float]:

# this regex split the string if not a number, not a letter ,not . or -
lon_tokens = re.split(r'[^\d\w.-]+', str_value)
logger.debug("lon tokens: %s" % (lon_tokens,))
# logger.debug("lon tokens: %s" % (lon_tokens,))

# manage the different kind of input by nr. of tokens
nr_lon_tokens = len(lon_tokens)
Expand All @@ -217,21 +217,21 @@ def interpret_longitude(cls, str_value: str) -> Optional[float]:

if lon_tokens[0][-1] in ["E", "W"]: # DDH

logger.debug("DDH")
# logger.debug("DDH")
lon = float(lon_tokens[0][0:-1])
if lon_tokens[0][-1].strip() == "W":
lon *= -1

else: # DD

logger.debug("DD")
# logger.debug("DD")
lon = float(lon_tokens[0])

elif nr_lon_tokens == 2:

if lon_tokens[1].strip() in ["W", "E"]: # DD H

logger.debug("DD H")
# logger.debug("DD H")
lon = float(lon_tokens[0])
if lon_tokens[1].strip() == "W":
lon *= -1
Expand All @@ -240,36 +240,36 @@ def interpret_longitude(cls, str_value: str) -> Optional[float]:

if lon_tokens[1][-1] in ["W", "E"]: # DMH

logger.debug("DMH")
# logger.debug("DMH")
lon = cls.dm2dd(lon_tokens[0], lon_tokens[1][0:-1], lon_tokens[1][-1])

else: # DM
logger.debug("DM")
# logger.debug("DM")
lon = cls.dm2dd(lon_tokens[0], lon_tokens[1])

elif nr_lon_tokens == 3:

if lon_tokens[2].strip() in ["W", "E"]: # DM H

logger.debug("DM H")
# logger.debug("DM H")
lon = cls.dm2dd(lon_tokens[0], lon_tokens[1], lon_tokens[2])

else: # DMS

if lon_tokens[2][-1] in ["W", "E"]: # DMSH

logger.debug("DMSH")
# logger.debug("DMSH")
lon = cls.dms2dd(lon_tokens[0], lon_tokens[1], lon_tokens[2][0:-1], lon_tokens[2][-1])

else:
logger.debug("DMS")
# logger.debug("DMS")
lon = cls.dms2dd(lon_tokens[0], lon_tokens[1], lon_tokens[2])

elif nr_lon_tokens == 4:

if lon_tokens[3].strip() in ["W", "E"]: # DMS H

logger.debug("DMS H")
# logger.debug("DMS H")
lon = cls.dms2dd(lon_tokens[0], lon_tokens[1], lon_tokens[2], lon_tokens[3])

else:
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeedsettings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Settings"
__version__ = '2021.1.6'
__version__ = '2021.1.7'
__copyright__ = 'Copyright 2021 University of New Hampshire, Center for Coastal and Ocean Mapping'

app_info = AppInfo()
Expand Down

0 comments on commit 94d503b

Please sign in to comment.