def getFVcom(latpt,lonpt,time_roms,depth_roms):
    url='http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3'
    nc = netCDF4.Dataset(url)
    lat = nc.variables['lat'][:]
    lon = nc.variables['lon'][:]
    Depth = nc.variables['h'][:]
    siglay=nc.variables['siglay'][:]
    time=nc.variables['time'][:]
    modtemp=nc.variables['temp'] 
    modtime=[]
    for i in range(len(time)):
        t=timedelta(days=float(time[i])).total_seconds()
        modtime.append(t)                        #change time days to seconds
    depth=(-Depth*siglay).transpose()                #each layer`s depth
    distance=dist(lonpt,latpt,lon,lat)
    node=np.argmin(distance)                 #get nearest node
    layer=[]
    for i in depth_roms[0:len(depth_roms)+1]:
        layer.append(np.argmin(abs(i-depth[node])))   #get layer of depth
    t_diff=(time_roms-datetime(1858,11,17)).total_seconds()     #1858,11,17 is FVCOM`s start time
    TIME=np.argmin(abs(t_diff-np.array(modtime)))
    Temp=[]
    for i in range(len(layer)):
        t=modtemp[TIME][i][node]
        Temp.append(t)
    Temp.reverse()
    return Temp
def get_roms(lat,lon,depth,time):
    url_1='http://tds.marine.rutgers.edu:8080/thredds/dodsC/roms/espresso/hidden/2006_da/his'
    nc_1=netCDF4.Dataset(url_1)
    time_1=nc_1.variables['ocean_time'][:]
    lats=nc_1.variables['lat_rho'][:]
    lons=nc_1.variables['lon_rho'][:]
    s_rho=nc_1.variables['s_rho'][:]
    h=nc_1.variables['h'][:]
    temp_1=nc_1.variables['temp']
    url_2='http://tds.marine.rutgers.edu:8080/thredds/dodsC/roms/espresso/2013_da/his_Best/ESPRESSO_Real-Time_v2_History_Best_Available_best.ncd'
    nc_2=netCDF4.Dataset(url_2)
    time_2=nc_2.variables['time'][:]
    temp_2=nc_2.variables['temp']
    TEMP=[]
    for i in depth.index:
        Distance=dist(lat[i],lon[i],lats,lons)
        near_index=np.argmin(Distance)
        index_one,index_two=near_index/len(Distance[0]),near_index%len(Distance[0])
        H=h[index_one,index_two]
        layer_depth=-s_rho*H
        index_D=np.argmin(np.abs(depth[i]-layer_depth))
        if (time[i]-datetime(2013,05,18)).total_seconds()/3600>25: #25 hour is the first time ni 2013_da
            index_T=np.argmin(np.abs((time[i]-datetime(2013,05,18)).total_seconds()/3600-time_2))
            tt=temp_2[index_T,index_D,index_one,index_two]
            if type(tt) not float:
                tt=-10
            TEMP.append(tt)
        else:
            index_T=np.argmin(np.abs((time[i]-datetime(2006,01,01)).total_seconds()-time_1))
            tt=temp_1[index_T,index_D,index_one,index_two]
            if type(tt) not float:
                tt=-10
            TEMP.append(tt)
        print i
