mtalpe / nctoolbox

Automatically exported from code.google.com/p/nctoolbox
0 stars 0 forks source link

nc.metadata issue with this dataset #45

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
>> 
url='http://geoport.whoi.edu/thredds/dodsC/coawst_2_2/fmrc/coawst_2_2_best.ncd';
>> nc=ncgeodataset(url);
>> nc.metadata
Warning: 
'water_condensate_added_by_precip_assimilaition_layer_between_two_isobaric'
 exceeds MATLAB's maximum name length of 63 characters and has been truncated to
 'water_condensate_added_by_precip_assimilaition_layer_between_tw'. 
> In ncdataset>ncdataset.metadata at 348
  In ncgeodataset>ncgeodataset.subsref at 356 
Warning:
'Pressure_vertical_velocity_layer_between_two_pressure_difference_from_ground'
 exceeds MATLAB's maximum name length of 63 characters and has been truncated to
 'Pressure_vertical_velocity_layer_between_two_pressure_differenc'. 
> In ncdataset>ncdataset.metadata at 348
  In ncgeodataset>ncgeodataset.subsref at 356 
Warning: 'Water_vapor_flux_convergence_vertical_int_layer_between_two_isobaric'
 exceeds MATLAB's maximum name length of 63 characters and has been truncated to
 'Water_vapor_flux_convergence_vertical_int_layer_between_two_iso'. 
> In ncdataset>ncdataset.metadata at 348
  In ncgeodataset>ncgeodataset.subsref at 356 
Invalid field name: 'v-component_of_storm_motion'.

Original issue reported on code.google.com by rsignell on 7 May 2012 at 8:28

GoogleCodeExporter commented 8 years ago
Sorry, wrong URL.  This is the one that is problematic:
>>> 
url='http://nomads.ncdc.noaa.gov/thredds/dodsC/narr/200609/20060920/narr-a_221_2
0060920_0300_000.grb';
>> nc=ncgeodataset(url);
>> nc.metadata
Warning: 
'water_condensate_added_by_precip_assimilaition_layer_between_two_isobaric'
 exceeds MATLAB's maximum name length of 63 characters and has been truncated to
 'water_condensate_added_by_precip_assimilaition_layer_between_tw'. 
> In ncdataset>ncdataset.metadata at 348
  In ncgeodataset>ncgeodataset.subsref at 356 
Warning:
'Pressure_vertical_velocity_layer_between_two_pressure_difference_from_ground'
 exceeds MATLAB's maximum name length of 63 characters and has been truncated to
 'Pressure_vertical_velocity_layer_between_two_pressure_differenc'. 
> In ncdataset>ncdataset.metadata at 348
  In ncgeodataset>ncgeodataset.subsref at 356 
Warning: 'Water_vapor_flux_convergence_vertical_int_layer_between_two_isobaric'
 exceeds MATLAB's maximum name length of 63 characters and has been truncated to
 'Water_vapor_flux_convergence_vertical_int_layer_between_two_iso'. 
> In ncdataset>ncdataset.metadata at 348
  In ncgeodataset>ncgeodataset.subsref at 356 
Invalid field name: 'v-component_of_storm_motion'.

Original comment by rsignell on 7 May 2012 at 8:29

GoogleCodeExporter commented 8 years ago
The offending line of code is:

Error in ncdataset/metadata (line 347)
                m.(v{i}) = obj.attributes(v{i});

In this line, ncdataset is using Matlab's dynamic field name to set a field on 
the structure 'm'. If v{i} was 'foo' then this line would essentially translate 
to:

  m.foo = obj.attributes('foo')

It looks like Matlab has a 63 character limit on fieldnames on a structure. The 
name truncation is less than ideal, but it can work for now. The problem here 
is the dash  in 'v-component_of_storm_motion'. That line translates to

  m.v-component_of_storm_motion = obj.attributes('v-component_of_storm_motion');

A dash is an operator (minus) in Matlab, so it's not allowed in a fieldname as 
retrieving that value from a structure would look like:

  v = m.v-component_of_storm_motion 

or, as Matlab sees it:

   v = m.v - component_of_storm_motion

A work around could be to:
  1) remap or escape illegal names. This could turn into a big ball of mud though and I do NOT recommend this approach.
  2) Recognize that the 'metadata' method is a convenience function. I would recommend that it NOT be used internally in other nctoolbox functions as it is not 100% reliable.  The recommend alternative is to use the attributes method; e.g.

  v = nc.attributes('v-component_of_storm_motion')
  p = nc.attributes('Pressure_vertical_velocity_layer_between_two_pressure_difference_from_ground')

Original comment by bschlin...@gmail.com on 7 May 2012 at 8:58

GoogleCodeExporter commented 8 years ago
Okay, I'm find with solution 2.  But let's truncate so that at least 
nc.metadata doesn't just bomb, right?

Original comment by rsignell on 7 May 2012 at 9:08

GoogleCodeExporter commented 8 years ago
 I posted a fix back to the hg repo. Overly long names are truncated.  Illegal names, like 'v-component_of_storm_motion', are just dropped skipped, but Matlab will warn you that they've been skipped.

But at least now it doesn't bomb.

Original comment by bschlin...@gmail.com on 7 May 2012 at 9:20