Re: re-converting 1D to 3D array.

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Tue Mar 09 2010 - 17:46:31 MST

Sho Kawazoe,

This is the second statement in your program:

   prc = fin->pr

Move up the four lines for lat1, lat2, lon1, lon2; and try this instead:

   prc = fin->pr(:,{lon1:lon2},{lat1:lat2})

   printVarSummary(prc)
   print(prc&lon)
   print(prc&lat)
   exit

If latitudes in the file go from high to low, then reverse the order
of lat1 and lat2 above. Same for longitudes.

Somehow you started making this reader more complicated than it
should be. This should work better. We do not need to discuss
conversion of dimensions unless your problem is more complicated
than it looks.

--Dave A.
NOAA/PSD/CIRES

Sho Kawazoe wrote:
> NCL users,
>
> I'm still very raw in my knowledge with ncl, and was wondering if anyone
> can help me out.
>
> I'm currently using precipitation data with MM5 (from EGS), and trying to
> mask a specific lat and lon point, with the ultimate purpose of outputting
> data within that specific grid, and truncating the data to where when I end
> up concatenating other files, I am well below the 2gb threshold.
>
> Steps leading to retrieving the desiredvalues in 1D looks fine, and the
> output file is well below the original input file size. However, when I
> reconvert the 1D to 3D, the file is back to the same size as the input file,
> and it looks like missing values are inputted into the output file, which
> doesn't make the file any smaller.
>
> Is there a way to reconvert the 1D array to 3D array and keep only the
> precip values we want, without the missing values(keep in mind that the
> associated metadata needs to be there as well)? A simple onedtond doesn't
> look like the solution, and I'm misunderstanding the coding.
>
> The script is as follows. Any help is appreciated.
>
> ;*****************************************************
> ; Read original NetCDF file.
> ;*****************************************************
>
> fin = addfile ("pr_MM5I_1979010103.nc","r")
>
> ;******************************************************
> ; Upload netCDF file variables, set dimensions
> ;******************************************************
>
> prc = fin->pr ; obtain pr(time,xc,yc) values. Dimension is in
> 3D
> lat = fin->lat
> lon = fin->lon
> time = fin->time
> Lambert_Conformal = fin->Lambert_Conformal
>
> dim = dimsizes(prc)
> ntime = dim(0)
> nlat = dim(1)
> nlon = dim(2)
>
> latlonmask2 = prc(:,:,:) ; assign dim size to masking var
> latlonmask2 = 0 ; initialization
>
> ;**************************************************************
> ; Indicate coordiate you want to analyze. Make sure you
> ; check the NetCDF file for correct lat lon specification!!
> ;
> ; Mask through time, xc, and yc for entire precip variable to
> ; analyze specifc regions
> ;**************************************************************
>
> lat1 = 37
> lat2 = 47
> lon1 = 269
> lon2 = 279
>
> do k = 1, ntime-1
> do j = 1, nlat-1
> do i = 1, nlon-1
> if (lat(j,i).ge.lat1 .and. lat(j,i).lt.lat2 .and. lon(j,i).gt.lon1
> .and. lon(j,i).le.lon2) then
> latlonmask2(k,j,i) = 1
> end if
> end do
> end do
> end do
>
> desiredvalues = mask(prc, latlonmask2, 1)
>
> ;********************************************************************
> ; Convert the masked region to a 1d array, which allows us to then
> ; use the ncl function "ind" to keep only the data from the region
> ; we are interested in looking at. This also keeps all the
> ; metadata associated with each precip value.
> ;*******************************************************************
>
> desired1d = ndtooned (desiredvalues) ; convert to 1d array
> indices = ind (.not.ismissing(desired1d)) ; keep precip values that
> have no missing data.
> output1d = desired1d(indices) ; all non-missing values
> desiredvalues = onedtond(output1d,dimsizes(desiredvalues))
> delete (desired1d) ; clean up if you wish.
> delete (indices)
>
> ;******************************************************************
> ; Create a new nc output file
> ;******************************************************************
>
> system("/bin/rm -f region_output.nc") ; remove any pre-existing
> file
> fout = addfile("region_output.nc","c")
> filedimdef(fout,"time",-1,True) ; Makes time an UNLIMITED
> dimension (as suggested by NCL)
>
> fout->prc = output1d
>
> fout->lat = lat
> fout->lon = lon
>
> end
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Mar 9 17:46:39 2010

This archive was generated by hypermail 2.1.8 : Thu Mar 11 2010 - 11:17:07 MST