Esempio n. 3
0
def get_roms(lat,lon,depth,time):
    url_1='http://tds.marine.rutgers.edu:8080/thredds/dodsC/roms/espresso/hidden/2006_da/his'
    nc_1=netCDF4.Dataset(url_1)
    time_1=nc_1.variables['ocean_time'][:]
    lats=nc_1.variables['lat_rho'][:]
    lons=nc_1.variables['lon_rho'][:]
    s_rho=nc_1.variables['s_rho'][:]
    h=nc_1.variables['h'][:]
    temp_1=nc_1.variables['temp']
    url_2='http://tds.marine.rutgers.edu:8080/thredds/dodsC/roms/espresso/2013_da/his_Best/ESPRESSO_Real-Time_v2_History_Best_Available_best.ncd'
    nc_2=netCDF4.Dataset(url_2)
    time_2=nc_2.variables['time'][:]
    temp_2=nc_2.variables['temp']
    TEMP=[]
    for i in depth.index:
        Distance=dist(lat[i],lon[i],lats,lons)
        near_index=np.argmin(Distance)
        index_one,index_two=near_index/len(Distance[0]),near_index%len(Distance[0])
        H=h[index_one,index_two]
        layer_depth=-s_rho*H
        index_D=np.argmin(np.abs(depth[i]-layer_depth))
        if (time[i]-datetime(2013,05,18)).total_seconds()/3600>25: #25 hour is the first time ni 2013_da
            index_T=np.argmin(np.abs((time[i]-datetime(2013,05,18)).total_seconds()/3600-time_2))
            tt=temp_2[index_T,index_D,index_one,index_two]
            if type(tt) not float:
                tt=-10
            TEMP.append(tt)
def small_dist_index(
    lon, lat, all_lon, all_lat
):  # obtain the index according to the exacted positon within 1 km with all other turtle position
    for i in range(len(all_lon)):
        if all_lon[i] == lon:
            start = i + 1
    index = []  # find the index within 1 kilometers
    for i in range(start, len(all_lon)):
        l = dist(lon, lat, all_lon[i], all_lat[i])
        if l <= 1:
            index.append(i)
    return index
Esempio n. 5
0
def find_range(day,t1,t2,index1,index2,lon1,lat1,lon2,lat2):
    one,two=[],[]
    for r in np.arange(0,30,2):
        ix1,ix2=[],[]
        for i in index1:
            for j in index2:
                
                l = dist(lon1[i], lat1[i],lon2[j],lat2[j])
                if l<r+2 and l>=r:
                    t=abs(t1[i]-t2[j])
                    if t<timedelta(days=day):
                         ix1.append(i)
                         ix2.append(j)
        one.append(ix1)  #have 15 value,each value also have many value
        two.append(ix2)
    return  one,two  
Esempio n. 6
0
def getFVcom(latpt,lonpt,time_roms):
    url='http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3'
    nc = netCDF4.Dataset(url)
    lats = nc.variables['lat'][:]
    lons = nc.variables['lon'][:]
    Depth = nc.variables['h'][:]
    siglay=nc.variables['siglay'][:]
    time=nc.variables['time'][200000:316008]#time between 2006-2013
    modtemp=nc.variables['temp'] 
    modtime=[]
    for i in range(len(time)):
        t=timedelta(days=float(time[i])).total_seconds()
        modtime.append(t)                        #change time days to seconds
    depth=(-Depth*siglay).transpose()                #each layer`s depth
    Temp=[]
    for i in latpt.index:
        distance=dist(lonpt[i],latpt[i],lons,lats)
        node=np.argmin(distance)                 #get nearest node
        t_diff=(time_roms[i]-datetime(1858,11,17)).total_seconds()     #1858,11,17 is FVCOM`s start time
        TIME=np.argmin(abs(t_diff-np.array(modtime)))
        T=modtemp[200000+TIME][44][node]
        Temp.append(T)
    nc.close()
    return Temp
Esempio n. 7
0
    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)
dist_ave=round(np.mean(diff_dist),2)
fig=plt.figure()
plt.bar(range(len(diff_dist)),diff_dist) 
plt.ylim([0,220])
plt.xlim([0,164])
plt.xlabel('Sort by time')
plt.ylabel('Distance unit:km')
plt.title('Dist,average='+str(dist_ave)+'(km). turtle:'+str(turtle_id))
plt.savefig('between_dive_dist.png')
 
fig=plt.figure()
Esempio n. 8
0
        'wave_height': buoywave2,
        'lat': buoylat2,
        'lon': buoylon2
    },
    index=tf_index2)
data2 = data.sort_index(by='time')

