except:
         print 'FVCOM is down?'
         modt = 'nan'  # the FVCOM must be down
 else:
     modt = 'nan'
 # get DOPPIO
 if max(df1.datet).to_pydatetime() >= dt(2017, 11, 1, 0, 0, 0):
     print 'looking for DOPPIO'
     try:
         modt_doppio = str(
             round(
                 c2f(
                     doppio_modules.get_doppio(
                         lat=df1[8][-1:].values[0],
                         lon=df1[7][-1:].values[0],
                         depth='bottom',
                         time=max(df1.datet).to_pydatetime() -
                         timedelta(days=4),
                         fortype='temperature'))[0], 1))
     except:
         modt_doppio = np.nan
     print 'looking for GOMOFS'
     try:
         modt_gomofs = str(
             round(
                 c2f(
                     gomofs_modules.get_gomofs(
                         max(df1.datet).to_pydatetime() -
                         timedelta(days=0), df1[8][-1:].values[0],
                         df1[7][-1:].values[0], 'bottom'))[0], 1))
     except:
depth = int(sys.argv[3])  #99999 for bottom
datet = dt(int(sys.argv[4]), int(sys.argv[5]), int(sys.argv[6]),
           int(sys.argv[7]), int(sys.argv[8]), 0)
clim_files_directory = '/net/data5/jmanning/clim/'
#####################

# get GOMOFS
try:
    t = gomofs_modules.get_gomofs(datet, lat, lon, depth)
    print('gomofs = ', '%.3f' % t)
except:
    print('gomofs not available?')

# get DOPPIO
try:
    t = doppio_modules.get_doppio(lat, lon, depth, datet, 'temperature')
    print('doppio = ', '%.3f' % t)
except:
    print('doppio not available?')

# get FVCOM
try:
    url = fvcom_modules.get_FVCOM_url(datet)
    t = fvcom_modules.get_FVCOM_temp(url, lat, lon, datet, depth)  #
    print('fvcom =', '%.3f' % t)
except:
    print('fvcom not available?')

# get CLIM
dflat = pd.read_csv(clim_files_directory + 'LatGrid.csv', header=None)
dflon = pd.read_csv(clim_files_directory + 'LonGrid.csv', header=None)
Ejemplo n.º 3
0
    if min(lats[i])<min_lat:
        min_lat=min(lats[i])
    if min(lons[i])<min_lon:
        min_lon=min(lons[i])
    if max(lats[i])>max_lat:
        max_lat=max(lats[i])
    if max(lons[i])>max_lon:
        max_lon=max(lons[i])

if (max_lon-min_lon)>(max_lat-min_lat):
    max_lat=max_lat+((max_lon-min_lon)-(max_lat-min_lat))/2.0
    min_lat=min_lat-((max_lon-min_lon)-(max_lat-min_lat))/2.0
else:
    max_lon=max_lon+((max_lat-min_lat)-(max_lon-min_lon))/2.0
    min_lon=min_lon-((max_lat-min_lat)-(max_lon-min_lon))/2.0
point_temp,index_1,index_2=dm.get_doppio(lat=input_lat,lon=input_lon,depth=input_depth,time=input_date_time)
if input_depth==99999:   #if input_depth=99999, we need output the bottom layer
    S_coordinate=1   #1 represent the bottom layer, 0 represent the surface layer
else:
    S_coordinate=float(input_depth)/float(doppio_depth[index_1][index_2])

#creat map
#Create a blank canvas       
fig=plt.figure(figsize = (20, 20))
fig.suptitle('DOPPIO model bottom temp(deg C) and depth(meter)',fontsize=35, fontweight='bold')

