[ncl-talk] delete array rows with duplicate time, lat, lon in ncl

Mary Haley haley at ucar.edu
Mon Jun 18 09:46:32 MDT 2018


Hi Sam,

I tried to download your NCL script, but the link said it was "deleted by
the owner".

To make sure I understand you correctly, are you saying that when you
select the range of interest, there are some lat/lon points that are
identical, and hence NCL errors out because it doesn't know how to contour
data that has duplicate lat/lon points?

I wrote a small script to see if I could reproduce your problem, but I
couldn't get it to error in the way you said yours did . Here's the script,
which doesn't produce a very pleasing plot because it basically ends up
with 3 points that it can contour:


  in258 = addfile("CalCOFI_temp_sal_on_25.8_isopycnal_by_cruise.nc","r")
  s258  = in258->r_salinity                      ; read all salinities
  lat3  = in258->latitude
  lon3  = in258->longitude
  time3 = in258->time

  printVarSummary(s258)
  printMinMax(s258,0)
  printVarSummary(lat3)
  printVarSummary(lon3)


  sal_val = 33.78     ; Salinity value to search on
  delta   = 0.025     ; based on delta range

  sal_val_min = sal_val - delta
  sal_val_max = sal_val + delta

  ind_sal = ind(sal_val_min.le.s258.and.s258.le.sal_val_max)

  s258_subset = s258(ind_sal)
  lat3_subset = lat3(ind_sal)
  lon3_subset = lon3(ind_sal)
  print(lat3_subset + " " +  lon3_subset + " " + s258_subset)

  s258_subset at lat1d = lat3_subset
  s258_subset at lon1d = lon3_subset

  wks = gsn_open_wks("x11","salinity_test")

  res = True
  res at gsnMaximize = True
  res at cnFillOn    = True
  res at cnLinesOn   = False
  res at cnFillMode  = "RasterFill"
  res at mpMinLatF   = min(lat3)
  res at mpMinLonF   = min(lon3)
  res at mpMaxLatF   = max(lat3)
  res at mpMaxLonF   = max(lon3)
  plot = gsn_csm_contour_map(wks,s258_subset,res)


On Sat, Jun 16, 2018 at 6:09 PM, Sam McClatchie <smcclatchie at fishocean.info>
wrote:

