def write(self, fn, header): o = open(fn, "w") o.write(header) now = self.sts while (now < self.ets): clr = cliRecord.cliRecord(now) clr.BPset( self.bpdata[now] ) clr.CLset( self.cldata[now.strftime("%Y-%m-%d")] ) clr.write( o ) now = now + 1 o.close()
def main(): # Lets load the rainfall first! loadClimate() loadClimateHeaders() # Load up rainfall polygons we wish to process wcursor.execute("""SELECT mgtzone, hrap_i from hrap_polygons WHERE used = 't'""") for row in wcursor: hrap_i = row['hrap_i'] mgtzone = row['mgtzone'] cf = editclifile.editclifile('/mnt/idep/data/clifiles/%s.dat' % (hrap_i,) ) cr = cliRecord.cliRecord(ts) cr.CLset(cl[mgtzone]) cf.editDaySavePrecip(ts, cr) del(cf) del(cr)
def main(): # Lets load the rainfall first! loadRainfall() loadClimate() loadClimateHeaders() loadTimes() # Load up rainfall polygons we wish to process rs = mydb.query("""SELECT mgtzone, hrap_i from hrap_polygons WHERE used = 't'""").dictresult() processedPoints = 0 for i in range(len(rs)): hrap_i = int(rs[i]['hrap_i']) mgtzone = rs[i]['mgtzone'] bktxt = doBreakPoint(hrap_i) #if (len(bktxt) > 0 or len(sys.argv) == 4): cf = editclifile.editclifile('/mnt/idep/data/clifiles/%s.dat' % (hrap_i,) ) cr = cliRecord.cliRecord(ts) cr.BPset(bktxt) cr.CLset(cl[mgtzone][0]) cf.editDay(ts, cr) cf.write() # os.system("/home/ldm/bin/pqinsert clifiles/%s.dat" % (hrap_i,) ) #if (insertJobQueue): # mydb.query("INSERT into job_queue (combo_id) \ # SELECT id from combos WHERE hrap_i = %s " % (hrap_i,) ) del(cf) del(cr) #if (processedPoints % 1000 == 0): # print "PROCESS UPDATE:", processedPoints processedPoints += 1 #print "build.py: %s clifiles changed!" % (processedPoints) if (insertJobQueue): mydb.query("DELETE from job_queue") mydb.query("INSERT into job_queue(combo_id) select id from combos")
SELECT mgtzone, hrap_i, x(transform(centroid(the_geom),4326)) as lon, y(transform(centroid(the_geom),4326)) as lat from hrap_polygons WHERE used = 't' and hrap_i = 10053 """).dictresult() for i in range(len(rs)): if i % 100 == 0: print 'Processed %s entries' % (i,) hrap_i = int(rs[i]['hrap_i']) mgtzone = rs[i]['mgtzone'] lat = rs[i]['lat'] lon = rs[i]['lon'] x,y = lib.nc_lalo2pt(nc, lat, lon) if y > (numpy.shape(nc.variables['lat'])[0] -1): y = numpy.shape(nc.variables['lat'])[0] - 1 data15 = precipitation[:,y,x] cf = editclifile.editclifile('clifiles/%s.dat' % (hrap_i,) ) sts = monthts ets = monthts + mx.DateTime.RelativeDateTime(months=1) now = sts while now < ets: cr = cliRecord.cliRecord(now) bktxt = doBreakPoint(data15, now.day) cr.BPset(bktxt) cr.CLset(climatedata[now.day][mgtzone][0]) cf.editDay(now, cr) now += mx.DateTime.RelativeDateTime(days=1) cf.write() del cf