Changeset 2294 in lmdz_wrf for trunk/tools
- Timestamp:
- Jan 28, 2019, 5:48:59 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_scientific.f90
r2292 r2294 5304 5304 5305 5305 CALL grid_within_polygon(Nvertex, vertexgrid, dxB, dyB, dxB*dyB, xCBvals, yCBvals, & 5306 NBvertexmax, xBBvals, yBBvals, Ngridsin(ix,iy), gridsin(ix,iy, :,:))5306 NBvertexmax, xBBvals, yBBvals, Ngridsin(ix,iy), gridsin(ix,iy,1:dxyB,:)) 5307 5307 5308 5308 IF (ALLOCATED(poinsin)) DEALLOCATE(poinsin) … … 5317 5317 5318 5318 CALL grid_spacepercen_within_reg(Nvertex, vertexgrid, dxB, dyB, NBvertexmax, xBBvals, & 5319 yBBvals, Ngridsin(ix,iy), poinsin, strict, pareas, percentages(ix,iy, :))5319 yBBvals, Ngridsin(ix,iy), poinsin, strict, pareas, percentages(ix,iy,1:dxyB)) 5320 5320 5321 5321 ! Filling areas -
trunk/tools/nc_var_tools.py
r2293 r2294 28225 28225 percens = percenst.transpose() 28226 28226 28227 # Remember we are in C-like! 28228 gridsin = gridsin - 1 28229 28227 28230 Ngridsinmax = np.max(Ngridsin) 28228 28231 else: … … 28278 28281 28279 28282 ainds = np.array(indices) 28283 # Remenber we are in C-like ... 28284 ainds = ainds - 1 28280 28285 if Ngridsin[0,islc] > 0: 28281 28282 28286 gridsin[0,0:Nt,0,islc] = ainds[0,0:Nt] 28283 28287 gridsin[1,0:Nt,0,islc] = ainds[1,0:Nt] … … 28296 28300 if not gen.searchInlist(onewnc.dimensions, 'fake'): 28297 28301 newdim = onewnc.createDimension('fake',1) 28302 newdim = onewnc.createDimension('slice_fake',1) 28303 newdim = onewnc.createDimension('fakebnds',4) 28304 newvar = onewnc.createVariable('fake','f',('fake')) 28305 newvar[:] = [0.] 28306 basicvardef(newvar, 'fake', 'fake variable for transforming ' + \ 28307 '1D variable without bounds', '-') 28308 newvar = onewnc.createVariable('slice_fake','f',('slice_fake')) 28309 newvar[:] = [0.] 28310 basicvardef(newvar, 'slice_fake', 'slicing along fake variable '+\ 28311 'for transforming variable without bounds', '-') 28312 newvar = onewnc.createVariable('slice_fake_bnds','f', \ 28313 ('fakebnds','fake')) 28314 fakebnds = np.zeros((4,1), dtype=np.float) 28315 fakebnds[0,0] = -1 28316 fakebnds[1,0] = 1 28317 fakebnds[2,0] = 1 28318 fakebnds[3,0] = -1 28319 newvar[:] = fakebnds 28320 basicvardef(newvar, 'slice_fake', 'slicing along fake variable '+\ 28321 'for transforming variable without bounds', '-') 28322 onewnc.sync() 28298 28323 28299 28324 if not gen.searchInlist(newslcvarns,dn): … … 28345 28370 anewvar[:] = areas[:] 28346 28371 28372 aanewvar = onewnc.createVariable(dn+'area','f',tuple(Srgrid), \ 28373 fill_value=gen.fillValueF) 28374 basicvardef(aanewvar ,dn+'area', "area of the slice", vu) 28375 aanewvar.setncattr('coordinates',' '.join(Srgrid[::-1])) 28376 28347 28377 pnewvar = onewnc.createVariable(dn+'gridpercen','f',tuple(Spgrid), \ 28348 28378 fill_value=gen.fillValueF) … … 28357 28387 gridsin[:,0:Ngridsin[j,i],j,i] 28358 28388 pnewvar[0:Ngridsin[j,i],i]= percens[0:Ngridsin[j,i],j,i] 28389 slicearea = 0. 28390 for iv in range(Ngridsin[j,i]): 28391 ix = gridsin[1,iv,i] 28392 iy = gridsin[0,iv,i] 28393 slicearea = slicearea + areas[iy,ix]*percens[iv,j,i] 28394 aanewvar[i]= slicearea 28359 28395 elif len(dv.shape) == 2: 28360 28396 for j in range(dyref): 28361 28397 for i in range(dxref): 28398 apolygon = np.zeros((4,2), dtype=np.float) 28399 apolygon[0,0] = refblon1D[i,0] 28400 apolygon[1,0] = refblon1D[i,1] 28401 apolygon[2,0] = refblon1D[i,1] 28402 apolygon[3,0] = refblon1D[i,0] 28403 apolygon[0,1] = refblat1D[j,1] 28404 apolygon[1,1] = refblat1D[j,1] 28405 apolygon[2,1] = refblat1D[j,0] 28406 apolygon[3,1] = refblat1D[j,0] 28407 ap = np.abs(fsci.module_scientific.shoelace_area_polygon(nvertex=4, poly=apolygon)) 28362 28408 innewvar[:,0:Ngridsin[j,i],j,i] = \ 28363 28409 gridsin[:,0:Ngridsin[j,i],j,i] 28364 28410 pnewvar[0:Ngridsin[j,i],j,i]= percens[0:Ngridsin[j,i],j,i] 28365 28411 slicearea = 0. 28412 aa = 0. 28413 pp = 0. 28414 for iv in range(Ngridsin[j,i]): 28415 ix = gridsin[1,iv,j,i] 28416 iy = gridsin[0,iv,j,i] 28417 apolygon[:,0] = xdimvarbnds2D[:,iy,ix] 28418 apolygon[:,1] = ydimvarbnds2D[:,iy,ix] 28419 ag = np.abs(fsci.module_scientific.shoelace_area_polygon(nvertex=4, poly=apolygon)) 28420 print ' lluis iv:', iv, ':', iy, ix, 'ag:', ag, 'areas:', areas[iy,ix], 'percens:', percens[iv,j,i] 28421 slicearea = slicearea + areas[iy,ix]*percens[iv,j,i] 28422 aa = aa + areas[iy,ix] 28423 pp = pp + percens[iv,j,i] 28424 aanewvar[j,i]= slicearea 28425 print ' areas Lluis =', refblon1D[i,:], 'x', refblat1D[j,:], \ 28426 'j i:', j,i, 'ap', ap, 'aanewvar:', slicearea, 'aa:', aa, 'pp:', pp 28427 if slicearea > ap: quit() 28428 28366 28429 onewnc.sync() 28367 28430 … … 28456 28519 Nin = NpointsAB[jB,iB,jA,iA] 28457 28520 innewvar[:,0:Nin,jB,iB,jA,iA] = pointsAB[:,0:Nin,jB,iB,jA,iA] 28458 print Nin, 'Lluis shapes sliceaA:', osliceaA.shape, 'sliceaB:', osliceaB.shape, \28459 'pnewvar:', pnewvar.shape, 'anewvar:', anewvar.shape28460 28521 for iv in range(Nin): 28461 print 'Lluis jB, iB, jA, iA:', jB,iB,jA,iA28462 print 'Lluis shapes inpointsA:', inpointsA.shape, 'inpointsB:', inpointsB.shape28463 print 'Lluis inpointsA:', inpointsA[iv,jA,iA], 'inpointsB:', inpointsB[iv,jB,iB]28464 28522 pA = oslicepA[inpointsA[iv,jA,iA],jA,iA] 28465 28523 pB = oslicepB[inpointsB[iv,jB,iB],jB,iB] 28466 print 'Lluis shapes pnewvar:', pnewvar.shape, 'pA:', pA, 'pB:', pB28467 28524 pnewvar[iv,jB,iB,jA,iA]= pA*pB 28468 28525 ixA = sliceinA[1,inpointsA[iv,jA,iA],jA,iA] 28469 28526 iyA = sliceinA[0,inpointsA[iv,jA,iA],jA,iA] 28470 print ' A:', ixA, iyA28471 28527 aA = osliceaA[iyA,ixA] 28472 28528 ixB = sliceinB[1,inpointsB[iv,jB,iB],jB,iB] 28473 28529 iyB = sliceinB[0,inpointsB[iv,jB,iB],jB,iB] 28474 print ' B:', ixB, iyB28475 28530 aB = osliceaB[iyB,ixB] 28476 28531 anewvar[jB,iB,jA,iA]= (aA*pA)*(aB*pB)
Note: See TracChangeset
for help on using the changeset viewer.