<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi Josh,<br>
<br>
as already answered at cdo support, the adapted script is running
well. Just to explain why yours is not working:<br>
- your data variable is SST not time<br>
- the data is not on a curvilinear grid so you have to change the
var@lon2d/var@lat2d part to var@lon1d/var@lat1d<br>
<br>
<pre><font color="#3366ff">load "$HOME/NCL/shapefiles/shapefile_utils.ncl"
shpname = "ospar_polygon_wdpa_simplified.shp"
maskname = "ospar_polygon_wdpa_simplified.nc"
print_shapefile_info(shpname)
f = addfile("SST.nc","r")
var = f-><b>SST(0,:,:)</b>
var@<b>lat1d</b> = f->LAT
var@<b>lon1d</b> = f->LON
opt = True
opt@return_mask = True ;-- this forces the return of a 0s and 1s mask array
mask_array = shapefile_mask_data(var, shpname, opt)
mask_array!0 = "y"
mask_array!1 = "x"
mask_array@coordinates = "LAT LON"
system("rm -f " + maskname)
fout = addfile(maskname,"c")
fout->mask_array = mask_array
fout->LAT = f->LAT
fout->LON = f->LON</font>
</pre>
<div class="moz-cite-prefix">-Karin<br>
<br>
Am 16.07.19 um 13:25 schrieb JoshAB1995--- via ncl-talk:<br>
</div>
<blockquote type="cite"
cite="mid:DM6PR03MB43480C5D6363BE8898985CFDC5CE0@DM6PR03MB4348.namprd03.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
<div class="WordSection1">
<p class="MsoNormal">Hi guys,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m brand new to NCL as I need to quickly
use it to convert a shapefile to a netcdf file. The idea is to
create a mask of marine protected areas included in the
shapefile. I’ve tried using the following code but as I’ve
highlighted in the code I run into some issues...</p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">load
"shapefile_utils.ncl"
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">shpname
= "ospar_polygon_wdpa_simplified.shp"
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">maskname
= "MPA_Mask.nc"
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">print_shapefile_info(shpname)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">f
= addfile("SST1.nc","r")<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">var
= f->time(0)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">var@lat2d
= f->LAT<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">var@lon2d
= f->LON<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">opt
= True<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">opt@return_mask
= True
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">mask_array
= shapefile_mask_data(var, shpname, opt)
<b><o:p></o:p></b></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">mask_array!0
= "y"
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">mask_array!1
= "x"
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">mask_array@coordinates
= "LAT LON"
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">system("rm
-f " + maskname)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">fout
= addfile(maskname,"c")<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">fout->mask_array
= mask_array<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">fout->LAT
= f->LAT<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">fout->LON
= f->LON<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA"><o:p> </o:p></span></p>
<p class="MsoNormal">Unfortunately I get the following error
message halfway through:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">mask_array
= shapefile_mask_data(var, shpname, opt)
<b><o:p></o:p></b></span></p>
<div>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">(0)
shapefile_mask_data: Error: not a valid rectilinear,
curvilinear, or uns<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#333333;background:#FAFAFA">tructured
grid</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Does anyone have any ideas as to why this
happens? I’ve attached the relevant data to this email (hoping
that it will send through).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Many thanks,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Josh<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sent from <a
href="https://go.microsoft.com/fwlink/?LinkId=550986"
moz-do-not-send="true">
Mail</a> for Windows 10</p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
ncl-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a class="moz-txt-link-freetext" href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></pre>
</blockquote>
<br>
</body>
</html>