Thanks Billy and Ansley for the suggestions/discussion. The following code, using xbox and ybox, should work for any model grid (...at least for the regular grid I'm using thus far). The formulas are based on Andrew Wittenberg's ferret documentation on grid cell areas ( ../../faq/averages-integrals-on-the-sphere).
let modelName = $1 let r_Earth = 6371.E3 ! Earth's radius (m)
use var_for_`modelName`.nc ! Load "var" from given model let pi=4*atan(1) let latRad = y[gy=var]*pi/180 ! Lats as radians let dlat = ybox[gy=var]*pi/180 ! lat spacing in radians let dlon = xbox[gx=var]*pi/180 ! ...lon spacing
let cell_area = r_Earth^2 * cos(latRad) * dlon * 2 * sin(dlat/2) ! area (lon,lat) in m2
define att/output cell_area.units="m2" ! Save to netcdf (with useful meta data!) for some future use define att/output cell_area.long_name="Grid cell areas for `modelName` (r_Earth = `r_Earth` m)" save/file="cell_area_for_`modelName`.nc" cell_area
---- Cheers,
Paul
On Sep 13, 2011, at 4:40 PM, William S. Kessler wrote: Isn't that what XBOX and YBOX do? I guess you'd have to scale by cos(latitude) if your grid is in degrees. let pi=4*atan(1) let cell_area = xbox[g=gridname]*ybox[g=gridname]*cos(pi*y[gy=gridname]/180) BK On Sep 13, 2011, at 2:52 PM, Paul Young wrote: Hi all,
I've seen that there are several entries in the archives about saving the area for a particular region (using @din; e.g. ../fu_2004/msg00026.html), but is there a simple way to return a variable that is dimensioned (nlon, nlat) and has the the grid cell areas for each cell? Else, do I need to step through and do the geometry myself?
I'm looping through a bunch of different models (perhaps some on spectral grids) and I'd like to have a generic script. I'm envisaging something like:
use "var_for_model_X.nc" !Load in any variable on the model grid (e.g. surface pressure: lon, lat, time)
let cell_areas = { something clever in one/two lines! } !Calculate areas [lon,lat]
save/file="cell_areas_for_model_X.nc" cell_areas !Save them to netcdf
I bet the solution is very simple and staring me in the face, but - as I can't see it - please forgive me for crowd-sourcing from the help list.
Cheers,
Paul
|