Skip to content

Commit

Permalink
bug fix with synthetic profile longitude when negative
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Oct 20, 2018
1 parent 227a4cd commit fdcc29b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion hyo/soundspeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())

__version__ = '2018.1.45'
__version__ = '2018.1.46'
__doc__ = "Sound Speed"
__author__ = '[email protected]; [email protected]; [email protected]; ' \
'[email protected]'
Expand Down
6 changes: 4 additions & 2 deletions hyo/soundspeed/atlas/rtofs/rtofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def query(self, lat, lon, datestamp=None, server_mode=False):
logger.info("no data from lookup!")
return None

ind = np.nanargmin(distances[0])
ind2 = np.unravel_index(ind, distances[0].shape)
# ind = np.nanargmin(distances[0])
# ind2 = np.unravel_index(ind, distances[0].shape)
# switching to the query location
# lat_out = latitudes[ind2]
# lon_out = longitudes[ind2]
Expand All @@ -274,6 +274,8 @@ def query(self, lat, lon, datestamp=None, server_mode=False):
ssp.meta.sensor_type = Dicts.sensor_types['Synthetic']
ssp.meta.probe_type = Dicts.probe_types['RTOFS']
ssp.meta.latitude = lat
if lon > 180.0: # Go back to negative longitude
lon -= 360.0
ssp.meta.longitude = lon
ssp.meta.utc_time = dt(year=datestamp.year, month=datestamp.month, day=datestamp.day)
ssp.meta.original_path = "RTOFS_%s" % datestamp.strftime("%Y%m%d")
Expand Down
3 changes: 3 additions & 0 deletions hyo/soundspeed/atlas/woa09/woa09.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def query(self, lat, lon, datestamp=None, server_mode=False):
valid = dist_arr != 99999999
num_values = t[valid].size

if lon > 180.0: # Go back to negative longitude
lon -= 360.0

# populate output profiles
ssp = Profile()
ssp.meta.sensor_type = Dicts.sensor_types['Synthetic']
Expand Down
3 changes: 3 additions & 0 deletions hyo/soundspeed/atlas/woa13/woa13.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ def query(self, lat, lon, datestamp=None, server_mode=False):
num_values = t[valid].size
logger.debug("valid: %s" % num_values)

if lon > 180.0: # Go back to negative longitude
lon -= 360.0

# populate output profiles
ssp = Profile()
ssp.meta.sensor_type = Dicts.sensor_types['Synthetic']
Expand Down
19 changes: 17 additions & 2 deletions hyo/soundspeed/db/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ def _create_ogr_lyr_and_fields(self, ds):
if lyr.CreateField(field) != 0:
raise RuntimeError("Creating field failed.")

field = ogr.FieldDefn('POINT_X', ogr.OFTReal)
if lyr.CreateField(field) != 0:
raise RuntimeError("Creating field failed.")

field = ogr.FieldDefn('POINT_Y', ogr.OFTReal)
if lyr.CreateField(field) != 0:
raise RuntimeError("Creating field failed.")

return lyr

def export_profiles_metadata(self, project_name, output_folder, ogr_format=GdalAux.ogr_formats['ESRI Shapefile']):
Expand Down Expand Up @@ -196,13 +204,20 @@ def export_profiles_metadata(self, project_name, output_folder, ogr_format=GdalA
ft.SetField('max_raw_d', row[22])

pt = ogr.Geometry(ogr.wkbPoint)
pt.SetPoint_2D(0, row[2].x, row[2].y)
lat = row[2].y
lon = row[2].x
if lon > 180.0: # Go back to negative longitude
lon -= 360.0
pt.SetPoint_2D(0, lon, lat)

ft.SetField('POINT_X', lon)
ft.SetField('POINT_Y', lat)

try:
ft.SetGeometry(pt)

except Exception as e:
RuntimeError("%s > pt: %s, %s" % (e, row[2].x, row[2].y))
RuntimeError("%s > pt: %s, %s" % (e, lon, lat))

if lyr.CreateFeature(ft) != 0:
raise RuntimeError("Unable to create feature")
Expand Down
2 changes: 1 addition & 1 deletion hyo/soundspeedmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

__version__ = '2018.1.45'
__version__ = '2018.1.46'
__doc__ = "Sound Speed Manager"
__author__ = '[email protected]; [email protected]; [email protected]; ' \
'[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion hyo/soundspeedsettings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

__version__ = '2018.1.45'
__version__ = '2018.1.46'
__doc__ = "Sound Speed Settings"
__author__ = '[email protected]; [email protected]; [email protected]; ' \
'[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def txt_read(*paths):
setup_args = dict()

setup_args['name'] = 'hyo.soundspeed'
setup_args['version'] = '2018.1.45'
setup_args['version'] = '2018.1.46'
setup_args['url'] = 'https://bitbucket.org/ccomjhc/hyo_soundspeed/'
setup_args['license'] = 'LGPLv2.1 or CCOM-UNH Industrial Associate license'
setup_args['author'] = 'Giuseppe Masetti(UNH,CCOM); Barry Gallagher(NOAA,OCS); ' \
Expand Down

0 comments on commit fdcc29b

Please sign in to comment.