early_2011 = []
after_2011 = []
early_2013 = []
after_2013 = []
early_mod = []
after_mod = []
for i in obsData.index:
    for j in indx:
        if dist(buoylat[0], buoylon[0], obslat[i],
                obslon[i]) < 50:  #distance is smaller than 50km
            if obstime[i].month == 8 and obstime[i].year == 2011:
                if obstime[i].day > 28:  #choose day after storm
                    after_2011.append(i)
        if dist(buoylat[0], buoylon[0], obslat[i], obslon[i]) < 50:
            if obstime[i].month == 8 and obstime[i].year == 2011:
                if obstime[i].day == 27:  #choose day before storm
                    early_2011.append(i)
    for j in indx2:
        if dist(buoylat2[0], buoylon2[0], obslat[i], obslon[i]) < 50:
            if obstime[i].month == 5 and obstime[i].year == 2013:
                if obstime[i].day == 26:  #choose day after storm
                    after_2013.append(i)
        if dist(buoylat2[0], buoylon2[0], obslat[i], obslon[i]) < 50:
            if obstime[i].month == 5 and obstime[i].year == 2013:
                if obstime[i].day == 24:  #choose day before storm
Esempio n. 9
0
for q in range(67, 99):
    pp.append((modData['lon'][q], modData['lat'][q]))
    #range of fvcom

FV_index = []
for i in obslat.index:
    'n=point_in_poly(pp,obslon[i],obslat[i])  '  #turtle
    n = point_in_poly(pp, obslon[i][0], obslat[i][0])  #ship
    if n == 1:
        #print i
        FV_index.append(i)  #ensure turtle data in range of FVcom
Depth = []
node = []
TIME = []
for i in FV_index:
    distance = dist(obslon[i], obslat[i], modData['lon'], modData['lat'])
    k = np.argmin(distance)  #get nearest node
    node.append(k)
    depth = []
    #print i
    for j in range(len(obsDepth[i])):
        m = Closest_num(obsDepth[i][j], np.array(
            modData['depthBYlayer']
            [k]))  #in the nearest node get which layer it belongs to
        depth.append(int(m))
    Depth.append(depth)

    t_diff = (obsTime[i] - datetime(
        1858, 11, 17)).total_seconds()  #1858,11,17 is FVCOM`s start time
    T = Closest_num(t_diff, np.array(modTime))  #get the nearest time
    TIME.append(T)
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
    TF = mx * mn
    if TF.any():
        index.append(i)
    i += 1
    print(i)
ctd_TF = pd.Series([True] * len(index), index=index)
ctd['TF'] = ctd_TF
print(ctd)
print('{0} is OK(including "null" lon and lat values.).'.format(
    len(ctd_TF) / 28975.0))
Esempio n. 11
0
indx2=[]
for i in tf_index2:
    buoytime2[i]=datetime.strptime(buoytime2[i], "%Y-%m-%d %H:%M")  # change str to datatime
    if 17.2<buoyspeed2[i]:
        indx2.append(i)                                            #choose which day has storm
data2=pd.DataFrame({'time':buoytime2,'wind_speed':buoyspeed2,'wave_height':buoywave2,
                  'lat':buoylat2,'lon':buoylon2},index=tf_index2)
data2 = data.sort_index(by='time')

early_2011=[]
after_2011=[]
early_2013=[]
after_2013=[]
for i in obsData.index:
    for j in indx:
        if dist(buoylat[0],buoylon[0],obslat[i],obslon[i])<50:        #distance is smaller than 50km
            if obstime[i].month==8 and obstime[i].year==2011:
                if obstime[i].day>28:                                 #choose day after storm 
                    after_2011.append(i) 
        if dist(buoylat[0],buoylon[0],obslat[i],obslon[i])<50:
            if obstime[i].month==8 and obstime[i].year==2011:
                if obstime[i].day==27:                                 #choose day before storm
                    early_2011.append(i)
    for j in indx2:
        if dist(buoylat2[0],buoylon2[0],obslat[i],obslon[i])<50:
            if obstime[i].month==5 and obstime[i].year==2013:
                if obstime[i].day==26:                                 #choose day after storm
                    after_2013.append(i)
        if dist(buoylat2[0],buoylon2[0],obslat[i],obslon[i])<50:
            if obstime[i].month==5 and obstime[i].year==2013:
                if obstime[i].day==24:                                #choose day before storm
