expand_intervaltree¶
- expand_intervaltree(tree, convert_fns, calto_fn)[source]¶
Convert an IntervalTree into the equivalent list of (CalTo, [CalFrom..]) 2-tuples.
The second argument for this function is a list of 2-tuples of (CalToArgs constructor argument for this dimension, value conversion function for this dimension). The conversion function takes in a set of integer indexes and converts it to a suitable (probably more human-readable value) for that dimension, e.g. a conversion from field ID to field name. So, for a dimension that supplies the 'antenna' argument to CalToArgs and should prefix 'DV' to each antenna index, the tuple for that dimension could be ('antenna', lambda id: {'DV%s' % i for i in field_ids}).
The third argument is the partially-applied CalToArgs constructor. A CalToArgs needs a number of arguments (vis, field, spw, etc.), each of which corresponds to a dimension of the IntervalTree and which must be supplied at CalToArgs creation time. To achieve this while iterating through the dimensions (when the constructor arguments are not fully known), object creation is delayed by performing just a partial application, adding the keyword for the current dimension to the partial application. At the final leaf node, when all constructor arguments have been partially applied, we can call the partial function and get the CalToArgs.
- Parameters:
tree -- the IntervalTree to convert
convert_fns -- the list of (argument name, conversion function) 2-tuples for the remaining dimensions
calto_fn -- the partial CalToArgs application
- Returns:
a list of (CalTo, [CalFrom..]) tuples