Sphinx logo

objcat – flexible, dynamically updated object catalog

The objcat module contains classes and functions for generating catalogs of objects. This catalog is unique in that it stores source information and can dynamical deriv quantities that are dynamically updated as their sources are changed. It also provides mechanisms for safely saving these object catalogss in a database, and someday soon will include a web interface to interact with the catalog via the internet.

Fundamentally, the catalog should be thought of as a tree (this kind, rather than this one) of FieldNode objects. Normally, a Catalog object acts as the root.

todo:add examples!

Classes and Inheritance Structure

Inheritance diagram of astropysics.objcat

Module API

class astropysics.objcat.ActionNode(parent, name=None)

Bases: astropysics.objcat.CatalogNode

This object is the superclass for nodes of a catalog that perform an action but do not store data. Thus, they have a parent, but no children.

Subclassing

  • If __init__() is overridden in a subclass, ActionNode.__init__() must be called.
  • Subclasses must override the abstract _doAction() method to define the action for the node. The first argument should be the node to act on. Additional arguments (passed on from __call__() should be documented in the class docstring.

If an action is desired without inserting the ActionNode into the graph, the following method is typically used:

output = SomeActionClass(None,param1=foo,param2=bar)(targetnode)
Parameters:
  • parent – The parent of this node or None for no parent.
  • name – The name of this node or None to use a default based on the class name.
class astropysics.objcat.AstronomicalObject(parent=None, name='default Name')

Bases: astropysics.objcat.StructuredFieldNode

A StructuredFieldNode with the basic fields for an astronomical object.

loc = <astropysics.objcat.Field object at 0x11340f7d0>
name = <astropysics.objcat.Field object at 0x11340f758>
sed = <astropysics.objcat.SEDField object at 0x112e51d10>
class astropysics.objcat.Catalog(name='default Catalog', parent=None)

Bases: astropysics.objcat.CatalogNode

This class represents a catalog of objects or catalogs.

A Catalog is essentially a node in the object tree that is typically (although not necessarily) the root of the catalog tree.

Iterator access is over the children, as is container testing and index access.

Attributes can also be accessed as catobj[attrname] (this allows access to Catalog attributes in the same way as FieldNodes)

actionchildren
extractField(*args, **kwargs)

Walk through the tree starting from this object and generate an array of the values for the requested fieldname if any FieldNode`s are in this :class:`Catalog.

The other arguments are for FieldNode.extractFieldAtNode() :

getFieldNames()

Searches the Catalog and finds all field names present in the children

getFieldValueNodes(fieldname, value)

Searches the Catalog and finds all objects with the requested name

insertInto(insertnode)

Inserts this Catalog into another catalog heirarchy in the place of a node insertnode . This will replace the current parent, if any.

Parameters:insertnode (CatalogNode) – The node to insert this Catalog in the place of. This Catalog becomes the parant of insertnode .
isRoot()
locateName(name)

Searches the Catalog and finds all objects with the requested name

mergeNode(node, skipdup=False, testfunc=None)

merges the given FieldNode into the catalog by reassigning all of it’s children to this Catalog

testfunc is a function that will be called on the node to be transferred, and if it is True, the node will be moved, or if not it will be left alone. If it is None, this test will be skipped

if skipdup is True, any nodes that already have an object of the same name will not be transferred

returns the number of objects added

class astropysics.objcat.CatalogNode(parent)

Bases: object

This object is the superclass for all elements/nodes of a catalog with both parents and children.

This is an abstract class that must have its initializer overriden.

Subclassing
  • Subclasses must call super(Subclass,self).__init__(parent) in their __init__
addChild(node)

Adds a node as a child of this node. Note that this will replace the added node’s current parent (if any)

children
idstr()

a string uniquely identifying the object in its catalog heirarchy

static load(file)

Load a previously saved CatalogNode.

Parameters:file – A file name or file-like object for a file storing a pickled CatalogNode.
Raises TypeError:
 If file does not contain a CatalogNode.
nnodes

this gives the number of total nodes at this point in the tree (including self - e.g. a leaf in the tree returns 1)

parent
removeChild(node)

Removes the requested child from this node, leaving it an orphan (i.e. it’s parent is None)

If child is not present, a ValueError will be raised

reorderChildren(neworder, inverseinds=False)

Change the order of the children

Parameters:
  • neworder
    Must be one of:
    • ‘reverse’
      Flip the order of the children
    • Array-like with integer values
      Specifies the new order of the children. (e.g. to reorder [a,b,c] to [c,a,b], neworder would be [2,0,1])
    • A callable
      Reorders the children as per the sort() list method, using the callable as the cmp argument - it is called as cmp(node1,node2) and should return -1 if node1<node2, 0 if equal, or 1 if node1>node2.
    • None
      Reorders as per standard python list sorting
  • inverseinds – If True and neworder is integer array-like, does inverse reordering (e.g. if neworder is [2,0,1] and the children are [c,a,b] ,the children are reordered to [a,b,c]). Otherwise, has no effect.
save(file, savechildren=True, **kwargs)

save this node as a file with the given name or file-like object

if savechildren is True, the entire subtree will be saved, if False, just this node

Note that the parent and everything above this point will NOT be saved (when reloaded the parent will be None)

extra kwargs are passed into utils.fpickle

visit(func, traversal='postorder', filter=False, includeself=True)

This function walks through the object and all its children, executing func(CatalogNode) and returning a list of the return values

Parameters:
  • func (a callable) – The function to call as func(node) on each node.
  • traversal

    The traversal order of the tree - can be:

    • ‘preorder’
    • ‘postorder’
    • an integer indicating at which index the root should be evaluated (pre/post are 0/-1)
    • a float between -1 and 1 indicating where the root should be evaluated as a fraction
    • ‘level’/’breathfirst’
    • None:only visit this Node
  • filter

    Sets a filter to control which nodes are visited. Can be:

    • False
      process and return all values
    • A callable
      is called as g(node) and if it returns False, the node will not be processed nor put in the list (also ignores anything that returns None)
    • any other
      If the node returns this value on processing, it will not be included in the returned list.
  • includeself (bool) – If False, the function will not visit the node itself (only the sub-trees)
Returns:

A list with the return values of visitfunc at each visited node.

exception astropysics.objcat.CycleError(message)

Bases: exceptions.Exception

This exception indicates a cycle was detected in some graph-like structure

exception astropysics.objcat.CycleWarning(message)

Bases: exceptions.Warning

This warning indicates a cycle was detected in some graph-like structure

class astropysics.objcat.DependentSource(depfields, pathnode, notifierfunc=None)

Bases: astropysics.objcat.Source

This class holds weak references to the Field`s that are necessary to generate values such as in :class:`DerivedValue.

This source must know the CatalogNode that it is expected to inhabit to properly interpret string codes for fields. Otherwise, the input fields must be Field objects.

If locator strings are given to depfields, these strings follow a simple mini-language to locate their target field. If they are strings without the ‘-‘ character, they will simply be treated as names within the same node. If a ‘-‘ is present, the text before the ‘-‘ follows the form “^^^.0.st” where a ‘^’ character indicates that the path should go up to the parent of the current node, ”.0” indicates to go to the first child, and ”.st” indicates that a LinkField with the name ‘st’ should be followed. Once the correct node is located, the text after the “-” indicates the name of the field on that node.

Thus,’^^^.0.st-field’ would go three needs up, into the first child, then into the node from a link named ‘st’, and would return the value of the field named “field”.

depfieldrefs
depstrs
getDeps(geterrs=False)

gets the values of the dependent field.

the return value is a list of the values in the fields if geterrs is False, or (value,upperr,lowerr) if it is True

location
notifierfunc
pathnode

The CatalogNode for dereferencing source names

populateFieldRefs()

this relinks all dead weakrefs using the dependancy strings and returns all of the references or raises a ValueError if any of the strings cannot be dereferenced

class astropysics.objcat.DerivedValue(f, sourcenode=None, flinkdict=None, ferr=False)

Bases: astropysics.objcat.FieldValue

A FieldValue that derives its value from a function of other FieldValues.

The values to use as arguments to the function are initially set through the default values of the function, and can be either references to fields or strings used to locate the dependencies in the catalog tree, using the sourcenode argument as the current source (see DependentSource for details of how dependent values are dereferenced)

Alternatively, the initializer argument flinkdict may be a dictionary of link values that overrides the defaults from the function.

if ferr is True, the return value of f should be a 3-sequence of the form (value,uppererror,lowererror), and the arguments of f will be passed as (depvalue,uerr,lerr) from the source FieldValues.

The class attribute failedvalueaction determines the action to take if a an exception is encountered while deriving the value and can be:

  • ‘raise’

    raise an exception (or pass one along)

  • ‘warn’

    issue a warning when it occurs, but continue execution with the value returned as None

  • ‘skip’

    the value will be returned as None but the value will be left invalid

  • ‘ignore’

    the value will be returned as None and will be marked valid

f is the function to use for deriving the value - must have default field links for every argument if flinkdict is None.

sourcenode specifies the current node to allow for links to be strings instead of explicit references to Fields.

flinkdict maps argument names to links, overriding the default values of the arguments of f

checkType(typetocheck)

ensure that the value of this FieldValue is of the requested Type (or None to accept anything). Any mismatches will throw a TypeError

errors
failedvalueaction = 'raise'
field

A function like Field.notifyValueChange

flinkdict
invalidate()

This marks this derivedValue as incorrect

source
sourcenode

The current location in the Catalog tree

value
class astropysics.objcat.Field(name=None, type=None, defaultval=None, usedef=None, descr=None, units=None)

Bases: _abcoll.MutableSequence

This class represents an attribute/characteristic/property of the FieldNode it is associated with. It stores the current value as well as all the other possible values.

The values, sources, and default properties will return the actual values contained in the FieldValues, while currentobj and iterating over the Field will return FieldValue objects. Calling the Field (no arguments) will return the current value itself

usedef specified if the default should be set – if True, defaultval will be used, if None, a None defaultval will be ignored but any other will be recognizd, and if False, no default will be set

The field should have a name, and can optionally be given a type. If the name is None, it will be inferred from the node it is placed inside.

currenterror
currentobj
currentsource
default

The default value is the FieldValue that has a the None Source - this property is the default value itself, not the fieldValue object

derived

returns a list of all the DerivedValue objects

description

The description of this Field.

errors
insert(key, val)

Insert a value into this Field.

Parameters:
  • key – The index or source at which to insert.
  • val – The FieldValue to add.
name
node

the node to which this Field belongs

notifyValueChange(oldvalobject=None, newvalobject=None)

notifies all registered functions that the value in this field has changed

(see registerNotifier)

observed

returns a list of all the ObservedValue objects except the default

registerNotifier(notifier, checkargs=True)

this registers a function to be called when the value changes or is otherwise rendered invalid. The notifier will be called as notifier(oldvalobj,newvalobj) BEFORE the value change is finalized.

sourcenames
sources
strCurr()

returns a string with the current value instead of the list of values (the behavior of str(Field_obj)

type

Selects the type to enforce for this field. if None, no type-checking will be performed if a numpy dtype, the value must be an array matching the dtype can also be a sequence of types (accepts all) or a function that will be called directly on the function that returns True if the type is valid.

units

The units of this Field.

values
class astropysics.objcat.FieldNode(parent, **kwargs)

Bases: astropysics.objcat.CatalogNode, _abcoll.Sequence

A node in the catalog that has Fields.

Note that for these subclasses, attribute access (e.g. node.fieldname) accesses the Field object, while mapping or sequence-style access (e.g node[‘fieldname’] or node[1]) directly accesses the current value of the field (or None if there is no value). This means that iterating over the object will also give values. To iterate over the Field objects, use the fields() method.

Further, setting an attribute (e.g. node[‘fieldname’] = value) has different behavior depending on the type of the input value:

  • an integer i: sets the current value for that field to the ith entry in the field
  • a string: sets the current value to the entry that has the provided source name
  • a tuple (string,value): sets the field entry for the source named by the string to the value, and sets that source as the current value
  • a tuple (string,(value,lerr[,uerr]): sets the field entry for the source named by the string to the value and sets the errors for that entry, and sets that source as the current value

Create a new fieldNode with the provided parent.

kwargs are assigned as node values as self[kwargkey] = kwargvalue

addField(field)
delField(fieldname)
extractField(*args, **kwargs)

Walk through the tree starting from this object.

If the kwarg siblings is set to True, this will also extract the siblings (e.g. the parent subtree, except for the parent itself), and this overwrites includeself.

The other arguments are for FieldNode.extractFieldAtNode() :

static extractFieldAtNode(node, fieldnames, traversal='postorder', filter=False, missing=0, converter=None, sources=False, errors=False, asrec=False, includeself=True)

This will walk through the tree starting from the FieldNode given by the node argument and generate an array of values for the specified fieldname.

Parameters:
  • node (a FieldNode object) – The node from which to extract fields.
  • fieldnames

    Can be:

    • A single field name string.
    • A sequence of fieldnames strings.
    • A comma-seperated string of field names.
  • traversal – see CatalogNode.visit()
  • filter – see CatalogNode.visit()
  • missing

    Determines the behavior in the event that a field is not present (or a non FieldNode is encountered) it can be:

    • ‘exception’
      raise an exception if the field is missing
    • ‘skip’
      do not include this object in the final array. If fieldnames references more than one field, only the first field will be used to determine if the node is skipped.
    • ‘mask’
      put 0 in the array location and return a mask of missing values as the second return value
    • ‘masked’
      return numpy.ma.MaskedArray objects instead of arrays, with the missing values masked
    • any other
      fill any missing entries with this value
  • converter (callable or None) – A function that is applied to the data before being added to the array (or None to perform no conversion).
  • sources (bool or string value ‘object’) – Determines if a sequence of sources should be returned - if False, only the array is returned. If True, the sources will be returned as described below. By default, string representations of the sources are returned. If it is set to ‘object’, the actual Source objects will be returned instead.
  • errors (bool) – If True, the errors will be returned (see return values below).
  • asrec (bool) – Is True, a record array is generated instead of a regular array. It can optionally specify the numpy data type of the values, if it is a sequence of size matching the number of fields, an equivalent comma-seperated string, or a dictionary mapping fieldnames to dtypes. Otherwise, the dtypes are inferred from the extracted arrays.
  • includeself (bool) – If True, this node itself will be included.
Returns:

If missing is ‘mask’, the below return values that are wrapped as a (returnval,mask) tuple. If errors are returned, they are (uppererror,lowererror) arrays, i.e. +/- . Can be:

  • a record array if asrec is True
  • an f x N array of values if sources and errors are False
  • (values,errors,sources) if sources and errors are True
  • (values,sources) if sources are True and errors are False
  • (values,errors) if errors are True and sources are False

fielddict
fieldnames
fields()

this yields an iterator over all of the Field objects (rather than their values, as regular sequence access does)

getFieldString(sep='n')

Generate a string with field:value pairs for all fields using sep as the seperator between the strings

getFieldValueNodes(fieldname, value)

Searches through the tree and returns all nodes for which a particular field name has the requested value

static getFieldValueNodesAtNode(node, fieldname, value, visitkwargs={})

Searches through the tree and returns all nodes for which a particular field name has the requested value

setToSource(src, missing='skip')

Sets a string or Source object passed in as the src argument as the current source for the requested FieldNode and it’s subtree.

missing can be:

  • ‘raise’/’exception’

    raise a ValueError if there is no value with that source

  • ‘warn’

    give a warning if the value is missing

  • ‘skip’

    do nothing

static setToSourceAtNode(node, src, missing='skip', traversal='postorder', siblings=False)

Sets a string or Source object passed in as the src argument as the current source for the requested FieldNode and it’s subtree.

missing can be:

  • ‘raise’/’exception’

    raise a ValueError if there is no value with that source

  • ‘warn’

    give a warning if the value is missing

  • ‘skip’

    do nothing

traversal is the type of traversal to perform on the subtree. See FieldNode.visit() for values.

If siblings is True, the function applies to all the children of this FieldNode's parent.

setToSourceAtSelf(*args, **kwargs)

Sets the given src string or Source object as the current source for this FieldNode and it’s subtree. Based on FieldNode.setToSourceAtNode() :

sourcenames
values
class astropysics.objcat.FieldValue

Bases: object

Superclass for values that belong to a field.

checkType(typetocheck)

ensure that the value of this FieldValue is of the requested Type (or None to accept anything). Any mismatches will throw a TypeError

source

The Source for this FieldValue

value

The value stored by this FieldValue

class astropysics.objcat.GraphAction(parent, nodename='Graphing Node', traversal='preorder', drawlayout='dot', drawkwargs={}, show=False, savefile=None, clf=False)

Bases: astropysics.objcat.ActionNode

This ActionNode will generate a networkx.DiGraph object representing the node and its children. Note that networkx must be installed for this to work.

When this object is called, it returns a networkx.DiGraph object.

clf = None

If True, matplotlib.pyplot.clf() will be called before the graph is drawn.

drawkwargs = None

A dictionary of keywords that are passed into networkx.draw() when drawing the graph.

drawlayout = None

Sets the layout used in drawing the graph. If a string, it specified a graphviz program name (e.g. ‘dot’,’neato’,’twopi’) use to position the graph nodes. It can also be a callable, in which case it will be called with the graph as the first argument to get the positions. This is intended to be used with networkx.layout functions, but a user-provided callable should work fine, too assuming it outputs correct positions.

pygraphviz = <module 'pygraphviz' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygraphviz/__init__.pyc'>
savefile = None

A string specifying the file name to save the graph to when the node is called. If None, the graph will not be saved.

show = None

If True, matplotlib.pyplot.show() will be called after the graph is drawn.

traversal = None

Sets the traversal type for generating the graph - is any valid CatalogNode.visit() traversal argument.

class astropysics.objcat.LinkField(name=None, type=<class 'astropysics.objcat.CatalogNode'>, units=None, descr=None)

Bases: astropysics.objcat.Field

A Field that only has values that point to other nodes.

Parameters:
  • name (str) – A string with the field’s name.
  • type (class) – The type of node that this link can accept. Must be CatalogNode or a subclass.

Note

If the current linked node has been removed, calling this will change the current object to the next valid link.

class astropysics.objcat.LinkValue(src, nodeval)

Bases: astropysics.objcat.FieldValue

A FieldValue that points to a node.

checkType(type)
value
class astropysics.objcat.MatplotAction(parent, nodename=None, clf=True, savefile=None, **kwargs)

Bases: astropysics.objcat.ActionNode

This ActionNode uses matplotlib to generate plots.

This class is an abstract class, requiring subclasses to implement the makePlot() method.

Keyword arguments when this action is called will be used to change the value of the object attribute with the same name as the keyword temporarily for only that call.

The defaultattrs class variable can be set for a class, and it must be a dictionary where the keys are strings. It will be used to initialize class variables, where the defaults are given by the values of defaultattrs .

The following example illustrates the use of the of a MatplotAction. Define the PlotXY by doing:

class PlotXY(MatplotAction):
    defaultattrs = dict(logx=False)

    def makePlot(self,node):
        from numpy import log10

        x,y = node.extractField('x,y')
        if self.logx:
            x = log10(x)
        scatter(x,y)
        xlabel('x')
        ylabel('y')

Then, if c is a Catalog with children that have x and y fields):

PlotXY(c)()

will produce a plot of x vs y, as well as adding the PlotXY object as a child of c. similarly:

PlotXY(logx=True)(c)

Will produce a plot of log(x) vs. y for c‘s chilren, but will not add the PlotXY object as a child of c.

Parameters:
  • parent – The parent to assign this node to or None for no parent.
  • nodename – The name of this node or None to use the default derived from the class name.
  • clf – If True, the figure will be cleared before plotting.
  • savefile – A string specifying the file name to save the plot to when the node is called. If None, the plot will not be saved.

Additional keyword can be used to set attributes that have defaults given by defaultattrs.

defaultattrs = {}
makePlot(node)

This method does the actual plotting.

Parameters:node – The node this action is associated with.
class astropysics.objcat.ObservedErroredValue(source, value, upperr=None, lowerr=None)

Bases: astropysics.objcat.ObservedValue

This value is an observed value with errorbars

The value is either (value,err) or (value,uperr,lowerr)

checkType(typetocheck)

ensure that the value and errors are of the requested Type (or None to accept anything). Any mismatches will raise a TypeError

errors

Errors on the measurement as a uppererror,lowererror tuple, or 0,0 if no errors are present.

hasSymmetricErrors()
class astropysics.objcat.ObservedValue(source, value)

Bases: astropysics.objcat.FieldValue

This value is an observed or otherwise measured value for the field with the associated Source.

value
class astropysics.objcat.PlottingAction2D(parent, xaxisname, yaxisname, nodename='2D Plotting Node', plottype='plot', plotkwargs=None, logify=None, ordering='postorder', filter=False)

Bases: astropysics.objcat.MatplotAction

Generates 2D plots by extracting fields from the catalog for two specified variables.

filter = None

Can be used to filter out unwanted values by setting to a callable that takes in a node and reurns True if it should be processed, or False if not. See FieldNode.extractFieldAtNode() for more details.

logify = None

Determines if a particular axis should be in log (base-10) form. If None, no axes will be log, otherwise, should be either ‘x’, ‘y’, or ‘xy’, specifying which axes should be made logarithmic.

ordering = None

Determines the order of the plotted arrays. If ‘sortx’ or ‘sorty’, the values will be sorted on the x and y axis, respectively. Otherwise, specifies the traversal argument for FieldNode.extractFieldAtNode() .

plotkwargs = None

Additional keywords to be passed into the plotting command, or None for defaults.

plottype = None

A string specifying the type of plot to make. Must be one of:

xaxisname = None

A string specifying the name of the field to use for the x-axis.

yaxisname = None

A string specifying the name of the field to use for the y-axis.

class astropysics.objcat.SEDField(name='SED', specunits='angstroms', defaultval=None, usedef=None, units=None, type=None, descr=None)

Bases: astropysics.objcat.Field

This field represents the Spectral Energy Distribution of this object - e.g. a collection of Spectra or Photometric measurements

default
getBand(bands, asflux=False, asdict=False)

determines the magnitude or flux in the requested band.

The first photometric measurement in this SEDField that has the band will be used - if not present, it will be computed from the first Spectrum with appropriate overlap. If none of these are found, a ValueError will be raised

if asflux is True, the result will be returned as a flux - otherwise, a magnitude is returned.

asdict returns a dictionary of results - otherwise, a sequence will be returned (or a scalar if only one band is requested)

getFullSED()

the generates a astropysics.spec.Spectrum object that represents all the information contained in this SEDField

getMasked()

return a copy of the values masked from the full SED

mask(val)

mask the value (either index or source name) to not appear in the full SED

phots
photsources
plotSED(specerrs=True, photerrs=True, plotbands=True, colors=('b', 'g', 'r', 'r', 'k'), log='', clf=True)

Generates a plot of the SED of this object.

colors is a tuple of colors as (spec,phot,specerr,photerr,other)

specs
specsources
specunits

The units to use in the objects of this SED - see astropysics.spec.HasSpecUnits for valid units

type
unmask(val)

unmask the value (either index or source name) to appear in the full SED

unmaskAll()

unmask all values (all appear in full SED)

class astropysics.objcat.Source(src, bibcode=None)

Bases: object

A source for an observation/measurement/value. Note that there is always only one instance if a source at a given time - any two Sources with the same source string are the same object

The source can optionally include a URL location to look up metadata like authors, publication date, etc (location property)

the constructor string can be of the form ‘str/loc’ in which case loc will be interpreted as the bibcode (see setBibcode() for valid forms) if it is not specified in the argument. If it is ‘str//loc’, the loc will not be validated (e.g. it is assumed to be a correct ADS abstract code).

abstract

The abstract for this Source

adsabs

The URL for the ADS abstract of this Source

adstimeout = 1
adsurl = 'adsabs.harvard.edu'
authors

The author list for this Source as a list of strings

static build_bibliography(sources='all', fn=None)

Generates and returns BibTeX bibliography for Source objects.

Parameters:
  • sources – A sequence of Source objects or the string ‘all’ to use all Source objects.
  • fn – A filename at which to save the BibTeX content, or None to not save.
Returns:

bibstr,fail where bibstr is a string with the BibTeX content and fail is a list of Source objects for which the lookup failed (usually because the Source has no bibcode)

Raises TypeError:
 

If sources is not a list of Source objects or ‘all’

static clearADSCache(adscode=None, disable=False)

this clears the cache of the specified adscode, or everything, if the adscode is None

date

The publication date of this Source

getBibEntry()

Retrieves the BibTeX entry for this Source. This data is retrieved from ADS and thus requires a network connection if it is not already cached.

Raises SourceDataError:
 If no bibcode is defined (see setBibcode()).
Returns:A string with the BibTeX formatted entry for this source.
getBibcode()

Returns the ADS bibliographic code for this source.

Returns:A string with the ADS bibcode or None if no bibcode is defined.
keywords

The keywords for this source, and the type of the keywords, if present

openADSAbstract(opentype=None, **kwargs)

Opens the ADS abstract for this source in a web browser.

Parameters:opentype

The type of web browser window to open. Can be:

Additionaly keyword arguments will be passed into the relevant function.

setBibcode(val)

Sets the ADS bibliographic code for this Source

Parameters:

val

The location reference for this bibcode. It may be any of the following:

  • A string of the form ‘arxiv: ####.####’

    The location is an ArXiv article identifier.

  • A string of the form ‘astro-ph: ####.####’

    Same as above.

  • A string of the form ‘doi: #.##/###

    The location is a Digital Object Identifier, commonly used by publishers to uniquely identify publications.

  • A string of the form ‘http://www.whatever.com/somewhere

    A direct URL to an ADS record.

  • Any other string

    Any other form will be interpreted as an ADS bibcode.

  • None

    The bibcode will be unset, and any ADS-related lookups for this source will fail.

Raises:
  • TypeError – If an improper type is provided for val.
  • SourceDataError – if the record cannot be located.
title

The publication title for this Source

static useADSCache(enable=True)

This is used to disable or enable the cache for ADS lookups - if the enable argument is True, the cache is enable (or unaltered if it is already active)) and if it is False, it will be disabled

note that if the cache is disabled, all entries are lost

exception astropysics.objcat.SourceDataError(message)

Bases: exceptions.Exception

This exception indicates a problem occured while trying to retrieve external Source-related data

class astropysics.objcat.StructuredFieldNode(parent, **kwargs)

Bases: astropysics.objcat.FieldNode

This class represents a FieldNode in the catalog that follows a particular data structure (i.e. a consistent set of Fields). It is meant to be subclassed to define generic types of objects in the catalog.

The fields and names are inferred from the class definition and hence the class attribute name must match the field name. Any FieldValues present in the class objects will be ignored.

The checkonload class attribute determines the action to take if an unaltered StructuredFieldNode is loaded and found to be inconsistent with the current class definition. It may be:

  • False/None/0

    Do no checking.

  • ‘warn’

    show a warning when the loaded object is inconsistent with the definition

  • ‘raise’

    raise a ValueError when the loaded object is inconsistent with the definition

  • ‘revert’

    silently revert to the current definition if inconsistencies are found

  • ‘revertwarn’

    issue a warning, then revert

addField(field)
alteredstruct

If True, the object no longer matches the specification given by the class. Note that this will remain True even if the offending fields are returned to their correct state.

checkonload = 'warn'
delField(fieldname)
static derivedFieldFunc(f=None, name=None, type=None, defaultval=None, usedef=None, units=None, ferr=False, **kwargs)

This method is to be used as a function decorator to generate a field with a name matching that of the function. Note that the function should NOT have self as the leading argument

Arguments are the same as for the Field constructor, except that leftover kwargs are passed in as links that override the defaults of the function.

The docstring of the function will be taken as the field’s description.

revert()

Revert this object back to the standard Fields for the class. Any deleted fields will be populated with the class Default Value any attributes that match the names of deleted Fields will be overwritten

TODO:test

class astropysics.objcat.TextTableAction(parent, arrnames, titles=None, details=None, caption=None, nodename='Table Node', tabformat='ascii', fmt='%.18e', errors=True, logify=None, ordering='postorder', savefile=None)

Bases: astropysics.objcat.ActionNode

This ActionNode generates and returns formatted text tables.

Calling this action generates the and returns the table, and saves it if the savefile attribute is not None:

Parameters:
  • node – The node at which to start plotting. If None, the parent will be used.
  • reorder – An array of indicies to change the order of the table before writing, or None to use the catalog ordering.
Type:

int array or None

Returns:

A string with the table data

arrnames = None

A sequence of field names to use to extract the data. If the special name ‘source’ is given, the sources used for each data set are included.

caption = None

A strings for a table caption or None to have no caption.

details = None

A sequence of strings giving more detailed information for for the fields - must match arrnames or be None to ignore.

errors = None

Include errorbar values in the table, if present.

fmt = None

The formatting specifier for each of the columns. Must be a single string or a sequence that matches arrnames.

logify = None

Determines tf a particular axis should be in log (base-10) form. If None, no axes will be log, otherwise, must be a sequence of bools matching arrnames that is True if the column should have the log of its data taken.

ordering = None

Determines the order of the plotted arrays. If ‘sort#’, the values will be sorted on the axis specified by #. Otherwise, specifies the traversal argument for FieldNode.extractFieldAtNode() .

savefile = None

A string specifying the file name to save the table to when the node is called. If None, the table will not be saved.

tabformat = None

The format for the text table. Can be ‘ascii(sep)’ for a table with sep as the seperator and newlines seperating the rows, ‘ascii’ is the same with space as the seperator, ‘latex’ for a LaTeX-style table, or ‘deluxetable’ for AASTex-style deluxtables.

titles = None

A sequence of titles for the fields - must match arrnames or be None to use arrnames as the titles.

astropysics.objcat.arrayToCatalog(values, source, fields, parent, errors=None, nodetype=<class 'astropysics.objcat.StructuredFieldNode'>, converters=None, filter=None, namefield=None, nameconv=None, setcurr=True)

Generates a catalog of nodes from the array of data.

See arrayToNodes for values,source,fields, and covnerter arguments.

parent is the object to use as the parent for all of the nodes (which will be returned, a string (in which case a Catalog object will be created and returned), or None (return value will be a sequence of nodes)

nodetype is the class to use to create the nodes (usually a subclass of StructuredFieldNode)

filter is a function that will be called on the array row and if it returns True, a node will be created, and if False, that row will be skipped

namefield is the field to use to apply the name of the node from the index of the array row. nameconv can be:

  • None: name field will be set to ‘<sourcestr>-i’
  • a callable: name field will be set to nameconv(i)
  • a sequence of mapping: name field will be set as nameconv[i]

if namefiled is None, no name will be applied

astropysics.objcat.arrayToNodes(values, source, fields, nodes, errors=None, matcher=None, converters=None, namefield=None, setcurr=True)

Applies values from an array to CatalogNodes.

values must be a 2-dimensional array or a 1-dimensional structured array. If a 2D array, the first dimension should be the fields, while the second dimension should be the nodes to be created.

source is a Source object or a string that will be converted to a Source object

nodes is either a container of nodes to visit or a CatalogNode in which all FieldNodes within will be used as the nodes to visit

fields is either a sequence of field names (must be at least as long as the array’s second index dimension) or a mapping from indecies to field names or structured array field names to FieldNode field names

if errors is not None, it should either be an object matching values in shape, or a tuple (upper,lower) and will be applied as the errors on the values

matcher is a callable called as matcher(arrayrow,node) - if it returns False, the array will be matched to the next node - if True, the array values will be applied to the node

converters are either a sequence of callables or a mapping from indecies to callables or structured array field names to callables that will be called on each array element before being added to the FieldNode as converter(value). If errors are provided, the converter will be called as converter((value,uerr,lerr)). If converters is None, no converting is performed.

namefield is a field name that will be set to a unique code of the form ‘src-i’ where i is element index of the array row (or None to apply no name). It can also be a 2-tuple (name,converter) where converter is a callable of the form converter(i) that should return the value to apply to the field.

astropysics.objcat.derivedFieldFunc(f=None, name=None, type=None, defaultval=None, usedef=None, units=None, ferr=False, **kwargs)

This method is to be used as a function decorator to generate a field with a name matching that of the function. Note that the function should NOT have self as the leading argument

Arguments are the same as for the Field constructor, except that leftover kwargs are passed in as links that override the defaults of the function.

The docstring of the function will be taken as the field’s description.

astropysics.objcat.load(file)

Load a previously saved CatalogNode.

Parameters:file – A file name or file-like object for a file storing a pickled CatalogNode.
Raises TypeError:
 If file does not contain a CatalogNode.
astropysics.objcat.save(node, file, savechildren=True)

save the specified node as a file with the given name or file-like object

if savechildren is True, the entire subtree will be saved, if False, just this node

Note that the parent and everything above this point will NOT be saved (when reloaded the parent will be None)

Table Of Contents

Previous topic

models – astronomy-specific models for pymodelfit

Next topic

ccd – image processing tools

This Page