for q in range(67,99):
    pp.append((modData['lon'][q],modData['lat'][q]))            
              #range of fvcom

FV_index=[]
for i in obslat.index:
    n=point_in_poly(pp,obslon[i],obslat[i])       #turtle
    'n=point_in_poly(pp,obslon[i][0],obslat[i][0])'   #ship
    if n==1:
        print i
        FV_index.append(i)               #ensure turtle data in range of FVcom 
Depth=[]
node=[]
TIME=[]
for i in FV_index:
    distance=dist(obslon[i],obslat[i],modData['lon'],modData['lat'])
    k=np.argmin(distance)                 #get nearest node
    node.append(k)
    depth=[]
    print i
    for j in range(len(obsDepth[i])):
        m=Closest_num(obsDepth[i][j],np.array(modData['depthBYlayer'][k]))   #in the nearest node get which layer it belongs to
        depth.append(int(m))
    Depth.append(depth)
    
    t_diff=(obsTime[i]-datetime(1858,11,17)).total_seconds()     #1858,11,17 is FVCOM`s start time
    T=Closest_num(t_diff,np.array(modTime))                      #get the nearest time
    TIME.append(T)
ctd_FV = pd.Series([True]*len(FV_index), index=FV_index)
obsData['in FVcom range'] = ctd_FV
obsData['modnode']=pd.Series(node,index=FV_index)
time_aves=[]
dist_aves=[]        #collect all average
for i in range(len(ids)):
    obs=obsData.ix[ids[i]]    
    goodTime=pd.Series(np_datetime(obs['END_DATE']), index=ids[i])
    goodlons=pd.Series(obs['LON'], index=ids[i])
    goodlats=pd.Series(obs['LAT'], index=ids[i])
    d=pd.DataFrame({'Time':goodTime,'lon':goodlons,'lat':goodlats},index=ids[i])   #each turtle`s modtemp and obstemp
    d=d.sort(['Time'])
    d.index=range(len(d))
    diff_dist=[]
    diff_time=[]
    for j in d.index:
        if j+1 == len(d):
            break
        dis=dist(d['lon'][j],d['lat'][j],d['lon'][j+1],d['lat'][j+1])
        diff_dist.append(dis)
        t=(d['Time'][j+1]-d['Time'][j]).total_seconds()/3600
        diff_time.append(t)
    time_ave=round(np.mean(diff_time))
    dist_ave=round(np.mean(diff_dist))    #each turtle`s average
    time_aves.append(time_ave)
    dist_aves.append(dist_ave)
ave_time=round(np.mean(np.array(time_aves)),2)
ave_dist=round(np.mean(np.array(dist_aves)),2)
std_time=round(np.std(np.array(time_aves)),2)
std_dist=round(np.std(np.array(dist_aves)),2)

time_aves.sort()
dist_aves.sort()
time_aves=pd.Series(time_aves)
    goodlons = pd.Series(obs['LON'], index=ids[i])
    goodlats = pd.Series(obs['LAT'], index=ids[i])
    d = pd.DataFrame({
        'Time': goodTime,
        'lon': goodlons,
        'lat': goodlats
    },
                     index=ids[i])  #each turtle`s modtemp and obstemp
    d = d.sort(['Time'])
    d.index = range(len(d))
    diff_dist = []
    diff_time = []
    for j in d.index:
        if j + 1 == len(d):
            break
        dis = dist(d['lon'][j], d['lat'][j], d['lon'][j + 1], d['lat'][j + 1])
        diff_dist.append(dis)
        t = (d['Time'][j + 1] - d['Time'][j]).total_seconds() / 3600
        diff_time.append(t)
    time_ave = round(np.mean(diff_time))
    dist_ave = round(np.mean(diff_dist))  #each turtle`s average
    time_aves.append(time_ave)
    dist_aves.append(dist_ave)
ave_time = round(np.mean(np.array(time_aves)), 2)
ave_dist = round(np.mean(np.array(dist_aves)), 2)
std_time = round(np.std(np.array(time_aves)), 2)
std_dist = round(np.std(np.array(dist_aves)), 2)

