<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Toni,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">If you just want an average of the data masked by a particular shapefile, it doesn't matter whether the shapefile has one features or several features. You can call the shapefile_mask_data function (in the <a href="http://www.ncl.ucar.edu/Applications/Scripts/shapefile_utils.ncl">shapefiles_utils.ncl</a> file), which takes your original data variable and sets values to missing if they fall outside the shapefile area:</div><br>  data_mask = shapefile_mask_data(data,"8x_100_west.shp",opt)<div><br></div><div><div class="gmail_default" style="font-size:small">Then, you can average that array with:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">  data_avg(data_mask)</div><div class="gmail_default" style="font-size:small"></div>I've attached a script (plot_data_masked_by_shapefiles.ncl)<span class="gmail_default" style="font-size:small"> and a couple of images </span>that shows how to do this with the original shapefile you gave me. </div><div><br></div><div><div class="gmail_default" style="font-size:small">In order to mask the data by two shapefiles, what you can do is have shapefile_mask_data return a mask array (an array of the same size but set to 0 where the data is outside the shapefile areas, and set to 1 inside the shapefile areas).  You can then use "where" ("mask" would also work) to apply the mask to whatever data you want:</div><div class="gmail_default" style="font-size:small">        </div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><font face="monospace, monospace">  shp_west_name = "8x_west.shp"<br>  shp_east_name = "8x_east.shp"   </font><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small">     </span></p><p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small">              </span></p><p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small"><span class="gmail_default" style="font-size:small">;---Calculate mask arrays based on shapefile data</span>                     </span><br></p><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@return_mask = True</font></div><div class="gmail_default"><font face="monospace, monospace">  data_mask_west = shapefile_mask_data(data,shp_west_name,opt)</font></div><div class="gmail_default"><font face="monospace, monospace">  data_mask_east = shapefile_mask_data(data,shp_east_name,opt)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">;---Keep the data at locations where mask arrays are equal to 1.</font></div><div class="gmail_default"><font face="monospace, monospace">  data_mask = where(data_mask_east.eq.1.or.data_mask_west.eq.1,data,data@_FillValue)</font></div><div class="gmail_default"><font face="monospace, monospace">  copy_VarMeta(data,data_mask)</font></div><div class="gmail_default"><br></div><div class="gmail_default"><br></div><div class="gmail_default">I think it's important to understand how the shapefile_mask_data is working on my data, so I usually like to plot it and then add markers at locations where the data was kept versus where it was masked. I included panel plots of both original data and masked data, and then separate plots of the masked data with the markers added. </div><div class="gmail_default"><br></div><div class="gmail_default">--Mary</div><div class="gmail_default"><br></div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 19, 2018 at 11:42 PM Toni Klemm <<a href="mailto:toni-klemm@tamu.edu">toni-klemm@tamu.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"><div dir="auto"><div dir="ltr"><span></span></div><div dir="ltr">Hi Mary,<div><br></div><div>Thank you very much! Your result is almost exactly what I’m trying to get. What I need is the average temperature / annual precipitation for all the counties together, not separate for each county or shapefile feature. I just tried it again with a shapefile in which each county is a separate feature, but unfortunately I got pretty much the same result as before. I attached the shapefiles (there are two sets, for counties with the center point east and west of the 100th meridian). I also attached a screenshot of the data result in Panoply and my NCL code.</div><div><br></div><div>I would greatly appreciate if you could take a look at the shapefile data and change it so it works correctly in NCL.<br><div><br class="gmail-m_-1866883561818586400webkit-block-placeholder"></div><div>
<div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:Calibri;font-size:14px;font-style:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="background-color:rgb(255,255,255)"><font>Thanks again,</font></span></div><div style="font-family:Calibri;font-size:14px;font-style:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="background-color:rgb(255,255,255)"><font>Toni</font></span></div><div style="font-family:Calibri;font-size:14px;font-style:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="background-color:rgb(255,255,255)"><font><br class="gmail-m_-1866883561818586400Apple-interchange-newline"><font color="#333300"><br></font></font></span></div><div style="font-family:Calibri;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font color="#333300"><b style="background-color:rgb(255,255,255)">Toni Klemm</b><b><span style="background-color:rgb(255,255,255)">, </span><span style="background-color:rgb(255,255,255)">Ph.D.</span></b></font><div><div><span style="background-color:rgb(255,255,255)"><font color="#333300">Postdoctoral Research Associate</font></span></div><div><span style="background-color:rgb(255,255,255)"><font color="#333300">Department of Ecosystem Science and Management</font></span></div><div><span style="background-color:rgb(255,255,255)"><font color="#333300">College of Agriculture and Life Sciences</font></span></div><div><span style="background-color:rgb(255,255,255)"><font color="#333300">Texas A&M University, College Station, TX</font></span></div><div style="color:rgb(0,0,0)">Contributor to the <a href="https://www.eccforum.org/" target="_blank">Early Career Climate Forum</a></div><div style="color:rgb(0,0,0)"><span style="color:rgb(51,51,153);background-color:rgb(255,255,255)"><a href="http://www.toni-klemm.de/" target="_blank">www.toni-klemm.de</a> | </span><a href="https://twitter.com/ToniKlemm" target="_blank">@toniklemm</a></div></div></div><div style="color:rgb(0,0,0);font-family:Calibri;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="color:rgb(0,0,0);font-family:Calibri;font-size:14px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div></div></div></div></div></div></div><br class="gmail-m_-1866883561818586400Apple-interchange-newline"></div><br class="gmail-m_-1866883561818586400Apple-interchange-newline"><br class="gmail-m_-1866883561818586400Apple-interchange-newline">
</div>
<div><br><blockquote type="cite"><div>On Dec 19, 2018, at 5:06 PM, Mary Haley <<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>> wrote:</div><br class="gmail-m_-1866883561818586400Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Toni,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Your shapefile has just one feature and several segments for that feature.  Usually the shapefiles we see have several features and several segments for each feature. Your shapefile is a little unusual, but not unheard of.  Unfortunately, the examples we have all do the averaging across shapefile *features* and not shapefile *segments*.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">This doesn't mean you can't do it with NCL.  See the attached plot, where I contoured some dummy 2D data over the area of interest and then generated a second plot where the values were averaged based on whether they fell inside one of these segments.  Is this what you are trying to accomplish?  If so, I'll clean up the code and send it to you.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 19, 2018 at 1:26 PM Toni Klemm <<a href="mailto:toni-klemm@tamu.edu" target="_blank">toni-klemm@tamu.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"><div>Hello All,<div><br></div><div>I am trying to use a shapefile of merged counties in the western Great Plains to create a spatial subset of temperature and precipitation data and calculate averages and totals for those counties as a whole. However, the data subset doesn't look anything like the shapefile (see the Panoply screenshot). I attached the shapefile as GIS files and screenshot. </div><div><br></div><div>My guess is that NCL gets confused about the disconnected-yet-combined counties and doesn't know how to process a shapefile like that. Does anyone know what I can do to make this work? Can I manipulate the shapefile data in QGIS somehow so NCL understands it? Alternatively I could process each county by itself and then average the results. But there are over 100 counties, which would take a very long time. </div><div><br></div><div>I appreciate any help!</div><div><br></div><div>Thank you very much,</div><div>Toni<br><div>
<div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br class="gmail-m_-1866883561818586400gmail-m_-6586768839414286389Apple-interchange-newline"><br></font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><b>Toni Klemm, Ph.D.<br></b>Postdoctoral Research Associate</font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Department of Ecosystem Science and Management</div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">College of Agriculture and Life Sciences</div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Texas A&M University, College Station, TX</div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri">Contributor to the <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.eccforum.org&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=_wmxrfPQsMF3vojIFKRAtdhltlvptw6M4HZ9fLg_3cQ&e=" target="_blank">Early Career Climate Forum</a><br><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.toni-2Dklemm.de&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=BUcEg1gjQSTNzMQTj8-c30-A9wVn4XtHJXwJ98GJFdc&e=" target="_blank">www.toni-klemm.de</a> | <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__twitter.com_toniklemm&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=4uj7i-TM4DYGnhfVvqE6_pSkQa5N6ZthvK0BCZWNzK8&e=" target="_blank">@toniklemm</a></font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br></font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br></font></div></div></div><br class="gmail-m_-1866883561818586400gmail-m_-6586768839414286389Apple-interchange-newline"></div><br class="gmail-m_-1866883561818586400gmail-m_-6586768839414286389Apple-interchange-newline"></div><br class="gmail-m_-1866883561818586400gmail-m_-6586768839414286389Apple-interchange-newline"></div><br class="gmail-m_-1866883561818586400gmail-m_-6586768839414286389Apple-interchange-newline"><br class="gmail-m_-1866883561818586400gmail-m_-6586768839414286389Apple-interchange-newline">
</div>
</div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div>_______________________________________________<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="https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=S4Vpn9B9dGEDj8PfFUyL3ZZyY6XSazVZ50UULc2pwEU&s=PmMsnjl-ihptp2YXVfcxUt782zRG1XbIMrqgS8bUQZg&e=" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>
<span id="gmail-m_-1866883561818586400cid:f_jpvsb4r80"><shapefile.000002.png></span></div></blockquote></div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div><div dir="ltr"></div></div><div dir="auto"><div dir="ltr"></div><div dir="ltr"><div></div></div></div></blockquote></div>