area weighted average with irregular ocean grid

From: Mira Berdahl <mberdahl_at_nyahnyahspammersnyahnyah>
Date: Wed Jul 10 2013 - 14:36:49 MDT

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,

The code is:

; NA_tos.ncl
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/popRemap.ncl"

;%%%%% read MPI data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  in = addfile("","r")
  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


;%%%%% read in the weights (area of grid cells %%%%%%%%%%%%%%%%
in = addfile("","r")
cellarea_mpi = in->areacello

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 =




Here is the output after running the script:

[mlosic@ncoeus Ocean]$ ncl testing_mpi.ncl
 Copyright (C) 1995-2009 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 5.1.0
 The use of this software is governed by a License Agreement.
 See 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]
            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: gridspecFile: areacello:
  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]
            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: gridspecFile:
  coordinates : lat lon
fatal:NclOneDValGetRangeIndex: start coordinate index out of range, can't
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:
Received on Wed Jul 10 14:36:57 2013

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