Convenience Functions

These are functions that are meant to be used as a quick and easy mechanism for common operations.

yt.convenience Convenience Functions

yt.convenience.load(*args, **kwargs)
This function attempts to determine the base data type of a filename or other set of arguments by calling yt.lagos.StaticOutput._is_valid() until it finds a match, at which point it returns an instance of the appropriate yt.lagos.StaticOutput subclass.
yt.convenience.all_pfs(max_depth=1, name_spec='*.hierarchy', **kwargs)
This function searchs a directory and its sub-directories, up to a depth of max_depth, for parameter files. It looks for the name_spec and then instantiates an EnzoStaticOutput from each. All subsequent kwargs are passed on to the EnzoStaticOutput constructor.
yt.convenience.max_spheres(width, unit, **kwargs)
This calls all_pfs() and then for each parameter file creates a AMRSphereBase for each one, centered on the point of highest density, with radius width in units of unit.

yt.funcs Miscellaneous Functions

yt.funcs.iterable(obj)
Grabbed from Python Cookbook / matploblib.cbook. Returns true/false for obj iterable.
yt.funcs.ensure_list(obj)
This function ensures that obj is a list. Typically used to convert a string to a list, for instance ensuring the fields as an argument is a list.
yt.funcs.just_one(obj)
yt.funcs.humanize_time(secs)
Takes secs and returns a nicely formatted string
yt.funcs.time_execution(func)

Decorator for seeing how long a given function takes, depending on whether or not the global ‘yt.timefunctions’ config parameter is set.

This can be used like so:

@time_execution

def some_longrunning_function(...):

yt.funcs.print_tb(func)

This function is used as a decorate on a function to have the calling stack printed whenever that function is entered.

This can be used like so:

@print_tb
def some_deeply_nested_function(...):
yt.funcs.rootonly(func)

This is a decorator that, when used, will only call the function on the root processor and then broadcast the results of the function to all other processors.

This can be used like so:

@rootonly
def some_root_only_function(...):
yt.funcs.deprecate(func)

This decorator issues a deprecation warning.

This can be used like so:

@rootonly
def some_really_old_function(...):
yt.funcs.pdb_run(func)

This decorator inserts a pdb session on top of the call-stack into a function.

This can be used like so:

@rootonly
def some_function_to_debug(...):
yt.funcs.insert_ipython(num_up=1)
Placed inside a function, this will insert an IPython interpreter at that current location. This will enabled detailed inspection of the current exeuction environment, as well as (optional) modification of that environment. num_up refers to how many frames of the stack get stripped off, and defaults to 1 so that this function itself is stripped off.
yt.funcs.get_pbar(title, maxval)
This returns a progressbar of the most appropriate type, given a title and a maxval.
yt.funcs.only_on_root(func, *args, **kwargs)
This function accepts a func, a set of args and kwargs and then only on the root processor calls the function. All other processors get “None” handed back.
yt.funcs.paste_traceback(exc_type, exc, tb)
This is a traceback handler that knows how to paste to the pastebin. Should only be used in sys.excepthook.

yt.config Configuration System

class yt.config.YTConfigParser(fn, defaults=None)

Bases: ConfigParser.ConfigParser

Simple class providing some functionality I wish existed in the ConfigParser module already

add_section(section)

Create a new section in the configuration.

Raise DuplicateSectionError if a section by the specified name already exists. Raise ValueError if name is DEFAULT or any of it’s case-insensitive variants.

get(section, option, raw=False, vars=None)

Get an option value for a given section.

All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument `raw’ is true. Additional substitutions may be provided using the `vars’ argument, which must be a dictionary whose contents overrides any pre-existing defaults.

The section DEFAULT is special.

has_option(section, option)
Check for the existence of a given option in a given section.
has_section(section)

Indicate whether the named section is present in the configuration.

The DEFAULT section is not acknowledged.

items(section, raw=False, vars=None)

Return a list of tuples with (name, value) for each option in the section.

All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument `raw’ is true. Additional substitutions may be provided using the `vars’ argument, which must be a dictionary whose contents overrides any pre-existing defaults.

The section DEFAULT is special.

options(section)
Return a list of option names for the given section name.
read(filenames)

Read and parse a filename or a list of filenames.

Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given.

Return list of successfully read files.

readfp(fp, filename=None)

Like read() but the argument must be a file-like object.

The `fp’ argument must have a `readline’ method. Optional second argument is the `filename’, which if not given, is taken from fp.name. If fp has no `name’ attribute, `<???>’ is used.

remove_option(section, option)
Remove an option.
remove_section(section)
Remove a file section.
sections()
Return a list of section names, excluding [DEFAULT]
set(section, opt, val)
This sets an option named opt to val inside section, creating section if necessary.
write(fp)
Write an .ini-format representation of the configuration state.

Comments

Feel free to leave comments! If you've got a GMail account, you can use https://www.google.com/accounts/o8/id as your OpenID URL.
comments powered by Disqus