<div dir="ltr">Thank you so much for this mask and the plot. </div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 9, 2017 at 8:19 AM, Mary Haley <span dir="ltr">&lt;<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">Ipshita,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Thanks for the file.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">There were a few errors in your script.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The big one is that you don&#39;t have an &quot;end&quot; statement for your function. You instead put two &quot;end&quot; statements at the very end of the script.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You need to remove one of the &quot;end&quot; statements at the end of the script and add one right after the line:</div><div class="gmail_default">







<p class="m_-1447417586728524789gmail-p1" style="font-size:small"><span class="m_-1447417586728524789gmail-s1"><font face="monospace, monospace">  return(data_mask)</font></span></p><p class="m_-1447417586728524789gmail-p1" style="font-size:small"><span class="m_-1447417586728524789gmail-s1">I think this might get your code to work again.</span></p><p class="m_-1447417586728524789gmail-p1" style="font-size:small"><span class="m_-1447417586728524789gmail-s1">I was able to run your script with this fix, but I first had to correct the filename and the variable name, because you gave me a different file than what is used in the script. </span></p><p class="m_-1447417586728524789gmail-p1" style="font-size:small"><span class="m_-1447417586728524789gmail-s1">Also, you have:</span></p><p class="m_-1447417586728524789gmail-p1" style="font-size:small"><font face="monospace, monospace">  res@tiMainString = filename</font></p><p class="m_-1447417586728524789gmail-p1" style="font-size:small">but &quot;filename&quot; is not defined.  I defined &quot;filename&quot; and changed your &quot;addfile&quot; line to this:</p><p class="m_-1447417586728524789gmail-p1"><font face="monospace, monospace">   filename = &quot;<a href="http://b.e11.B1850C5CN.f09_g16.005.cam.h0.PRECSL.070001-079912.nc" target="_blank">b.e11.B1850C5CN.f09_g16.005.<wbr>cam.h0.PRECSL.070001-079912.nc</a><wbr>&quot;<br>   f        =  addfile(filename,&quot;r&quot;)</font></p><p class="m_-1447417586728524789gmail-p1"><br></p><p class="m_-1447417586728524789gmail-p1">I don&#39;t have the India_adm files, so I changed this code to use IND_adm instead, which I already had.</p><span class="HOEnZb"><font color="#888888"><p class="m_-1447417586728524789gmail-p1"><br></p><p class="m_-1447417586728524789gmail-p1">--Mary</p></font></span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 5:44 PM, Ipshita Majhi <span dir="ltr">&lt;<a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Mary,<div><br></div><div>Here are the errors I am getting after incorporating what you recommended. </div><div><br></div><div><div>(0)<span class="m_-1447417586728524789m_-8041866798785902672gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>gsn_csm_map_ce: Warning: you set mpMaxLonF to a value &gt; 180, but</div><div>(0)<span class="m_-1447417586728524789m_-8041866798785902672gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>                didn&#39;t set mpCenterLonF. Setting mpCenterLonF to 179.375</div><div>ERROR 10: Pointer &#39;hFeat&#39; is NULL in &#39;OGR_F_GetGeometryRef&#39;.</div><div><br></div><div>ERROR 10: Pointer &#39;hGeom&#39; is NULL in &#39;OGR_G_GetGeometryCount&#39;.</div><div><br></div><div>ERROR 10: Pointer &#39;hGeom&#39; is NULL in &#39;OGR_G_GetPointCount&#39;.</div><div><br></div><div>fatal:[&quot;Execute.c&quot;:5734]:varia<wbr>ble (geometry) is not in file (f)</div><div>fatal:[&quot;Execute.c&quot;:7743]:Execu<wbr>te: Error occurred at or near line 26 in file shapefile_India.ncl</div><div><br></div><div>fatal:[&quot;Execute.c&quot;:7743]:Execu<wbr>te: Error occurred at or near line 145 in file shapefile_India.ncl</div></div><div>******************************<wbr>********</div><div>Is it because my version of NCL is 6.1.0?</div><div><br></div><div>Here is my file that you had requested​<div class="gmail_chip gmail_drive_chip" style="width:396px;height:18px;max-height:18px;padding:5px;color:rgb(34,34,34);font-family:arial;font-style:normal;font-weight:bold;font-size:13px;border:1px solid rgb(221,221,221);line-height:1;background-color:rgb(245,245,245)"><a href="https://drive.google.com/a/alaska.edu/file/d/0BxwHbkyQt46bU2J0VGwyREh0eTA/view?usp=drive_web" style="display:inline-block;max-width:366px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-decoration:none;padding:1px 0;border:none" target="_blank"><img style="vertical-align:bottom;border:none" src="https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png"> <span dir="ltr" style="color:rgb(17,85,204);text-decoration:none;vertical-align:bottom">b.e11.B1850C5CN.f09_g16.005.c<wbr>am.h0.PRECSL.07000...</span></a><img style="opacity:0.55;float:right;display:none"></div>​</div></div><div class="m_-1447417586728524789HOEnZb"><div class="m_-1447417586728524789h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 8, 2017 at 2:36 PM, Mary Haley <span dir="ltr">&lt;<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Can you provide the b.e11 NetCDF file?  You can email me offline about this if you want.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I do recognize the code you included because it&#39;s code that I wrote, but it&#39;s hard to debug without the data file.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Also, did you look at the &quot;shapefile_mask_data&quot; function on the shapefiles example page?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">In particular, you could look at example shapefile_11.ncl:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><a href="http://www.ncl.ucar.edu/Applications/shapefiles.shtml#ex11" target="_blank">http://www.ncl.ucar.edu/Applic<wbr>ations/shapefiles.shtml#ex11</a><br></div><div class="gmail_default"><br></div><div class="gmail_default">You can first try it with minimal options to see what happens:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">  opt       = True</font></div><div class="gmail_default"><font face="monospace, monospace">  opt@debug = True<br></font></div><div class="gmail_default"><font face="monospace, monospace">  ts_mask   = shapefile_mask_data(ts,India_s<wbr>hp,opt)<br>  printVarSummary(ts_mask)</font></div><div class="gmail_default"><font face="monospace, monospace">  printMinMax(ts_mask,0)</font></div><div class="gmail_default"><br></div><div class="gmail_default">I can&#39;t remember, but you might need to call this too:</div><div class="gmail_default"><br></div><div class="gmail_default"><div style="font-size:12.8px"><font face="monospace, monospace">  copy_VarMeta(ts,ts_mask)      ; Copy all metadata</font></div><div><br></div></div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-1447417586728524789m_-8041866798785902672h5">On Wed, Mar 8, 2017 at 12:59 PM, Ipshita Majhi <span dir="ltr">&lt;<a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-1447417586728524789m_-8041866798785902672h5"><div dir="ltr">Dear NCL Users,<div><br></div><div>I am trying to create a mask for India, using shapefile. I am not getting any error but there is no plot begin created. I will be grateful if someone could guide me about it. Here is the code:</div><div><br></div><div>******************************<wbr>***************************</div><div><div>;*****************************<wbr>*******************</div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/gsn_code.ncl&quot; </div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/gsn_csm.ncl&quot; </div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/contributed.ncl&quot; </div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/shea_util.ncl&quot; </div><div>;*****************************<wbr>*******************</div><div>;Read data to plot and mask</div><div>;*****************************<wbr>******************* </div><div>function mask_data_with_India_country(c<wbr>ountry_code,data) </div><div>begin</div><div><br></div><div>mask_start_time = get_cpu_time()     ; For timing results</div><div><br></div><div>;---Convert rectilinear grid to 2D grid, but laid out as 1D array.</div><div>  dims  = dimsizes(data)</div><div>  lat1d = ndtooned(conform_dims(dims,dat<wbr>a&amp;$data!0$,0))</div><div>  lon1d = ndtooned(conform_dims(dims,dat<wbr>a&amp;$data!1$,1))</div><div><br></div><div>  shapefile_name = &quot;IND_adm0.shp&quot;</div><div> ;---Open shapefile and read lat/lon values.</div><div>  sfilename = &quot;IND_adm0.shp&quot;</div><div>  f = addfile(sfilename,&quot;r&quot;)</div><div>  segments = f-&gt;segments</div><div>  geometry = f-&gt;geometry</div><div>  segsDims = dimsizes(segments)</div><div>  geomDims = dimsizes(geometry)</div><div><br></div><div>;---Read global attributes  </div><div>  geom_segIndex = f@geom_segIndex</div><div>  geom_numSegs  = f@geom_numSegs</div><div>  segs_xyzIndex = f@segs_xyzIndex</div><div>  segs_numPnts  = f@segs_numPnts</div><div>  numFeatures   = geomDims(0)</div><div>  </div><div>  lon  = f-&gt;x</div><div>  lat  = f-&gt;y</div><div>  nlatlon = dimsizes(lat)</div><div>  </div><div>  min_lat = min(lat)</div><div>  max_lat = max(lat)</div><div>  min_lon = min(lon)</div><div>  max_lon = max(lon)</div><div><br></div><div>  print(&quot;=======================<wbr>===========================&quot;)</div><div>  print(&quot;Shapefile : &quot;  + sfilename)</div><div>  print(&quot;min_lat &quot; + min_lat)</div><div>  print(&quot;max_lat &quot; + max_lat)</div><div>  print(&quot;min_lon &quot; + min_lon)</div><div>  print(&quot;max_lon &quot; + max_lon)</div><div>  </div><div>   ii_latlon = ind(min_lat.le.lat1d.and.lat1d<wbr>.le.max_lat.and.\</div><div>                  min_lon.le.lon1d.and.lon1d.le.<wbr>max_lon)</div><div>  nii = dimsizes(ii_latlon)</div><div>  print(nii + &quot; values to check&quot;)</div><div>  print(numFeatures + &quot; feature(s) to traverse with a maximum of &quot; + \</div><div>        nlatlon + &quot; points&quot;)</div><div>  </div><div>  </div><div> ;---Create array to hold new data mask, and set all values to 0 initially.</div><div>  data_mask_1d = new(dimsizes(lat1d),integer)</div><div>  data_mask_1d = 0</div><div><br></div><div>;</div><div>; This is the loop that checks every point in lat1d/lon1d to see if it</div><div>; is inside or outside of the country. If it is inside, then data_mask_1d</div><div>; will be set to 1.</div><div>;</div><div>  ikeep = 0    ; Counter to see how many points were found inside the country</div><div>  do n=0,nii-1</div><div>    ii = ii_latlon(n)</div><div>    is_inside = False</div><div>    i = 0</div><div>    do while(.<a href="http://not.is_inside.and.i.lt" target="_blank">not.is_inside.and.i.lt</a>.<wbr>numFeatures)</div><div>       startSegment = geometry(i, geom_segIndex)</div><div>       numSegments  = geometry(i, geom_numSegs)</div><div>       do seg=startSegment, startSegment+numSegments-1</div><div>         startPT = segments(seg, segs_xyzIndex)</div><div>         endPT   = startPT + segments(seg, segs_numPnts) - 1</div><div>         if(data_mask_1d(ii).ne.1.and.<wbr>\</div><div>            gc_inout(lat1d(ii),lon1d(ii),\</div><div>                     lat(startPT:endPT),lon(startP<wbr>T:endPT))) then</div><div>           data_mask_1d(ii) = 1</div><div>           ikeep = ikeep+1</div><div>           is_inside = True</div><div>           continue</div><div>         end if</div><div>       end do</div><div>       i = i + 1</div><div>    end do</div><div>  end do</div><div>  print(ikeep + &quot; values kept&quot;)</div><div>  print(&quot;=======================<wbr>===========================&quot;) </div><div><br></div><div>; Create a 2D data array of same size as original data,</div><div>; but with appropriate values masked.</div><div>;</div><div>  data_mask = (where(onedtond(data_mask_1d,d<wbr>ims).eq.1,data,\</div><div>              data@_FillValue))</div><div>  copy_VarMeta(data,data_mask)      ; Copy all metadata</div><div><br></div><div>;---Print timings</div><div>  mask_end_time = get_cpu_time()</div><div>  print(&quot;Elapsed time in CPU second for &#39;mask_data_with_India_country&#39; = &quot; + \</div><div>         (mask_end_time-mask_start_tim<wbr>e))</div><div><br></div><div>  return(data_mask)</div><div>  </div><div>;-----------------------------<wbr>------------------------------<wbr>-----------</div><div>; Main code</div><div>;-----------------------------<wbr>------------------------------<wbr>-----------</div><div>begin</div><div>;---Shapefile to use for masking. Using &quot;Bolivia&quot; here (BOL).</div><div>India_code = &quot;India&quot;</div><div>India_name = India_code + &quot;_adm&quot;</div><div>India_shp  = India_name + &quot;/&quot; + India_name + &quot;0.shp&quot;</div><div><br></div><div>;---Read lat/lon off shapefile</div><div> s         = addfile(India_shp,&quot;r&quot;)</div><div> slat      = s-&gt;y</div><div> slon      = s-&gt;x</div><div><br></div><div>;---Read precipitation data to contour and mask</div><div>  f        =  addfile(&quot;<a href="http://b.e11.B1850C5CN.f09_g16.005.cam.h0.PRECC.070001-079912.nc" target="_blank">b.e11.B1850C5CN.f09_<wbr>g16.005.cam.h0.PRECC.070001-07<wbr>9912.nc</a>&quot;,&quot;r&quot;)</div><div>  ts       = f-&gt;PRECC(0,:,:)</div><div>  printVarSummary(ts)</div><div><br></div><div>;---Start the graphics</div><div>  wtype          = &quot;x11&quot;       ; &quot;png&quot;</div><div>; wtype@wkWidth  = 2500        ; use for &quot;png&quot; or &quot;x11&quot;</div><div>; wtype@wkHeight = 2500</div><div><br></div><div>  wks = gsn_open_wks(wtype,&quot;mask_India<wbr>_&quot;+India_code)</div><div><br></div><div>  res                 = True                    ; plot mods desired</div><div><br></div><div>  res@cnFillOn        = True                    ; turn on color</div><div>  res@cnFillMode      = &quot;RasterFill&quot;</div><div>  res@cnLinesOn       = False                   ; turn off lines</div><div>  res@cnLineLabelsOn  = False                   ; turn off labels</div><div><br></div><div>  res@mpMinLatF       = min(ts&amp;lat)</div><div>  res@mpMaxLatF       = max(ts&amp;lat)</div><div>  res@mpMinLonF       = min(ts&amp;lon)</div><div>  res@mpMaxLonF       = max(ts&amp;lon)</div><div><br></div><div>;---Create global plot of original data</div><div>  res@tiMainString    = filename</div><div>  plot = gsn_csm_contour_map(wks,ts, res)</div><div><br></div><div>;---Mask &quot;ts&quot; against India shapefile outlines</div><div>  ts_mask = mask_data_with_India_country(I<wbr>ndia_code,ts)</div><div>  printVarSummary(ts_mask)</div><div><br></div><div>;---Set some additional resources for the second set of plots</div><div><br></div><div>  res@gsnDraw         = False                   ; don&#39;t draw yet</div><div>  res@gsnFrame        = False                   ; don&#39;t advance frame yet</div><div><br></div><div>;---Pick &quot;nice&quot; contour levels for both plots</div><div>  mnmxint = nice_mnmxintvl( min(ts_mask), max(ts_mask), 18, False)</div><div>  res@cnLevelSelectionMode = &quot;ManualLevels&quot;</div><div>  res@cnMinLevelValF       = mnmxint(0)</div><div>  res@cnMaxLevelValF       = mnmxint(1)</div><div>  res@cnLevelSpacingF      = mnmxint(2)/2.</div><div><br></div><div>  res@mpMinLatF       = min(slat)</div><div>  res@mpMaxLatF       = max(slat)</div><div>  res@mpMinLonF       = min(slon)</div><div>  res@mpMaxLonF       = max(slon)</div><div><br></div><div>  res@gsnRightString  = &quot;&quot;</div><div>  res@gsnLeftString   = &quot;&quot;</div><div><br></div><div>  res@lbLabelBarOn    = False</div><div><br></div><div>;---Create plot of original data</div><div>  res@tiMainString    = &quot;original data zoomed in&quot;</div><div>  plot_orig = gsn_csm_contour_map(wks,ts, res)</div><div><br></div><div>;---Create plot of masked data</div><div>  res@tiMainString = &quot;with country mask&quot;</div><div>  plot_mask = gsn_csm_contour_map(wks,ts_mas<wbr>k, res)</div><div><br></div><div>;---Add shapefile outlines to both plots</div><div>  lnres             = True</div><div>  lnres@gsLineColor = &quot;NavyBlue&quot;</div><div><br></div><div>  id_orig = gsn_add_shapefile_polylines(wk<wbr>s,plot_orig,India_shp,lnres)</div><div>  id_mask = gsn_add_shapefile_polylines(wk<wbr>s,plot_mask,India_shp,lnres)</div><div><br></div><div>;---Panel both plots on one page</div><div>  pres                  = True</div><div>  pres@txString         = ts@long_name + &quot; (&quot; + ts@units + &quot;)&quot;</div><div>  pres@gsnMaximize      = True</div><div>  pres@gsnPanelLabelBar = True</div><div>  gsn_panel(wks,(/plot_orig,plot<wbr>_mask/),(/1,2/),pres)</div><div>end</div><div>end</div><span class="m_-1447417586728524789m_-8041866798785902672m_3922079773347379442HOEnZb"><font color="#888888"><div><br></div><div><br></div>-- <br><div class="m_-1447417586728524789m_-8041866798785902672m_3922079773347379442m_-7272105917876497920gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div><div><div>******************************<wbr>******************************<wbr>******************************<wbr>*************************</div><div><span style="font-size:small">&quot;I slept and dreamt that life was joy. I awoke and saw that life was service. I acted and behold, service was joy.&quot; - Rabindranath Tagore</span><br></div><div><span style="font-size:small">******************************<wbr>******************************<wbr>******************************<wbr>**************************</span></div><div><br></div><div>Ipshita Majhi<br></div>PhD Candidate<br></div>University of Alaska , Fairbanks<br></div>Atmospheric Science Department<br></div><a href="tel:(907)%20978-4220" value="+19079784220" target="_blank">(907)978-4220</a> <a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a><br></div></div></div></div>
</font></span></div></div>
<br></div></div>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_-1447417586728524789m_-8041866798785902672gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div><div><div>******************************<wbr>******************************<wbr>******************************<wbr>*************************</div><div><span style="font-size:small">&quot;I slept and dreamt that life was joy. I awoke and saw that life was service. I acted and behold, service was joy.&quot; - Rabindranath Tagore</span><br></div><div><span style="font-size:small">******************************<wbr>******************************<wbr>******************************<wbr>**************************</span></div><div><br></div><div>Ipshita Majhi<br></div>PhD Candidate<br></div>University of Alaska , Fairbanks<br></div>Atmospheric Science Department<br></div><a href="tel:(907)%20978-4220" value="+19079784220" target="_blank">(907)978-4220</a> <a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a><br></div></div></div></div>
</div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div><div><div>*******************************************************************************************************************</div><div><span style="font-size:small">&quot;I slept and dreamt that life was joy. I awoke and saw that life was service. I acted and behold, service was joy.&quot; - Rabindranath Tagore</span><br></div><div><span style="font-size:small">********************************************************************************************************************</span></div><div><br></div><div>Ipshita Majhi<br></div>PhD Candidate<br></div>University of Alaska , Fairbanks<br></div>Atmospheric Science Department<br></div>(907)978-4220 <a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a><br></div></div></div></div>
</div>