[ncl-talk] masking the contiguous United States

Mary Haley haley at ucar.edu
Sat Jul 4 22:45:53 MDT 2015


If you have lat/lon coordinate arrays attached to your data, then can try
the "lonFlip" function to convert your data to be -180 to 180 longitude:

http://www.ncl.ucar.edu/Document/Functions/Contributed/lonFlip.shtml

If you don't have coordinate arrays, but instead are using the special
lat2d/lon2d or lat1d/lon1d attributes, then you can try the "where"
function:

NEE_AVG at lon2d = where(lon2d.gt.180, lon2d - 360, lon2d)

Note: I don't know what your longitude array is called.  I'm just using
"lon2d" as an example here.  You can operate on the attribute directly:

NEE_AVG at lon2d = where(NEE_AVG @lon2d.gt.180, NEE_AVG @lon2d - 360, NEE_AVG@
lon2d)

You will also need to update your minlon/maxlon attributes to be in -180 to
180

  opt at minlon = -130   ; 230 - 360
  opt at maxlon = -65   ; 295 - 360


--Mary



On Sat, Jul 4, 2015 at 9:34 PM, Ming Chen <chen1718 at umn.edu> wrote:

> I think I know why it is happening... The data I'm trying to mask has the
> longitude from 0 to 357.5, while the shapefile has the longitude from
> -179.1 to 179.8...
>
> Does anyone has suggestion how I can fix that? Thanks!
>
> Ming
>
>
>
> On Sat, Jul 4, 2015 at 10:19 PM, Ming Chen <chen1718 at umn.edu> wrote:
>
>> Hi all,
>>
>> I was trying to mask the contiguous United States using a shape file and
>> the script "shapefile_mask_data.ncl", but got all missing values.
>>
>> I used ncl 6.2.1. The script I used is here:
>>
>> ;Begins to calculate US averaged NEE
>>   shp_filename = "coastl_usa.shp"
>>   opt = True
>>   opt at minlat = 20
>>   opt at maxlat = 50
>>   opt at minlon = 230
>>   opt at maxlon = 295
>>   opt at debug  = True
>>   opt at keep   = True
>>   opt at loop_check   = True
>>   data_mask    = shapefile_mask_data(NEE_AVG,shp_filename,opt)
>>   NEE_scalar   = wgt_areaave(data_mask,1.,1.,0) ;averaged NEE over the
>> United States
>>
>>
>> And here is the message I got:
>> (0)    ==================================================
>> (0)    Shapefile:         coastl_usa.shp
>> (0)    Areas of interest: the whole shapefile
>> (0)    min_lat_chk:       20
>> (0)    max_lat_chk:       50
>> (0)    min_lon_chk:       230
>> (0)    max_lon_chk:       295
>> (0)    min_lat_data:      -90
>> (0)    max_lat_data:      90
>> (0)    min_lon_data:      0
>> (0)    max_lon_data:      357.5
>> (0)    13824 data values originally
>> (0)    Will keep data values inside given shapefile areas
>> (0)    ==================================================
>> (0)    0 data values kept
>> (0)    shapefile_mask_data: elapsed time: 0.930859 CPU seconds.
>> (0)    ==================================================
>>
>> I can see there are 13824 data points in my NEE_AVG data. And I have plot
>> that without problem. Why there was no data masked?
>>
>> Thanks,
>> Ming
>>
>>
>> --
>> Department of Soil, Water and Climate
>> 439 Borlaug Hall 1991 Upper Buford Cir.
>> St. Paul 55108
>> MN USA
>> Office: 612-624-1645
>> http://www.biometeorology.umn.edu/people_ming.php
>>
>
>
>
> --
> Department of Soil, Water and Climate
> 439 Borlaug Hall 1991 Upper Buford Cir.
> St. Paul 55108
> MN USA
> Office: 612-624-1645
> http://www.biometeorology.umn.edu/people_ming.php
>
> _______________________________________________
> 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/20150704/b9363055/attachment.html 


More information about the ncl-talk mailing list