#! /usr/bin/python # -*- coding: iso-8859-15 -*- ''' ======================================================================== Pre-processing navigation data files from RV "G.O. SARS". Merge navigation and gravity data, using interpolation. A time constant is provided - START_UNIX_TIME - and gravity records which are older will just be skipped. The reason is that gravity records starts before the vessel left harbour, and navigation data are available when the ship left the shoreline (much later). Survey: R/V "G.O. SARS" Period: 30 June 2008 - 17 July 2008 P.I.: Prof. Dr. Rolf Birger Pedersen Input: Two files: GRAV_FILE_NAME NAV_FILE_NAME from folder given by PATH (see declaration of these constants below). Output: File with name OUTFILE (constant, see below), in current directory ########################### ### W-A-R-N-I-N-G ### ########################### Depth interpolation suffers from extensive sections of missing depth data in navigation input data. Further processing of gravity data will possibly alter the metod of depth interpolation that is used here. Documentation: http://www2.geo.uib.no/gravitymeter_wiki/index.php?n=Main.SARS2008 Version: ----------------------------------------------------- Rev. Date By Description ----------------------------------------------------- 0.1 13 March 2009 OM Initial version University of Bergen Dept. of Earth Science N o r w a y ======================================================================= ''' from numarray import array,Float64 from cubicSpline import * PATH = "/home/olem/www/2008-SARS/navdata/" GRAV_FILE_NAME = "gravdata-stage-1.txt" NAV_FILE_NAME = "navdata-stage-1.txt" OUTFILE = "gravdata-final.txt" START_UNIX_TIME = 1214807736 # = first record in navdata file -> 30.06.2008,063536,70.457768333,17.148941667 NavTime_array = [] Lat_array = [] Lon_array = [] Depth_array = [] DepthTime_array = [] #---- First extract time, lat, lon and depth from nav data file, and place values into separate arrays f = open(PATH + '/' + NAV_FILE_NAME) for Line in f: s = Line.strip().split(',') # Explode after stripping off trailing in line UnixTime = s[0] NavTime_array.append(int(UnixTime)) Lat = s[3] Lat_array.append(float(Lat)) Lon = s[4] Lon_array.append(float(Lon)) Depth = s[7] if (len(Depth) != 0) and (Depth != "0.00"): # Skip empty depth field, or if it's zero Depth_array.append(float(Depth)) DepthTime_array.append(int(UnixTime)) f.close() #---- Next prepare interpolation on Time/Latatitude, Time/Longitude and Time/Depth data sets xData = array(NavTime_array, type='Float64') xDepthData = array(DepthTime_array, type='Float64') yLatData = array(Lat_array, type='Float64') kLat = curvatures(xData,yLatData) yLonData = array(Lon_array, type='Float64') kLon = curvatures(xData,yLonData) yDepthData = array(Depth_array, type='Float64') kDepth = curvatures(xDepthData,yDepthData) #--- Prepare output file g = open(OUTFILE, "w") RecordsWritten = 0 #---- Then loop over all gravity records and calculate interpolated lat/lon/depth for each f = open(PATH + '/' + GRAV_FILE_NAME) for Line in f: s = Line.strip().split(',') # Explode after stripping off trailing in line UnixTime = int(s[0]) Date = s[1] Time = s[2] Gravity = s[3] if UnixTime >= START_UNIX_TIME: # Skip records older then START_UNIX_TIME x = UnixTime Lat_Interpolated = evalSpline(xData,yLatData,kLat,x) Lon_Interpolated = evalSpline(xData,yLonData,kLon,x) Depth_Interpolated = evalSpline(xDepthData,yDepthData,kDepth,x) if Depth_Interpolated <= 0.0: Depth_Interpolated = 0.0 RecordsWritten +=1 g.write("%d,%s,%s,%1.9f,%1.9f,%1.1f,%s\n" % \ (UnixTime, Date, Time, Lat_Interpolated, Lon_Interpolated, Depth_Interpolated, Gravity)) f.close() g.close() print "Done" print "Wrote %d records to file: %s" % (RecordsWritten, OUTFILE)