def start(date_from_changed, date_to_changed, isCrossValidation): f = open('log_universal.txt', 'w') #INTERPOLATE global date_to global date_from global sate_lite_deri global sate_lite_value date_from = date_from_changed date_to = date_to_changed print date_from, date_to list_all_station = getAllObservation() sate_lite_deri, z_sate_to_surface = getSateliteDeriMap() print z_sate_to_surface global sate_lite_value sate_lite_value = get_sate_lite_value(date_to, z_sate_to_surface) #shulf for ten-fold cross validation if isCrossValidation: shuff_dic = slide(FOLD, list_all_station) se = 0 se_satelite = 0 se_sate_count = 0 for x in xrange(0,len(shuff_dic)): print str(FOLD) + '-FOLD: '+ str(x) +' -------------------------' #for item in shuff_dic[x]: # print item, '\n' se_normal, se_sate_i, se_sate_count_i = main_program(shuff_dic[x], isCrossValidation) se = se + se_normal if se_sate_i != 0: se_satelite = se_satelite + se_sate_i se_sate_count = se_sate_count + se_sate_count_i if se_sate_count != 0: print 'LOOP SE: ', str(se/(x+1)), 'SE_SATE: ', str(se_satelite/se_sate_count) print 'SE: ', str(se/FOLD), 'SE_SATE: ', str(se_satelite/se_sate_count) f.write('SE: ' + str(se/FOLD) + '\n') f.write('SE_SATE: '+ str(se_satelite/se_sate_count)) else: item = [[], reIndex(list_all_station)] #item = [[], list_all_station] main_program(item, isCrossValidation) f.close()
#plt.colorbar() #plt.show() for item in list_: print item #insertTerraToDB(list_) def insertTerraToDB(list_): con = None try: con = psycopg2.connect(database='fimo_db', user='******') cur = con.cursor() query = "INSERT INTO terra_2 ( terra_date, terra_time,terra_station_id, terra_temp, terra_humid, terra_rain) VALUES ( %s, %s, %s,%s,%s,%s)" cur.executemany(query, list_) con.commit() except psycopg2.DatabaseError, e: if con: con.rollback() print 'Error %s' % e sys.exit(1) finally: if con: con.close() print 'GOT ', len(list_) #Main #List of observation (id, lat, lon, area_id, alt) list_obs = getAllObservation() dir_path="D:\Thanhnx\Disk_uet\ThanhUET\Dropbox 2012\Dropbox\Master\Research\DuBaoChayRung\DuLieuVeTinh\MOD07L2\\2011_Terra_01" # insert the path to the directory of interest here dirList=os.listdir(dir_path) time.sleep(10) for fname in dirList: print fname read_a_file(list_obs, dir_path + "\\"+ fname)
point = (minLat + i*shift,minLon + j*shift) f.write(str(i)+' '+ str(j)+ ':'+ str(point) +'\n') #if isInVietnam(point): result[i][j], derivation[i][j] = krigeOne(point, neighbor, list_all_station, list_data, G, D) trendValue = getTrendValue(trend_curve, point[0], point[1]) #print trendValue result[i][j] = result[i][j] + trendValue #exportGeotiff('filename', raster, row, col, shift, minLon, minLat) if isCrossValidation == False: exportGeotiff('t08_GEOTIFF_simple_kriging_one_model', result, row, col, shift, minLon, minLat ) saveAsPng(result) saveAsPng(derivation) if isCrossValidation: return calculateSE(result, list_all_test, minLat, minLon, shift, date_to) #INTERPOLATE isCrossValidation = False list_all_station = getAllObservation() #shulf for ten-fold cross validation if isCrossValidation: shuff_dic = slide(10, list_all_station) se = 0 for x in xrange(0,len(shuff_dic)): se = se + main_program(shuff_dic[x], isCrossValidation) print str(se/10) f.write('SE: ' + str(se/10) + '\n') else: item = [[], list_all_station] main_program(item, isCrossValidation) f.close()
#Insert weather area id # -*- coding: utf-8 -*- import psycopg2 from get_data import getAllObservation f = open('workfile.txt', 'w') list_sta = getAllObservation() list_new = []# This list contain area id size = len(list_sta) #IMPORTING ''' con = None try: con = psycopg2.connect(database='fimo_db', user='******') updated = 0 cur = con.cursor() for item in list_data: print 'updating ', item.id, item.name_tram cur.execute("UPDATE station SET station_lat=%s ,station_long = %s,station_alt =%s WHERE station_id=%s", (item.lat,item.lon, item.alt, item.id)) con.commit() updated =updated + cur.rowcount print updated except psycopg2.DatabaseError, e: if con: con.rollback() print 'Error %s' % e sys.exit(1) finally: