Skip to content

Commit

Permalink
Cleaning up redudant imports
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon committed Jan 26, 2024
1 parent 65ae7e4 commit 41c0c00
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 134 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import distutils
import os
import shutil
import numpy as N
import numpy as np
import ctypes.util
import sys

Expand Down Expand Up @@ -251,7 +251,7 @@ def check_extensions():

for i in range(len(ext_list)):

ext_list[i].include_dirs = [N.get_include(), "src", os.path.join("src", "pyfmi"), incdirs]
ext_list[i].include_dirs = [np.get_include(), "src", os.path.join("src", "pyfmi"), incdirs]
ext_list[i].library_dirs = [libdirs]
ext_list[i].language = "c"
ext_list[i].libraries = ["fmilib_shared"] if sys.platform.startswith("win") else ["fmilib"] #If windows shared, else static
Expand Down
4 changes: 2 additions & 2 deletions src/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import zipfile
import tempfile
import platform as PL
import platform as plat
import os
import sys
import shutil
Expand Down Expand Up @@ -261,7 +261,7 @@ def get_platform_dir():
else:
platform = 'linux'

if PL.architecture()[0].startswith('32'):
if plat.architecture()[0].startswith('32'):
platform += '32'
else:
platform += '64'
Expand Down
4 changes: 1 addition & 3 deletions src/common/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import numpy as N
import numpy as np
import scipy
import scipy.io
from scipy import interpolate
scipy_minmaj = tuple(map(int, scipy.__version__.split('.')[:2]))
if scipy_minmaj >= (1, 8):
# due to a DeprecationWarning, we do below, this will likely need another change in a future update of scipy.
Expand Down Expand Up @@ -1405,7 +1403,7 @@ def _get_interpolated_trajectory(self, data_index):
time_vector = self._read_trajectory_data(0, False)
data = self._read_trajectory_data(data_index, False)

f = interpolate.interp1d(time_vector, data, fill_value="extrapolate")
f = scipy.interpolate.interp1d(time_vector, data, fill_value="extrapolate")

self._data_2[data_index] = f(diag_time_vector)

Expand Down
5 changes: 2 additions & 3 deletions src/common/plotting/plot_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from matplotlib import rcParams
import fnmatch
import re
import oss

#GUI modules
try:
Expand All @@ -49,8 +50,6 @@
except ImportError:
print("JModelica Python package was not found.")

#Import general modules
import os as O

ID_GRID = 15001
ID_LICENSE = 15002
Expand Down Expand Up @@ -290,7 +289,7 @@ def OnMenuOpen(self, event):
#If OK load the results
if dlg.ShowModal() == wx.ID_OK:
for n in dlg.GetFilenames():
self._OpenFile(O.path.join(dlg.GetDirectory(),n))
self._OpenFile(os.path.join(dlg.GetDirectory(),n))

dlg.Destroy() #Destroy the popup window

Expand Down
15 changes: 1 addition & 14 deletions src/pyfmi/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""

import numpy as N
import scipy as S
import pylab as P

class DebugInformation:

Expand Down Expand Up @@ -61,7 +61,6 @@ def _load_data(self):
break

def plot_time_distribution(self, normalized=False):
import pylab as P

if normalized:
total_time = N.sum(self.real_time)
Expand All @@ -79,8 +78,6 @@ def plot_time_distribution(self, normalized=False):
P.show()

def plot_cumulative_time_elapsed(self, log_scale=False):
import pylab as P

cumulative_sum = N.cumsum(self.real_time)

if log_scale:
Expand All @@ -97,8 +94,6 @@ def plot_cumulative_time_elapsed(self, log_scale=False):
P.show()

def plot_step_size(self):
import pylab as P

P.semilogy(self.simulated_time,N.diff([0.0]+self.simulated_time),drawstyle="steps-pre")
P.ylabel("Step-size")
P.xlabel("Time [s]")
Expand All @@ -107,14 +102,10 @@ def plot_step_size(self):
P.show()

def _plot_events(self):
import pylab as P

for ev in self.events:
P.axvline(x=ev,color='r')

def plot_event_indicators(self, mask=None, region=None):
import pylab as P

ev_ind = N.array(self.event_indicators)
time = N.array(self.simulated_time)
ev_ind_name = N.array(["event_ind_%d"%i for i in range(len(ev_ind[0,:]))])
Expand Down Expand Up @@ -183,8 +174,6 @@ def _load_data(self):


def plot_order(self):
import pylab as P

