Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions pyNN/utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import functools
import numpy
from importlib import import_module

from pyNN.core import deprecated


Expand Down Expand Up @@ -88,12 +88,12 @@ def get_simulator(*arguments):
"""
Import and return a PyNN simulator backend module based on command-line
arguments.

The simulator name should be the first positional argument. If your script
needs additional arguments, you can specify them as (name, help_text) tuples.
If you need more complex argument handling, you should use argparse
directly.

Returns (simulator, command-line arguments)
"""
import argparse
Expand Down Expand Up @@ -189,25 +189,33 @@ def load_population(filename, sim):
return population


def normalized_filename(root, basename, extension, simulator, num_processes=None):
def normalized_filename(root, basename, extension, simulator, num_processes=None, use_iso8601=False):
"""
Generate a file path containing a timestamp and information about the
simulator used and the number of MPI processes.

The date is used as a sub-directory name, the date & time are included in the
filename.
If use_iso8601 is True, follow https://en.wikipedia.org/wiki/ISO_8601
"""
timestamp = datetime.now()
if use_iso8601:
date = timestamp.strftime("%Y-%m-%d")
date_time = timestamp.strftime("%Y-%m-%dT%H:%M:%S")
else:
date = timestamp.strftime("%Y%m%d")
date_time = timestamp.strftime("%Y%m%d-%H%M%S")

if num_processes:
np = "_np%d" % num_processes
else:
np = ""
return os.path.join(root,
timestamp.strftime("%Y%m%d"),
date,
"%s_%s%s_%s.%s" % (basename,
simulator,
np,
timestamp.strftime("%Y%m%d-%H%M%S"),
date_time,
extension))


Expand Down