[ncl-talk] Removing missing values from a 1D data
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Wed Nov 15 16:15:40 MST 2017
Jiali Wang,
Here is efficient code that uses vector subscripting to select the desired
values. This is untested. Give this a try:
a = addfile("200303101200.CHRTOUT_DOMAIN3"+".nc","r")
st = a->streamflow
lat = a->latitude
lon = a->longitude
ord = a->order ;;do filter based on this number, we only want order>2
ind_valid = ind (ord(:) .gt. 2)
if (.not. ismissing (ind_valid(0))) then
system("/bin/rm -f simple.nc")
ncdf = addfile("simple.nc" ,"c")
ncdf->streamflow = st(ind_valid)
ncdf->lat = lat(ind_valid)
ncdf->lon = lon(ind_valid)
;;;;;;or output in txt format
opt = True
opt at fout = "foo.txt"
write_matrix(st(ind_valid), "10f7.2", opt)
end if
--Dave
On Wed, Nov 15, 2017 at 3:54 PM, Wang, Jiali <jialiwang at anl.gov> wrote:
> Dear NCL group,
>
>
>
> I am having a similar question as this post https://www.ncl.ucar.edu/Suppo
> rt/talk_archives/2011/1499.html but unfortunately i didn’t get it..
>
>
>
> I have a 1D data set (station data) as shown below. I would like to filter
> out the lower orders (order smaller than 2). I do this using “where”, so I
> get lots of missing values for those stations with lower orders. But these
> values take lots of space, so I want to get rid of them and output a much
> lighter data only for the stations with non-missing values. Below is what
> my data and my NCL script look like. Could you please take a look and
> advice? With my script I am still having all the missing value in my output.
>
>
>
> ncdump -c 200303091200.CHRTOUT_DOMAIN3
>
> netcdf \200303091200 {
>
> dimensions:
>
> station = 3678397 ;
>
> time = 1 ;
>
> variables:
>
> float latitude(station) ;
>
> latitude:long_name = "Station latitude" ;
>
> latitude:units = "degrees_north" ;
>
> float longitude(station) ;
>
> longitude:long_name = "Station longitude" ;
>
> longitude:units = "degrees_east" ;
>
> float streamflow(station) ;
>
> streamflow:units = "meter^3 / sec" ;
>
> streamflow:long_name = "River Flow" ;
>
> int order(station) ;
>
> order:long_name = "Strahler Stream Order" ;
>
> =============
>
> a = addfile("200303101200.CHRTOUT_DOMAIN3"+".nc","r")
>
> st = a->streamflow
>
> lat = a->latitude
>
> lon = a->longitude
>
> ord = a->order ;;do filter based on this number, we only want order>2
>
>
>
> st1 = new(dimsizes(st),typeof(st))
>
> lat1 = new(dimsizes(lat),typeof(lat))
>
> lon1 = new(dimsizes(lon),typeof(lon))
>
>
>
> st at _FillValue = -9999
>
> st1 = where(ord .gt. 2, st, st at _FillValue)
>
> lat1 = where(ord .gt. 2, lat, st at _FillValue)
>
> lon1 = where(ord .gt. 2, lon, st at _FillValue)
>
>
>
> if (.not.all(ismissing(st1))) then ;;I think this “if” statement has
> some problem, but I am not sure what’s the right one should be..
>
> system("/bin/rm -f simple.nc")
>
> ncdf = addfile("simple.nc" ,"c")
>
> ncdf->streamflow = st1
>
> ncdf->lat = lat1
>
> ncdf->lon = lon1
>
> ;;;;;;or output in txt format
>
> opt = True
>
> opt at fout = "foo.txt"
>
> write_matrix(st1, "10f7.2", opt)
>
> end if
>
>
>
> ==============
>
>
>
> Thanks!
>
>
>
> Jiali Wang, Ph. D
>
> Environmental Science Division
>
> Argonne National Laboratory
>
> Tel: 630-252-2848
>
> http://www.evs.anl.gov/about-evs/staff/detail/index.cfm?/Wang/Jiali
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171115/37f438e6/attachment.html>
More information about the ncl-talk
mailing list