time_aves.sort()
dist_aves.sort()
time_aves = pd.Series(time_aves)
Esempio n. 15
0
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime,timedelta
import netCDF4
from matplotlib.mlab import griddata
import sys
sys.path.append('../modules')
import basemap
from basemap import basemap_usgs,basemap_standard
from turtleModule import dist,str2ndlist
lat_AB01=42.0368
lon_AB01=-70.1313
lat=np.arange(41.7797,42.0368,0.025)
lon=np.arange(-70.4873,-70.0,0.035)
time=[datetime(2004,9,17),datetime(2004,9,27)]
distance_AB01=dist(lon[0],lat[0],lon_AB01,lat_AB01)
deepest=[14.6066,27.6068,27.792999,31.504299,34.486198,36.026402,37.494999,38.680599,
                                         40.936199,35.314899,25.784]
fig=plt.figure()
ax=fig.add_subplot(111)
distance=list(np.array([dist(lon[0],lat[0],lon[-1],lat[-1])])/len(lat)*range(1,len(lat)+1))
polygon=[]
for j in range(len(deepest)):
   polygon.append([distance[j],deepest[j]])
polygon.append([distance[-1],max(deepest)+1])
polygon.append([distance[0],max(deepest)+1])
plt.ylim([max(deepest)+1,0])
plt.xlim([min(distance),max(distance)])
pg=plt.Polygon(polygon,color='red')  
ax.add_patch(pg)
plt.show()
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 20 11:11:18 2015
creat ctdWithdepthofbottom_fvcom.csv with FVCOM depth
@author: zdong
"""

import numpy as np
import pandas as pd
from turtleModule import str2ndlist, np_datetime, dist
import netCDF4
##########################################################
url = "http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3"
nc = netCDF4.Dataset(url)
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
h = nc.variables['h'][:]
obsData = pd.read_csv('ctd_FVcom_temp.csv')
tf_index = np.where(obsData['in FVcom range'].notnull())[0]
obsLon, obsLat = obsData['LON'][tf_index], obsData['LAT'][tf_index]
depth = []
for i in tf_index:
    nearest_dist = np.argmin(dist(obsLon[i], obsLat[i], lon, lat))
    depth.append(h[nearest_dist])
obsData['depth_of_bottom_fvcom'] = pd.Series(depth, index=tf_index)
obsData.to_csv('ctdWithdepthofbottom_fvcom.csv')
Esempio n. 17
0
for i in np.arange(52,34,-1):    
    temp_roms=[]
    LAT_roms.append(lats_roms[i][50])
    LON_roms.append(lons_roms[i][50])
    H_roms.append(h_roms[i][50])       #52,34 and 50 is location from shallow to deep
    for j in range(36):                              #this is roms`s layers
        temp_roms.append(temps_roms[40000][j][i][50])
    Temp_roms.append(temp_roms)

ttt_roms=np.array(Temp_roms).transpose()

hh_roms=[]
for i in H_roms:
    hh_roms.append(-i*s_rho)
hh=np.array(hh_roms).transpose()
distance=list(np.array([dist(LON_roms[0],LAT_roms[0],LON_roms[-1],LAT_roms[-1])])/len(LAT_roms)*range(1,len(LAT_roms)+1))   #this is distance between location
distances=[]
for i in range(36):
    distances.append(distance)

temp_hycom=[]
for i in range(len(LON_roms)):
    t=getHYcom(LAT_roms[i],LON_roms[i],TIME_roms,hh_roms[i])
    temp_hycom.append(t)
ttt_hycom=np.array(temp_hycom).transpose()

temp_fvcom=[]
for i in range(len(LON_roms)):
    t=getFVcom(LAT_roms[i],LON_roms[i],TIME_roms,hh_roms[i])
    temp_fvcom.append(t)
ttt_fvcom=np.array(temp_fvcom).transpose()
Esempio n. 18
0
    obs=obsData.ix[ids[i]]    
    goodTime=pd.Series(np_datetime(obs['END_DATE']), index=ids[i])
    goodlons=pd.Series(obs['LON'], index=ids[i])
    goodlats=pd.Series(obs['LAT'], index=ids[i])
    d=pd.DataFrame({'Time':goodTime,'lon':goodlons,'lat':goodlats},index=ids[i])
    d=d.sort(['Time'])
    d.index=range(len(d))
    diff_dist=[]
    diff_time=[]
    for j in d.index:
        if j+1 == len(d):
            diff_dist.append(0)
            diff_time.append(0)
            break
        if j>0:
            dis=dist(d['lon'][0],d['lat'][0],d['lon'][j],d['lat'][j])
            diff_dist.append(dis)
            t=(d['Time'][j]-d['Time'][0]).total_seconds()/3600/24
            diff_time.append(t)
    time_ave=int(np.max(diff_time))
    dist_ave=int(np.max(diff_dist))
    time_aves.append(time_ave)
    dist_aves.append(dist_ave)
    
time_aves.sort()
dist_aves.sort()
time_aves=pd.Series(time_aves)
dist_aves=pd.Series(dist_aves)
y1=time_aves.value_counts()
y1=y1.sort_index()
y2=dist_aves.value_counts()
def nearest_point_index2(lon, lat, lons, lats):
    d = dist(lon, lat, lons, lats)
    min_dist = np.min(d)
    index = np.where(d == min_dist)
    return index
Esempio n. 20
0
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)
dist_ave = round(np.mean(diff_dist), 2)
fig = plt.figure()
plt.bar(range(len(diff_dist)), diff_dist)
plt.ylim([0, 220])
plt.xlim([0, 164])
plt.xlabel('Sort by time')
plt.ylabel('Distance unit:km')
plt.title('Dist,average=' + str(dist_ave) + '(km). turtle:' + str(turtle_id))
plt.savefig('between_dive_dist.png')

fig = plt.figure()
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 20 11:11:18 2015
creat ctdWithdepthofbottom_fvcom.csv with FVCOM depth
@author: zdong
"""

