<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello dear ncl-users,</p>
    <p>I would like to know how to remove the ensemble mean from the
      corresponding time of each ensemble member, the method i used is
      not correct as it performs time average and i want to do ensemble
      average. The idea is to calculate ensemble mean each year (this
      also removes the seasonal cycle). </p>
    <p>my original data is x=  time | 240] x [ens | 100] x [lat | 45] x
      [lon | 90]</p>
    <p>;First method</p>
    <p> dimx = dimsizes(x)<br>
         ntim = dimx(0)          ; 240<br>
         nens = dimx(1)          ; 100<br>
         nlat = dimx(2)          ; 45<br>
         mlon = dimx(3)          ; 90<br>
      <br>
       <br>
        x@_FillValue = -9.96921e+36<br>
        ens_mean1=dim_avg_n_Wrap(x,1)<br>
        printVarSummary(ens_mean1)        ;[time | 240]  x [lat | 45] x
      [lon | 90]<br>
      <br>
         x1 = x<br>
         do n=0,nens-1<br>
         hist_anom1(:,n,:,:) = hist_anom(:,n,:,:) - ens_mean1<br>
         end do<br>
    </p>
    <p>;=second
      method=================================================================<br>
      ; Compute  monthly anomalies from the mean climatology to remove
      seasonal cycle or to use<br>
      ; rmMonAnnCycTLL (x) Removes the annual cycle from monthly data
      and subtracts the long term means from each month.<br>
;==================================================================<br>
      <br>
         xClm  = clmMonTLLL(x)                                ;
      climatologies for each ensemble member<br>
         printVarSummary(xClm)                                ; [month |
      12] x [ens | 100] x [lat | 45] x [lon | 90]<br>
         printMinMax(xClm,0)                                  ;   :
      min=-226.887   max=161.211cm<br>
         print("============")<br>
      <br>
         xAnom = calcMonAnomTLLL(x,xClm)                     ; anomalies
      from each ensemble member climatology<br>
         printVarSummary(xAnom)                              ; [time |
      240] x [ens | 100] x [lat | 45] x [lon | 90]<br>
         printMinMax(xAnom,0)                                ; 
      min=-0.737722   max=0.83556<br>
         print("============")<br>
    </p>
    <p>;3rd method<br>
;==================================================================<br>
         xClmMonEns = new((/nmos,nlat,mlon/), typeof(x), x@_FillValue)<br>
      do nmo=0,nmos-1<br>
            work := reshape(x(nmo::nmos,:,:,:) ,(/nyrs*nens,nlat,mlon/))<br>
            xStat = dim_stat4_n(work,0 )       ; (4,nlat,mlon)<br>
            xClmMonEns(nmo,:,:) = xStat(0,:,:)<br>
         end do<br>
                           ; meta data<br>
         xClmMonEns@long_name = "Monthly Climatology"<br>
         xClmMonEns@LONG_NAME = "Monthly Climatology over all Ensemble
      Members"<br>
         xClmMonEns@units     = x@units<br>
         copy_VarCoords(x(0,0,:,:), xClmMonEns(0,:,:))<br>
         xClmMonEns!0 = "month"<br>
         printVarSummary(xClmMonEns)<br>
         print("-----")<br>
         printMinMax(xClmMonEns,0)<br>
      <br>
;==================================================================<br>
      ;  Remove the ensemble monthly climatology from each ensemble
      member                                                 
      ;==================================================================<br>
                                                                                                                        
      printVarSummary(x)<br>
        
