d = (temp[1,a,b]-temp[0,a,b])/(lyrDepth[1]-lyrDepth[0]) * \ (depth-lyrDepth[0]) + temp[0,a,b] else: ind = closest_num(depth, lyrDepth) d = (temp[ind,a,b]-temp[ind-1,a,b])/(lyrDepth[ind]-lyrDepth[ind-1]) * \ (depth-lyrDepth[ind-1]) + temp[ind-1,a,b] t.append(d) modTemp.append(t) modTemp = np.array(modTemp) return modTemp #########################################MAIN CODE##################################################################################################### FONTSIZE = 25 obs = pd.read_csv('ctdWithModTempByDepth.csv') # Extracted from "errorMap.py" tf_index = np.where(obs['TF'].notnull())[0] # Get the index of good data. obsLon, obsLat = obs['LON'][tf_index], obs['LAT'][tf_index] obsTime = pd.Series(np_datetime(obs['END_DATE'][tf_index]), index=tf_index) obsTemp = pd.Series(str2ndlist(obs['TEMP_VALS'][tf_index]), index=tf_index) # obsTemp = pd.Series(bottom_value(obs['TEMP_VALS'][tf_index]), index=tf_index) obsDepth = pd.Series(str2ndlist(obs['TEMP_DBAR'][tf_index]), index=tf_index) # obsDepth = obs['MAX_DBAR'][tf_index] modLayer = pd.Series(str2ndlist(obs['modDepthLayer'][tf_index],bracket=True), index=tf_index) # bracket is to get rid of symbol "[" and "]" in string modNearestIndex = pd.Series(str2ndlist(obs['modNearestIndex'][tf_index], bracket=True), index=tf_index) starttime = datetime(2009, 8, 24) endtime = datetime(2013, 12, 13) # for depth tempMod = pd.Series(str2ndlist(obs['modTempByDepth'][tf_index],bracket=True), index=tf_index) ''' # for layers tempObj = wtm.waterCTD() url = tempObj.get_url(starttime, endtime)
cbar.ax.set_yticks(fontsize=20) plt.axis([0, 30, 0, 30]) plt.xticks(fontsize=20) plt.yticks(fontsize=20) plt.plot(x, x, 'r-', linewidth=2) plt.plot(x2, y2, 'y-', linewidth=2) # plt.title('R-squard: %.4f' % r_squared, fontsize=FONTSIZE) plt.savefig('obsVSmodelDeepestBottom2.png', dpi=200) return ax1, ax2, r_squared #############################MAIN CODE########################################### FONTSIZE = 14 # obs = pd.read_csv('ctd_extract_TF.csv') obs = pd.read_csv('ctdWithModTempByDepth.csv') obstime1 = np_datetime(obs['END_DATE']) tf_index = np.where((obs['TF'].notnull()) & (obstime1 >= datetime(2009, 10, 11, 2, 0)))[0] obslat, obslon = obs['LAT'][tf_index].values, obs['LON'][tf_index].values obstime = np_datetime(obs['END_DATE'][tf_index]) # obsdepth = mean_value(obs['TEMP_DBAR'][tf_index]) obsdepth = obs['MAX_DBAR'][tf_index].values # obstemp = mean_value(obs['TEMP_VALS'][tf_index]) obstemp = bottom_value(obs['TEMP_VALS'][tf_index]) obsdata = pd.DataFrame({ 'depth': obsdepth, 'temp': obstemp, 'lon': obslon, 'lat': obslat, 'time': obstime }).sort_index(by='depth')
obsturtle_id=pd.Series(obsData['PTT'][tf_index],index=tf_index) secondData=pd.read_csv('12487_location.csv') tf_index1 = np.where(secondData['index'].notnull())[0] time=pd.Series(secondData['time'],index=tf_index1) depth=pd.Series(secondData['depth'],index=tf_index1) temp=pd.Series(secondData['temp'],index=tf_index1) lon=pd.Series(secondData['lon'],index=tf_index1) lat=pd.Series(secondData['lat'],index=tf_index1) inde=pd.Series(secondData['index'],index=tf_index1) indx=[] for i in tf_index: if obsturtle_id[i]==118905: #this turtle is same turtle with 4-second turtle indx.append(i) obsLon, obsLat = obsData['LON'][indx], obsData['LAT'][indx] obsTime = pd.Series(np_datetime(obsData['END_DATE'][indx]), index=indx) obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS'][indx]), index=indx) obsDepth = pd.Series(str2ndlist(obsData['TEMP_DBAR'][indx]), index=indx) modTemp = pd.Series(obsData['modTempByDepth'],index=indx) for i in indx: modTemp[i]=str2list(modTemp[i],bracket=True) INDX=[] for j in tf_index1: if i==inde[j]: INDX.append(j) #find indices which are in same area fig=plt.figure() ax=fig.add_subplot(111) ax.plot(temp[INDX],depth[INDX],'ro-', label='raw',linewidth=1) ax.plot(modTemp[i],obsDepth[i],'go--' ,label='roms',linewidth=3) ax.plot(obsTemp[i],obsDepth[i],'bo--', label='telemetered',linewidth=3) ax.set_xlim([0, 30])
hycom_Data = pd.read_csv('ctd_withHYCOMtemp.csv') tf_index = np.where(obsData['TF'].notnull())[0] obsturtle_id = pd.Series(obsData['PTT'][tf_index], index=tf_index) indx = [] for i in tf_index: if obsturtle_id[i] == example[e]: # we can get each turtle's ILD indx.append(i) Temp = pd.Series(str2ndlist(obsData['TEMP_VALS'][indx]), index=indx) Indx = [] # get rid of the profile without ten record points for i in indx: if len(Temp[i]) == 10: Indx.append(i) Data = obsData.ix[Indx] HYCOM_Data = hycom_Data.ix[Indx] print 'len(roms_tf): ', len(Indx) obsTime = pd.Series(np_datetime(Data['END_DATE'].values), index=Indx) obsTemp = pd.Series(str2ndlist(Data['TEMP_VALS'].values), index=Indx) obsDepth = pd.Series(str2ndlist(Data['TEMP_DBAR'].values), index=Indx) modTemp = pd.Series(str2ndlist(Data['modTempByDepth'].values, bracket=True), index=Indx) hycom_Temp = pd.Series(str2ndlist(HYCOM_Data['modtemp_HYCOM'].values, bracket=True), index=Indx) fvcom_Data = pd.read_csv('ctdWithdepthofbottom_fvcom.csv') tf = np.where(fvcom_Data['in FVcom range'].notnull())[ 0] # get the index of good data fvcom_id = pd.Series(obsData['PTT'][tf], index=tf) indx1 = [] for i in tf:
cbar.ax.set_yticks(fontsize=20) plt.axis([0, 30, 0, 30]) plt.xticks(fontsize=20) plt.yticks(fontsize=20) plt.plot(x, x, 'r-', linewidth=2) plt.plot(x2, y2, 'y-', linewidth=2) # plt.title('R-squard: %.4f' % r_squared, fontsize=FONTSIZE) plt.savefig('obsVSmodelDeepestBottom2.png',dpi=200) return ax1, ax2, r_squared #############################MAIN CODE########################################### FONTSIZE = 25 # obs = pd.read_csv('ctd_extract_TF.csv') obs = pd.read_csv('ctd_good.csv') tf_index = np.where(obs['TF'].notnull())[0] obslat, obslon = obs['LAT'][tf_index].values, obs['LON'][tf_index].values obstime = np_datetime(obs['END_DATE'][tf_index]) # obsdepth = mean_value(obs['TEMP_DBAR'][tf_index]) obsdepth = obs['MAX_DBAR'][tf_index].values # obstemp = mean_value(obs['TEMP_VALS'][tf_index]) obstemp = bottom_value(obs['TEMP_VALS'][tf_index]) obsdata = pd.DataFrame({'depth':obsdepth, 'temp':obstemp, 'lon':obslon, 'lat':obslat, 'time':obstime}).sort_index(by='depth') starttime = datetime(2009, 8, 24) endtime = datetime(2013,12 ,13) tempobj = wtm.water_roms() url = tempobj.get_url(starttime, endtime) # temp = tempobj.watertemp(obslon, obslat, obsdepth, obstime, url) temp = tempobj.watertemp(obsdata['lon'].values, obsdata['lat'].values, obsdata['depth'].values, obsdata['time'].values, url) temp = pd.Series(temp, index = obsdata['temp'].index)
''' Extract data file ctd_extract_good.csv, add new column "TF". If TF==True, data is good. If TF==False, data is bad. ''' import pandas as pd import numpy as np from datetime import datetime, timedelta from turtleModule import mon_alpha2num, np_datetime, dist r = 3 # the ctd position that has gps position within (r) kilometers might be considered as good data. hour = 3 # the ctd time that has gps time within (hour) hours might be considered as good data. ctd = pd.read_csv('2014_04_16_rawctd.csv') # original data file ctdlat = ctd['LAT'] ctdlon = ctd['LON'] ctdtime = np_datetime(ctd['END_DATE']) gps = pd.read_csv('2014_04_16_rawgps.csv') # orginal data file gpslat = gps['LAT'] gpslon = gps['LON'] gpstime = np_datetime(gps['D_DATE']) lonsize = [np.min(ctdlon), np.max(ctdlon)] latsize = [np.min(ctdlat), np.max(ctdlat)] index = [] i = 0 for lat, lon, ctdtm in zip(ctdlat, ctdlon, ctdtime): l = dist(lon, lat, gpslon, gpslat) p = np.where(l < r) maxtime = ctdtm + timedelta(hours=hour) mintime = ctdtm - timedelta(hours=hour) mx = gpstime[p[0]] < maxtime mn = gpstime[p[0]] > mintime
""" Extract data file ctd_extract_good.csv, add new column "TF". If TF==True, data is good. If TF==False, data is bad. """ import pandas as pd import numpy as np from datetime import datetime, timedelta from turtleModule import mon_alpha2num, np_datetime, dist r = 3 # the ctd position that has gps position within (r) kilometers might be considered as good data. hour = 3 # the ctd time that has gps time within (hour) hours might be considered as good data. ctd = pd.read_csv("2014_04_16_rawctd.csv") # original data file ctdlat = ctd["LAT"] ctdlon = ctd["LON"] ctdtime = np_datetime(ctd["END_DATE"]) gps = pd.read_csv("2014_04_16_rawgps.csv") # orginal data file gpslat = gps["LAT"] gpslon = gps["LON"] gpstime = np_datetime(gps["D_DATE"]) lonsize = [np.min(ctdlon), np.max(ctdlon)] latsize = [np.min(ctdlat), np.max(ctdlat)] index = [] i = 0 for lat, lon, ctdtm in zip(ctdlat, ctdlon, ctdtime): l = dist(lon, lat, gpslon, gpslat) p = np.where(l < r) maxtime = ctdtm + timedelta(hours=hour) mintime = ctdtm - timedelta(hours=hour) mx = gpstime[p[0]] < maxtime
from turtleModule import str2ndlist,draw_basemap,np_datetime,whichArea ################################################################################### criteria =10 # criteria for error url = 'http://tds.marine.rutgers.edu:8080/thredds/dodsC/roms/espresso/hidden/2006_da/his?lon_rho[0:1:81][0:1:129],lat_rho[0:1:81][0:1:129],u[0:1:69911][0:1:35][0:1:81][0:1:128],v[0:1:69911][0:1:35][0:1:80][0:1:129]' data = netCDF4.Dataset(url) lons, lats = data.variables['lon_rho'], data.variables['lat_rho'] lonA, latA = lons[81][0], lats[81][0] # Vertex of ROMS area. lonB, latB = lons[81][129], lats[81][129] lonC, latC = lons[0][129], lats[0][129] lonD, latD = lons[0][0], lats[0][0] obsData = pd.read_csv('ctdWithdepthofbottom_roms.csv') modTemp = pd.Series(str2ndlist(obsData['modTempByDepth'],bracket=True), index=obsData.index) # if str has '[' and ']', bracket should be True obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS']), index=obsData.index) obsDepth = pd.Series(str2ndlist(obsData['TEMP_DBAR']), index=obsData.index) obsTime = pd.Series(np_datetime(obsData['END_DATE']),index=obsData.index) depthBottom = pd.Series(obsData['depth_bottom'],index=obsData.index) for i in obsData.index: if depthBottom[i]>200: depthBottom[i]=200 #Just a little points are deeper than 200m.Removing them can plot depth betterex) obsLons, obsLats = obsData['LON'], obsData['LAT'] lon_i = np.linspace(-78,-69,100) lat_i = np.linspace(33,42,100) depth_i=griddata(np.array(obsLons),np.array(obsLats),np.array(depthBottom),lon_i,lat_i,interp='linear') SPRING=[] SUMMER=[] FALL=[] WINTER=[] YEAR=[] for i in obsTime.index:
import matplotlib.pyplot as plt from turtleModule import dist,np_datetime #############################main code################################################## obsData = pd.read_csv('ctdWithModTempByDepth.csv') tf_index = np.where(obsData['TF'].notnull())[0] obsturtle_id=pd.Series(obsData['PTT'][tf_index],index=tf_index) obsturtle_ids=obsturtle_id.unique() turtle_id=obsturtle_ids[0] #which turtle you want to plot.such as 0~106 indx=[] #collect index of the turtle which you want to plot for i in tf_index: if obsturtle_id[i] == turtle_id: indx.append(i) obs=obsData.ix[indx] goodTime=pd.Series(np_datetime(obs['END_DATE']), index=indx) goodlons=pd.Series(obs['LON'], index=indx) goodlats=pd.Series(obs['LAT'], index=indx) d=pd.DataFrame({'Time':goodTime,'lon':goodlons,'lat':goodlats},index=indx) d=d.sort(['Time']) d.index=range(len(d)) diff_dist=[] #collect distance diff_time=[] #collect time for i in d.index: if i+1 == len(d): break dis=dist(d['lon'][i],d['lat'][i],d['lon'][i+1],d['lat'][i+1]) diff_dist.append(dis) t=(d['Time'][i+1]-d['Time'][i]).total_seconds()/3600 diff_time.append(t) time_ave=round(np.mean(diff_time),2)
''' import numpy as np import pandas as pd from datetime import datetime, timedelta import netCDF4 import matplotlib.pyplot as plt from matplotlib import path from turtleModule import mon_alpha2num, np_datetime, str2list from watertempModule import water_roms ###########################main code################################################# ctddata = pd.read_csv('ctdWithModTempByDepth.csv') shallow = ctddata.ix[17] # 17, 19, 22 deep = ctddata.ix[13469] # 18914 shallowtime = np_datetime(shallow['END_DATE']) shallowtemp = [float(temp) for temp in shallow['TEMP_VALS'].split(',')] #modelobj = water_roms() #modelurl = modelobj.get_url(shallowtime, shallowtime+timedelta(hours=1)) depth = [int(dep) for dep in shallow['TEMP_DBAR'].split(',')] modeltemp = str2list(shallow['modTempByDepth'], bracket=True) ''' modeltemp = [] for dep in depth: print dep modeltemp.append(modelobj.watertemp(shallow['LON'], shallow['LAT'], dep, shallowtime, modelurl)) ''' deeptime = np_datetime(deep['END_DATE']) deeptemp = [float(temp) for temp in deep['TEMP_VALS'].split(',')] #modelobj2 = water_roms()
Created on Thu Feb 19 12:06:47 2015 'compare temperature of turtle and roms model before and after a storm' @author: zdong,yifan """ import numpy as np import pandas as pd import matplotlib as mpl from datetime import datetime,timedelta import matplotlib.pyplot as plt from turtleModule import str2ndlist,dist,np_datetime ################################################################## obsData=pd.read_csv('tu94wModel.csv',index_col=0) turtle_id=obsData['PTT'] obslat = obsData['LAT'] obslon = obsData['LON'] obstime = pd.Series(np_datetime(obsData['date']),index=obsData.index) obsDepth=pd.Series(str2ndlist(obsData['obstemp']),index=obsData.index) obstemp=pd.Series(str2ndlist(obsData['depth']),index=obsData.index) buoyData=pd.read_csv('ndbc_2011.csv') #data of wind speed and wave height in 2011 tf_index=np.where(buoyData['TF'].notnull())[0] buoylat = pd.Series(buoyData['lat'],index=tf_index) buoylon = pd.Series(buoyData['lon'],index=tf_index) buoyspeed=pd.Series(buoyData['wind_speed'],index=tf_index) buoywave=pd.Series(buoyData['wave_height'],index=tf_index) buoytime = pd.Series(buoyData['Date'],index=tf_index) indx=[] for i in tf_index: buoytime[i]=datetime.strptime(buoytime[i], "%Y-%m-%d %H:%M") # change str to datatime if 17.2<buoyspeed[i]: if buoywave[i]>5.5:
''' Extract data file ctd_extract_good.csv, add new column "TF". If TF==True, data is good. If TF==False, data is bad. ''' import pandas as pd import numpy as np from datetime import datetime, timedelta from turtleModule import mon_alpha2num, np_datetime, dist r = 3 # the ctd position that has gps position within (r) kilometers might be considered as good data. hour = 3 # the ctd time that has gps time within (hour) hours might be considered as good data. ctd = pd.read_csv('2014_04_16_rawctd.csv') # original data file ctdlat = ctd['LAT'] ctdlon = ctd['LON'] ctdtime = np_datetime(ctd['END_DATE']) gps = pd.read_csv('2014_04_16_rawgps.csv') # orginal data file gpslat = gps['LAT'] gpslon = gps['LON'] gpstime = np_datetime(gps['D_DATE']) lonsize = [np.min(ctdlon), np.max(ctdlon)] latsize = [np.min(ctdlat), np.max(ctdlat)] index = [] i = 0 for lat, lon, ctdtm in zip(ctdlat, ctdlon, ctdtime): l = dist(lon, lat, gpslon, gpslat) p = np.where(l<r) maxtime = ctdtm+timedelta(hours=hour) mintime = ctdtm-timedelta(hours=hour) mx = gpstime[p[0]]<maxtime mn = gpstime[p[0]]>mintime
import matplotlib.pyplot as plt from turtleModule import dist, np_datetime #############################main code################################################## obsData = pd.read_csv('ctdWithModTempByDepth.csv') tf_index = np.where(obsData['TF'].notnull())[0] obsturtle_id = pd.Series(obsData['PTT'][tf_index], index=tf_index) obsturtle_ids = obsturtle_id.unique() turtle_id = obsturtle_ids[0] #which turtle you want to plot.such as 0~106 indx = [] #collect index of the turtle which you want to plot for i in tf_index: if obsturtle_id[i] == turtle_id: indx.append(i) obs = obsData.ix[indx] goodTime = pd.Series(np_datetime(obs['END_DATE']), index=indx) goodlons = pd.Series(obs['LON'], index=indx) goodlats = pd.Series(obs['LAT'], index=indx) d = pd.DataFrame({ 'Time': goodTime, 'lon': goodlons, 'lat': goodlats }, index=indx) d = d.sort(['Time']) d.index = range(len(d)) diff_dist = [] #collect distance diff_time = [] #collect time for i in d.index: if i + 1 == len(d): break
@author: zhobin """ 'compare temperature before and after a storm' import numpy as np import pandas as pd import matplotlib as mpl from datetime import datetime,timedelta import matplotlib.pyplot as plt from turtleModule import str2ndlist,dist,np_datetime ################################################################## obsData=pd.read_csv('ctdwithoutbad_roms.csv',index_col=0) turtle_id=pd.Series(obsData['PTT'],index=obsData.index) obslat = pd.Series(obsData['LAT'],index=obsData.index) obslon = pd.Series(obsData['LON'],index=obsData.index) obstime = pd.Series(np_datetime(obsData['END_DATE']),index=obsData.index) obsDepth=pd.Series(str2ndlist(obsData['TEMP_DBAR']),index=obsData.index) obstemp=pd.Series(str2ndlist(obsData['TEMP_VALS']),index=obsData.index) buoyData=pd.read_csv('ndbc_2011.csv') #data of wind speed and wave height in 2011 tf_index=np.where(buoyData['TF'].notnull())[0] buoylat = pd.Series(buoyData['lat'],index=tf_index) buoylon = pd.Series(buoyData['lon'],index=tf_index) buoyspeed=pd.Series(buoyData['wind_speed'],index=tf_index) buoywave=pd.Series(buoyData['wave_height'],index=tf_index) buoytime = pd.Series(buoyData['Date'],index=tf_index) indx=[] for i in tf_index: buoytime[i]=datetime.strptime(buoytime[i], "%Y-%m-%d %H:%M") # change str to datatime if 17.2<buoyspeed[i]: if buoywave[i]>5.5:
# -*- coding: utf-8 -*- """ Created on Mon Jan 26 09:06:18 2015 @author: zhaobin """ 'make a movie about each turtle`s temperature' import pandas as pd import numpy as np import matplotlib.pyplot as plt from matplotlib import animation from datetime import datetime from turtleModule import str2ndlist, np_datetime ############################################################################# obsData = pd.read_csv('ctdwithoutbad.csv', index_col=0) obsTime = pd.Series(np_datetime(obsData['END_DATE']), index=obsData.index) #obsData=obsData.sort_index(by='END_DATE') modTemp = pd.Series( str2ndlist(obsData['modTempByDepth'], bracket=True), index=obsData.index) # if str has '[' and ']', bracket should be True obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS']), index=obsData.index) obsDepth = pd.Series(str2ndlist(obsData['TEMP_DBAR']), index=obsData.index) obsLon, obsLat = obsData['LON'], obsData['LAT'] obsturtle_id = pd.Series(obsData['PTT'], index=obsData.index) obsturtle_ids = obsturtle_id.unique() length = len(obsturtle_ids) #length is number of turtles ids = [] for i in range(length): ids.append([]) for i in range(length): for j in obsData.index:
a, b, c = v[i-1], v[i], v[i+1] diff1 = abs(b - c) #diff1 is not used diff2 = abs(b - a) if diff2>e: v[i] = a return v ######################################################### obsData = pd.read_csv('ctdWithModTempByDepth.csv', index_col=0) tf_index = np.where(obsData['TF'].notnull())[0] obsData = obsData.ix[tf_index] id = obsData['PTT'].drop_duplicates().values tID = id[3] # 0~4, 6,7,8,9, turtle ID. layers = pd.Series(str2ndlist(obsData['modDepthLayer'], bracket=True), index=obsData.index) # If str has '[' and ']', bracket should be True. modNearestIndex = pd.Series(str2ndlist(obsData['modNearestIndex'].values, bracket=True), index=obsData.index) obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS'].values), index=obsData.index) obsTime = pd.Series(np_datetime(obsData['END_DATE'].values), index=obsData.index) modTemp = pd.Series(str2ndlist(obsData['modTempByDepth'].values,bracket=True), index=obsData.index) layers = layers[obsData['PTT']==tID] modNearestIndex = modNearestIndex[obsData['PTT']==tID] time = obsTime[obsData['PTT']==tID] temp = obsTemp[obsData['PTT']==tID] #modTemp=pd.Series(str2ndlist(obsData['TEMP_VALS'][temp.index],bracket=True), index=temp.index) ''' starttime, endtime=np.amin(time), np.amax(time)+timedelta(hours=1) modObj = wtm.waterCTD() url = modObj.get_url(starttime, endtime) #something wrong with ROMS website oceantime = netCDF4.Dataset(url).variables['ocean_time'] modTempAll = netCDF4.Dataset(url).variables['temp'] modTemp = getModTemp(modTempAll, obsTime, layers, modNearestIndex, starttime, oceantime) modTemp = pd.Series(modTemp, index=temp.index) '''
import pandas as pd import numpy as np import matplotlib.pyplot as plt from turtleModule import str2ndlist,np_datetime from datetime import timedelta obsData = pd.read_csv('ctdWithModTempByDepth.csv') tf_index = np.where(obsData['TF'].notnull())[0] # get the index of good data obsturtle_id=pd.Series(obsData['PTT'][tf_index],index=tf_index) indx=[] # this indx is to get the specifical turtle all index in obsData ,if we use the "where" function ,we just get the length of tf_index. for i in tf_index: if obsturtle_id[i]==129777: #we can change the turtle id we interest indx.append(i) Temp = pd.Series(str2ndlist(obsData['TEMP_VALS'][indx]), index=indx) Time = pd.Series(np_datetime(obsData['END_DATE'][indx]), index=indx) Time.sort() Indx=[] for i in Time.index: if len(Temp[i])==10: Indx.append(i) Data = obsData.ix[Indx] obsTime = pd.Series(np_datetime(Data['END_DATE'].values), index=Indx) obsTemp = pd.Series(str2ndlist(Data['TEMP_VALS'].values), index=Indx) obsDepth = pd.Series(str2ndlist(Data['TEMP_DBAR'].values), index=Indx) Index=range(len(Indx)) obsTime.index=Index obsTemp.index=Index obsDepth.index=Index
obsData = pd.read_csv('ctdWithModTempByDepth.csv') tf_index = np.where(obsData['TF'].notnull())[0] # get the index of good data obsturtle_id = pd.Series(obsData['PTT'][tf_index], index=tf_index) secondData = pd.read_csv('turtle_12487_tdr.csv') time = pd.Series(secondData['Date']) depth = pd.Series(secondData['Depth']) temp = pd.Series(secondData['temp']) indx = [] for i in tf_index: if obsturtle_id[ i] == 118905: #this turtle is same turtle with 4-second turtle indx.append(i) obsLon, obsLat = obsData['LON'][indx], obsData['LAT'][indx] obsTime = pd.Series(np_datetime(obsData['END_DATE'][indx]), index=indx) obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS'][indx]), index=indx) obsDepth = pd.Series(str2ndlist(obsData['TEMP_DBAR'][indx]), index=indx) INDX = [] for i in secondData.index[0:2200000]: #after 2200000,time is > 2014 time[i] = datetime.strptime(time[i], "%Y/%m/%d %H:%M:%S") # change str to datatime if time[i].year == 2013: if time[i].month == 5: if time[i].day > 22: INDX.append(i) if 5 < time[i].month < 9: INDX.append(i) #get in same time if i % 100000 == 0: print(i)
from turtleModule import np_datetime obsData = pd.read_csv('ctdWithModTempByDepth.csv') obsturtle_id = pd.Series(obsData['REF']) obsturtle_ids = obsturtle_id.unique() ids = [] #collect all indexes of each turtle for i in range(len(obsturtle_ids)): ids.append([]) for j in range(len(obsturtle_id)): if obsturtle_id[j] == obsturtle_ids[i]: ids[i].append(j) time_aves = [] #collect each turtle`s average profile for i in range(len(ids)): obs = obsData.ix[ids[i]] d = pd.Series(np_datetime(obs['END_DATE']), index=ids[i]) d = d.order() d.index = range(len(d)) diff_time = [ ] #list the number of days between every two profile of each turtle for j in d.index: if j + 1 == len(d): break t = (d[j + 1] - d[j]).total_seconds() / 3600 / 24 diff_time.append(t) if sum(diff_time) == 0: print i else: time_ave = round((len(d) / sum(diff_time)), 1) #profile per day for each turtle (average) time_aves.append(time_ave)
######################################################### obsData = pd.read_csv('ctdWithModTempByDepth.csv', index_col=0) tf_index = np.where(obsData['TF'].notnull())[0] obsData = obsData.ix[tf_index] id = obsData['PTT'].drop_duplicates().values #print('turtle id:', id) tID = id[3] # 0~4, 6,7,8,9, turtle ID. layers = pd.Series( str2ndlist(obsData['modDepthLayer'], bracket=True), index=obsData.index) # If str has '[' and ']', bracket should be True. modNearestIndex = pd.Series(str2ndlist(obsData['modNearestIndex'].values, bracket=True), index=obsData.index) obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS'].values), index=obsData.index) obsTime = pd.Series(np_datetime(obsData['END_DATE'].values), index=obsData.index) modTemp = pd.Series(str2ndlist(obsData['modTempByDepth'].values, bracket=True), index=obsData.index) layers = layers[obsData['PTT'] == tID] modNearestIndex = modNearestIndex[obsData['PTT'] == tID] time = obsTime[obsData['PTT'] == tID] temp = obsTemp[obsData['PTT'] == tID] #modTemp=pd.Series(str2ndlist(obsData['TEMP_VALS'][temp.index],bracket=True), index=temp.index) ''' starttime, endtime=np.amin(time), np.amax(time)+timedelta(hours=1) modObj = wtm.waterCTD() url = modObj.get_url(starttime, endtime) #something wrong with ROMS website oceantime = netCDF4.Dataset(url).variables['ocean_time'] modTempAll = netCDF4.Dataset(url).variables['temp'] modTemp = getModTemp(modTempAll, obsTime, layers, modNearestIndex, starttime, oceantime)
elif depth < lyrDepth[0]: # Obs is deeper than first layer which is the bottom. Temp = (temp[1,a,b]-temp[0,a,b])/(lyrDepth[1]-lyrDepth[0]) * \ (depth-lyrDepth[0]) + temp[0,a,b] else: ind = closest_num(depth, lyrDepth) Temp = (temp[ind,a,b]-temp[ind-1,a,b])/(lyrDepth[ind]-lyrDepth[ind-1]) * \ (depth-lyrDepth[ind-1]) + temp[ind-1,a,b] t.append(Temp) modTemp.append(t) modTemp = np.array(modTemp) return modTemp FONTSIZE = 25 obsData = pd.read_csv('ctd_good.csv') tf_index = np.where(obsData['TF'].notnull())[0] obsLon, obsLat = obsData['LON'][tf_index], obsData['LAT'][tf_index] obsTime = pd.Series(np_datetime(obsData['END_DATE'][tf_index]), index=tf_index) obsTemp = pd.Series(str2ndlist(obsData['TEMP_VALS'][tf_index]), index=tf_index) # obsTemp = pd.Series(bottom_value(obs['TEMP_VALS'][tf_index]), index=tf_index) obsDepth = pd.Series(str2ndlist(obsData['TEMP_DBAR'][tf_index]), index=tf_index) modLayer = pd.Series(str2ndlist(obsData['modDepthLayer'][tf_index],bracket=True), index=tf_index) modNearestIndex = pd.Series(str2ndlist(obsData['modNearestIndex'][tf_index], bracket=True), index=tf_index) starttime = datetime(2009, 8, 24) endtime = datetime(2013, 12, 13) tempObj = wtm.waterCTD() url = tempObj.get_url(starttime, endtime) # modTemp1 = tempObj.watertemp(obsLon.values, obsLat.values, obsDepth.values, obsTime.values, url) modDataAll = tempObj.get_data(url) oceantime = modDataAll['ocean_time'] modTempAll = modDataAll['temp'] s_rho = modDataAll['s_rho']
depth=(-h*siglay).transpose() #each layer`s depth Depth=[] for i in range(len(depth)): d=[] for j in depth[i]: d.append(round(j,3)) Depth.append(d) modData['depthBYlayer']=pd.Series(Depth) obsData=pd.read_csv('ctd_extract_good.csv') tf_index=np.where(obsData['TF'].notnull())[0] #this is turtle data obslat=pd.Series(obsData['LAT'][tf_index],index=tf_index) obslon=pd.Series(obsData['LON'][tf_index],index=tf_index) obsDepth = pd.Series(str2ndlist(obsData['TEMP_DBAR'][tf_index]), index=tf_index) obsTime=pd.Series(np_datetime(obsData['END_DATE'][tf_index]),index=tf_index) #this is CTD ''' obsData=pd.read_csv('ship06-08_ch.csv') #this is ship data obslat=pd.Series(str2ndlist(obsData['lat'],bracket=True)) obslon=pd.Series(str2ndlist(obsData['lon'],bracket=True)) obsDepth = pd.Series(str2ndlist(obsData['depth'],bracket=True)) obsTime=pd.Series(obsData['time']) for i in range(len(obsTime)): obsTime[i]=datetime.strptime(obsTime[i], "%Y-%m-%d %H:%M:%S") # change str to datatime #this is ship ''' pp=[(-75.6127,38.2253) ,(-75.6394,39.8235),(-74.3474,40.7558),(-69.9301,44.6404),(-61.717,46.9046),(-57.1221,41.8435)] for q in range(67,99): pp.append((modData['lon'][q],modData['lat'][q])) #range of fvcom FV_index=[]