diff=diff[['date','mean','median','min','max','std']]
        return diff

# Forth, the main program ############################################################################
for k in range(len(site)):
#################read-in obs data##################################
        print site[k]
        [lati,loni,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        #[lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
        if surf_or_bott=='bott':
            #dept=[bd[0]-0.25*bd[0],bd[0]+.25*bd[0]]
            dept=[bd-0.25*bd,bd+.25*bd]
        else:
            dept=[0,5]
        #(obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k], input_time=[dt(2006,1,10,1,0),dt(2013,12,31,0,0)], dep=dept)
        (obs_dt,obs_temp,distinct_dep)=getobs_tempsalt(site[k],intime,dept)
        #depthinfor.append(site[k]+','+str(bd[0])+','+str(distinct_dep)+'\n') # note that this distinct depth is actually the overall mean
        depthinfor.append(site[k]+','+str(bd)+','+str(distinct_dep)+'\n') # note that this distinct depth is actually the overall mean
        obs_dtindex=[]
        if intend_to=='temp':            
            for kk in range(len(obs_temp)):
                #obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
                obs_dtindex.append(dt.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_temp,index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(dt.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_salt,index=obs_dtindex)   
        print 'observed Dataframe is ready'

##################generate resample DataFrame and putput file################################################
示例#2
0
if mode=='_post2007':
           starttime_mod=dt.datetime(2008,1,1,0,0,0,0,pytz.UTC)

for k in range(len(site)):
#################read-in obs data##################################
        print site[k]
        #[lati,loni,on,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        [lati,loni,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        #[lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
        if surf_or_bott=='bott':
            #dept=[bd[0]-0.25*bd[0],bd[0]+.25*bd[0]]
            dept=[bd-0.25*bd,bd+.25*bd]
        else:
            dept=[0,5]
        #(obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k], input_time=[dt.datetime(1880,1,1),dt.datetime(2010,12,31)], dep=dept)
        (obs_dt,obs_temp,distinct_dep)=getobs_tempsalt(site[k], input_time=[starttime_mod,endtime_mod], dep=dept)
        #depthinfor.append(site[k]+','+str(bd[0])+','+str(distinct_dep)+'\n') # note that this distinct depth is actually the overall mean
        depthinfor.append(site[k]+','+str(bd)+','+str(distinct_dep)+'\n') # note that this distinct depth is actually the overall mean
        obs_dtindex=[]
        if intend_to=='temp':            
            for kk in range(len(obs_temp)):
                #obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_temp,index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_salt,index=obs_dtindex)   
        print 'observed Dataframe is ready'

##################generate resample DataFrame and putput file################################################
示例#3
0
#################read-in obs data##################################
        print site[k]
        [lati,loni,on,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        [lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
        '''           
        [obs_dt,obs_temp]=getemolt_temp(site[k]) # extracts time series
        obs_dtindex=[]
        for kk in range(len(obs_temp)):
            obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
            obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
        '''
        if surf_or_bott=='bott':
            dept=[bd[0]-0.25*bd[0],bd[0]+.25*bd[0]]
        else:
            dept=[0,5]
        (obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k], input_time=[dt.datetime(1880,1,1),dt.datetime(2010,12,31)], dep=dept)
        depthinfor.append(site[k]+','+str(bd[0])+','+str(distinct_dep[0])+'\n')
        obs_dtindex=[]
        if intend_to=='temp':            
            for kk in range(len(obs_temp)):
                obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_temp,index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_salt,index=obs_dtindex)   
        print 'obs Dataframe is ready'

##################generate resample DataFrame and putput file################################################
        reobsdaf=resamda(obstso)
示例#4
0
        #################read-in obs data##################################
        print site[k]
        [lati,loni,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        if surf_or_bott=='bott':
            dept=[bd-0.25*bd,bd+.25*bd]
        else:
            dept=[0,5]
        ######################################################################################
        if month_time<12:
           input_time=[dt.datetime(2008,int(month_time),1,0,0,0,0,pytz.UTC),dt.datetime(2008,int(month_time)+1,1,0,0,0,0,pytz.UTC)]
        else:
           input_time=[dt.datetime(2008,int(month_time),1,0,0,0,0,pytz.UTC),dt.datetime(2008,int(month_time),31,0,0,0,0,pytz.UTC)]
        dep=dept

        print 'extracting eMOLT data using ERDDAP.. hold on'      
        (datet,temp,depths)=getobs_tempsalt(site[k],input_time)
        obstso=pd.DataFrame(temp,index=datet)
        print 'obs Dataframe is ready .. now getting model before assimilation'
        if month_time<10:
            month_time=str(0)+str(month_time)
            urlbeforeassi='http://www.smast.umassd.edu:8080/thredds/dodsC/models/fvcom/NECOFS/Archive/eMOLT/gom'+str(month_time)+'_0001.nc'
            nb = netCDF4.Dataset(urlbeforeassi)
            nb.variables
            latb = nb.variables['lat'][:]
            lonb = nb.variables['lon'][:]
            timesb = nb.variables['time']
            jdb = netCDF4.num2date(timesb[:],timesb.units)
            for kk in range(len(jdb)): # make these model times timezone aware
               jdb[kk]=jdb[kk].replace(tzinfo=pytz.UTC)
            varb = nb.variables[vname]
            print 'Now find the index of space and time in the before assimilation model'
示例#5
0
        diff=diff[['date','mean','median','min','max','std']]
        return diff

# Forth, the main program ############################################################################
for k in range(len(site)):
#################read-in obs data##################################
        print site[k]
        [lati,loni,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        #[lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
        if surf_or_bott=='bott':
            #dept=[bd[0]-0.25*bd[0],bd[0]+.25*bd[0]]
            dept=[bd-0.25*bd,bd+.25*bd]
        else:
            dept=[0,5]
        #(obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k], input_time=[dt(2006,1,10,1,0),dt(2013,12,31,0,0)], dep=dept)
        (obs_dt,obs_temp,distinct_dep)=getobs_tempsalt(site[k], input_time=intime)
        #depthinfor.append(site[k]+','+str(bd[0])+','+str(distinct_dep)+'\n') # note that this distinct depth is actually the overall mean
        depthinfor.append(site[k]+','+str(bd)+','+str(distinct_dep)+'\n') # note that this distinct depth is actually the overall mean
        obs_dtindex=[]
        if intend_to=='temp':            
            for kk in range(len(obs_temp)):
                #obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
                obs_dtindex.append(dt.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_temp,index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(dt.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_salt,index=obs_dtindex)   
        print 'observed Dataframe is ready'

##################generate resample DataFrame and putput file################################################
示例#6
0
numperday=24
intend_to='temp'##############notice intend_to can be 'temp'or'salinity'
surf_or_bott='bott'
starttime=dt.datetime(2003,1,1)
endtime=dt.datetime(2010,12,31)
for k in range(len(site)):
#################read-in obs data##################################
        print site[k]
        [lati,loni,on,bd]=getemolt_latlon(site[k]) # extracts lat/lon based on site code
        print bd
        [lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
        if surf_or_bott=='bott':
            dept=[bd[0]-0.25*bd[0],bd[0]+.25*bd[0]]
        else:
            dept=[0,5]
        (obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k], input_time=[starttime,endtime], dep=dept)
        depthinfor.append(site[k]+','+str(bd[0])+','+str(distinct_dep[0])+'\n')
        obs_dtindex=[]
        if intend_to=='temp':            
            for kk in range(len(obs_temp)):
                obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_temp,index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_salt,index=obs_dtindex)   
        print 'obs Dataframe is ready'
        resamdaobs=float64(obstso[0]).resample('A',how=['count','mean'])
        
        resamdaobs.ix[resamdaobs['count']<7500,['mean']] = 'NaN'
示例#7
0
    dist2 = dx * dx + dy * dy
    # dist1=np.abs(dx)+np.abs(dy)
    i = np.argmin(dist2)
    # min_dist=np.sqrt(dist2[i])
    return i  # ,min_dist


for k in range(len(site)):
    #################read-in obs data##################################
    print site[k][:]
    [lati, loni, bd] = getemolt_latlon(site[k][:])  # extracts lat/lon based on site code
    if surf_or_bott == "bott":
        dept = [bd - 0.25 * bd, bd + 0.25 * bd]  # use depth ranges within 25% of water column depth
    else:
        dept = [0, 5]
    (obs_dt, obs_temp, depths) = getobs_tempsalt(site[k], input_time=[starttime, endtime], dep=dept)
    # distinct_dep=unique(depths)
    distinct_dep = list(set(depths))
    depthinfor.append(site[k][:] + "," + str(bd) + "," + str(round(distinct_dep[0], 3)) + "\n")
    obs_dtindex = []
    for kk in range(len(obs_temp)):
        obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10], "%Y-%m-%d"))
    obstso = pd.DataFrame(obs_temp, index=obs_dtindex)
    print "obs Dataframe is ready"
    resamdaobs = float64(obstso[0]).resample(
        "A", how=["count", "mean"], loffset=td(days=-182.5)
    )  # need to offset because it uses the end of the averaging period as a timestamp by default
    resamdaobs.ix[resamdaobs["count"] < 75, ["mean"]] = "NaN"
    # the following makes a special results for cases where there is not a full year of data so , we plot this later with a bigger marker
    resamdaobsdot = resamdaobs[(resamdaobs["count"] > 7500) & (resamdaobs["count"] < 8160)]
    if modobs == "both":
示例#8
0
        print bd
        [lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
        print lati,loni
        '''           
        [obs_dt,obs_temp]=getemolt_temp(site[k]) # extracts time series
        obs_dtindex=[]
        for kk in range(len(obs_temp)):
            obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
            obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
        '''
        if surf_or_bott=='bott':
            dept=[bd[0]-0.25*bd[0],bd[0]+.25*bd[0]]
            #dept=[14,33]
        else:
            dept=[0,5]
        (obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k], input_time=[dt.datetime(1880,1,1),dt.datetime(2010,12,31)], dep=dept)
        depthinfor.append(site[k]+','+str(bd[0])+','+str(distinct_dep[0])+'\n')
        obs_dtindex=[]
        if intend_to=='temp':            
            for kk in range(len(obs_temp)):
                obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_temp,index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(datetime.strptime(str(obs_dt[kk])[:10],'%Y-%m-%d'))
            obstso=pd.DataFrame(obs_salt,index=obs_dtindex)   
        print 'obs Dataframe is ready'

##################generate resample DataFrame and putput file################################################
        reobsdaf=resamda(obstso)
示例#9
0
            dept = [0, 5]
#        (obs_dt,obs_temp,obs_salt,distinct_dep)=getobs_tempsalt(site[k],
######################################################################################
        if month_time < 12:
            input_time = [
                dt.datetime(2008, int(month_time), 1),
                dt.datetime(2008,
                            int(month_time) + 1, 1)
            ]
        else:
            input_time = [
                dt.datetime(2008, int(month_time), 1),
                dt.datetime(2008, int(month_time), 31)
            ]
        dep = dept
        obs_dt, obs_temp, obs_salt, distinct_dep = getobs_tempsalt(
            site[k], input_time, dep)
        obs_dtindex = []
        if intend_to == 'temp':
            for kk in range(len(obs_temp)):
                obs_temp[kk] = f2c(obs_temp[kk])  # converts to Celcius
                obs_dtindex.append(
                    datetime.strptime(
                        str(obs_dt[kk])[:19], '%Y-%m-%d %H:%M:%S'))
            obstso = pd.DataFrame(obs_temp, index=obs_dtindex)
        else:
            for kk in range(len(obs_salt)):
                obs_dtindex.append(
                    datetime.strptime(
                        str(obs_dt[kk])[:19], '%Y-%m-%d %H:%M:%S'))
            obstso = pd.DataFrame(obs_salt, index=obs_dtindex)
        print 'obs Dataframe is ready'