Exemplo n.º 1
0
    def getSensorImage(self):
        self.wakeup()
        self.__ser.write("LOOP 1\n");

        self.checkAck()

        buf = self.__ser.read(99)
        
        if buf[0:3] != "LOO":
            raise Exception("Start of block was not LOO")
            
        img = SensorImage()
        img.WindSpeed = mph2kts(struct.unpack("<B", buf[14])[0])
        img.AverageWindSpeed = mph2kts(struct.unpack("<B", buf[15])[0])
        img.WindDirection = struct.unpack("<H", buf[16:18])[0]
        img.IndoorTemperature = f2c(float(struct.unpack("<H", buf[9:11])[0])/10)
        img.IndoorRelativeHumidity = struct.unpack("<B", buf[11])[0]
        img.OutdoorTemperature = f2c(float(struct.unpack("<H", buf[12:14])[0])/10)
        img.OutdoorRelativeHumidity = struct.unpack("<B", buf[33])[0]
        img.QFE = inHg2hPa(float(struct.unpack("<H", buf[7:9])[0])/1000.0)
        img.QFETrend = struct.unpack("<b", buf[3])[0]
        img.Forecast = struct.unpack("<B", buf[89])[0]
        
        img.RainRate = float(struct.unpack("<H", buf[41:43])[0]) * 0.2
        img.RainDay = float(struct.unpack("<H", buf[50:52])[0])* 0.2
        
        img.OutdoorDewpoint = dewpoint_approximation(img.OutdoorTemperature, img.OutdoorRelativeHumidity)
        
        stationcrc = struct.unpack(">H", buf[97:100])[0]
        
        crc = 0
        
        ccitt = CRC_CCITT()
        for c in buf[:97]:
            crc = ccitt.update_crc(crc, ord(c))

        if (stationcrc != crc):
            raise Exception("CRC error, image crc does not match our crc!")
                
        img.Timestamp = time.time()

        return img
Exemplo n.º 2
0
ax1.set_xlim(min(ydg), max(ydg))
ax1.set_ylim(min(tmin), max(tmax))
plt.legend(loc='best')
if depth == 1:
    dd = '_surf'
else:
    dd = ''
plt.title(site + dd +
          ' daily averages (with 30 year research vessel climatology in blue)')
#plt.title('OC01 at 77 meters SNE Shelf')
ax1.grid(True)

c = ax1.axis()
ax2 = ax1.twinx()
ax2.set_ylabel('Celsius')
ax2.axis(ymin=f2c(c[2])[0], ymax=f2c(c[3])[0])
ax2.set_xlim(min(ydg), max(ydg))

# here we add the climatology curve by getting a value each month
print 'adding climatology ...'
clim_files_directory = '/net/data5/jmanning/clim/'
climt, datett = [], []
[lat1, lon1] = getemolt_latlon(site)
for k in range(12):
    datett.append(dt.datetime(2012, k + 1, 1, 0, 0,
                              0))  # note that it assumes year 2012
    climt.append(getclim(lat1, lon1, dt.datetime(2012, k + 1, 1, 0, 0, 0)))
datett.append(dt.datetime(2013, 1, 1, 0, 0,
                          0))  # adds one more point to close out the year
climt.append(climt[0])
ax2.plot(datett, climt, linewidth=4)
Exemplo n.º 3
0
"""
Compares eMOLT with FVCOM bottom temp
@author: jmanning, rsignell, yacheng
"""
import matplotlib.pyplot as plt
import netCDF4
from getdata import getemolt_latlon, getemolt_temp
from conversions import dm2dd, f2c
from utilities import nearxy

site = 'BN01'
[lati, loni, on] = getemolt_latlon(site)  # 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)  # extracts time series
for kk in range(len(obs_temp)):
    obs_temp[kk] = f2c(obs_temp[kk])  # converts to Celcius

# now get the model output
urlfvcom = 'http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3'
nc = netCDF4.Dataset(urlfvcom)
nc.variables
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
times = nc.variables['time']
jd = netCDF4.num2date(times[:], times.units)
vname = 'temp'
var = nc.variables[vname]

