Example #1
0
import matplotlib.pyplot as plt
from MODULES import DIST, FIG_PLOT_emolt_30yr, get_emolt_data
##################################################################
one_minute = 1.0 / 60
form = cgi.FieldStorage()
alat = float(form.getvalue('alat'))
alon = float(form.getvalue('alon'))
method = form.getvalue('way')
lonsize = [alon - 5 * one_minute, alon + 5 * one_minute]
latsize = [alat - 5 * one_minute, alat + 5 * one_minute]
WAYS = [
    ' ', 'Wind speed(m/s)', 'Wave height(m)', 'Bottom temperature(degC)',
    'current'
]
way = ['', 'wind', 'wave', 'bottom_temp', 'current']
dist_emolt, data_emolt, emolt_name = get_emolt_data(alon, alat)
start_time, end_time = min(data_emolt['time']), max(data_emolt['time'])
if method == 'bottom temperature':
    url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3/mean'
    try:
        nc = netCDF4.Dataset(url)
        lons = nc.variables['lon'][:]
        lats = nc.variables['lat'][:]
        time = nc.variables['time'][:]
        temp = nc.variables['temp']
        Dist = []
        for i in range(len(lons[:])):
            Dist.append(DIST(lons[i], lats[i], alon, alat))
        index_nearest = np.argmin(Dist)
        depth_fvcom = nc.variables['h'][index_nearest]  #get depth of fvcom
        t1 = (start_time -
 for i in range(len(lons[:])):
     Dist.append(DIST(lons[i],lats[i],alon,alat))
 index_nearest=np.argmin(Dist)
 depth_fvcom=nc.variables['h'][index_nearest]  #get depth of fvcom
 T,TEMP_f=[],[]
 TEMP=temp[:,-1,index_nearest]
 for i in range(len(time)):   
     t=datetime.datetime(1858,11,17)+datetime.timedelta(days=int(time[i]))+datetime.timedelta(seconds=int(time[i]%1*24*3600))
     t=gmt_to_loc(t)
     T.append(t)   
 for i in range(len(T)):
     T[i]=T[i].replace(year=2000,tzinfo=None)
 for i in range(len(TEMP)):
     TEMP_f.append(TEMP[i]*1.8+32)
 fig,ax,ax2=FIG_PLOT_emolt(TEMP,T,alon,alat,method,WAYS,TEMP_f)
 dist_emolt,data_emolt,emolt_name=get_emolt_data(alon,alat)
 i_emolt=[] 
 start,end=min(data_emolt['time']).year,max(data_emolt['time']).year
 dif_year=end-start+1
 for i in range(dif_year):
     i_emolt.append([]) 
     c=data_emolt[data_emolt.time>=datetime.datetime(start+i,1,1,0,0,0)]
     d=c[c.time<=datetime.datetime(start+i,12,31,23,59,59)].index.values
     i_emolt[i].extend(d)
 I_emolt,INDX,TIME,TEMP=[],[],[],[]
 for i in range(dif_year):
     I_emolt.append([])
     for j in range(len(i_emolt[i])):
         TIME.append(data_emolt['time'][i_emolt[i][j]].replace(year=2000))
         TEMP.append(data_emolt['temperature'][i_emolt[i][j]]*1.8+32)
         I_emolt[i].append(i_emolt[i][j])