# [ncl-talk] Computing max of monthly NO2 data each year

Jack Ogaja jack.ogaja at gmail.com
Tue Sep 29 14:01:52 MDT 2015

```Alan,

That is how it should be, and I agree that people should consider concise and efficient approach in coding. However, I wasn’t sure what such changes(rewriting the entire code) would mean to Thierno and the original aim.

Jack

> On 29 Sep 2015, at 21:18, Alan Brammer <abrammer at albany.edu> wrote:
>
> Looks like You got things sorted with Jack pretty well.
>
> I went through and cleaned up your code a little, to make it a little more concise in my opinion.  Functionally it will be the same, but if you go through and understand my changes here it may help you in the future.
>
> f1 = "Europe_bis_ncl.txt"
>
> EU at _FillValue = -9999
> EU!0 = "time"
> EU!1 = "variable"
> ;; if the dimeensions are named they can be reordered very easily.
>
> ;************************************************
> ; to plot multiple lines, you must put them into
> ; a mulidimensional array
> ;************************************************
>
> nraw = 8
> ncol = 276
> nmax = ncol/12
>
> EU_plot      = new((/nraw,ncol/),float, EU at _FillValue)
> EU_plot(:6,:) = EU(variable|:, time|120:395)  ; name the dimensions and reorder easily.
> EU_plot(7,:) = dim_avg_n(EU_plot(0:6,:),0)
>
> EUmax := new((/nraw,nmax/),float, EU_plot at _FillValue)
>
>
> ;; rather than having 3 different iterable integers, simplify things with an array up front.
> ;;;;
> t_lbd = ispan(0, ncol-12, 12)   ;  lower bounds to find max over.
> t_ubd = t_lbd + 11              ;  upper bounds to find max over.
>
>
> do t=0,dimsizes(t_lbd)-1
>   EUmax(:,t) = dim_max_n(EU_plot(:,t_lbd(t):t_ubd(t)),1)   ;; use the array based functions where possible.
> end do
>
> print(EUmax)
>
>
>
>
> On Tue, Sep 29, 2015 at 12:22 PM, Doumbia <thiernodoumbia at yahoo.fr <mailto:thiernodoumbia at yahoo.fr>> wrote:
> I add some thing in your code and it gives me the good results.
> yr = i would be yr = i+1.
>
> The new script is:
> do n=0,7
>     yr=0
>     k =0
>     do i = 11,275,12
>        EUmax(n,k) = max(EU_plot(n,yr:i))
>        k=k+1
>        yr=i+1
>     end do
>  end do
>
> Jack, thank again.
> Thierno
>
> > Le 29 Sep 2015 à 18:02, Doumbia <thiernodoumbia at yahoo.fr <mailto:thiernodoumbia at yahoo.fr>> a écrit :
> >
> > Hi Jack,
> > I really appreciate your teaching skills.
> >
> > I recognize that there’s weird things in my script but I apologize for that, I am new in NCL.
> >
> > Unfortunately, your suggestions don’t give the good results i.e. the maximum of monthly NO2 data for each year. I compared these results with those obtained from excel.
> >
> > You are right, the "EU(120:395,0)” is for 1990 to 2012 (23 years).
> >
> > Thank you for your help.
> >
> > Thierno
> >
> >
> >>
> >> ...
> >> “The results I’ve obtained aren’t what I expected.”
> >> ...
> >> Well, even Aristotle would struggle to figure out what you expected if you didn't tell him…
> >>
> >> Your script still got visible mistakes though. For example the loop is quite extravagant:
> >> …
> >> k = ispan(0,11,1)
> >> do n=0,7
> >>  do i = 0,275,12
> >>   do j=0,11
> >>     EUmax(n,:) = max(EU_plot(n,i+k(j))) <== “j” will always be the same type as, and equal to “k(j)”?
> >>   end do
> >>  end do
> >> end do
> >> …
> >> and since the left side of your equation has a free dimension, the variable will always be overwritten up to the end of the loop.
> >>
> >> You can clean the loop and do something like,
> >> do n=0,7
> >>    yr=0
> >>    k =0
> >>    do i = 11,275,12
> >>       EUmax(n,k) = max(EU_plot(n,yr:i))
> >>       k=k+1
> >>       yr=i
> >>    end do
> >> end do
> >>
> >> I was also wondering whether from your file “EU(120:395,0)” will give you information from 2000 to 2012(12 years)? Probably that is the unexpected result you mentioned. Who knows?
> >>
> >> I hope that helps.
> >>
> >> Jack
> >>
> >>> On 29 Sep 2015, at 15:02, Doumbia <thiernodoumbia at yahoo.fr <mailto:thiernodoumbia at yahoo.fr>> wrote:
> >>>
> >>> Dear ncl users,
> >>>
> >>> I am trying to compute the monthly maximum NO2 in a yearly basis.
> >>>
> >>> My input file contains 7 columns representing different variables and 396 lines (monthly mean NO2 data from 1980 to 2012). I am only interested by the 2000-2012 period .
> >>>
> >>> The results I’ve obtained aren’t what I expected.
> >>> <max_of_monthly_data.ncl><Europe_bis_ncl.txt>
> >>> I will appreciate any help to resolve this.
> >>>
> >>> Please find attached my script as well as my input file.
> >>>
> >>> Thank you in advance,
> >>> Thierno
> >>>
> >>> _______________________________________________
> >>> ncl-talk mailing list
> >>> ncl-talk at ucar.edu <mailto: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 <mailto: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/20150929/df947871/attachment.html
```