changeset 1143:8ac52ebff5f7

avoid using chdir
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 21 Apr 2020 00:55:02 -0400
parents b3ee75b4978a
children 6a8fe3ed3bc6
files trafficintelligence/storage.py
diffstat 1 files changed, 2 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/trafficintelligence/storage.py	Mon Apr 20 15:42:08 2020 -0400
+++ b/trafficintelligence/storage.py	Tue Apr 21 00:55:02 2020 -0400
@@ -6,7 +6,6 @@
 import shutil
 from copy import copy
 import sqlite3, logging
-from os import chdir
 
 from numpy import log, min as npmin, max as npmax, round as npround, array, sum as npsum, loadtxt, floor as npfloor, ceil as npceil, linalg, int32, int64
 from pandas import read_csv, merge
@@ -662,9 +661,7 @@
     'Loads prototype ids and matchings (if stored)'
     prototypes = []
     if Path(filename).is_file():
-        filename = str(Path(filename).resolve())
-        pwd = Path.cwd()
-        chdir(Path(filename).parent)
+        parentPath = Path(filename).resolve().parent
         with sqlite3.connect(filename) as connection:
             cursor = connection.cursor()
             objects = []
@@ -674,7 +671,7 @@
                     prototypes.append(moving.Prototype(row[0], row[1], row[2], row[3]))
                 if withTrajectories:
                     for p in prototypes:
-                        p.setMovingObject(loadTrajectoriesFromSqlite(p.getFilename(), p.getTrajectoryType(), [p.getNum()])[0])
+                        p.setMovingObject(loadTrajectoriesFromSqlite(str(parentPath/p.getFilename()), p.getTrajectoryType(), [p.getNum()])[0])
                     # loadingInformation = {} # complicated slightly optimized
                     # for p in prototypes:
                     #     dbfn = p.getFilename()
@@ -689,7 +686,6 @@
                 printDBError(error)
         if len(set([p.getTrajectoryType() for p in prototypes])) > 1:
             print('Different types of prototypes in database ({}).'.format(set([p.getTrajectoryType() for p in prototypes])))
-        chdir(pwd)
     return prototypes
 
 def savePOIsToSqlite(filename, gmm, gmmType, gmmId):