Пример #1
0
def initHourlyVar(stn, var, miss):
    import ucanCallMethods

    var_dict = {
        'prcp': [5, 'inch', '%4.2f'],
        'temp': [23, 'degF', '%4.0f'],
        'dwpt': [22, 'degF', '%4.0f'],
        'wspd': [28, 'miles/hour', '%4.1f'],
        'tsky': [33, 'count', '%3.1f'],
        'stpr': [18, 'inch_Hg', '%6.3f'],
        'ceil': [35, '100 feet', '%7.0f'],
        'wthr': [20, '', '%{abbr}s'],
        'ccnd': [30, '', '%{abbr}s'],
        'chgt': [31, 'feet', '%.0f '],
        'visi': [26, 'miles', '%5.2f'],
    }

    miss_str = "%s" % miss
    major, units, format = var_dict[var]

    try:
        ucan = ucanCallMethods.general_ucan()
        data = ucan.get_data()
        v = data.newTSVarNative(major, 0, stn)
        if units: v.setUnits(units)
        v.setDataStringFormat(format)
        v.setMissingDataAsString(miss_str)
        v.setMissingDataAsFloat(miss)
    except:
        print "Error initializing:", var
        list = ucanCallMethods.print_exception()
        for item in list:
            print item

    return (v)
Пример #2
0
	def initialize_ucan(self) :
		ucan = general_ucan(user_name="downy_mildew")
		self.data = ucan.get_data()
		q = ucan.get_query()
		r = q.getUcanFromIdAsSeq(self.stn_id,self.type)
		q.release()
		if len(r) > 2 or len(r) == 0:
			print 'init ucan failure',self.stn_id,self.type,r
			sys.exit()
				
		self.ucanId = r[0].ucan_id
Пример #3
0
    def initialize_ucan(self):
        ucan = general_ucan(user_name="downy_mildew")
        self.data = ucan.get_data()
        q = ucan.get_query()
        r = q.getUcanFromIdAsSeq(self.stn_id, self.type)
        q.release()
        if len(r) > 2 or len(r) == 0:
            print 'init ucan failure', self.stn_id, self.type, r
            sys.exit()

        self.ucanId = r[0].ucan_id
Пример #4
0
def get_stations_with_var (state,varMajors=None,start=None,end=None) :
	import Meta
	from omniORB import CORBA
	import ucanCallMethods
	any = CORBA.Any
	tc = CORBA.TypeCode
	tc_short = CORBA.TC_short
	tc_long = CORBA.TC_long
	tc_string = CORBA.TC_string
	tc_nativeId = CORBA.TypeCode(Meta.MetaQuery.NativeId)
	tc_shortSeq = tc(Meta.ShortSeq)
	tc_floatSeq = tc(Meta.FloatSeq)
	NativeId = Meta.MetaQuery.NativeId
	NameAny = Meta.MetaQuery.NameAnyPair
	# set up ucan
	ucan = ucanCallMethods.general_ucan()

	dictionary = {}
	try:
		postal = state.upper()
		if varMajors == None:
			varMajors = [1,2,4]
		if start == None:
			start = (0001,1,1)
		if end == None :
			end = (9999,12,31)
		query = ucan.get_query()
		qualifier =      [ NameAny ('postal',      any(tc_string,postal) )]
		qualifier.append ( NameAny ('var_major_id',any(tc_shortSeq,varMajors) ) )
		qualifier.append ( NameAny ('begin_date',  any(tc_shortSeq,start) )  ) 
		qualifier.append ( NameAny ('end_date',    any(tc_shortSeq,end) )  ) 
		results = query.getStnInfoAsSeq(qualifier,())
		query.release()
		if len(results) == 0:
			return {}
		else:
			dictionary = {}
			for item in results :
				r = NameAny_to_dict(item)
				dictionary[r['ucan_id']] = r
	except:
		print_exception()
	return dictionary 
