<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi Rick and ncl-users,</div><div dir="ltr">I realized that my code below provides the cumulative sum, </div><div dir="ltr">whereas I just want to record the values of each area listed in "opt@shape_name"  in a single variable. </div><div dir="ltr">If you or someone else could help me to avoid this cumulative sum, I would appreciate it. <br></div><div dir="ltr"><br></div><div>... below is part of the code I had attached in my first post</div><div dir="ltr">...</div><div dir="ltr"><div dir="ltr">;-- Open and read data off the shapefile </div><div dir="ltr">   dirShapf = "./"</div><div dir="ltr">   shp_name = "gadm36_1.shp"</div><div dir="ltr">   shp_path = dirShapf+shp_name</div><div dir="ltr">   ;print_shapefile_info(shp_path)</div><div dir="ltr">   </div><div dir="ltr">   ratio_mask  = sample</div><div dir="ltr">   </div><div dir="ltr">   ;-- Put trend values to the areas that I don't want masked</div><div dir="ltr">   ;get the size of the lat/lon grid of variable data</div><div dir="ltr">   iNumlat = dimsizes(sample&latitude)</div><div dir="ltr">   iNumlon = dimsizes(sample&longitude)</div><div dir="ltr">   </div><div dir="ltr">   ; Create a new variable to put in the daily trends for each region </div><div dir="ltr">   ; and fill the other grids with the value 1.</div><div dir="ltr">   ;maskedRatio = new((/iNumlat,iNumlon/),float,sample@_FillValue)</div><div dir="ltr">   ;copy_VarMeta(ratio_mask, maskedRatio)</div><div dir="ltr"><br></div><div dir="ltr">   maskedRatio = ratio_mask</div><div dir="ltr">   maskedRatio = 0</div><div dir="ltr"><br></div><div dir="ltr">   ;-- Loop over the country/region/province</div><div dir="ltr">   do ir=0,dimsizes(reg_names)-1</div><div dir="ltr">      vname = reg_names(ir)</div><div dir="ltr">      print("region ="+vname)</div><div dir="ltr">      ;print(vtrend(62,ir)/100.)</div><div dir="ltr"><br></div><div dir="ltr">      ;set masking options </div><div dir="ltr">      opt                            = True    </div><div dir="ltr">      opt@keep                = True  </div><div dir="ltr">      opt@shape_var       = "NAME_1" </div><div dir="ltr">      opt@shape_names = (/vname/) </div><div dir="ltr">      opt@return_mask    = True    </div><div dir="ltr">      ;opt@debug             = True    </div><div dir="ltr">      </div><div dir="ltr">      ;mask the sample data by country/region/province</div><div dir="ltr">      ratio_mask      = ratio_mask + (/shapefile_mask_data(sample,shp_path,opt)/)</div><div dir="ltr">      copy_VarMeta(sample, ratio_mask) </div><div dir="ltr">   </div><div dir="ltr">      do j=0,iNumlat-1</div><div dir="ltr">         do i=0,iNumlon-1</div><div dir="ltr">            if ((.not.ismissing(ratio_mask(j,i))).and.(ratio_mask(j,i) .eq. 1)) then</div><div dir="ltr">                maskedRatio(j,i) = maskedRatio(j,i) + vtrend(62,ir)/100.</div><div dir="ltr">            end if</div><div dir="ltr">         end do</div><div dir="ltr">      end do</div><div dir="ltr"><br></div><div dir="ltr">   end do ; end looping over the list of string names in "shape_names"</div><div dir="ltr"><br></div><div dir="ltr">   printMinMax(maskedRatio, True)</div><div dir="ltr">...</div><div dir="ltr"><br></div><div>Sincerely,</div><div>Thierno</div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le sam. 20 juin 2020 à 21:16, Thierno Doumbia <<a href="mailto:elthiedo@gmail.com">elthiedo@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto">Thank you Rick, the initialization of the two variables was missing. <div dir="auto"><br><div dir="auto">Thierno</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 19 juin 2020 à 23:07, Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I don't know for certain. If the regions are not overlapping, what about initializing "data" and "data_mask" to zero and then simply adding the loop results back into those variable each time? Something like <br></div><div><br></div><div>data = data +  (/shapefile_mask_data(dgrid_fs,shp_path,opt)/)<br>...</div><div>data_mask(j,i) = data_mask(j,i) + vtrend(0,ir)/100.</div><div><br></div><div>Rick</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 19, 2020 at 1:24 PM Thierno Doumbia <<a href="mailto:elthiedo@gmail.com" rel="noreferrer" target="_blank">elthiedo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Hi,<div dir="auto">If that is exactly what I done, it was not what I wanted. In this case how do I get a single variable containing data for all regions ? </div><div dir="auto"><br></div><div dir="auto">Thank you </div>Thierry<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 19 juin 2020 à 20:53, Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" rel="noreferrer" target="_blank">brownrig@ucar.edu</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>If I read the script correctly, it looks like you are looping over region names and over writing the variables "data" and "data_mask" each time through. Then  the plot is generated after the loop has terminated -- the values of data and data_mask would contain the last region.</div><div><br></div><div>??</div><div>Rick</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 19, 2020 at 12:23 PM Thierno Doumbia via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" rel="noreferrer noreferrer" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Dear NCL community,</div><div dir="ltr"><br><div><div>As indicated in the subject line of this mail, I have a problem to create a gridded netcdf file containing constant values for different regions of the globe, using world administrative boundaries shapefile as a mask.</div><div>My code seems to be working for one region. But when I try to loop through multiple regions, the result is not what I expected. Please find attached my code, the obtained plot and a sample of my data.</div><div><br></div><div>I would appreciate it if you would check to see what I have done wrong. </div></div><div><br></div><div>Sincerely,</div>-- <br><div dir="ltr">Thierry</div></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" rel="noreferrer noreferrer" target="_blank">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 noreferrer noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote></div>
</blockquote></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">DOUMBIA    Thierno</div>