Example #1
0
        if m > max_abs_pressure:
            max_abs_pressure = m
        m_ind = [i for i, j in enumerate(data['pressure']) if j ==m] # this line finds the index of the max depth
        
        
        #this loop here will take the readings only when the fish is going down
        for j in names:
            vars()[j] = []
            for i in np.arange(1,float(m_ind[0])):
                if data['pressure'][i]-data['pressure'][i-1] >0:
                    vars()[j].append(data[str(j)][i])
                    
        depth = sw.depth(pressure, xyzt['lat_DD.dd'])        
        c3515 = 42.9140
        condr = [x/c3515 for x in cond]
        salinity = sw.salt(condr, temp, pressure)
        density = sw.dens(salinity, temp,pressure)  
        griddeddata=[]
    
        for k in names2:
            griddeddata = np.interp(grid_depth,depth,vars()[k],right=np.NaN)
            griddeddata = griddeddata[0:]
            vars()['grid_'+k][:,file[0]] = vars()['griddeddata']

        f.close()
    except:
        failedloadfiles.append(str(file))
        print ("Could not process " + file[1])
        for k in names2:
            vars()['grid_'+k][:,file[0]] = np.NaN
def parseScience(gliderTbdDir, fileType):
    """
    Module:     parseScience()
    Date:       2012-11-27
    Author:     [email protected]
    Modified:   2013-10-15
        By:     [email protected]
    Inputs:     None
    Outputs:    Inserts into SQLite database file
    Purpose:    Grabs a db cursor and calls dbd2asc for all non-parsed tbd
                files. Looks for 'sci_' and splits sensor list. Finds pos
                of sensors of interest so list can change if tbdlist.dat
                changes. Uses pos of SOI to store values in correct field.
    """

    cur = gliderlog.cursor()
    curParsed = gliderlog.cursor()
    sbdParsedStructure = 0
    #
    #Regex for lines beginning with m_present_time
    #m_present_time structure: '1277271054.36734
    pattMPresentTime = re.compile(r'1[0-9]{9}\.[0-9]{5}')
    #
    select = "select %sfile from %sFiles where parsed = 0 \
ORDER BY %sfile ASC" % (fileType, fileType, fileType)
    cur.execute(select)
    for(tbdFile) in cur:
        if DEBUG > 0:
            print "Running dbd2asc on %s/%s" % (gliderTbdDir, tbdFile[0])
        command = "/opt/dinkum/dbd2asc -c /opt/glider_data_pipeline/cache \
%s/%s" % (gliderTbdDir, tbdFile[0])
        p = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
        (sIn, sOut) = (p.stdin, p.stdout)
        myBuffer = sOut.xreadlines()
        #
        curInsert = gliderlog.cursor()
        curInsert.execute('begin')
        for (line) in myBuffer:
            #2011-06-02 rdc changed to sci_ to reflect new tbd file format
            #Look to see if line starts with "sci_"  -- assume that a list
            #of sensors follows. Split into sensors, create tbdSensors
            #table and store values in tbdSensorReadings.
            if (line.startswith("sci_")):
                #we need to split and create here, not print
                sensorList = line.split()
                if (DEBUG > 1):
                    print "sensorList: %s" % (sensorList)
                if DEBUG > 1:
                    for (sensor) in sensorList:
                        print "Factored %s" % (sensor)
                #Get order of sensors
                m_present_timePos = sensorList.index('sci_m_present_time')
                sci_water_tempPos = sensorList.index('sci_water_temp')
                sci_water_condPos = sensorList.index('sci_water_cond')
                sci_water_pressurePos = sensorList.index('sci_water_pressure')
                sci_bbfl2s_chlor_scaledPos = sensorList.index('sci_bbfl2s_chlor_scaled')

            if pattMPresentTime.search(line):
                index = 0
                matchobj = pattMPresentTime.search(line)
                if matchobj:
                    if DEBUG > 1:
                        print "MATCH ON pattMPresentTime"
                        print "m_present_time: %s" % matchobj.group(0)
                    m_present_time = float(matchobj.group(0))
                    line  = line.replace('NaN','nan')
                    sensorReadings = line.split()
                    if DEBUG > 1:
                        print sensorReadings
                sci_water_cond = float(sensorReadings[sci_water_condPos])
                sci_water_temp = float(sensorReadings[sci_water_tempPos])
                sci_water_pressure = float(sensorReadings[sci_water_pressurePos])
                sci_water_condRatio = (sci_water_cond*0.23302418791070513)
                #Salinity and density calculations and db update
            #
                if (sci_water_condRatio > 0 and sci_water_temp > 0 and \
sci_water_pressure > 0):
                    calc_salinity = sw.salt(sci_water_condRatio, \
sci_water_temp, sci_water_pressure)

                    #get most recent position
                    #[TO DO] Fudge it for now -- add to plotValues
                    lon = -82
                    lat = 27
                    absSalinty = gsw.SA_Sstar_from_SP(calc_salinity, \
sci_water_pressure, lon, lat)[0]
                    calc_density = (gsw.rho(absSalinty, sci_water_temp, \
sci_water_pressure) - 1000)
                else:
                    sci_water_condRatio = 'nan'
                    calc_salinity = 'nan'
                    calc_density = 'nan'
                    absSalinty = 'nan'

                curInsert.execute("INSERT INTO plotValues(m_present_time,\
m_depth, m_water_depth, sci_water_temp, sci_water_cond, sci_water_pressure,\
calc_salinity, absSalinty, calc_density,sci_bbfl2s_chlor_scaled, sci_moteopd_corr1,\
sci_moteopd_corr2,sci_moteopd_corr3,sci_moteopd_corr4,sci_moteopd_corr5,\
sci_moteopd_corr6,sci_moteopd_corr7,sci_moteopd_corr8,sci_moteopd_corr9,\
sci_moteopd_corr10,sci_moteopd_corr11,m_avg_climb_rate,m_avg_dive_rate,m_lat, \
m_lon, m_tot_horz_dist, m_avg_speed,sci_moteopd_volt) \
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", \
(sensorReadings[m_present_timePos],'nan','nan',\
sensorReadings[sci_water_tempPos],sci_water_condRatio,\
sensorReadings[sci_water_pressurePos],calc_salinity, \
absSalinty, calc_density,sensorReadings[sci_bbfl2s_chlor_scaledPos],0,0,0,0,0,0,0,0,0,0,0 \
,'nan','nan','nan','nan','nan','nan',0))
        curInsert.execute('commit')
        curInsert.close()
        select = "UPDATE %sFiles set parsed = '1' where %sfile = '%s'" \
% (fileType, fileType, tbdFile[0])
        curParsed.execute(select)
        curParsed.close()
    cur.close()