Пример #5
0
def get_stations_with_var (state,varMajors=None,start=None,end=None) :
	import Meta
	from omniORB import CORBA
	import ucanCallMethods
	any = CORBA.Any
	tc = CORBA.TypeCode
	tc_short = CORBA.TC_short
	tc_long = CORBA.TC_long
	tc_string = CORBA.TC_string
	tc_nativeId = CORBA.TypeCode(Meta.MetaQuery.NativeId)
	tc_shortSeq = tc(Meta.ShortSeq)
	tc_floatSeq = tc(Meta.FloatSeq)
	NativeId = Meta.MetaQuery.NativeId
	NameAny = Meta.MetaQuery.NameAnyPair
	# set up ucan
	ucan = ucanCallMethods.general_ucan()

	dictionary = {}
	try:
		postal = state.upper()
		if varMajors == None:
			varMajors = [1,2,4]
		if start == None:
			start = (0001,1,1)
		if end == None :
			end = (9999,12,31)
		query = ucan.get_query()
		qualifier =      [ NameAny ('postal',      any(tc_string,postal) )]
		qualifier.append ( NameAny ('var_major_id',any(tc_shortSeq,varMajors) ) )
		qualifier.append ( NameAny ('begin_date',  any(tc_shortSeq,start) )  ) 
		qualifier.append ( NameAny ('end_date',    any(tc_shortSeq,end) )  ) 
		results = query.getStnInfoAsSeq(qualifier,())
		query.release()
		if len(results) == 0:
			return {}
		else:
			dictionary = {}
			for item in results :
				r = NameAny_to_dict(item)
				dictionary[r['ucan_id']] = r
	except:
		print_exception()
	return dictionary 
Пример #6
0
    def __init__(self, base_date=None, max_days_per_request=30):
        if base_date is None:
            base_date = (1900, 1, 1, 0)
        elif isinstance(base_date, list):
            base_date = tuple(base_date)

        if isinstance(base_date, tuple):
            if len(base_date) == 3:
                self.base_date = base_date + (0, )
            elif len(base_date) == 4:
                self.base_date = base_date
            else:
                errmsg = "Invalid value for `base_date` : %s"
                raise ValueError, errmsg % str(base_date)
        else:
            errmsg = "Invalid type for `base_date` : %s"
            raise ValueError, errmsg % str(type(base_date))

        self.hours_per_request = max_days_per_request * 24
        self.request_delta = relativedelta(hours=self.hours_per_request)

        self.ucan = ucanCallMethods.general_ucan()
Пример #7
0
			"sod": ('19960418','99991231'),  "val": ('20000420','20101125'),  "wat": ('20010316','20101231'),
			"way": ('19960423','99991231'),  "wgl": ('20070329','99991231'),  "avo": ('19960423','20030713'),
			"bar": ('20010502','99991231'),  "cam": ('19990609','20010809'),  "cat": ('20030708','20060726'),
			"cha": ('19960523','20020809'),  "sci": ('19980409','20041019'),  "por": ('20100406','99991231'),
			"vso": ('20100508','99991231'),  "vsb": ('20100501','99991231'),  "ved": ('20100513','99991231'),
			"vpu": ('20100513','99991231'),  "per": ('20080406','99991231'),  "2wi": ('20100608','99991231'),
			"arm": ('20100608','20101214'),  "1lo": ('20090718','20120707'),  "har": ('20100429','20100927'),
			"vca": ('20100616','99991231'),  "clw": ('20100722','99991231')}

miss = -999
lt_end_hour = 23

class DateMismatch (Exception):
	pass

ucan = ucanCallMethods.general_ucan()

#--------------------------------------------------------------------------------------------	
def get_metadata (station_id,id_type=None):
	ucanid = None
	station_name = station_id
	try:
		if not id_type:
			if station_id[0:1] >= '1' and station_id[0:1] <= '9' and station_id[1:2] >= '0' and station_id[1:2] <= '9':
				id_type = 'njwx'
			elif len(station_id) == 4:
				id_type = 'icao'
			elif station_id[0:3] == "cu_" or station_id[0:3] == "um_" or station_id[0:3] == "uc_" or station_id[0:3] == "un_":
				id_type = 'cu_log'
			elif station_id[0:3] == "ew_":
				station_id = station_id[3:]
