Skip to content

Instantly share code, notes, and snippets.

@JordanMakesMaps
Created August 4, 2017 03:00
Show Gist options
  • Save JordanMakesMaps/e61da3f6081b92754a451f6b85b326dc to your computer and use it in GitHub Desktop.
Save JordanMakesMaps/e61da3f6081b92754a451f6b85b326dc to your computer and use it in GitHub Desktop.
#Jordan Pierce
#This is a program that can be used with a Lowrance fishfinder in order to obtain
# the GPS locations, depth soundings, elevation, and temperatures. The program
# takes in a file in .csv format, strips the data listed above and stores it into a
# multidimensional array. The array then goes through and transforms the
# GCS positions (Lowrence uses a Mercator meter format), to an decimal degree format
# that can be used to project the locations on an standard projection (WGS84),
# [Function: MeterstoDeg()]. The last thing it does it takes all of the excess values,
# the zeros, and the NULL values for each record and removes them. The GPS records
# a position between .1-.9 seconds, while the depth sounder records a value every
# .1 seconds, because of this, their are many records that have no GPS locations
# but plenty of other fluff I didn't need [Extractonator()]. It then stores the
# rest of the information to another .csv file that can be used in mapping
# software (ArcGIS)
#
# I made this program specifically to make a 3D model of a body of water, using
# a Lowrance fishfinder, and ArcGIS. The variables saved are just the ones I needed
# but changes are welcomed if needed. Cheers.
#-------------------------------------------------------------------------------------
#Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime
#This function takes in two arrays, lat and lon, and the number of records.
#It takes the values, transforms them, and stores them into new arrays, and
# then returns it back to main.
##------------------------------------------------------------------------------------
def MetersToDeg(Lat, Lon, MAX):
RADtoDEG = 57.295779513082322
EarthRad = 6356752.3142
count = 0
New_lat = []
New_lon = []
#Formula to do the transformation for Lat
for i in range(0,MAX):
temp = float(Lat[count]/EarthRad)
temp = np.exp(temp)
temp = (2*np.arctan(temp))-(np.pi/2)
temp = temp * RADtoDEG
New_lat.append(temp)
count+=1
#Formula to do the transformation for Lon
count = 0
for i in range(0, MAX):
temp = float(Lon[count])
New_lon.append(temp/EarthRad * RADtoDEG)
count+=1
return New_lat, New_lon
##--------------------------------------------------------------------------------
#This function takes the new arrays, and the other information, and loops through
# all of them. If the record doesn't contain a NULL value as a coordinate, then
# the record is saved to a new array. A lot of the sounding information is lost
# but it's due to the fact that it takes measurements 10x faster than the GPS.
# I figured the data lost isn't that important because the amount of change in the
# bathymetry within one second isn't going to be drastic. A way to save the data
# could be implemented, or even averaged for each coordinate if you so desire.
# The new arrays with the data are returned to main.
##--------------------------------------------------------------------------------
def Extractonator(New_lat, New_lon, Elevation, Temp, Depth, MAXVALUE):
lat = []
lon = []
elevation = []
temp = []
depth = []
count = 0
print "Points:"
while count < MAXVALUE:
if New_lat[count] != 0.0:
lat.append(New_lat[count])
lon.append(New_lon[count])
elevation.append(Elevation[count])
temp.append(Temp[count])
depth.append(Depth[count])
count+=1
print count
count = 0
return lat, lon, elevation, temp, depth
##------------------------------------------------------------------------------
#Main
#requests input from the user
ans = raw_input("Enter the file name and extension: ")
print 'Filename: ', ans
#Stores the filename
filename = file(ans)
#opens the file using Panda
Position = pd.read_csv(ans)
#arrays for each (in panda format (integers), must be changed to doubles)
Lat = Position.PositionY
Lon = Position.PositionX
#Checks to make sure the positions are paired correctly (just in case)
if Lat.size == Lon.size:
MAXVALUE = Lat.size
else:
print 'bad data'
exit()
#Program call and new arrays
New_lat, New_lon = MetersToDeg(Lat,Lon, MAXVALUE)
Elevation = Position.Altitude
Temp = Position.WaterTemp
Depth = Position.Depth
lat, lon, elevation, temp, depth = Extractonator(New_lat, New_lon, Elevation, Temp, Depth, MAXVALUE)
#outputs the data using Pandas in a orderly, .csv format for use in other software
df = pd.DataFrame({'depth':depth,'temp':temp,'lat':lat,'lon':lon,'elevation':elevation})
df.to_csv('OutputSonar.txt', columns = ('depth', 'temp', 'lat', 'lon', 'elevation'),sep= '\t')
print 'Done. File outputted to folder'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment