예제 #1
0
        cnt += 1
        if cnt < 16:
            out.write(line)
            continue

        tokens = line.split()
        if len(tokens) == 10:
            if ts > 0:
                out.write(
                    "%s\t%s\t%s\t%s\t%3.1f\t%3.1f\t%4.0f\t%4.1f\t%s\t%4.1f\n%s"
                    % (ts.day, ts.month, ts.year, bps, hic, loc, srad, wvl, drct, dwpc, bpdata)
                )

            ts = mx.DateTime.DateTime(int(tokens[2]), int(tokens[1]), int(tokens[0]))
            bps = int(tokens[3])
            hic = mesonet.f2c(float(climate[mgtzone][ts]["high"]))
            loc = mesonet.f2c(float(climate[mgtzone][ts]["low"]))
            srad = float(climate[mgtzone][ts]["rad"])
            wvl = float(climate[mgtzone][ts]["wvl"])
            drct = 0
            dwpc = mesonet.f2c(float(climate[mgtzone][ts]["dewp"]))
            bpdata = ""
        elif len(tokens) == 2:
            bpdata += line

    out.write(
        "%s\t%s\t%s\t%s\t%3.1f\t%3.1f\t%4.0f\t%4.1f\t%s\t%4.1f\n%s"
        % (ts.day, ts.month, ts.year, bps, hic, loc, srad, wvl, drct, dwpc, bpdata)
    )
    out.close()
예제 #2
0
def ob2synop(ob):
    """
    Take a given observation {dictionary} and return a sao coded text
    http://weather.unisys.com/wxp/Appendices/Formats/SYNOP.html
    """
    ar = ["0"] * 50
# character 0  	=  	iR  	-  	the precipitation data indicator
#0 -- Precipitation in groups 1 and 3
#1 -- Precipitation reported in group 1 only
#2 -- Precipitation reported in group 3 only
#3 -- Precipitation omitted, no precipitation
#4 -- Precipitation omitted, no observation 
    if ob.has_key("phour") and ob["phour"] is not None:
        ar[0] = "1"
    else:
        ar[0] = "4"
    
#character 1 	=	iX 	- 	weather data and station type indicator
#1 -- manned station -- weather group included
#2 -- manned station -- omitted, no significant weather
#3 -- manned station -- omitted, no weather observation
#4 -- automated station -- weather group included (see automated weather codes 4677 and 4561)
#5 -- automated station -- omitted, no significant weather
#6 -- automated station -- omitted, no weather observation
#7 -- automated station -- weather group included (see automated weather codes 4680 and 4531) 
    ar[1] = "4"

    #character 2 	=	h 	- 	height above ground of base of lowest cloud
    ar[2] = "/"
    if ob.has_key("skyl1") and ob["skyl1"] is not None and ob["skyl1"] > 0:
        ar[2] = lookup_skyl( ob["skyl1"] * 0.3048 )

    #characters 3-4 	=	VV 	- 	visibility in miles and fractions
    ar[3:5] = "//"
    if ob.has_key("vsby") and ob["vsby"] is not None and ob["vsby"] >= 0:
        ar[3:5] = lookup_vis( ob["vsby"] * 1.609344 )

    #character 5 	=	N 	- 	total amount of cloud cover
    ar[5] = "/"
    if ob.has_key("skyc1") and ob.has_key("skyc2") and ob.has_key("skyc3"):
        ar[5] = lookup_skyc( ob['skyc1'], ob['skyc2'], ob['skyc3'] )
 

    #characters 6-7 	= 	dd 	- 	direction from which wind is blowing
    if ob.has_key("drct") and ob['drct'] is not None:
        ar[6:8] = "%02i" % (ob['drct'] / 10.0,)

    #characters 8-9 	= 	ff 	- 	wind speed in knots
    if ob.has_key("sknt") and ob['sknt'] is not None:
        ar[8:10] = "%02i" % (ob['sknt'],)

    #If character 10 = "1", then
    #    character 11 	=	sn 	- sign of temperature
    #   characters 12-14 	= 	TTT 	- current air temperature
    if ob.has_key("tmpf") and ob['tmpf'] is not None:
        ar[10] = "1"
        tmpc = mesonet.f2c( ob["tmpf"] )
        if tmpc < 0:
            ar[11] = "1"
            tmpc = -1. * tmpc
        ar[12:15] = "%03i" % (tmpc * 10.0,)

    #If character 15 = "2", then
    #
    # character 16 	= 	sn 	- sign of temperature
    # characters 17-19 	= 	Td 	- dew point
    if ob.has_key("dwpf") and ob['dwpf'] is not None:
        ar[15] = "2"
        dwpc = mesonet.f2c( ob["dwpf"] )
        if dwpc < 0:
            ar[16] = "1"
            dwpc = -1. * dwpc
        ar[17:20] = "%03i" % (dwpc * 10.0,)

    #If character 20 = "3", then
    #
    #      characters 21-24 	= 	PO 	- station pressure (not plotted)
    if ob.has_key("alti") and ob["alti"] is not None:
        ar[20] = "3"
        ar[21:25] = str( "%4i" % (ob["alti"] * 33.8638866667 * 10.0,))

    #If character 25 = "4", then
    #
    #      characters 26-29 	= 	PPPP 	- pressure reduced to sea level
    if ob.has_key("pmsl") and ob["pmsl"] is not None:
        ar[25] = "4"
        ar[26:30] = str( "%4i" % (ob["pmsl"] * 10.0,))

