# Re: area weighted average with irregular ocean grid

From: Jian Zheng <jzheng8606_at_nyahnyahspammersnyahnyah>
Date: Wed Jul 10 2013 - 15:18:46 MDT

Hi,

You can try function region_ind to get the indices for region of interest.
http://www.ncl.ucar.edu/Document/Functions/Contributed/region_ind.shtml

Jian

On Wed, Jul 10, 2013 at 2:36 PM, Mira Berdahl
<mberdahl@envsci.rutgers.edu>wrote:

> Hi there,
>
> I'm trying to calculate the area weighted average of sea surface
> temperature in a certain region of the North Atlantic, but my input file
> is on an irregular ocean grid. When I try to use lat2d and lon2d I am
> unable to convert from i,j to lat,lon so I get an error saying that my
> coordinate subscripts are out of range. Code and output are below.
>
> Do I have to go through and regrid the dataset in order to obtain lat lon
> as degrees? Or is using lat2d and lon2d sufficient, but I'm doing
> something incorrectly?
>
> Many thanks,
> Mira
>
>
> The code is:
>
> ;************************************************
> ; NA_tos.ncl
> ;************************************************
> ;************************************************
> begin
>
>
> tos_mpi = in->tos
> tos_mpi!1 = "lat"
> tos_mpi!2 = "lon"
> tos_mpi&lat = in->j
> tos_mpi&lon = in->i
> tos_mpi@lat2d = in->lat
> tos_mpi@lon2d = in->lon
>
> printVarSummary(tos_mpi)
>
>
> ;%%%%% read in the weights (area of grid cells %%%%%%%%%%%%%%%%
> cellarea_mpi = in->areacello
> printVarSummary(cellarea_mpi)
>
> cellarea_mpi!1 = "lat"
> cellarea_mpi!2 = "lon"
> cellarea_mpi@lat2d = in->lat
> cellarea_mpi@lon2d = in->lon
>
> ;%%% calculate the area weighted NA temperature based on area of grid
> cells.
>
> NA_tos_mpi =
>
> wgt_areaave2(tos_mpi(:,{50:65},{310:340}),cellarea_mpi({50:65},{310:340}),0)
>
> delete(cellarea_mpi)
> delete(tos_mpi)
> delete(wgtx)
> delete(wgty)
> delete(NA_tos_mpi)
>
> end
>
> ;***************************************************************
>
>
>
>
> Here is the output after running the script:
>
> [mlosic@ncoeus Ocean]\$ ncl testing_mpi.ncl
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.1.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> Variable: tos_mpi
> Type: float
> Total Size: -1591607296 bytes
> 675840000 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 12000] x [lat | 220] x [lon | 256]
> Coordinates:
> time: [15.5..365226.5]
> lat: [1..220]
> lon: [1..256]
> Number Of Attributes: 12
> lon2d : <ARRAY of 56320 elements>
> lat2d : <ARRAY of 56320 elements>
> standard_name : sea_surface_temperature
> long_name : Sea Surface Temperature
> comment : "this may differ from ""surface temperature"" in regions
> of sea ice."
> units : K
> cell_methods : time: mean
> cell_measures : area: areacello
> missing_value : 1e+20
> _FillValue : 1e+20
> associated_files : baseURL:
> http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile:
> gridspec_ocean_fx_MPI-ESM-P_past1000_r0i0p0.nc areacello:
> areacello_fx_MPI-ESM-P_past1000_r0i0p0.nc
> coordinates : lat lon
>
>
> Variable: cellarea_mpi
> Type: float
> Total Size: 225280 bytes
> 56320 values
> Number of Dimensions: 2
> Dimensions and sizes: [j | 220] x [i | 256]
> Coordinates:
> j: [1..220]
> i: [1..256]
> Number Of Attributes: 7
> standard_name : cell_area
> long_name : Ocean Grid-Cell Area
> units : m2
> missing_value : 1e+20
> _FillValue : 1e+20
> associated_files : baseURL:
> http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile:
> gridspec_ocean_fx_MPI-ESM-P_past1000_r0i0p0.nc
> coordinates : lat lon
> fatal:NclOneDValGetRangeIndex: start coordinate index out of range, can't
> continue
> fatal:Could not obtain coordinate indexes, unable to perform subscript
> fatal:Execute: Error occurred at or near line 39 in file testing_mpi.ncl
>
> _______________________________________________
> 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 Wed Jul 10 15:18:55 2013

This archive was generated by hypermail 2.1.8 : Fri Jul 12 2013 - 16:37:39 MDT