import numpy as np
import pandas as pd
from turtleModule import str2ndlist,np_datetime,dist
import netCDF4
##########################################################
url="http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3"
nc=netCDF4.Dataset(url)
lat=nc.variables['lat'][:]
lon=nc.variables['lon'][:]
h=nc.variables['h'][:]
obsData = pd.read_csv('ctd_FVcom_temp.csv')
tf_index = np.where(obsData['in FVcom range'].notnull())[0]
obsLon, obsLat = obsData['LON'][tf_index], obsData['LAT'][tf_index]
depth=[]
for i in tf_index:
    nearest_dist=np.argmin(dist(obsLon[i],obsLat[i],lon,lat))
    depth.append(h[nearest_dist])
obsData['depth_of_bottom_fvcom']=pd.Series(depth,index=tf_index)
obsData.to_csv('ctdWithdepthofbottom_fvcom.csv')
    node=np.argmin(distance)                 #get nearest node
    t_diff=(time_roms-datetime(1858,11,17)).total_seconds()     #1858,11,17 is FVCOM`s start time
    TIME=np.argmin(abs(t_diff-np.array(modtime)))
    Temp=[]
    for i in range(45):
        t=modtemp[TIME][i][node]
        Temp.append(t)
    return Temp,depth[node],Depth[node]
#########################################################
lat_AB01=42.0368
lon_AB01=-70.1313                       #location of AB01
lat=np.arange(42.0368,41.7797,-0.025)
lon=np.arange(-70.1313,-70.4873,-0.035)  #location of vertical transect

time=[datetime(2004,9,19),datetime(2004,9,25)]   #choose two days
distance_AB01=dist(lon[0],lat[0],lon_AB01,lat_AB01)
fig = plt.figure()
for q in range(len(time)):
    Temp,depth,deepest=[],[],[]
    for i in range(len(lat)):
        t,d,D=getFVcom(lat[i],lon[i],time[q])
        depth.append(d)
        deepest.append(D)
        Temp.append(t)
    distance=list(np.array([dist(lon[0],lat[0],lon[-1],lat[-1])])/len(lat)*range(0,len(lat)))   #this is distance between location       
    distances=[]
    for i in range(45):
        distances.append(distance)
    dd=np.array(distances).transpose()
    TEMP,DEPTH,DIST=[],[],[]
    for i in range(len(Temp)):
