[ncl-talk] Error in creating Nino34 index from CMIP5 models

Dennis Shea shea at ucar.edu
Sat Nov 17 16:40:40 MST 2018


[1] Mary is correct. The sample file is using a *rectilinear* grid. Hence,
NCL's *coordinate subscripting* (* {...} *) can be used.

[2] The grid for 'tos_Omon_IPSL-CM5A-LR_historical_r1i1p1_185001-200512.nc
is *curvilinear. *Mary offered one appraoch.  Here is another approach.

  f       = *addfile*("tos_Omon_IPSL-CM5A-LR_historical_r1i1p1_185001-200512.nc"
,"r")
  x       = f->tos                      ; (ntim,nlat,mlon)
  lat2d = f->lat                       ; (nlat,mlon)
  lon2d = f->lon

;---Set all values outside of NINO-3.4 region to _FillValue

  LAT2D = *conform*(x, lat2d, (/1,2/))   ; (ntim,nlat,mlon)
  LON2D = *conform*(x, lon2d, (/1,2/))   ; (ntim,nlat,mlon)

  x     = where(LAT2D.ge.latS .and. LAT2D.le.latN .and. \
                LON2D.ge.lonL .and. LON2D.le.lonR       \
               ,x, x at _FillValue)
  delete( [/ LAT2D, LON2D /] )         ; no longer needed

is a curvilinear grid.

*The rest is almost identical to the example.*

;---Create a monthly climatology

  xClm  = clmMonTLL(x)
  printVarSummary(xClm)                ; (nmos,nlat,mlon)
  printMinMax(xClm,0)
  print("---")

;---Calculate anomalies at each grid point

  xAnom =  calcMonAnomTLL(x, xClm)
  printVarSummary(xAnom)               ; (ntim,nlat,mlon)
  printMinMax(xAnom,0)
  print("---")

;---Weighted areal averages & anomalies (time series)
;---Really: No need to weight ... small latitudinal extent

  wgt2      = cos(0.01745329*lat2d)    ; (nlat,mlon)

  xAvg      = wgt_areaave2(x, wgt2, 0)
  copy_VarCoords(x(:,0,0), xAvg)
  xAvg at long_name = "NONO34 areal avg"
  printVarSummary(xAvg)                ; (ntim)
  printMinMax(xAvg,0)
  print("---")

  xAnomAvg = wgt_areaave2(xAnom, wgt2, 0)   ; (ntim)
  copy_VarCoords(x(:,0,0), xAnomAvg)
  xAnomAvg at long_name = *"NINO34* areal avg anomalies: ENSO34 Index"
  printVarSummary(xAnomAvg)
  printMinMax(xAnomAvg,0)
  print("---")

;---Compute standardized anomalies

  xAnomStd = xAnomAvg/stddev(xAnomAvg)      ; (ntim)
  copy_VarCoords(xAnomAvg, xAnomStd)
  xAnomStd at long_name = "*Standardized NINO34*"
  printVarSummary(xAnomStd)
  printMinMax(xAnomStd,0)
  print("---")


On Sat, Nov 17, 2018 at 3:59 PM Mary Haley <haley at ucar.edu> wrote:

> Dear Kwesi,
>
> You didn't provide a script, but my guess is that you are trying to
> subscript your data array using latitude / longitude coordinates, similar
> to this line which was in the original script:
>
>   X      = mon_fullyear( in->SST(:,{latS:latN},{lonL:lonR}), 0)
>
> The original example was written for data on a rectilinear lat/lon grid
> that has latitude/longitude coordinate arrays.
>
> Your data is curvilinear, which means it is represented by 2D lat/lon
> arrays.  It does have coordinate arrays attached to it, but they are simply
> integer indexes and NOT lat/lon coordinate arrays:
>
>        int j(j) ;
>                 j:units = "1" ;
>                 j:long_name = "cell index along second dimension" ;
>         int i(i) ;
>                 i:units = "1" ;
>                 i:long_name = "cell index along first dimension" ;
>
> If you need to subset your data using lat/lon coordinates, you will need
> to either use the getind_latlon2d
> <http://www.ncl.ucar.edu/Document/Functions/Contributed/getind_latlon2d.shtml>
> function or the region_ind
> <http://www.ncl.ucar.edu/Document/Functions/Contributed/region_ind.shtml>
> function.  You can see some examples at:
>
> http://www.ncl.ucar.edu/Applications/latlon_subset.shtml
>
> Look at either latlon_subset_2.ncl or latlon_subset_3.ncl.
>
> Good luck,
>
> --Mary
>
>
> On Sat, Nov 17, 2018 at 7:57 AM Kwesi A. Quagraine <starskykwesi at gmail.com>
> wrote:
>
>> Hello Nclers,
>>
>> I am experiencing an error when calculating Nino34 index (
>> indices_nino_1.ncl
>> <https://www.ncl.ucar.edu/Applications/Scripts/indices_nino_1.ncl>)
>> using CMIP5 models; The error message is; fatal:Coordinate subscript type
>> mismatch. Subscript (2) can not be coerced to type of coordinate variable,
>> subscript (0).
>>
>> Ncdump of file gives;
>>
>> netcdf tos_Omon_IPSL-CM5A-LR_historical_r1i1p1_185001-200512 {
>> dimensions:
>>         time = UNLIMITED ; // (1872 currently)
>>         j = 149 ;
>>         i = 182 ;
>>         bnds = 2 ;
>>         vertices = 4 ;
>> variables:
>>         double time(time) ;
>>                 time:bounds = "time_bnds" ;
>>                 time:units = "days since 1850-01-01 00:00:00" ;
>>                 time:calendar = "noleap" ;
>>                 time:axis = "T" ;
>>                 time:long_name = "time" ;
>>                 time:standard_name = "time" ;
>>         double time_bnds(time, bnds) ;
>>         int j(j) ;
>>                 j:units = "1" ;
>>                 j:long_name = "cell index along second dimension" ;
>>         int i(i) ;
>>                 i:units = "1" ;
>>                 i:long_name = "cell index along first dimension" ;
>>         float lat(j, i) ;
>>                 lat:standard_name = "latitude" ;
>>                 lat:long_name = "latitude coordinate" ;
>>                 lat:units = "degrees_north" ;
>>                 lat:bounds = "lat_vertices" ;
>>         float lon(j, i) ;
>>                 lon:standard_name = "longitude" ;
>>                 lon:long_name = "longitude coordinate" ;
>>                 lon:units = "degrees_east" ;
>>                 lon:bounds = "lon_vertices" ;
>>         float lat_vertices(j, i, vertices) ;
>>                 lat_vertices:units = "degrees_north" ;
>>         float lon_vertices(j, i, vertices) ;
>>                 lon_vertices:units = "degrees_east" ;
>>         float tos(time, j, i) ;
>>                 tos:standard_name = "sea_surface_temperature" ;
>>                 tos:long_name = "Sea Surface Temperature" ;
>>                 tos:comment = "\"this may differ from \"\"surface
>> temperature\"\" in regions of sea ice.\"" ;
>>                 tos:units = "K" ;
>>                 tos:original_name = "sosstsst" ;
>>                 tos:original_units = "degC" ;
>>                 tos:history = "2011-07-04T20:18:27Z altered by CMOR:
>> Converted units from \'degC\' to \'K\'. 2011-07-04T20:18:27Z altered by
>> CMOR: replaced missing value flag (9.96921e+36) with standard missing value
>> (1e+20)." ;
>>                 tos:cell_methods = "time: mean (interval: 30 minutes)" ;
>>                 tos:cell_measures = "area: areacello" ;
>>                 tos:missing_value = 1.e+20f ;
>>                 tos:_FillValue = 1.e+20f ;
>>                 tos:associated_files = "baseURL:
>> http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile:
>> gridspec_ocean_fx_IPSL-CM5A-LR_historical_r0i0p0.nc areacello:
>> areacello_fx_IPSL-CM5A-LR_historical_r0i0p0.nc" ;
>>                 tos:coordinates = "lat lon" ;
>>
>> // global attributes:
>>                 :institution = "IPSL (Institut Pierre Simon Laplace,
>> Paris, France)" ;
>>                 :institute_id = "IPSL" ;
>>                 :experiment_id = "historical" ;
>>                 :source = "IPSL-CM5A-LR (2010) : atmos : LMDZ4 (LMDZ4_v5,
>> 96x95x39); ocean : ORCA2 (NEMOV2_3, 2x2L31); seaIce : LIM2 (NEMOV2_3);
>> ocnBgchem : PISCES (NEMO:
>>
>> Any help on this will be much appreciated. Thanks in advance.
>>
>> Best regards
>> Kwesi
>> ------------
>> Try not to become a man of success but rather a man of value- Albert
>> Einstein
>>
>> Kwesi A. Quagraine
>> Department of Physics
>> School of Physical Sciences
>> College of Agriculture and Natural Sciences
>> University of Cape Coast
>> Cape Coast, Ghana
>>
>> Alt. Email: kwesi at csag.uct.ac.za
>> Web: http://www.recycleupghana.org/
>> Office: +27 21 650 3164
>> Skype: quagraine_cwasi
>> _______________________________________________
>> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181117/4cc60193/attachment.html>


More information about the ncl-talk mailing list