printMinMax(x,0)                                                                                                     
      print("===")<br>
      <br>
          xAnom = x<br>
         do nt=0,ntim-1<br>
            nmo = nt%12<br>
           do ne=0,nens-1<br>
              xAnom(nt,ne,:,:) = (/ x(nt,ne,:,:) - xClmMonEns(nmo,:,:)
      /) ; anomaly array<br>
           end do<br>
         end do<br>
         xAnom@long_name = "Anomalies from Climatology"<br>
      <br>
         printVarSummary(xAnom)<br>
         printMinMax(xAnom,0)<br>
         print("===")<br>
    </p>
    <div class="moz-cite-prefix">On 6/12/2020 2:06 PM, Rashed Mahmood
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAOmfQPpEhqfDXJx7uPy+tpJ+GLeiqwY89EwQ+WOufS=b13YuSQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div>Please add ncl-talk in subsequent messages...</div>
        <div><br>
        </div>
        <div>In that case, my suggestion in previous message should
          work.</div>
        <div><br>
        </div>
        <div>Rashe<br>
        </div>
      </div>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, Jun 12, 2020 at 1:55
          PM Sri nandini <<a href="mailto:bax8609@uni-hamburg.de"
            moz-do-not-send="true">bax8609@uni-hamburg.de</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div>
            <p>Thank you.</p>
            <p>I wish to remove the ensemble mean from each
              corresponding time of each ensemble.</p>
            <p>Sri<br>
            </p>
            <div>On 12.06.20 13:48, Rashed Mahmood wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">
                <div>If you just want to remove ensemble mean then you
                  could do the following:</div>
                <div><br>
                </div>
                <div>x_new      = x</div>
                <div> ens_mean = dim_avg_n_Wrap(x,1) <br>
                </div>
                <div>do n=0,nens-1</div>
                <div>   x_new(:,n,:,:) = x(:,n,:,:) - ens_mean <br>
                </div>
                <div>end do</div>
                <div><br>
                </div>
                <div>However, please make sure that this is what you
                  want!, it is up to you to decide and know what you are
                  trying to accomplish here. Your variable names suggest
                  that there could be some confusion...</div>
                <div><br>
                </div>
                <div>Cheers,</div>
                <div>Rashed<br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Fri, Jun 12, 2020
                  at 12:50 PM Sri nandini via ncl-talk <<a
                    href="mailto:ncl-talk@mailman.ucar.edu"
                    target="_blank" moz-do-not-send="true">ncl-talk@mailman.ucar.edu</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">Hello dear
                  ncl-users,<br>
                  <br>
                  I want to know the best way to remove the ensemble
                  mean from the <br>
                  corresponding time of each ensemble member. Can
                  someone tell me if the <br>
                  following code is correct? i do not get any error but
                  i wanted to be <br>
                  sure of the method.<br>
                  <br>
                  Thanx in advance<br>
                  <br>
                  Sri<br>
                  <br>
;==================================================================<br>
                  ;  Remove the ensemble mean from each ensemble member<br>
;==================================================================<br>
                      dimx = dimsizes(x)<br>
                      ntim = dimx(0)          ; 240<br>
                      nens = dimx(1)          ; 100<br>
                      nlat = dimx(2)          ; 45<br>
                      mlon = dimx(3)          ; 90<br>
                  <br>
                      nmos = 12<br>
                      nyrs = ntim/nmos         ; 21<br>
                  <br>
                      printVarSummary(x)       ;[time | 240] x [ens |
                  100] x [lat | 45] x [lon | 90]<br>
                      ens_mean=dim_avg_n_Wrap(x,1)<br>
                      printVarSummary(ens_mean);[time | 240]  x [lat |
                  45] x [lon | 90]<br>
                  <br>
                       detrended_x = x<br>
                       do nt=0,ntim-1<br>
                         nmo = nt%12<br>
                        do ne=0,nens-1<br>
                           detrended_x(nt,ne,:,:) = (/ x(nt,ne,:,:) -
                  ens_mean(nmo,:,:) /) ; detrended array<br>
                        end do<br>
                      end do<br>
                      detrended_x@long_name = “Ensemble mean removed”<br>
                  <br>
                      printVarSummary(detrended_x)<br>
                     [time | 240] x [ens | 100] x [lat | 45] x [lon |
                  90]<br>
                  <br>
                  _______________________________________________<br>
                  ncl-talk mailing list<br>
                  <a href="mailto:ncl-talk@mailman.ucar.edu"
                    target="_blank" moz-do-not-send="true">ncl-talk@mailman.ucar.edu</a><br>
                  List instructions, subscriber options, unsubscribe:<br>
                  <a
                    href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>