Esempio n. 1
0
def load_snapshot(snapshot_name):
    """
    Load the simulation stored in snapshot_name.
    """
    # unpickling the PicklableClassAttributes() executes startup_commands and
    # sets PO class parameters.

    snapshot_name = param.resolve_path(snapshot_name)

    # If it's not gzipped, open as a normal file.
    try:
        snapshot = gzip.open(snapshot_name,'r')
        snapshot.read(1)
        snapshot.seek(0)
    except (IOError,NameError):
        snapshot = open(snapshot_name,'r')

    try:
        pickle.load(snapshot)
    except ImportError:
        # CEBALERT: Support snapshots where the unpickling support
        # (UnpickleEnvironmentCreator) cannot be found because the
        # support itself was moved from topo.command.basic to
        # topo.command.__init__! Was it a bad idea to have the support
        # code loaded via an object?
        sys.modules['topo.command.basic'] = topo.command
        # Could instead set find_global on cPickle.Unpickler (could
        # support all import changes that way, as alternative to what
        # we currently do), but I'm reluctant to mess with cPickle's
        # default way of finding things. (Also it would be specific to
        # cPickle; would be different for pickle.)

        snapshot.seek(0)
        try:
            pickle.load(snapshot)
        except:
            import traceback

            m = """
            Snapshot could not be loaded.

            Please file a support request via topographica.org.

Loading error:
%s
            """%traceback.format_exc()

            param.Parameterized(name="load_snapshot").warning(m)


    snapshot.close()

    # Restore subplotting prefs without worrying if there is a
    # problem (e.g. if topo/analysis/ is not present)
    try:
        from topo.analysis.featureresponses import Subplotting
        Subplotting.restore_subplots()
    except:
        p = param.Parameterized(name="load_snapshot")
        p.message("Unable to restore Subplotting settings")
Esempio n. 2
0
def load_snapshot(snapshot_name):
    """
    Load the simulation stored in snapshot_name.
    """
    # unpickling the PicklableClassAttributes() executes startup_commands and
    # sets PO class parameters.

    snapshot_name = param.resolve_path(snapshot_name)

    # If it's not gzipped, open as a normal file.
    try:
        snapshot = gzip.open(snapshot_name, 'r')
        snapshot.read(1)
        snapshot.seek(0)
    except (IOError, NameError):
        snapshot = open(snapshot_name, 'r')

    try:
        pickle.load(snapshot)
    except ImportError:
        # CEBALERT: Support snapshots where the unpickling support
        # (UnpickleEnvironmentCreator) cannot be found because the
        # support itself was moved from topo.command.basic to
        # topo.command.__init__! Was it a bad idea to have the support
        # code loaded via an object?
        sys.modules['topo.command.basic'] = topo.command
        # Could instead set find_global on cPickle.Unpickler (could
        # support all import changes that way, as alternative to what
        # we currently do), but I'm reluctant to mess with cPickle's
        # default way of finding things. (Also it would be specific to
        # cPickle; would be different for pickle.)

        snapshot.seek(0)
        try:
            pickle.load(snapshot)
        except:
            import traceback

            m = """
            Snapshot could not be loaded.

            Please file a support request via topographica.org.

Loading error:
%s
            """ % traceback.format_exc()

            param.Parameterized(name="load_snapshot").warning(m)

    snapshot.close()

    # Restore subplotting prefs without worrying if there is a
    # problem (e.g. if topo/analysis/ is not present)
    try:
        from topo.analysis.featureresponses import Subplotting
        Subplotting.restore_subplots()
    except:
        p = param.Parameterized(name="load_snapshot")
        p.message("Unable to restore Subplotting settings")
Esempio n. 3
0
def load_snapshot(snapshot_name):
    """
    Load the simulation stored in snapshot_name.
    """
    # unpickling the PicklableClassAttributes() executes startup_commands and
    # sets PO class parameters.

    snapshot_name = param.resolve_path(snapshot_name)

    # If it's not gzipped, open as a normal file.
    try:
        snapshot = gzip.open(snapshot_name,'r')
        snapshot.read(1)
        snapshot.seek(0)
    except (IOError,NameError):
        snapshot = open(snapshot_name,'r')

    try:
        pickle.load(snapshot)
    except:
        import traceback

        m = """
        Snapshot could not be loaded.

        Please file a support request via topographica.org.
    
Loading error:
%s
        """%traceback.format_exc()

        param.Parameterized(name="load_snapshot").warning(m)


    snapshot.close()

    # Restore subplotting prefs without worrying if there is a
    # problem (e.g. if topo/analysis/ is not present)
    try: 
        from topo.analysis.featureresponses import Subplotting
        Subplotting.restore_subplots()
    except:
        p = param.Parameterized(name="load_snapshot")
        p.message("Unable to restore Subplotting settings")