Esempio n. 23
0
turtle_id = obsData['PTT'][tf_index]

shipData = pd.read_csv('ship06-08_MODELtemp.csv', index_col=0)
shipid = shipData['id']
shiplat = shipData['LAT']
shiplon = shipData['LON']
shiptime = pd.Series(
    (datetime.strptime(x, "%Y-%m-%d %H:%M:%S") for x in shipData['time']))
shipdepth = pd.Series(str2ndlist(shipData['depth'], bracket=True))
shiptemp = pd.Series(str2ndlist(shipData['temperature'], bracket=True))

index = []  #index of turtle
indx = []  #index of shipboard
for i in tf_index:
    for j in shipData.index:
        l = dist(obslon[i], obslat[i], shiplon[j], shiplat[j])
        if l < r2 and l >= r1:
            #print l        #distance
            maxtime = obstime[i] + timedelta(days=day)
            mintime = obstime[i] - timedelta(days=day)
            mx = shiptime[j] < maxtime
            mn = shiptime[j] > mintime
            TF = mx * mn
            if TF == 1:  #time
                index.append(i)  #turtle index
                indx.append(j)  #ship index

INDX = pd.Series(indx).unique()
data = pd.DataFrame(range(len(indx)))
s_id,t_id,s_time,t_time,s_lat,s_lon,t_lat,t_lon=[],[],[],[],[],[],[],[]
for i in INDX:
Esempio n. 24
0
shipData1=pd.read_csv('ship_FVcom_temp.csv')         #this ship`s FVCOM temperature
tf_index_fvcom=np.where(shipData1['modtempBYdepth'].notnull())[0]
modtemp_fvcom=pd.Series(shipData1['modtempBYdepth'],index=tf_index_fvcom)
for i in tf_index_fvcom:
    modtemp_fvcom[i]=str2list(modtemp_fvcom[i],bracket=True)
shipData2=pd.read_csv('ship_withHYCOMtemp.csv')
tf_index_hycom=np.where(shipData2['modtemp_HYCOM'].notnull())[0]
modtemp_hycom=pd.Series(shipData2['modtemp_HYCOM'],index=tf_index_hycom)#this ship`s HYCOM temperature
for i in tf_index_hycom:
    modtemp_hycom[i]=str2list(modtemp_hycom[i],bracket=True)

index_hycom = []     #index of turtle
indx_hycom=[]        #index of shipboard 
for i in tf_index_HYCOM:
    for j in tf_index_hycom:
        l = dist(obslon[i], obslat[i],shiplon[j],shiplat[j])
        if l<r:
            print l        #distance
            maxtime = obstime[i]+timedelta(days=day)
            mintime = obstime[i]-timedelta(days=day)
            mx = shiptime[j]<maxtime
            mn = shiptime[j]>mintime
            TF = mx*mn  
            if TF==1:      #time
                index_hycom.append(i)     #turtle index
                indx_hycom.append(j)      #ship index
#print index_hycom,indx_hycom

index,indx=[],[]
for i in index_hycom:
    if i in tf_index_FVCOM:
Esempio n. 25
0
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
    TF = mx * mn
    if TF.any():
        index.append(i)
    i += 1
    print(i)
ctd_TF = pd.Series([True] * len(index), index=index)
ctd["TF"] = ctd_TF
print(ctd)
print('{0} is OK(including "null" lon and lat values.).'.format(len(ctd_TF) / 28975.0))
print("{0} is OK.".format(len(ctd_TF) / 15657.0))
Esempio n. 26
0
def nearest_point_index2(lon, lat, lons, lats):
    d = dist(lon, lat, lons ,lats)
    min_dist = np.min(d)
    index = np.where(d==min_dist)
    return index