#If character 30 = "5", then
#
#      character 31 	= 	a 	- characteristic of barograph
#      characters 32-34 	= 	ppp 	- pressure change, last 3 hrs.

#If character 35 = "6", then
#
#      characters 36-38 	= 	RRR 	- precipitation
#      character 39 	= 	tR 	- time duration of precipitation
    if ob.has_key("phour") and ob["phour"] is not None and ob["phour"] >= 0:
        ar[35] = "6"
        ar[36:39] = str( "%3i" % ( ob["phour"] * 25.4, ))
        ar[39] = "5" # 1 hour total

#If character 40 = "7", then
#
#     characters 41-42 	= 	ww 	- present weather
#      character 43 	= 	W1 	- most significant past weather
#      character 44 	= 	W2 	- 2nd most sig. past weather
    #ar[40:45] = "7////"
#
#If character 45 = "8", then
#
#      character 46 	= 	Nh 	- Fraction of sky cover
#      character 47 	= 	CL 	- cloud type, low clouds
#      character 48 	= 	CM 	- cloud type, medium clouds
#      character 49 	= 	CH 	- cloud type, high clouds
    #ar[45:50] = "8////"

    return "".join( ar )
예제 #3
0
파일: yearly.py 프로젝트: KayneWest/iem
mcursor.execute("""
    SELECT id from stations WHERE network in ('IA_ASOS', 'MO_ASOS','KS_ASOS','NE_ASOS','SD_ASOS','ND_ASOS',
    'MN_ASOS','WI_ASOS','IL_ASOS','IN_ASOS','MI_ASOS') and archive_begin < '1960-01-01'
    """)
for row in mcursor:
    stations.append( row[0] )
stations = ['DSM','XXXXX']
for yr in range(1951,2012):
    acursor.execute("""
    SELECT valid + '10 minutes'::interval, tmpf, dwpf from t%s WHERE station in %s
    and extract(month from valid) in (6,7,8) and dwpf > -30 and tmpf > -30
    """ % (yr, str(tuple(stations))))
    hourly = numpy.zeros( (24,), 'f')
    counts = numpy.zeros( (24,), 'f')
    for row in acursor:
        dwpc = mesonet.f2c( row[2] )
        e  = 6.112 * math.exp( (17.67 * dwpc) / (dwpc + 243.5))
        mixr =  0.62197 * e / (1000.0 - e)
        if mixr > 0:
            hourly[ row[0].hour - 1] += mixr
            counts[ row[0].hour - 1] += 1
        
    climate[:,yr-1951] = hourly / counts * 1000.
    avgV = numpy.sum(hourly) / numpy.sum(counts) * 1000.
    print yr, avgV 
    
    

import matplotlib.pyplot as plt

fig = plt.figure()