def height_computing(args): imager, neighbors, Date, TimeStamp, DocumFilename = args f = inpath + imager.camID + '/' + Date + '/' + imager.camID + '_' + Date + TimeStamp + '.jpg' if not os.path.exists(f): return -1 img = cam.image(imager, f) img.undistort(imager, rgb=True) if img.red is not None: img.cloud_mask(imager) else: # if img.red is None or img.layers <= 0: if WRITE: Document = open(DocumFilename, 'a') Document.write("img.red is None or img.layers <=0") Document.close() return -1 h = [[]] * img.layers for neighbor in neighbors: f_nb = f.replace(imager.camID, neighbor.camID) img_nb = cam.image(neighbor, f_nb) img_nb.undistort(neighbor, rgb=True) if img_nb.red is not None: img_nb.cloud_mask(neighbor) else: if PRINT: print("img_nb.red is None") continue distance = 6367e3 * geo.distance_sphere(img.lat, img.lon, img_nb.lat, img_nb.lon) for ih in range(img.layers): if (len(h[ih])) >= 1: continue res = cam.cloud_height(img, img_nb, layer=ih, distance=distance) if len(res) >= 1 and res[0] < 30 * distance and res[ 0] > 0.5 * distance: h[ih] = res[0] if PRINT: print("with camera " + imager.camID + "neighbor " + neighbor.camID) print("the cloud height is") print(res[0]) return res[0] # if len(h) >= img.layers: # if PRINT: # print("with camera " + imager.camID + " neighbor " + neighbor.camID) # print("len(h) = " + str(len(h))) # print("img.layers =" + str(img.layers)) # break if (len(h[0]) == 0): if PRINT: print("len(h[0]) == 0") return -1
def height(args): imager,neighbors,day=args ymd=day[:8] flist = sorted(glob.glob(inpath+imager.camID+'/'+ymd+'/'+imager.camID+'_'+day+'*jpg')) if len(flist)<=0: return for f in flist: basename=f[-23:-4] if os.path.isfile(tmpfs+f[-18:-10]+'/'+basename+'.hkl') and (~REPROCESS): ######already processed, skip continue # print('Procesing', basename) fpickle = glob.glob(tmpfs+f[-18:-10]+'/'+basename+'*pkl') img=None if len(fpickle)<=0: img=cam.preprocess(imager,f,tmpfs); else: with open(fpickle[0],'rb') as input: try: img=pickle.load(input); except EOFError: img=None if img is None or img.red is None: continue if img.layers<=0: img.dump_img(tmpfs+f[-18:-10]+'/'+f[-23:-4]+'.hkl'); continue; if img.layers>=1: h = [np.nan]*img.layers for inghb,neighbor in enumerate(neighbors): bname=basename.replace(imager.camID,neighbor.camID); fp_nb = glob.glob(tmpfs+f[-18:-10]+'/'+bname+'*pkl') img1=None; if len(fp_nb)<=0: fnb=f.replace(imager.camID,neighbor.camID) img1=cam.preprocess(neighbor,fnb,tmpfs); ###img object contains four data fields: rgb, red, rbr, and cm else: with open(fp_nb[0],'rb') as input: try: img1=pickle.load(input); except EOFError: img1=None if img1 is None or img1.red is None: continue distance = 6367e3*geo.distance_sphere(img.lat,img.lon,img1.lat,img1.lon) for ih in range(img.layers): if np.isfinite(h[ih]): continue if (ih>=1) and (distance<500): break; res=cam.cloud_height(img,img1,layer=ih+1, distance=distance) if np.isfinite(res) and res<20*distance and res>0.5*distance: h[ih]=int(res); # print('Cloud height computed for', f[-23:]); # print('Cloud layer',ih+1,':',res,' computed with cameras ',img.camID,img1.camID,'(distance:',distance,'m)') if not SAVE_FIG: fig,ax=plt.subplots(2,2,figsize=(10,10),sharex=True,sharey=True); ax[0,0].imshow(img.rgb); ax[0,1].imshow(img1.rgb); ax[0,0].set_title(img.camID); ax[0,1].set_title(img1.camID) ax[1,0].imshow(img.cm); ax[1,1].imshow(img1.cm); ax[1,0].set_title(str(6367e3*geo.distance_sphere(img.lat,img.lon,img1.lat,img1.lon))) plt.tight_layout(); plt.show(); if np.isfinite(h[-1]): break # img.height+=[h]; img.height=h; img.dump_img(tmpfs+f[-18:-10]+'/'+f[-23:-4]+'.hkl');