<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">It just occurred to me that perhaps the "#" operator is not want you want. This is for a matrix product, and has a very different meaning than simple matrix multiplication.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">If you are trying to multiply two arrays together, and one is a subset in size of the other, as is the case with your arrays, then you want to use "conform" to conform the smaller array to the larger array, and then do the multiplication. It would look like this:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><span style="font-size:12.8px"> B = conform(sce,sce_area,(/1,2/)) * sce</span><br></div><div class="gmail_default" style="font-size:small"><span style="font-size:12.8px"><br></span></div><div class="gmail_default"><span style="font-size:12.8px">Or do you really need to do a matrix product? If so, then the original code that you had with the loop is correct. My "improvement" was wrong.</span></div><div class="gmail_default"><span style="font-size:12.8px"><br></span></div><div class="gmail_default"><span style="font-size:12.8px">--Mary</span></div><div class="gmail_default"><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 1, 2016 at 11:39 AM, Ipshita Majhi <span dir="ltr"><<a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a>></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>HI Mary,</div><div><br></div><div>Thank you for the input. Here are the printVarSummary of the two variables. When I multiply the two variables I get this</div><div><br></div><div>*************************************************************************************</div><div>fatal:Mat: One of the operands exceeds the rank of 2, can't continue<br></div><div>*************************************************************************************</div><div>Variable: sce</div><div>Type: byte</div><div>Total Size: 19259328 bytes</div><div> 19259328 values</div><div>Number of Dimensions: 3</div><div>Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[time | 2487] x [lat | 88] x [lon | 88]</div><div>Coordinates: </div><div> time: [7..17409]</div><div>Number Of Attributes: 10</div><div> lon2d :<span style="white-space:pre-wrap">        </span><ARRAY of 7744 elements></div><div> lat2d :<span style="white-space:pre-wrap">        </span><ARRAY of 7744 elements></div><div> long_name :<span style="white-space:pre-wrap">        </span>NOAA/NCDC Climate Data Record of snow cover extent</div><div> standard_name :<span style="white-space:pre-wrap">        </span>surface_snow_binary_mask</div><div> grid_mapping :<span style="white-space:pre-wrap">        </span>coord_system</div><div> coordinates :<span style="white-space:pre-wrap">        </span>longitude latitude time snow_cover_threshold</div><div> valid_range :<span style="white-space:pre-wrap">        </span>( 0, 1 )</div><div> flag_values :<span style="white-space:pre-wrap">        </span>( 0, 1 )</div><div> flag_meanings :<span style="white-space:pre-wrap">        </span>no_snow snow_covered</div><div> _FillValue :<span style="white-space:pre-wrap">        </span>-9</div><div>(0)<span style="white-space:pre-wrap">        </span>2487</div><div>(1)<span style="white-space:pre-wrap">        </span>6</div><div><br></div><div>***********************************************************************************</div><div><div>Variable: sce_area</div><div>Type: float</div><div>Total Size: 30976 bytes</div><div> 7744 values</div><div>Number of Dimensions: 2</div><div>Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[rows | 88] x [cols | 88]</div><div>Coordinates: </div><div>Number Of Attributes: 7</div><div> long_name :<span style="white-space:pre-wrap">        </span>cell area in km^2</div><div> standard_name :<span style="white-space:pre-wrap">        </span>cell_area</div><div> grid_mapping :<span style="white-space:pre-wrap">        </span>coord_system</div><div> coordinates :<span style="white-space:pre-wrap">        </span>longitude latitude</div><div> units :<span style="white-space:pre-wrap">        </span>km^2</div><div> valid_range :<span style="white-space:pre-wrap">        </span>( 10676.8, 41804.6 )</div><div> _FillValue :<span style="white-space:pre-wrap">        </span>-999.9</div></div><div><br></div><div>*********************************************************************************</div><div><div><br></div></div><div><br></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Mar 1, 2016 at 7:39 AM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>></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">You didn't actually state what the problem was, so I guess you meant to say that the plot is incorrect?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You didn't provide any information about your data. As we tell users frequently, use "printVarSummary" to help us see what what your variables look like:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">printVarSummary(B)</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">You shouldn't need to allocate space for B and then fill it. Try replacing this code:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><span><div class="gmail_default"><font face="monospace, monospace"> B = new((/2487,88,88/),float)</font></div><div class="gmail_default"><font face="monospace, monospace"> do i = 0,2486</font></div><div class="gmail_default"><font face="monospace, monospace"> B(i,:,:)=sce(i,:,:)#sce_area(:,:)</font></div><div class="gmail_default"><font face="monospace, monospace"> end do</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div></span><div class="gmail_default"><font face="arial, helvetica, sans-serif">with:</font></div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">sce_area_3d = conform_dims(dimsizes(sce),sce_area,(/1,2/))</font></div><div class="gmail_default"><font face="monospace, monospace">B = sce # sce_area_3d</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">One idea for the plot: maybe you need to turn off the addition of a cyclic point:</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">res@gsnAddCyclic = False</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">If none of this helps, then please include output from "printVarSummary" of all your variables.</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Thanks,</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">--Mary</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Mon, Feb 29, 2016 at 12:12 PM, Ipshita Majhi <span dir="ltr"><<a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a>></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><div dir="ltr">Dear NCL,<div><br></div><div>I want to plot snow cover extent after multiplying it with snow cover area. Here is the code for it. I am also attaching the figure with this email.</div><div><br></div><div><div>;*******************************************</div><div>;Reading in the weekly snow cover extent </div><div>;*******************************************</div><div><br></div><div>a=addfile("~/Documents/NCL_files/Sea_ice/<a href="http://nhsce_v01r01_19661004_20140602.nc" target="_blank">nhsce_v01r01_19661004_20140602.nc</a>","r")</div><div>sce=a->snow_cover_extent ; The values are either 0 or 1</div><div><br></div><div>lat=a->latitude</div><div>lon=a->longitude</div><div><br></div><div>sce!1="lat"</div><div>sce!2="lon"</div><div><br></div><div>sce@lat2d=lat</div><div>sce@lon2d=lon</div><div><br></div><div>;********************************************</div><div>:Reading in the snow cover are</div><div>;********************************************</div><div><br></div><div>sce_area=a->area</div><div><br></div><div>sce_area!0="lat"</div><div>sce_area!1="lon"</div><div><br></div><div>copy_VarAtts(sce,sce_area)</div><div>copy_VarCoords_1(sce,sce_area)</div><div><br></div><div>;*******************************************</div><div>;Muliplying Snow cover extent and Area</div><div>;*******************************************</div><div><br></div><div>B = new((/2487,88,88/),float)</div><div><br></div><div> do i = 0,2486</div><div> B(i,:,:)=sce(i,:,:)#sce_area(:,:)</div><div> end do</div><div><br></div><div>B!0="time" </div><div>B!1="lat"</div><div>B!2="lon" </div><div> </div><div>B@lat2d=lat</div><div>B@lon2d=lon</div><div><br></div><div>copy_VarAtts(sce,B)</div><div>copy_VarCoords_1(sce,B)</div><div><br></div><div>printVarSummary(B)</div><div><br></div><div>B@_FillValue = -9</div><div><br></div><div> </div><div>;************************************************</div><div>; create plot</div><div>;************************************************</div><div> wks = gsn_open_wks("pdf" ,"Snow_cover_area") </div><div> res = True ; plot mods desired</div><div> res@gsnPolar = "NH" ; specify the hemisphere</div><div> plot = gsn_csm_contour_map_polar(wks,B(0,:,:),res) ; create the plot</div><div><br></div>
</div></div>
<br></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="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr"><div><div><div><div>Ipshita Majhi<br></div>PhD Candidate<br></div>University of Alaska , Fairbanks<br></div>Atmospheric Science Department<br></div><a href="tel:%28907%29978-4220" value="+19079784220" target="_blank">(907)978-4220</a> <a href="mailto:ipmajhi@alaska.edu" target="_blank">ipmajhi@alaska.edu</a><br></div></div>
</font></span></div>
</blockquote></div><br></div>