P.plot(self.simulated_time, self.order,drawstyle="steps-pre")
P.grid()
P.xlabel("Time [s]")
Expand All @@ -198,8 +187,6 @@ def plot_order(self):
P.show()

def plot_error(self, threshold=None, region=None, legend=True):
import pylab as P

err = N.array(self.weighted_error)
time = N.array(self.simulated_time)
if region:
Expand Down
10 changes: 5 additions & 5 deletions src/pyfmi/examples/fmi20_bouncing_ball_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os as O

import os
import pylab as P
import numpy as N

from pyfmi import load_fmu

curr_dir = O.path.dirname(O.path.abspath(__file__));
path_to_fmus = O.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me2 = O.path.join(path_to_fmus,"ME2.0")
curr_dir = os.path.dirname(os.path.abspath(__file__))
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me2 = os.path.join(path_to_fmus,"ME2.0")

def run_demo(with_plots=True):
"""
Expand All @@ -39,7 +39,7 @@ def run_demo(with_plots=True):
"""

#Load the FMU by specifying the fmu and the directory
bouncing_fmu = load_fmu(O.path.join(path_to_fmus_me2, 'bouncingBall.fmu'))
bouncing_fmu = load_fmu(os.path.join(path_to_fmus_me2, 'bouncingBall.fmu'))

Tstart = 0.5 #The start time.
Tend = 3.0 #The final simulation time.
Expand Down
14 changes: 7 additions & 7 deletions src/pyfmi/examples/fmi_bouncing_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os as O

import os
import pylab as P
import numpy as N

from pyfmi import load_fmu

curr_dir = O.path.dirname(O.path.abspath(__file__));
path_to_fmus = O.path.join(curr_dir, 'files', 'FMUs','ME1.0')
path_to_fmus2 = O.path.join(curr_dir, 'files', 'FMUs','ME2.0')
curr_dir = os.path.dirname(os.path.abspath(__file__));
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs','ME1.0')
path_to_fmus2 = os.path.join(curr_dir, 'files', 'FMUs','ME2.0')

def run_demo(with_plots=True, version="2.0"):
"""
Demonstrates how to use JModelica.org for simulation of
ME FMUs version 1.0 and 2.0.
"""
if version == '1.0':
fmu_name = O.path.join(path_to_fmus,'bouncingBall.fmu')
fmu_name = os.path.join(path_to_fmus,'bouncingBall.fmu')
else:
fmu_name = O.path.join(path_to_fmus2,'bouncingBall.fmu')
fmu_name = os.path.join(path_to_fmus2,'bouncingBall.fmu')

model = load_fmu(fmu_name)

Expand All @@ -49,7 +49,7 @@ def run_demo(with_plots=True, version="2.0"):
# Plot the solution
if with_plots:
# Plot the height
fig = P.figure()
P.figure()
P.clf()
P.subplot(2,1,1)
P.plot(t, h_res)
Expand Down
14 changes: 7 additions & 7 deletions src/pyfmi/examples/fmi_bouncing_ball_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os as O

import os
import pylab as P
import numpy as N

from pyfmi import load_fmu

curr_dir = O.path.dirname(O.path.abspath(__file__));
path_to_fmus = O.path.join(curr_dir, 'files', 'FMUs', 'CS1.0')
path_to_fmus2 = O.path.join(curr_dir, 'files', 'FMUs', 'CS2.0')
curr_dir = os.path.dirname(os.path.abspath(__file__));
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs', 'CS1.0')
path_to_fmus2 = os.path.join(curr_dir, 'files', 'FMUs', 'CS2.0')

def run_demo(with_plots=True, version='2.0'):
"""
Expand All @@ -32,9 +32,9 @@ def run_demo(with_plots=True, version='2.0'):
"""

if version == '1.0':
fmu_name = O.path.join(path_to_fmus,'bouncingBall.fmu')
fmu_name = os.path.join(path_to_fmus,'bouncingBall.fmu')
else:
fmu_name = O.path.join(path_to_fmus2,'bouncingBall.fmu')
fmu_name = os.path.join(path_to_fmus2,'bouncingBall.fmu')
model = load_fmu(fmu_name)

res = model.simulate(final_time=2.)
Expand All @@ -49,7 +49,7 @@ def run_demo(with_plots=True, version='2.0'):
# Plot the solution
if with_plots:
# Plot the height
fig = P.figure()
P.figure()
P.clf()
P.subplot(2,1,1)
P.plot(t, h_res)
Expand Down
2 changes: 1 addition & 1 deletion src/pyfmi/examples/fmi_bouncing_ball_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from pyfmi import load_fmu