> Hello
>
> I have an annoyingly simple problem. I want to plot salinity on an
> isopycnal surface for about 75 oceanographic stations (where there are
> depth profiles) arranged on an irregularly spaced, ragged grid. The data
> are in a flat netcdf file that cannot be read by the Climate Data Operators.
>
> ------------------------------------
>
> smcc at jaguar:/data/dynamic_data/projects/projects2018/visualization/data$
> ncdump -h CalCOFI_temp_sal_on_26.5_isopycnal_by_cruise.nc
> netcdf CalCOFI_temp_sal_on_26.5_isopycnal_by_cruise {
> dimensions:
>     row = 62 ;
>     sta_id_strlen = 11 ;
> variables:
>     char sta_id(row, sta_id_strlen) ;
>         sta_id:_Encoding = "ISO-8859-1" ;
>         sta_id:coordinates = "time latitude longitude" ;
>         sta_id:description = "8-digit CalCOFI line and station
> designation" ;
>         sta_id:ioos_category = "Identifier" ;
>         sta_id:long_name = "Line and Station" ;
>     int r_depth(row) ;
>         r_depth:actual_range = 125, 271 ;
>         r_depth:coordinates = "time latitude longitude" ;
>         r_depth:description = "Reported Depth the bottle was tripped" ;
>         r_depth:ioos_category = "Identifier" ;
>         r_depth:long_name = "Reported Bottle Depth" ;
>         r_depth:units = "meters" ;
>     float r_temp(row) ;
>         r_temp:actual_range = 7.83f, 9.04f ;
>         r_temp:coordinates = "time latitude longitude" ;
>         r_temp:description = "Reported Temperature of water at the depth
> the bottle was tripped" ;
>         r_temp:ioos_category = "Temperature" ;
>         r_temp:long_name = "Reported Temperature" ;
>         r_temp:units = "degree C" ;
>     float r_salinity(row) ;
>         r_salinity:actual_range = 33.975f, 34.215f ;
>         r_salinity:coordinates = "time latitude longitude" ;
>         r_salinity:description = "Practical Salinity Scale, 1978 (UNESCO,
> 1981a)" ;
>         r_salinity:ioos_category = "Salinity" ;
>         r_salinity:long_name = "Reported Salinity" ;
>         r_salinity:units = "psu" ;
>     float r_sigma(row) ;
>         r_sigma:actual_range = 26.475f, 26.525f ;
>         r_sigma:coordinates = "time latitude longitude" ;
>         r_sigma:ioos_category = "Other" ;
>         r_sigma:long_name = "Reported Potential Density of water" ;
>     float latitude(row) ;
>         latitude:_CoordinateAxisType = "Lat" ;
>         latitude:actual_range = 30.186f, 36.709f ;
>         latitude:axis = "Y" ;
>         latitude:ioos_category = "Location" ;
>         latitude:long_name = "Latitude" ;
>         latitude:standard_name = "latitude" ;
>         latitude:units = "degrees_north" ;
>     float longitude(row) ;
>         longitude:_CoordinateAxisType = "Lon" ;
>         longitude:actual_range = -124.637f, -117.533f ;
>         longitude:axis = "X" ;
>         longitude:ioos_category = "Location" ;
>         longitude:long_name = "Longitude" ;
>         longitude:standard_name = "longitude" ;
>         longitude:units = "degrees_east" ;
>     double time(row) ;
>         time:_CoordinateAxisType = "Time" ;
>         time:actual_range = 1365319440., 1367199780. ;
>         time:axis = "T" ;
>         time:description = "Time" ;
>         time:ioos_category = "Time" ;
>         time:long_name = "Time" ;
>         time:standard_name = "time" ;
>         time:time_origin = "01-JAN-1970 00:00:00" ;
>         time:units = "seconds since 1970-01-01T00:00:00Z" ;
>
> // global attributes:
>         :acknowledgment = "University of California, San Diego Scripps
> Institution" ;
>         :cdm_data_type = "Point" ;
>         :Conventions = "COARDS, CF-1.6, Unidata Dataset Discovery v1.0" ;
>         :date_issued = "2013-07-17" ;
>         :date_modified = "2013-07-17" ;
>         :Easternmost_Easting = -117.533f ;
>         :featureType = "Point" ;
>         :geospatial_lat_max = 36.709f ;
>         :geospatial_lat_min = 30.186f ;
>         :geospatial_lat_units = "degrees_north" ;
>         :geospatial_lon_max = -117.533f ;
>         :geospatial_lon_min = -124.637f ;
>         :geospatial_lon_units = "degrees_east" ;
>         :history = "2018-04-22T00:58:55Z (source database)\n",
>             "2018-04-22T00:58:55Z http://oceanview.pfeg.noaa.
> gov/erddap/tabledap/siocalcofiHydroBottleReport.ncCF?sta_id%2Cr_depth%2Cr_
> temp%2Cr_salinity%2Cr_sigma%2Clatitude%2Clongitude%2Ctime&
> r_sigma%3E=26.475&r_sigma%3C=26.525&time%3E=2013-03-01T12%
> 3A52%3A58Z&time%3C=2013-05-01T12%3A52%3A58Z" ;
>         :id = "siocalcofiHydroBottleReport_3bf6_a84f_a01b" ;
>         :infoUrl = "http://www.calcofi.org/new.
> data/index.php/reporteddata/2013-09-30-23-23-27/database-
> tables-description"
> <http://www.calcofi.org/new.data/index.php/reporteddata/2013-09-30-23-23-27/database-tables-description>
> ;
>         :institution = "UCSD SIO" ;
>         :license = "The data may be used and redistributed for free but is
> not intended\n",
>             "for legal use, since it may contain inaccuracies. Neither the
> data\n",
>             "Contributor, ERD, NOAA, nor the United States Government, nor
> any\n",
>             "of their employees or contractors, makes any warranty,
> express or\n",
>             "implied, including warranties of merchantability and fitness
> for a\n",
>             "particular purpose, or assumes any legal liability for the
> accuracy,\n",
>             "completeness, or usefulness, of this information." ;
>         :Northernmost_Northing = 36.709f ;
>         :project = "CalCOFI" ;
>         :publisher_email = "jwilkinson at ucsd.edu" <jwilkinson at ucsd.edu> ;
>         :publisher_name = "James Wilkinson" ;
>         :sourceUrl = "(source database)" ;
>         :Southernmost_Northing = 30.186f ;
>         :standard_name_vocabulary = "CF-11" ;
>         :subsetVariables = "sta_id" ;
>         :summary = "SIO Hydrographic data" ;
>         :time_coverage_end = "2013-04-29T01:43:00Z" ;
>         :time_coverage_start = "2013-04-07T07:24:00Z" ;
>         :title = "CalCOFI SIO Hydrographic Bottle Report data" ;
>         :Westernmost_Easting = -124.637f ;
>
> ----------------------------------------------------
> To obtain enough salinity points on the density surface (26.5 for
> example), I selected the data based on a small range of densities (+/-
> 0.025). This means that at a few (time,lat,long) stations there is more
> than one density point in the range. Consequently, I obtain some
> (time,lat,long) stations where there is more than one salinity selected for
> the isopycnal, and this causes the contour plot to fail.
>
> Here is my question:
> Since I cannot use CDO with this netcdf file (it is not the right format
> of netcdf), can I select and eliminate the duplicates efficiently in NCL?
> ------------------------------------------------
> I was thinking something like this?
>
> in258 = addfile("../data/CalCOFI_temp_sal_on_25.8_isopycnal_by_cruise.nc
> ","r")
>   s258  = in258->r_salinity                      ; read all salinities
>   lat3  = in258->latitude
>   lon3  = in258->longitude
>   time3 = in258->time
>   ; printVarSummary(s258)
>   ; printVarSummary(lat3)
>   ; printVarSummary(lon3)
>   ; print(time3)
>   ; print(get_unique_values(time3))
>
>   x     = (/ (/time3/),(/lat3/),(/lon3/),(/s258/) /)
>    print(x)
>   x1D   = ndtooned(x)
>    print(x1D)
>   i1D   = ind(get_unique_values(x1D(0,??))); need to index the original
> position of unique times
>   exit()
>   i     = ind_resolve(i1D, dimsizes(x) )
> --------------------------------------------------
>
> The plot I am working on is here:
> "https://my.pcloud.com/publink/show?code=XZLSJf7ZOh5xn41l5yVWQTzpE2Y5zy
> TG0LeX"
> <https://my.pcloud.com/publink/show?code=XZLSJf7ZOh5xn41l5yVWQTzpE2Y5zyTG0LeX>
>
> The NCL code is here:
> "https://my.pcloud.com/publink/show?code=XZMSJf7Za13geSDAd0hh0ppltNa2PH
> kfYBUk"
> <https://my.pcloud.com/publink/show?code=XZMSJf7Za13geSDAd0hh0ppltNa2PHkfYBUk>
>
> The data are here:
> "https://my.pcloud.com/publink/show?code=XZASJf7Z5CO19wADqnbAHt5NQa10Rh
> aXr91X"
> <https://my.pcloud.com/publink/show?code=XZASJf7Z5CO19wADqnbAHt5NQa10RhaXr91X>
>
> Thanks in advance,
> Sam
> --
> Sam McClatchie (fisheries oceanographer)
> & Elena Turin (accounting & auditing)
> FishOcean Enterprises
> 38 Upland Rd, Huia, Auckland 0604, New Zealand
> cell: 027 752 8495
> Internet <http://www.fishocean.info>
>
>
> "The time has come", the tui said,
> "to talk of many things:
> Of songs - and ferns - and flowering flax,
> of Pukekos and dreams ..."
>
> (not Lewis Carroll)
>
> _______________________________________________
> 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/20180618/6c7804bc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SamMcClatchie2_small.jpg
Type: image/jpeg
Size: 45362 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180618/6c7804bc/attachment.jpg>


More information about the ncl-talk mailing list