# find nearest point to desired location and time
inode = nearxy(lon, lat, loni, lati)
index = netCDF4.date2index(
Exemplo n.º 4
0
"""
Compares eMOLT with FVCOM bottom temp
@author: jmanning, rsignell, yacheng
"""
import matplotlib.pyplot as plt
import netCDF4
from getdata import getemolt_latlon,getemolt_temp
from conversions import dm2dd,f2c
from utilities import nearxy

site='BN01'
[lati,loni,on]=getemolt_latlon(site) # 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) # extracts time series
for kk in range(len(obs_temp)):
  obs_temp[kk]=f2c(obs_temp[kk]) # converts to Celcius

# now get the model output
urlfvcom = 'http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3'
nc = netCDF4.Dataset(urlfvcom)
nc.variables
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
times = nc.variables['time']
jd = netCDF4.num2date(times[:],times.units)
vname = 'temp'
var = nc.variables[vname]

# find nearest point to desired location and time
inode = nearxy(lon,lat,loni,lati)
index=netCDF4.date2index([obs_dt[0],obs_dt[-1]],times,select='nearest')#find the model time index at start & end pf obs
# get data
[lati,loni,on,bd]=getemolt_latlon(site)# extracts lat/lon based on site code
[lati,loni]=dm2dd(lati,loni)#converts decimal-minutes to decimal degrees
'''
dept=[0,5]
(obs_dt,obs_temps,obs_salt)=getobs_tempsalt(site, input_time=[dt.datetime(2004,6,7),dt.datetime(2004,6,24)], dep=dept)
obs_tempslist=[]
for i in range(len(obs_temps)):
         obs_tempslist.append(f2c(obs_temps[i]))
dfsur=pd.DataFrame(obs_tempslist,index=obs_dt)
'''
dept=[bd[0]-0.4*bd[0],bd[0]+0.35*bd[0]]
(obs_dt,obs_tempb,obs_salt)=getobs_tempsalt(site, input_time=[dt.datetime(2004,6,7),dt.datetime(2004,6,24)], dep=dept)
obs_tempblist=[]
for i in range(len(obs_tempb)):
         obs_tempblist.append(f2c(obs_tempb[i]))
dfbot=pd.DataFrame(obs_tempblist,index=obs_dt)
#dfsur=dfsur.ix[dfsur.index.hour==0]
#dfbot=dfbot.ix[dfbot.index.hour==0]
# get model

modtso=getFVCOM_bottom_tempsalt_netcdf(lati,loni,dt.datetime(2004,6,7),dt.datetime(2004,6,24),layer=range(45),vname='temp')
#modtso=modtso.ix[modtso.index.hour==0] 
for i in range(len(dfbot)):
    fig=plt.figure()
    plt.plot(modtso.values[i],range(0,-45,-1),'g*')
#    plt.plot([float32(dfsur[0][i]),float32(dfbot[0][i])],[0,-44],'r*')
    plt.plot([float32(dfbot[0][i])],[-44],'r*')
    plt.ylim(-45,1)
    plt.xlabel('layer(0-44)')
    plt.ylabel('Temprature(Centigrade)')
Exemplo n.º 6
0
Compares eMOLT with FVCOM bottom temp
@author: jmanning, rsignell, yacheng
"""
import matplotlib.pyplot as plt
import netCDF4
from getdata import getemolt_latlon,getemolt_temp
from conversions import dm2dd,f2c
from utilities import nearxy

site='BN01'
[lati,loni,on]=getemolt_latlon(site) # extracts lat/lon based on site code
[lati,loni]=dm2dd(lati,loni) #converts decimal-minutes to decimal degrees
[obs_dt,obs_tempf]=getemolt_temp(site) # extracts time series
obs_temp=[]
for kk in range(len(obs_tempf)):
  obs_temp.append(f2c(obs_tempf[kk])) # converts to Celcius

# now get the model output
urlfvcom = 'http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/hindcasts/30yr_gom3'
nc = netCDF4.Dataset(urlfvcom)
nc.variables
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
times = nc.variables['time']
jd = netCDF4.num2date(times[:],times.units)
vname = 'temp'
var = nc.variables[vname]

# find nearest point to desired location and time
inode = nearxy(lon,lat,loni,lati)
index=netCDF4.date2index([obs_dt[0],obs_dt[-1]],times,select='nearest')#find the model time index at start & end pf obs