#Draw contour lines and temperature maps in detail
ax1=fig.add_axes([0.07,0.03,0.85,0.95])
ax1.set_title(input_date_time, loc='center')
ax1.axes.title.set_size(24)
#ax12=ax1.twinx()
def classify_by_boat(telemetry_status, start_time, end_time, dict):

    try:
        tele_dict = dict['tele_dict']
        Doppio_dict = dict['Doppio']
        GoMOLFs_dict = dict['GoMOLFs']
        FVCOM_dict = dict['FVCOM']
        start_time = dict[
            'end_time']  # if dict['end_time'] is wrong, please comment this code

    except:
        dict = {}
        tele_dict = {}
        Doppio_dict = {}
        GoMOLFs_dict = {}
        FVCOM_dict = {}
    telemetrystatus_df = read_telemetrystatus(telemetry_status)
    #download the data of telementry
    tele_df = read_telemetry(
    )  #path='/home/jmanning/Desktop/telementry.csv')   #tele_df means telemeterd data
    #screen out the data of telemetry in interval
    valuable_tele_df = pd.DataFrame(
        data=None,
        columns=['vessel_n', 'esn', 'time', 'lon', 'lat', 'depth',
                 'temp'])  #use to save the data from start time to end time
    for i in range(len(tele_df)):
        tele_time_str=str(tele_df['year'].iloc[i])+'-'+str(tele_df['month'].iloc[i])+'-'+str(tele_df['day'].iloc[i])+' '+\
                                         str(tele_df['Hours'].iloc[i])+':'+str(tele_df['minates'].iloc[i])+':'+'00'
        tele_time = datetime.strptime(tele_time_str, '%Y-%m-%d %H:%M:%S')
        if start_time < tele_time <= end_time:
            valuable_tele_df=valuable_tele_df.append(pd.DataFrame(data=[[tele_df['vessel_n'][i],tele_df['esn'][i],tele_time,tele_df['lon'][i],\
                                                                         tele_df['lat'][i],tele_df['depth'][i],tele_df['temp'][i]]],\
                                                                        columns=['vessel_n','esn','time','lon','lat','depth','temp']))
    #clean the index of valuable telementry data
    if len(valuable_tele_df) > 0:
        valuable_tele_df.index = range(len(valuable_tele_df))
        dict['end_time'] = valuable_tele_df['time'][len(valuable_tele_df) - 1]
    print(len(valuable_tele_df))
    for j in range(len(telemetrystatus_df)):
        if telemetrystatus_df['Boat'][j] not in tele_dict.keys():
            tele_dict[telemetrystatus_df['Boat'][j]] = pd.DataFrame(
                data=None, columns=['time', 'temp', 'depth', 'lat', 'lon'])
        if telemetrystatus_df['Boat'][j] not in Doppio_dict.keys():
            Doppio_dict[telemetrystatus_df['Boat'][j]] = pd.DataFrame(
                data=None, columns=['time', 'temp', 'depth', 'lat', 'lon'])
        if telemetrystatus_df['Boat'][j] not in GoMOLFs_dict.keys():
            GoMOLFs_dict[telemetrystatus_df['Boat'][j]] = pd.DataFrame(
                data=None, columns=['time', 'temp', 'depth', 'lat', 'lon'])
        if telemetrystatus_df['Boat'][j] not in FVCOM_dict.keys():
            FVCOM_dict[telemetrystatus_df['Boat'][j]] = pd.DataFrame(
                data=None, columns=['time', 'temp', 'depth', 'lat', 'lon'])

        dop_nu = []
        gmf_nu = []
        tele_nu = []
        fvc_nu = []
        for i in valuable_tele_df.index:  #valuable_tele_df is the valuable telemetry data during start time and end time
            if int(valuable_tele_df['vessel_n'][i].split('_')
                   [1]) == telemetrystatus_df['Vessel#'][j]:
                dtime = valuable_tele_df['time'][i]
                latp = float(valuable_tele_df['lat'][i])
                lonp = float(valuable_tele_df['lon'][i])
                tele_nu.append([
                    dtime, latp, lonp,
                    float(valuable_tele_df['temp'][i]),
                    float(valuable_tele_df['depth'][i])
                ])

                try:  #try to get doppio data in the same locattion
                    #                    print('dpo:',lat,lon,dtime)
                    dpo_temp, dpo_depth = dpo.get_doppio(
                        lat=latp,
                        lon=lonp,
                        depth='bottom',
                        time=dtime.strftime("%Y-%m-%d %H:%M:%S"),
                        fortype='tempdepth')
                except:
                    dpo_temp, dpo_depth = np.nan, np.nan
                dop_nu.append([dtime, latp, lonp, dpo_temp, dpo_depth])
                try:  #try to get the gomofs data in the same location
                    gmf_temp, gmf_depth = gmf.get_gomofs(date_time=dtime,
                                                         lat=latp,
                                                         lon=lonp,
                                                         depth='bottom',
                                                         fortype='tempdepth')
                except:
                    gmf_temp, gmf_depth = np.nan, np.nan
                gmf_nu.append([dtime, latp, lonp, gmf_temp, gmf_depth])
                try:
                    FV_temp, FV_depth = fv.get_FVCOM_bottom_temp(lati=latp,
                                                                 loni=lonp,
                                                                 dtime=dtime,
                                                                 layer=-1)
                except:
                    FV_temp, FV_depth = np.nan, np.nan
                fvc_nu.append([dtime, latp, lonp, FV_temp, FV_depth])
                valuable_tele_df = valuable_tele_df.drop(
                    i)  #if this line has been classify, delete this line
        if len(dop_nu) > 0:
            Doppio_dict[telemetrystatus_df['Boat'][j]]=Doppio_dict[telemetrystatus_df['Boat'][j]].append(pd.DataFrame(data=dop_nu,\
                            columns=['time','lat','lon','temp','depth']),ignore_index=True)
        if len(gmf_nu) > 0:
            GoMOLFs_dict[telemetrystatus_df['Boat'][j]]=GoMOLFs_dict[telemetrystatus_df['Boat'][j]].append(pd.DataFrame(data=gmf_nu,\
                            columns=['time','lat','lon','temp','depth']),ignore_index=True)
        if len(tele_nu) > 0:
            tele_dict[telemetrystatus_df['Boat'][j]]=tele_dict[telemetrystatus_df['Boat'][j]].append(pd.DataFrame(data=tele_nu,\
                            columns=['time','lat','lon','temp','depth']),ignore_index=True)
        if len(fvc_nu) > 0:
            FVCOM_dict[telemetrystatus_df['Boat'][j]]=tele_dict[telemetrystatus_df['Boat'][j]].append(pd.DataFrame(data=fvc_nu,\
                            columns=['time','lat','lon','temp','depth']),ignore_index=True)

    dict['tele_dict'] = tele_dict
    dict['Doppio'] = Doppio_dict
    dict['GoMOLFs'] = GoMOLFs_dict
    dict['FVCOM'] = FVCOM_dict
    return dict