@@ -285,24 +285,44 @@ def resolveValue(name, value, aliasDict):
285
285
#
286
286
result = None
287
287
288
- # If the value is a string, attempt to resolve it.
288
+ # Breakout context
289
289
#
290
- if True == isinstance (value , str ) or True == isinstance (value , unicode ):
291
- # Attempt to split the value on '__'.
290
+ done = False
291
+
292
+ while False == done :
293
+ done = True
294
+
295
+ # If the value is not a string, get a string representation.
296
+ #
297
+ if False == isinstance (value , str ) and False == isinstance (value , unicode ):
298
+ value = str (value )
299
+
300
+ # If the value starts with 'http', interpret the entire string as a
301
+ # resolved URL.
302
+ #
303
+ if value [0 :4 ] == 'http' :
304
+ result = value
305
+
306
+ break
307
+
308
+ # Attempt to split the value on '__' to see if there is a context
309
+ # part to the value.
292
310
#
293
311
valueParts = value .split ('__' )
294
312
295
313
# If there is a context part, resolve the value as a name.
296
314
#
297
315
if 2 == len (valueParts ):
298
316
result = resolveName (value , aliasDict )
317
+
318
+ break
299
319
300
320
# If the name exists in the alias dictionary, and if the value exists
301
321
# in the sub-dictionary for the name, create a URL using the pattern
302
322
# for the value. A wildcard (*) for a value key in the dictionary
303
323
# matches any value.
304
324
#
305
- elif name in aliasDict ['values' ]:
325
+ if name in aliasDict ['values' ]:
306
326
subDict = aliasDict ['values' ][name ]
307
327
308
328
pattern = None
@@ -314,6 +334,8 @@ def resolveValue(name, value, aliasDict):
314
334
315
335
if pattern is not None :
316
336
result = makeURL (value , pattern )
337
+
338
+ break
317
339
318
340
# Return the resolved name if one was found.
319
341
#
@@ -342,39 +364,33 @@ def parseAttributes(ncObj, aliasDict):
342
364
attrValue = ncObj .getncattr (attrName )
343
365
attrType = parseType (attrValue )
344
366
345
- # If the value is not an array, make it a list.
367
+ # If the value is an array, make it a list.
346
368
#
347
- if False == isinstance (attrValue , numpy .ndarray ):
348
- attrValue = [ attrValue ]
369
+ if True == isinstance (attrValue , numpy .ndarray ):
370
+ attrValue = list ( attrValue )
349
371
350
372
# Get the URL (if any) for the attribute.
351
373
#
352
374
nameURL = resolveName (attrName , aliasDict )
353
375
354
- # Construct a list of attribute value and URL pairs .
376
+ # Get the URL (if any) for the value .
355
377
#
356
- valueList = []
378
+ valueURL = resolveValue ( attrName , attrValue , aliasDict )
357
379
358
- for value in attrValue :
359
- # Get the URL (if any) for the value.
360
- #
361
- valueURL = resolveValue (attrName , value , aliasDict )
362
-
363
- # If the value is a string, wrap it in '"' characters.
364
- #
365
- if True == isinstance (value , str ) or True == isinstance (value , unicode ):
366
- value = '"' + str (value ) + '"'
367
-
368
- valueEntry = { 'element' : value }
380
+ # If the value is a string, wrap it in '"' characters.
381
+ #
382
+ if True == isinstance (attrValue , str ) or True == isinstance (attrValue , unicode ):
383
+ attrValue = '"' + str (attrValue ) + '"'
384
+
385
+ valueEntry = { 'element' : attrValue }
369
386
370
- if valueURL is not None :
371
- valueEntry ['url' ] = valueURL
372
-
373
- valueList .append (valueEntry )
387
+ if valueURL is not None :
388
+ valueEntry ['url' ] = valueURL
389
+
374
390
375
391
# Build the attribute entry. If there is a name URL add it.
376
392
#
377
- attrEntry = {'name' : attrName , 'value' : valueList , 'type' : attrType }
393
+ attrEntry = {'name' : attrName , 'value' : valueEntry , 'type' : attrType }
378
394
379
395
if nameURL is not None :
380
396
attrEntry ['url' ] = nameURL
@@ -388,11 +404,11 @@ def parseAttributes(ncObj, aliasDict):
388
404
return attrList
389
405
390
406
391
- def parseNcObj (ncObj , aliasDict ):
407
+ def parseGroup (ncObj , aliasDict ):
392
408
'''
393
- Build dimension, variable, and attribute lists for the object.
409
+ Build dimension, variable, and attribute lists for the group object.
394
410
395
- ncObj [in] The netCDF4 object to parse.
411
+ ncObj [in] The netCDF4 group object to parse.
396
412
aliasDict [in] A dictionary of URI patterns keyed by the elements they
397
413
replace.
398
414
returns A nested set of dictionaries and lists describing the object
@@ -482,6 +498,46 @@ def parseNcObj(ncObj, aliasDict):
482
498
return dataDict
483
499
484
500
501
+ def parseDataset (ncObj , aliasDict ):
502
+ '''
503
+ Build a set of group dictionaries for the netCDF4 Dataset object.
504
+
505
+ ncObj [in] The netCDF4 Dataset object to parse.
506
+ aliasDict [in] A dictionary of URI patterns keyed by the elements they
507
+ replace.
508
+ returns A nested set of dictionaries and lists describing the object
509
+ contents.
510
+ '''
511
+
512
+ # Parse the contents of the root group of the netCDF file. Add a groupName
513
+ # element and store it in a groups list.
514
+ #
515
+ groupList = []
516
+
517
+ groupEntry = parseGroup (ncObj , aliasDict )
518
+
519
+ groupEntry ['groupName' ] = 'global'
520
+
521
+ groupList .append (groupEntry )
522
+
523
+ # If there are any other groups, add them as well.
524
+ #
525
+ for groupName , groupObj in ncObj .groups .iteritems ():
526
+ groupEntry = parseGroup (groupObj , aliasDict )
527
+
528
+ groupEntry ['groupName' ] = groupName
529
+
530
+ groupList .append (groupEntry )
531
+
532
+ # Add the group list to a top-level dictionary.
533
+ #
534
+ dataDict = { 'groups' : groupList }
535
+
536
+ # Return the dictionary.
537
+ #
538
+ return dataDict
539
+
540
+
485
541
def ncldDump (inputFile , aliasFile , outputFile ):
486
542
'''
487
543
Generate an HTML page from a netCDF-LD file. The page will contain CDL
@@ -504,9 +560,9 @@ def ncldDump(inputFile, aliasFile, outputFile):
504
560
#
505
561
ncObj = netCDF4 .Dataset (inputFile , 'r' )
506
562
507
- # Parse the contents of the netCDF file into a dictionary.
563
+ # Parse the contents into a dictionary.
508
564
#
509
- ncDict = parseNcObj (ncObj , aliasDict )
565
+ ncDict = parseDataset (ncObj , aliasDict )
510
566
511
567
# Add a filePath entry.
512
568
#
0 commit comments