Re: Problem in MASK/WHERE function

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 26 2010 - 10:31:54 MDT

Hi Liang,

The mask or where functions should work fine, as long as lat2d and lon2d have the same dimensions as "x".

It looks like this may not be case, given the output from "printVarSummary(x)":

> Dimensions and sizes: [latitude | 216] x [longitude | 288]
> Coordinates:
> latitude: [-89.58334..89.58334]
> longitude: [0.625..359.375]

It looks like "latitude" is actually a 1D array of length 216, and "longitude" a 1D array of length 288.

You can "conform" latitude and longitude to be 2D arrays of the same size as "x" using conform:

  x@lat2d = conform(x,x->latitude,0)
  x@lon2d = conform(x,x->longitude,1)

--Mary

On Apr 26, 2010, at 9:23 AM, Liang Guo wrote:

> Hi,
>
> I am using NCL v5.2.0. I try to using MASK function to set all values
> outside a specified region to a missing value. And I follow example 5
> shown in MASK function webpage, and it looks like:
> =============================
> begin
> ;
> f = addfile ("raw/50_ht_1983.nc", "r")
>
> x = f->ht(0,0,:,:)
> x@lat2d = f->latitude
> x@lon2d = f->longitude
> printVarSummary (x)
>
> latMin = -20
> latMax = 60
> lonMin = 110
> lonMax = 270
>
> x = mask(x,(x@lat2d.ge.latMin .and. x@lat2d.le.latMax .and.
> x@lon2d.ge.lonMin .and. x@lon2d.le.lonMax), True)
> ; x = where((x@lat2d.ge.latMin .and. x@lat2d.le.latMax .and.
> x@lon2d.ge.lonMin .and. x@lon2d.le.lonMax), x, x@_FillValue)
> ;
> end
> ======================
>
> However, I got error:
> ===================================
> Variable: x
> Type: float
> Total Size: 248832 bytes
> 62208 values
> Number of Dimensions: 2
> Dimensions and sizes: [latitude | 216] x [longitude | 288]
> Coordinates:
> latitude: [-89.58334..89.58334]
> longitude: [0.625..359.375]
> Number Of Attributes: 15
> lon2d : <ARRAY of 288 elements>
> lat2d : <ARRAY of 216 elements>
> p : 1000
> t : 45
> source : Unified Model Output (Vn 6.1):
> name : ht
> title : Height
> date : 01/03/83
> time : 00:00
> long_name : Height
> units : m
> missing_value : 2e+20
> _FillValue : 2e+20
> valid_min : -43.29757
> valid_max : 27644.69
> fatal:And: Dimension size, for dimension number 0, of operands does
> not match, can't continue
>
> fatal:Execute: Error occurred at or near line 15 in file try.ncl
> ========================================
>
> I cannot find what is wrong, also if I try WHERE function
> alternatively, I got same error.
>
> Thank you
>
> Liang
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 26 10:32:02 2010

This archive was generated by hypermail 2.1.8 : Thu Apr 29 2010 - 08:05:27 MDT