[ncl-talk] Sequences of values
Rashed Mahmood
rashidcomsis at gmail.com
Sat Mar 24 12:30:37 MDT 2018
Hi Guigma,
For 1 dimensional series you can use the following. however, you would need
to adapt this to your 3D data sets through loops/ind function and need to
do TESTING, this is a very time consuming process.
begin
; X1 = (/0,1,0,0,1,1,1,1,1,0,0,1,0,1,1,1,1,0,0,1,0/) ; orignal
X1 = (/0,1,0,0,1,1,1,1,1,0,0,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,1,0,1,1/) ;
for testing
X2 = new(dimsizes(X1),integer)
do n=0,dimsizes(X1)-1
if(n.eq.0)
if(X1(n).eq.1.and.X1(n+1).eq.0)
X2(n) = 0
else
X2(n) = X1(n)
end if
end if
if(n.gt.0.and.n.lt.dimsizes(X1)-1)
if(X1(n).eq.1)
if(X1(n-1).eq.0.and.X1(n+1).eq.0)
X2(n) = 0
else
X2(n) = X1(n)
end if
else
X2(n) = X1(n)
end if
end if
if(n.eq.dimsizes(X1)-1)
if(X1(n).eq.1.and.X1(n-1).eq.1)
X2(n) = X1(n)
else
X2(n) = 0
end if
end if
end do
print(X1+" ... "+X2)
end
Note I have NOT tested it as much one should so I would let you to test and
find out if that is what you are looking for.
Cheers,
Rashed
On Sat, Mar 24, 2018 at 6:44 AM, Kiswendsida Hyacinthe GUIGMA <
karongseba at gmail.com> wrote:
> Thank you for your reply and for your help.
> Actually, before to post my question, I tried to make a use of
> dim_numrun_n but it didn't solve my problem.
>
> You misunderstood a bit my [1]. I said that I successfully did that... So
> it is OK for that.
>
> For [2] , what the dim_numrun_n function allows is just to do a count.
> What me I'd rather like is to set to _FillValue (or to 0 if use of where
> function) all values that are not in a sequence of at least 04 days. As an
> example I would like to have something as follows:
> X1=(/0,1,0,0,1,1,1,1,1,0,0,1,0,1,1,1,1,0,0,1,0,/) ==========> X2= (/0,*0*
> ,0,0,1,1,1,1,1,0,0,*0*,0,1,1,1,1,0,0,*0*,0,/).
> In other words it is to replace all "isolated" 1s by 0.
>
> Kindest regards
>
>
>
>
>
> -----------------------------
> GUIGMA
>
>
> On Friday, 23 March 2018, 22:17:11 GMT, Dennis Shea <shea at ucar.edu>
> wrote:
>
>
> Sorry, I'm I am not looking at any code.
>
> tcrit = 30.
>
> f = addfile(...)
> T = f->T ; (time,lat,lon)
>
>
> [1] "setting values below the threshold to _FillValue" is simple.
>
> https://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml
>
> Tcrit = where(T.ge.tcrit, T, T at _FillValue)
> copy_VarMeta(T, Tcrit)
> ===========
> [2] You do not need to do [1]
>
> Maybe you could use the following function:
>
> =========
> http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_numrun_n.shtml
> ****Look at the examples****
> =========
>
> T10= where(T.ge.tcrit,1, 0)
> T10 at long_name = "Exceed=1; No=0"
> copy_VarCoords(T, T10)
> printVarSummary(T10)
>
> r0 = *dim_numrun_n* (T10, *0*, 0) ; (ntim,nlat,mlon)
> r1 = *dim_numrun_n* (T10, *1*, 0)
> copy_VarCoords(T, r0)
> copy_VarCoords(T, r1)
>
> ;---Pick one grid point to see what is happening
>
> LAT = ..
> LON = ..
> print(T(:,{LAT},{LON})+" "+Tcrit(:,{LAT},{LON})+" "+T10(:,{LAT},{LON}) \
> +" "r0(:,{LAT},{LON})+" "+r1(:,{LAT},{LON})
>
>
>
> On Fri, Mar 23, 2018 at 3:29 PM, Kiswendsida Hyacinthe GUIGMA <
> karongseba at gmail.com> wrote:
>
> Dear NCL users,
> I have 3D (time,lat,lon) array of temperature from which I would like to
> keep only sequences (consecutive days) exceeding a certain threshold. This
> consist concretely in setting values below the threshold to _FillValue.
> The length of sequence is set to 4. So far, have been able to set to
> _FillValu only individual days that exceed the threshold. Then I would be
> pleased if you could provide me with a method to also set to _FillValue
> values that are not into sequences of at least 04 days.
>
> Please find attached my data and my code.
>
> Regards
>
>
> -----------------------------
> GUIGMA
>
> ______________________________ _________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/ mailman/listinfo/ncl-talk
> <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180324/9442ca5e/attachment.html>
More information about the ncl-talk
mailing list