curr_dir = os.path.dirname(os.path.abspath(__file__));
curr_dir = os.path.dirname(os.path.abspath(__file__))
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me1 = os.path.join(path_to_fmus,"ME1.0")
path_to_fmus_cs1 = os.path.join(path_to_fmus,"CS1.0")
Expand Down
14 changes: 7 additions & 7 deletions src/pyfmi/examples/fmu_with_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os as O
import os
import numpy as N
import pylab as p

from pyfmi import load_fmu

curr_dir = O.path.dirname(O.path.abspath(__file__));
path_to_fmus = O.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me1 = O.path.join(path_to_fmus,"ME1.0")
path_to_fmus_cs1 = O.path.join(path_to_fmus,"CS1.0")
curr_dir = os.path.dirname(os.path.abspath(__file__))
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me1 = os.path.join(path_to_fmus,"ME1.0")
path_to_fmus_cs1 = os.path.join(path_to_fmus,"CS1.0")

def run_demo(with_plots=True):
"""
Demonstrates how to simulate an FMU with inputs.
See also simulation_with_input.py
"""
fmu_name = O.path.join(path_to_fmus_me1,'SecondOrder.fmu')
fmu_name = os.path.join(path_to_fmus_me1,'SecondOrder.fmu')

# Generate input
t = N.linspace(0.,10.,100)
Expand Down Expand Up @@ -61,7 +61,7 @@ def run_demo(with_plots=True):
assert N.abs(res.final('u')*1.e1 - (-8.3907153)) < 1e-3

if with_plots:
fig = p.figure()
p.figure()
p.subplot(2,1,1)
p.plot(time_sim, x1_sim, time_sim, x2_sim)
p.subplot(2,1,2)
Expand Down
14 changes: 7 additions & 7 deletions src/pyfmi/examples/fmu_with_input_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os as O
import os
import numpy as N
import pylab as p

from pyfmi import load_fmu

curr_dir = O.path.dirname(O.path.abspath(__file__));
path_to_fmus = O.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me1 = O.path.join(path_to_fmus,"ME1.0")
path_to_fmus_cs1 = O.path.join(path_to_fmus,"CS1.0")
curr_dir = os.path.dirname(os.path.abspath(__file__))
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs')
path_to_fmus_me1 = os.path.join(path_to_fmus,"ME1.0")
path_to_fmus_cs1 = os.path.join(path_to_fmus,"CS1.0")

def run_demo(with_plots=True):
"""
Demonstrates how to simulate an FMU with an input function.
See also simulation_with_input.py
"""
fmu_name = O.path.join(path_to_fmus_me1,'SecondOrder.fmu')
fmu_name = os.path.join(path_to_fmus_me1,'SecondOrder.fmu')

# Create input object
input_object = ('u', N.cos)
Expand All @@ -53,7 +53,7 @@ def run_demo(with_plots=True):
assert N.abs(res.final('u')*1.e1 - (1.54251449888)) < 1e-3

if with_plots:
fig = p.figure()
p.figure()
p.subplot(2,1,1)
p.plot(time_sim, x1_sim, time_sim, x2_sim)
p.subplot(2,1,2)
Expand Down
9 changes: 0 additions & 9 deletions src/pyfmi/fmi.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,9 @@
"""
Module containing the FMI interface Python wrappers.
"""
import os
import sys
import logging
import fnmatch
import re
from collections import OrderedDict

import numpy as N
cimport numpy as N

N.import_array()

cimport pyfmi.fmil_import as FMIL

cdef FMIL.fmi_version_enu_t import_and_get_version(FMIL.fmi_import_context_t*, char*, char*, int)
Expand Down
4 changes: 1 addition & 3 deletions src/pyfmi/fmi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ For profiling:
# distutils: define_macros=CYTHON_TRACE_NOGIL=1
"""
import os
import sys
import logging
import fnmatch
import re
Expand All @@ -42,8 +41,7 @@ from numpy cimport PyArray_DATA

cimport pyfmi.fmil_import as FMIL

from pyfmi.common.core import create_temp_dir, delete_temp_dir
from pyfmi.common.core import create_temp_file, delete_temp_file
from pyfmi.common.core import create_temp_dir

from pyfmi.fmi_util import cpr_seed, enable_caching
from pyfmi.fmi_util cimport encode, decode
Expand Down
Loading

0 comments on commit 41c0c00

Please sign in to comment.