[ncl-talk] Remove SST data for specific area

Mary Haley haley at ucar.edu
Wed Aug 30 09:29:52 MDT 2017


Quick FYI: in general you want to avoid "do" loops, as they can be slow in
scripting languages.

Using"conform_dims" as Guido suggested would be faster:

dims2d = (/dimsizes(lat), dimsizes(lon)/)
lat2d  = conform_dims(dims2d,lat,0)
lon2d  = conform_dims(dims2d,lon,1)

http://www.ncl.ucar.edu/Document/Functions/Built-in/conform_dims.shtml

--Mary



On Wed, Aug 30, 2017 at 2:34 AM, Guido Cioni <guidocioni at gmail.com> wrote:

> One way to go would be to use the 1-D array anyway by doing a smart
> conform. Otherwise you can create 2-D "dummy" variables using these
> functions:
>
> undef("create_lon2d")
> function create_lon2d(lat[*]:numeric, lon[*]:numeric)
> local x, i
> begin
>   x = new((/dimsizes(lat),dimsizes(lon)/),typeof(lat))
>   do i=0,dimsizes(lat)-1
>     x(i,:) = lon
>   end do
>   return(x)
> end
>
> undef("create_lat2d")
> function create_lat2d(lat[*]:numeric, lon[*]:numeric)
> local y, i
> begin
>   y = new((/dimsizes(lat),dimsizes(lon)/),typeof(lat))
>   do i=0,dimsizes(lon)-1
>     y(:,i) = lat
>   end do
>   return(y)
> end
>
>     lat2d = create_lat2d(lat,lon)
>     lon2d = create_lon2d(lat,lon)
>
> On 30. Aug 2017, at 10:29, Dinuka Silva <dinu.kera at gmail.com> wrote:
>
>
> printVarSummary(x) is as follows.
>
>
> Variable: x
> Type: float
> Total Size: 454377600 bytes
>             113594400 values
> Number of Dimensions: 3
> Dimensions and sizes:   [time | 1753] x [latitude | 180] x [longitude |
> 360]
> Coordinates:
>             time: [15.49999..53340.5]
>             latitude: [89.5..-89.5]
>             longitude: [-179.5..179.5]
> Number Of Attributes: 8
>   lon2d :       <ARRAY of 360 elements>
>   lat2d :       <ARRAY of 180 elements>
>   _FillValue :  -1e+30
>   standard_name :       sea_surface_temperature
>   long_name :   sst
>   units :       C
>   cell_methods :        time: lat: lon: mean
>   missing_value :       -1e+30
> fatal:And: Dimension size, for dimension number 0, of operands does not
> match, can't continue
>
> It looks like "latitude" and "longitude" are 1D arrays . How can I make
> them to be 2D arrays.
>
> Dinuka.
>
>
> On Wed, Aug 30, 2017 at 4:04 PM, Guido Cioni <guidocioni at gmail.com> wrote:
>
>> Dinuka,
>> don’t start new topic if the problem is always the same. People will get
>> confused when they search for answers.
>>
>> Did you check that your latitude and longitude are 2-D arrays?
>> The error is exactly telling you where the problem is.
>>
>>
>> Il giorno 30 ago 2017, alle ore 07:30, Dinuka Silva <dinu.kera at gmail.com>
>> ha scritto:
>>
>> Hi all,
>>
>> I want to remove SST data of one box ({03N - 12N}, {90E- 140E}) and then
>> find the correlation between remaining SST data and rainfall index. I want
>> to know how can I remove the SST data of that box. SST data has 3
>> dimensions. I used mask function but I got error message.
>>
>> x =  fin2->sst(:,:,:)
>>
>>     x at lat2d = fin2->latitude
>>     x at lon2d = fin2->longitude
>>
>>
>>     latMin  = 03
>>     latMax  = 12
>>     lonMin  = 90
>>     lonMax  = 140
>>
>>   x   = mask (x, conform(x, (x at lat2d.ge.latMin .and.x at lat2d.le.latMax .
>> and.x at lon2d.ge.lonMin .and.x at lon2d.le.lonMax), (/1,2/)), True)
>> printVarSummary(x)
>>
>>
>> The error message : Dimension size, for dimension number 0, of operands
>> does not match, can't continue
>>
>>
>> Thanks for your help.
>> Dinuka
>>
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon> Virus-free.
>> www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> Guido Cioni
> http://guidocioni.altervista.org
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170830/bcb3d92c/attachment.html>


More information about the ncl-talk mailing list