; Ref: https://www.ncl.ucar.edu/Document/Functions/Built-in/wgt_areaave.shtml ; Example 1 ; Not using wgt_areaave, as suggested by Dennis Shea: ;The data values on 'SMAP_L2_SM_P_E_*h5' are from satellite swaths. "L2" ;The data variable ("soil_moisture") and the location variables: "latitude" and "longitude" are all one-dimensional. It looks like the swath values and the associated latitude & longitude locations were just made into one-dimensional arrays. ;There is no need to perform and areal average when using such a small area [specifically such a small latitudinal range]. .The following should suffice: ; ; latS = 37.45 ; latN = 37.80 ; lonL = 45.8 ; lonR = 4603 ; ; sm = f->soil_moisture ; [*] ; lat = f->latitude ; [*] ; lon = f->longitude ; [*] ; ; ism = ind(.not.ismissing(sm) .and. lat.ge.latS .and. lat.le.latN \ ; .and. lon.ge.lonL .and. lon.le.lonR) ; npts = dimsizes(ism) ; ; sm_avg = avg(sm(ism)) ;============================== ==================== ;Side points: ; ;Alessandra's suggestions would be appropriate if the original data were on a rectilinear grid and then had been placed onto 1D arrays. Then, if you knew the appropriate nlat and mlon sizes you could have used ; ; xGrid = conform_dims( (/nlat,mlon/), x1d) ; (nlat,mlon); similar to onedtond ; ;=== ;The documentation for wgt_areaave should be clarified. This function expects a rectilinear grid. ;---main code begin ;---Read multiple h5 file(s) SPL2_E_nms = systemfunc("ls ./SPL2SMP_E/SMAP_L2_SM_P_E_11*.h5") ; print(SPL2_E_nms) SPL2_E_nmsc = str_get_cols(SPL2_E_nms,35,42) sm_avg = new(dimsizes(SPL2_E_nms), float) printVarSummary(sm_avg) ;---Creating file to write sm_avg values. sm_avg_file = "sm_avg_file.txt" header_sm_avg =(/" date sm_avg"/) hlist_sm_avg =[/header_sm_avg/] write_table(sm_avg_file,"w",hlist_sm_avg," %s ") ;---Computing Soil Moisture Average in the domain do i=0, dimsizes(SPL2_E_nms)-1 print(i) SPL2_E_f = addfile(SPL2_E_nms(i), "r") ; printVarSummary(SPL2_E_f) grp_smrd = "/Soil_Moisture_Retrieval_Data/" var_long_name = "SMAP: Soil Moisture" ; default long_name is too long ;---Set variable name varName = "soil_moisture" ;---Set variable and group path var_path = grp_smrd + varName var = SPL2_E_f->$var_path$ ; printVarSummary(var) ; printMinMax(var, 0) ;---Same lat/lon dimension sizes but maybe different -9999.0 latName = "latitude" lat_path = grp_smrd + latName lat = SPL2_E_f->$lat_path$ ; printVarSummary(lat2d) ; printMinMax(lat2d, 0) lonName = "longitude" lon_path = grp_smrd + lonName lon = SPL2_E_f->$lon_path$ ; printVarSummary(lon2d) ; printMinMax(lon2d, 0) ;---Manually add _FillValue ; lat2d@_FillValue = -9999.0 ; lon2d@_FillValue = -9999.0 ; printMinMax(lat2d, 0) ; printMinMax(lon2d, 0) ; var1d = new(dimsizes(var), typeof(var)) ; var1d := var ;---Determine domain ; Ajabshir(37.5,45.85) ; Azarshahr(37.75,45.98) ; Domain(37.80/45.8/37.45/46.03) (N/W/S/E) ; --37.80----- ; | | ; 45.8 46.03 ; | | ; ---37.45---- ;---Following are from email Dennis Shea: latS = 37.45 latN = 37.80 lonL = 45.8 lonR = 46.03 ; sm = f->soil_moisture ; [*] ; lat = f->latitude ; [*] ; lon = f->longitude ; [*] ism = ind(.not.ismissing(var) .and. lat.ge.latS .and. lat.le.latN \ .and. lon.ge.lonL .and. lon.le.lonR) npts = dimsizes(ism) sm_avg(i) = avg(var(ism)) ; print(sm_avg) write_table(sm_avg_file,"a",[/SPL2_E_nmsc(i), sm_avg(i)/], " %s %4.1f") end do end