Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve file not found error when center features path isn't absolute #201

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 11 additions & 4 deletions enspara/apps/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,18 @@ def write_centers_indices(path, indices):


def write_centers(result, args):
center_features = args.center_features
if args.features:
np.save(args.center_features, result.centers)
np.save(center_features, result.centers)
else:
outdir = os.path.dirname(args.center_features)
logger.info("Saving cluster centers at %s", outdir)
# If the center_features path is absolute, the pickle file ought to
# be written to the abs path, else relative to the current dir
if os.path.isabs(center_features):
outdir = os.path.dirname(center_features)
else:
outdir = os.path.relpath(center_features, '.')

logger.info("Saving cluster centers at %s", center_features)

try:
os.makedirs(outdir)
Expand All @@ -425,7 +432,7 @@ def write_centers(result, args):

centers = load_asymm_frames(result.center_indices, args.trajectories,
args.topologies, args.subsample)
with open(args.center_features, 'wb') as f:
with open(center_features, 'wb') as f:
pickle.dump(centers, f)


Expand Down