- Timestamp:
- Jan 9, 2017, 2:40:29 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1398 r1400 44 44 # compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory 45 45 # compute_tevolboxtraj_radialsec: Function to compute tevolboxtraj_radialsec: temporal evolution at a given point along a number of radii at a given frequency following a trajectory 46 # curve_section: Function to provide a section of a file following a given curve 46 47 # DataSetSection: Function to get a section (values along a dimension) of a given data-set 47 48 # DataSetSection_multidims: Function to get a section (values along multiple dimensions) of a given data-set … … 258 259 259 260 for dn in dnames: 260 print ' ' + fname + ': adding dim:',dn,' ...' 261 if oc.dimensions[dn].isunlimited(): 262 newdim = nc.createDimension(dn, None) 263 else: 264 newdim = nc.createDimension(dn, len(oc.dimensions[dn])) 261 if not gen.searchInlist(nc.dimensions, dn): 262 print ' ' + fname + ': adding dim:',dn,' ...' 263 if oc.dimensions[dn].isunlimited(): 264 newdim = nc.createDimension(dn, None) 265 else: 266 newdim = nc.createDimension(dn, len(oc.dimensions[dn])) 265 267 266 268 nc.sync() … … 18438 18440 [iBL],[jBL] to `right-up' grid point [iUR],[jUR] and [Ncurve] number of line-points with 18439 18441 [xdimn],[ydimn] name of the x and y dimensions 18440 'lonlatline',[londimn]|[lonvarname],[latdimn]|[latvarname],[ iSW],[jSW],[iNE],[jNE],[Ncurve]: line from starting18441 `SW' lonlat point [lonSW],[latSW] to `NE' lonlat point [lonNE],[latNE] and [Ncurve] line-points18442 'lonlatline',[londimn]|[lonvarname],[latdimn]|[latvarname],[lonSW],[latSW],[lonNE],[latNE],[Ncurve]: line from 18443 starting `SW' lonlat point [lonSW],[latSW] to `NE' lonlat point [lonNE],[latNE] and [Ncurve] line-points 18442 18444 with '[lon/latdimn]|[lon/latvarn]' name of the dimension and variable-dimension of longitude 18443 18445 and latitude 18444 'gridfilecurve',[xdimn],[ydimn],[curvefile]: line following grid-values in the file18446 'gridfilecurve',[xdimn],[ydimn],[curvefile]: curve following grid-values in the file 18445 18447 [curvefile](x y; two columns space separated, '#' commment) with [xdimn],[ydimn] name of the x and y dimensions 18446 'lonlatfilecurve',[londimn]|[lonvarname],[latdimn]|[latvarname],[curvefile]: line following18448 'lonlatfilecurve',[londimn]|[lonvarname],[latdimn]|[latvarname],[curvefile]: curve following 18447 18449 lonlat-values in the file [curvefile](lon lat; two columns space separated, '#' commment) with 18448 18450 '[lon/latdimn]|[lon/latvarn]' name of the dimension and variable-dimension of longitude … … 18524 18526 curve = np.zeros((Ncurve,2), dtype=np.float) 18525 18527 for icv in range(Ncurve): 18526 curve[icv,0] = l onSW + Dycurve*icv18527 curve[icv,1] = l atSW + Dxcurve*icv18528 curve[icv,0] = latSW + Dycurve*icv 18529 curve[icv,1] = lonSW + Dxcurve*icv 18528 18530 18529 18531 elif values.split(',')[0] == 'gridfilecurve': … … 18627 18629 18628 18630 # Getting curve-values 18629 loccurve, curvewgts, Nwgts, curveloc3x3 = gen.curvelocalize_2D(curve,xvals,yvals) 18631 loccurve, curvewgts, Nwgts, curveloc3x3, exctloccurve = gen.curvelocalize_2D( \ 18632 curve,xvals,yvals) 18630 18633 18631 18634 # Creation of file … … 18647 18650 basicvardef(newvar,'ycurve', 'y-' +Lcurvey+ ' localization of the curve', cyunit) 18648 18651 18649 # variables 18652 # variable curvetype 18653 curvetype = values.split(',')[0] 18654 newvar = newnc.createVariable(curvetype, 'c') 18655 if curvetype == 'gridline': 18656 desc = "line from starting `bottom-left` grid point [iBL],[jBL] to " + \ 18657 "`right-up` grid point [iUR],[jUR] and [Ncurve] number of line-points " + \ 18658 "with [xdimn],[ydimn] name of the x and y dimensions" 18659 set_attributek(newvar,'description',desc,'S') 18660 set_attributek(newvar,'xdimn',xdimn,'S') 18661 set_attributek(newvar,'ydimn',ydimn,'S') 18662 set_attributek(newvar,'iBL',iBL,'I') 18663 set_attributek(newvar,'jBL',jBL,'I') 18664 set_attributek(newvar,'iUR',iUR,'I') 18665 set_attributek(newvar,'jUR',jUR,'I') 18666 set_attributek(newvar,'Ncurve',Ncurve,'I') 18667 elif curvetype == 'lonlatline': 18668 desc = "line from starting `SW` lonlat point [lonSW],[latSW] to `NE` " + \ 18669 "lonlat point [lonNE],[latNE] and [Ncurve] line-points with " + \ 18670 "`[lon/latdimn]|[lon/latvarn]` name of the dimension and " + \ 18671 "variable-dimension of longitude and latitude" 18672 set_attributek(newvar,'description',desc,'S') 18673 set_attributek(newvar,'londimn',xdimn,'S') 18674 set_attributek(newvar,'lonvarname',xvardimn,'S') 18675 set_attributek(newvar,'latdimn',ydimn,'S') 18676 set_attributek(newvar,'latvarname',yvardimn,'S') 18677 set_attributek(newvar,'lonSW',lonSW,'R') 18678 set_attributek(newvar,'latSW',latSW,'R') 18679 set_attributek(newvar,'lonNE',lonNE,'R') 18680 set_attributek(newvar,'latNE',latNE,'R') 18681 set_attributek(newvar,'Ncurve',Ncurve,'I') 18682 elif curvetype == 'gridfilecurve': 18683 desc = "curve following grid-values in the file [curvefile](x y; two " + \ 18684 "columns space separated, `#` commment) with [xdimn],[ydimn] name of " + \ 18685 "the x and y dimensions" 18686 set_attributek(newvar,'description',desc,'S') 18687 set_attributek(newvar,'xdimn',xdimn,'S') 18688 set_attributek(newvar,'ydimn',ydimn,'S') 18689 set_attributek(newvar,'curvefile',curvefile,'S') 18690 elif curvetype == 'lonlatfilecurve': 18691 desc = "curve following lonlat-values in the file [curvefile](lon lat; " + \ 18692 "two columns space separated, `#` commment) with `[lon/latdimn]|" + \ 18693 "[lon/latvarn]` name of the dimension and variable-dimension of " + \ 18694 "longitude and latitude" 18695 set_attributek(newvar,'description',desc,'S') 18696 set_attributek(newvar,'londimn',xdimn,'S') 18697 set_attributek(newvar,'lonvarname',xvardimn,'S') 18698 set_attributek(newvar,'latdimn',ydimn,'S') 18699 set_attributek(newvar,'latvarname',yvardimn,'S') 18700 set_attributek(newvar,'curvefile',curvefile,'S') 18701 18702 # Localization curve within file 18703 newvar = newnc.createVariable('icurve', 'f8', ('curve')) 18704 newvar[:] = exctloccurve[:,1] 18705 basicvardef(newvar,'icurve', 'x-axis localization of the curve', '1') 18706 18707 newvar = newnc.createVariable('jcurve', 'f8', ('curve')) 18708 newvar[:] = exctloccurve[:,0] 18709 basicvardef(newvar,'jcurve', 'y-axis localization of the curve', '1') 18710 18711 # variable weight 18650 18712 newvar = newnc.createVariable('weights', 'f', ('box','box','curve')) 18651 18713 for icv in range(Ncurve): … … 18653 18715 basicvardef(newvar,'weights', 'weights on the 3x3 around box following curve','1') 18654 18716 18655 # variable s18717 # variable Nweigth 18656 18718 newvar = newnc.createVariable('Nweights', 'f', ('curve')) 18657 18719 newvar[:] = Nwgts[:] … … 18659 18721 'following curve', '-') 18660 18722 18661 # variable s18723 # variable coordweights 18662 18724 newvar = newnc.createVariable('coordweights', 'f', ('pt','boxbox','curve')) 18663 18725 for icv in range(Ncurve): … … 18666 18728 '3x3 around box following curve', '-') 18667 18729 18730 # File variables to get the section 18668 18731 for vn in varns: 18669 18732 if not onc.variables.has_key(vn): … … 18676 18739 18677 18740 ovar = onc.variables[vn] 18678 dimvar = list(ovar.dimensions) 18679 if gen.searchInlist(dimvar, xdimn): dimvar.remove(xdimn) 18680 if gen.searchInlist(dimvar, ydimn): dimvar.remove(ydimn) 18681 18682 varcurve = interp_curve(ovar, xdimn, ydimn, loccurve, curvewgts, Nwgts, \ 18683 curveloc3x3) 18684 18685 # Writing values of variable along the curve 18686 add_dims(onc,newnc,dimvar) 18687 18688 newvar = newnc.createVariable(vn+'curve', 'f4', tuple(dimvar+['curve'])) 18689 newvar[:] = varcurve[:] 18690 add_varattrs(onc,newnc,[vn],[vn+'curve']) 18691 set_attribute(newvar,'along','xcurve,ycurve') 18741 if len(ovar.shape) == 0: 18742 print warnmsg 18743 print ' ' +fname+ ": scalar variable '" + vn + "' section impossible !!" 18744 newvar = newnc.createVariable(vn, ovar.dtype) 18745 newvar[:] = ovar[:] 18746 add_varattrs(onc,newnc,[vn],[vn]) 18747 else: 18748 print ' ' + fname + ": adding section of '" + vn + "' ..." 18749 dimvar = list(ovar.dimensions) 18750 if gen.searchInlist(dimvar, xdimn): dimvar.remove(xdimn) 18751 if gen.searchInlist(dimvar, ydimn): dimvar.remove(ydimn) 18752 18753 varcurve = interp_curve(ovar, xdimn, ydimn, loccurve, curvewgts, Nwgts, \ 18754 curveloc3x3) 18755 18756 # Writing values of variable along the curve 18757 add_dims(onc,newnc,dimvar) 18758 18759 newvar = newnc.createVariable(vn+'curve', 'f4', tuple(dimvar+['curve'])) 18760 newvar[:] = varcurve[:] 18761 add_varattrs(onc,newnc,[vn],[vn+'curve']) 18762 set_attribute(newvar,'along','xcurve,ycurve') 18763 set_attribute(newvar,'curve',curvetype) 18764 newnc.sync() 18692 18765 18693 18766 # Global attributes … … 18708 18781 return 18709 18782 18710 values = 'gridline,x,y,8.,8.,16.,16.,32'18711 curve_section(values,'/home/lluis/PY/test.nc','var')18712 18713 18783 #quit()
Note: See TracChangeset
for help on using the changeset viewer.