def getModTemp(modTempAll, obsTime, modLayer, modNearestIndex, s_rho, waterDepth, starttime, oceantime): ''' Return model temp based on observation layers or depth ''' print "This program has assign the temp of island and land to 10000" indx = closest_num((starttime - datetime(2006, 1, 1)).total_seconds(), oceantime) modTemp = [] l = len(modLayer.index) for i in modLayer.index: # Loop the model location ''' # For layers print i, l, 'getModTemp' timeIndex = closest_num((obsTime[i]-datetime(2006,01,01)).total_seconds(), oceantime)-ind modTempTime = modTempAll[timeIndex] modTempTime[modTempTime.mask] = 10000 t = np.array([modTempTime[modLayer[i][j],modNearestIndex[i][0], modNearestIndex[i][1]] \ for j in range(len(modLayer[i]))]) modTemp.append(t) ''' # For depth print i, l, 'getModTemp' timeIndex1 = closest_num( (obsTime[i] - datetime(2006, 01, 01)).total_seconds(), oceantime) timeIndex = timeIndex1 - indx temp = modTempAll[timeIndex] #print temp #temp[mask_rho] = 10000 # Assign the temp of island and land to 10000 a, b = int(modNearestIndex[i][0]), int( modNearestIndex[i][1]) # index of nearest model node t = [] for depth in obsDepth[i]: depth = -depth locDepth = waterDepth[ a, b] # Get the bottom depth of this location. waterDepth is 'h' lyrDepth = s_rho * locDepth # Depth of each layer if depth > lyrDepth[ -1]: # Obs is shallower than last layer which is the surface. Temp = (temp[-2,a,b]-temp[-1,a,b])/(lyrDepth[-2]-lyrDepth[-1]) * \ (depth-lyrDepth[-1]) + temp[-1,a,b] 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
def getModTemp(modTempAll, ctdTime, ctdLayer, ctdNearestIndex, s_rho, waterDepth, starttime, oceantime): ''' Return model temp based on observation layers(commented out) or depth ''' indx = closest_num((starttime - datetime(2006, 1, 1)).total_seconds(), oceantime) modTemp = [] l = len(ctdLayer.index) for i in ctdLayer.index: ''' # For layers print i, l, 'getModTemp' timeIndex = closest_num((ctdTime[i]-datetime(2006,01,01)).total_seconds(), oceantime)-ind modTempTime = modTempAll[timeIndex] modTempTime[modTempTime.mask] = 10000 t = np.array([modTempTime[ctdLayer[i][j],ctdNearestIndex[i][0], ctdNearestIndex[i][1]] \ for j in range(len(ctdLayer[i]))]) modTemp.append(t) ''' # For depth print(i, l, 'getModTemp') print('ctdTime[i]', ctdTime[i]) timeIndex1 = closest_num( (ctdTime[i] - datetime(2006, 1, 1)).total_seconds(), oceantime) timeIndex = timeIndex1 - indx temp = modTempAll[timeIndex] temp[temp.mask] = 10000 a, b = int(ctdNearestIndex[i][0]), int( ctdNearestIndex[i][1]) # index of nearest model node t = [] for depth in ctdDepth[i]: depth = -depth locDepth = waterDepth[a, b] # Get the bottom depth of this location. lyrDepth = s_rho * locDepth # Depth of each layer print(lyrDepth[-1], depth) if depth > lyrDepth[ -1]: # Obs is shallower than last layer which is the surface. d = (temp[-2,a,b]-temp[-1,a,b])/(lyrDepth[-2]-lyrDepth[-1]) * \ (depth-lyrDepth[-1]) + temp[-1,a,b] elif depth < lyrDepth[ 0]: # Obs is deeper than first layer which is the bottom. 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
def get_url(starttime, endtime): url_oceantime = 'http://tds.marine.rutgers.edu/thredds/dodsC/roms/espresso/2013_da/his/ESPRESSO_Real-Time_v2_History_Best?time[0:1:31931]' oceantime = netCDF4.Dataset( url_oceantime).variables['time'][:] #if url2006, ocean_time. t1 = (starttime - datetime(2013, 5, 18)).total_seconds( ) / 3600 # for url2006 it's 2006,01,01; for url2013, it's 2013,05,18, and needed to be devide with 3600 t2 = (endtime - datetime(2013, 5, 18)).total_seconds() / 3600 index1 = closest_num(t1, oceantime) index2 = closest_num(t2, oceantime) url = 'http://tds.marine.rutgers.edu/thredds/dodsC/roms/espresso/2013_da/his/ESPRESSO_Real-Time_v2_History_Best?h[0:1:81][0:1:129],s_rho[0:1:35],lon_rho[0:1:81][0:1:129],lat_rho[0:1:81][0:1:129],temp[{0}:1:{1}][0:1:35][0:1:81][0:1:129],time' url = url.format(index1, index2) return url
def getModTemp(modTempAll, obsTime, obsLayer, obsNearestIndex, starttime, oceantime): ''' Return the mod temp corresponding to observation based on layers, not depth ''' ind = closest_num((starttime -datetime(2013,5,18)).total_seconds()/3600, oceantime) modTemp = [] l = len(obsLayer.index) for i in obsLayer.index: timeIndex = closest_num((obsTime[i]-datetime(2013,5,18)).total_seconds()/3600, oceantime)-ind modTempTime = modTempAll[timeIndex] # modTempTime[modTempTime.mask] = 10000 t = [modTempTime[obsLayer[i][j],obsNearestIndex[i][0], obsNearestIndex[i][1]] \ for j in range(len(obsLayer[i]))] modTemp.append(t) modTemp = np.array(modTemp) return modTemp
def getModTemp(modTempAll, ctdTime, ctdLayer, ctdNearestIndex, s_rho, waterDepth, starttime, oceantime): ''' Return model temp based on observation layers(commented out) or depth ''' indx = closest_num((starttime -datetime(2006,01,01)).total_seconds(), oceantime) modTemp = [] l = len(ctdLayer.index) for i in ctdLayer.index: ''' # For layers print i, l, 'getModTemp' timeIndex = closest_num((ctdTime[i]-datetime(2006,01,01)).total_seconds(), oceantime)-ind modTempTime = modTempAll[timeIndex] modTempTime[modTempTime.mask] = 10000 t = np.array([modTempTime[ctdLayer[i][j],ctdNearestIndex[i][0], ctdNearestIndex[i][1]] \ for j in range(len(ctdLayer[i]))]) modTemp.append(t) ''' # For depth print i, l, 'getModTemp' print 'ctdTime[i]', ctdTime[i] timeIndex1 = closest_num((ctdTime[i]-datetime(2006,01,01)).total_seconds(), oceantime) timeIndex = timeIndex1 - indx temp = modTempAll[timeIndex] temp[temp.mask] = 10000 a, b = int(ctdNearestIndex[i][0]), int(ctdNearestIndex[i][1]) # index of nearest model node t = [] for depth in ctdDepth[i]: depth = -depth locDepth = waterDepth[a, b]# Get the bottom depth of this location. lyrDepth = s_rho * locDepth# Depth of each layer print lyrDepth[-1], depth if depth > lyrDepth[-1]: # Obs is shallower than last layer which is the surface. d = (temp[-2,a,b]-temp[-1,a,b])/(lyrDepth[-2]-lyrDepth[-1]) * \ (depth-lyrDepth[-1]) + temp[-1,a,b] elif depth < lyrDepth[0]: # Obs is deeper than first layer which is the bottom. 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
def getModTemp(modTempAll, obsTime, modLayer, modNearestIndex, s_rho, waterDepth, starttime, oceantime): ''' Return model temp based on observation layers or depth ''' indx = closest_num((starttime -datetime(2006,1,1)).total_seconds(), oceantime) modTemp = [] l = len(modLayer.index) for i in modLayer.index: # Loop the model location ''' # For layers print i, l, 'getModTemp' timeIndex = closest_num((obsTime[i]-datetime(2006,01,01)).total_seconds(), oceantime)-ind modTempTime = modTempAll[timeIndex] modTempTime[modTempTime.mask] = 10000 t = np.array([modTempTime[modLayer[i][j],modNearestIndex[i][0], modNearestIndex[i][1]] \ for j in range(len(modLayer[i]))]) modTemp.append(t) ''' # For depth timeIndex1 = closest_num((obsTime[i]-datetime(2006,01,01)).total_seconds(), oceantime) timeIndex = timeIndex1 - indx temp = modTempAll[timeIndex] temp[temp.mask] = 10000 # Assign the temp of island and land to 10000 a, b = int(modNearestIndex[i][0]), int(modNearestIndex[i][1]) # index of nearest model node t = [] for depth in obsDepth[i]: depth = -depth locDepth = waterDepth[a, b]# Get the bottom depth of this location. waterDepth is 'h' lyrDepth = s_rho * locDepth# Depth of each layer if depth > lyrDepth[-1]: # Obs is shallower than last layer which is the surface. Temp = (temp[-2,a,b]-temp[-1,a,b])/(lyrDepth[-2]-lyrDepth[-1]) * \ (depth-lyrDepth[-1]) + temp[-1,a,b] 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
def getModTemp(modTempAll, obsTime, obsLayer, obsNearestIndex, starttime, oceantime): ''' Return the mod temp corresponding to observation based on layers, not depth ''' ind = closest_num( (starttime - datetime(2013, 5, 18)).total_seconds() / 3600, oceantime) modTemp = [] l = len(obsLayer.index) for i in obsLayer.index: timeIndex = closest_num( (obsTime[i] - datetime(2013, 5, 18)).total_seconds() / 3600, oceantime) - ind modTempTime = modTempAll[timeIndex] # modTempTime[modTempTime.mask] = 10000 t = [modTempTime[obsLayer[i][j],obsNearestIndex[i][0], obsNearestIndex[i][1]] \ for j in range(len(obsLayer[i]))] modTemp.append(t) modTemp = np.array(modTemp) return modTemp