Пример #8
0
                  help='show all available debug output')
options, args = parser.parse_args()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

stars = '*' * 72
dataset = args[0]
ucanid = 33686
sid = 'cu_gfr'
network = 'cu_log'
tsvar = tsvars[dataset][network][0]
major = tsvar['major']
minor = tsvar['minor']
units = tsvar['units']

ucan = ucanCallMethods.general_ucan()

query = ucan.get_query()
result = query.getUcanFromIdAsSeq(sid, network)
query.release()
print '%d : %s : ucan id : %s' % (ucanid, sid, result[-1].ucan_id)

query = ucan.get_query()
metadata = query.getInfoForUcanIdAsSeq(ucanid, ())
metadata = ucanCallMethods.NameAny_to_dict(metadata[-1].fields)
query.release()

print 'print metatadata for %d : %s', (ucanid, sid)
print metadata
print '\n%s\n' % stars
Пример #9
0
	def initialize_ucan(self) :
		ucan = general_ucan(user_name="potato_blight_page")
		self.data = ucan.get_data()
Пример #10
0
 def initialize_ucan(self):
     ucan = general_ucan(user_name="potato_blight_page")
     self.data = ucan.get_data()
Пример #11
0
def getNearestCoop(baselat, baselon, varmajor, sd, ed, detailed_check):
    import math
    from mx import DateTime
    from omniORB import CORBA
    import Meta, Data, ucanCallMethods

    NameAny = Meta.MetaQuery.NameAnyPair
    LatLonDistance = Meta.MetaQuery.LatLonDistance
    any = CORBA.Any
    tc = CORBA.TypeCode
    tc_shortseq = tc(Meta.ShortSeq)
    tc_floatseq = tc(Meta.FloatSeq)
    tc_LatLonDistance = CORBA.TypeCode(Meta.MetaQuery.LatLonDistance)

    ucan = ucanCallMethods.general_ucan()

    if detailed_check == 1:
        sd_dt = DateTime.DateTime(sd[0], sd[1], sd[2], 0)
        ed_dt = DateTime.DateTime(ed[0], ed[1], ed[2], 0)

    search_rad = 40.  # initial radius 40 miles
    non_matches = []

    query = ucan.get_query()

    while search_rad < 101:
        qual = [
            NameAny('var_major_id', any(tc_shortseq, [varmajor])),
            NameAny('begin_date', any(tc_shortseq, sd)),
            NameAny('end_date', any(tc_shortseq, ed)),
            NameAny(
                'near_latlon',
                any(tc_LatLonDistance,
                    LatLonDistance(baselat, baselon, search_rad, 'miles'))),
        ]

        results = query.getStnInfoAsSeq(qual, ('coop_id', ))
        if len(results) > 0:
            for r in results:
                d = ucanCallMethods.NameAny_to_dict(r)
                cid = d.get('coop_id', '')
                uid = d.get('ucan_id', '')
                if cid != '' and uid != '':
                    if cid in non_matches:
                        continue  #already checked

                    if detailed_check == 1:
                        # Make sure the valid date range is within dates of interest
                        try:
                            data_daily = ucan.get_data()
                            vals = None
                            vals = data_daily.newTSVar(varmajor, 0, uid)
                            dates = vals.getValidDateRange()
                            svd_dt = DateTime.DateTime(*dates[0])
                            evd_dt = DateTime.DateTime(*dates[1])
                            vals.release()
                        except:
                            if vals: vals.release()
                            non_matches.append(cid)
                            output = ucanCallMethods.print_exception()
                            for i in output:
                                print i
                            continue

                    if detailed_check == 0 or \
                      (detailed_check == 1 and sd_dt >= svd_dt and ed_dt <= evd_dt):
                        query.release()
                        return (cid)
                    else:
                        non_matches.append(cid)

        search_rad = search_rad + 60.  #increase radius by 60 miles

    query.release()
    return (-1)