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

A few more or less obvious fixes for speed of SasView startup #2275

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/sas/qtgui/Utilities/Reports/ReportDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import logging
import traceback
from xhtml2pdf import pisa
from typing import Optional

from PyQt5 import QtWidgets, QtCore
Expand Down Expand Up @@ -142,6 +141,8 @@ def save_pdf(data, filename):
: data: html string
: filename: name of file to be saved
"""
# import moved from top due to cost
from xhtml2pdf import pisa
try:
# open output file for writing (truncated binary)
with open(filename, "w+b") as resultFile:
Expand Down
12 changes: 5 additions & 7 deletions src/sas/qtgui/Utilities/Reports/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
import base64
from io import BytesIO

import matplotlib.figure

import dominate
from dominate.tags import *
from dominate.util import raw

import html2text

from xhtml2pdf import pisa

import sas.sasview
import sas.system.version
import sasmodels
Expand Down Expand Up @@ -153,7 +149,7 @@ def add_data_details(self, data: Data1D):



def add_plot(self, fig: matplotlib.figure.Figure, image_type="png", figure_title: Optional[str]=None):
def add_plot(self, fig, image_type="png", figure_title: Optional[str]=None):
""" Add a plot to the report

:param fig: matplotlib.figure.Figure, Matplotlib figure object to add
Expand All @@ -174,7 +170,7 @@ def add_plot(self, fig: matplotlib.figure.Figure, image_type="png", figure_title
else:
raise ValueError("image_type must be either 'svg' or 'png'")

def _add_plot_svg(self, fig: matplotlib.figure.Figure):
def _add_plot_svg(self, fig):
try:
with BytesIO() as svg_output:
fig.savefig(svg_output, format="svg")
Expand All @@ -185,7 +181,7 @@ def _add_plot_svg(self, fig: matplotlib.figure.Figure):
logging.error("Creating of report images failed: %s" % str(ex))
return

def _add_plot_png(self, fig: matplotlib.figure.Figure):
def _add_plot_png(self, fig):
try:
with BytesIO() as png_output:
if sys.platform == "darwin":
Expand Down Expand Up @@ -267,6 +263,8 @@ def save_text(self, filename: str):
print(self.text, file=fid)

def save_pdf(self, filename: str):
# import moved because of costly import time
from xhtml2pdf import pisa
with open(filename, 'w+b') as fid:
try:
pisa.CreatePDF(str(self._html_doc),
Expand Down
5 changes: 2 additions & 3 deletions src/sas/qtgui/Utilities/ResultPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from PyQt5 import QtGui
from PyQt5 import QtWidgets

from bumps.dream.stats import var_stats, format_vars


class ResultPanel(QtWidgets.QTabWidget):
"""
FitPanel class contains fields allowing to fit models and data
Expand Down Expand Up @@ -55,6 +52,8 @@ def updateBumps(self):
sys.modules['bumps.gui.plot_view'] = PlotView

def onPlotResults(self, results, optimizer="Unknown"):
# import moved here due to its cost
from bumps.dream.stats import var_stats, format_vars
# Clear up previous results
for view in (self.convergenceView, self.correlationView,
self.uncertaintyView, self.traceView):
Expand Down
3 changes: 1 addition & 2 deletions src/sas/sascalc/calculator/sas_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from scipy.spatial.transform import Rotation
from periodictable import formula, nsf

from .geni import Iq, Iqxy

if sys.version_info[0] < 3:
def decode(s):
return s
Expand Down Expand Up @@ -179,6 +177,7 @@ def calculate_Iq(self, qx, qy=None):
:Param y: array of y-values
:return: function value
"""
from .geni import Iq, Iqxy
# transform position data from sample to beamline coords
x, y, z = self.transform_positions()
sld = self.data_sldn - self.params['solvent_SLD']
Expand Down
16 changes: 14 additions & 2 deletions src/sas/sascalc/pr/p_invertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import numpy as np

from . import calc
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -50,6 +49,7 @@ def residuals(self, pars):
:param pars: input parameters.
:return: residuals - list of residuals.
"""
from . import calc
pars = np.float64(pars)

residuals = []
Expand All @@ -66,6 +66,7 @@ def pr_residuals(self, pars):
:param pars: input parameters.
:return: residuals - list of residuals.
"""
from . import calc
pars = np.float64(pars)

residuals = []
Expand Down Expand Up @@ -329,6 +330,7 @@ def iq(self, pars, q):

:return: I(q)
"""
from . import calc
q = np.float64(q)
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand All @@ -349,6 +351,7 @@ def get_iq_smeared(self, pars, q):

:return: I(q), either scalar or vector depending on q.
"""
from . import calc
q = np.float64(q)
q = np.atleast_1d(q)
pars = np.float64(pars)
Expand All @@ -370,6 +373,7 @@ def pr(self, pars, r):

:return: P(r)
"""
from . import calc
r = np.float64(r)
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand All @@ -390,7 +394,7 @@ def get_pr_err(self, pars, pars_err, r):

:return: (P(r), dP(r))
"""

from . import calc
pars = np.atleast_1d(np.float64(pars))
r = np.atleast_1d(np.float64(r))

Expand Down Expand Up @@ -421,6 +425,7 @@ def basefunc_ft(self, d_max, n, q):

:return: nth Fourier transformed base function, evaluated at q.
"""
from . import calc
d_max = np.float64(d_max)
n = int(n)
q = np.float64(q)
Expand All @@ -441,6 +446,7 @@ def oscillations(self, pars):
:param pars: c-parameters.
:return: oscillation figure of merit.
"""
from . import calc
nslice = 100
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand All @@ -459,6 +465,7 @@ def get_peaks(self, pars):
:param pars: c-parameters.
:return: number of P(r) peaks.
"""
from . import calc
nslice = 100
pars = np.float64(pars)
count = calc.npeaks(pars, self.d_max, nslice)
Expand All @@ -473,6 +480,7 @@ def get_positive(self, pars):
:param pars: c-parameters.
:return: fraction of P(r) that is positive.
"""
from . import calc
nslice = 100
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand All @@ -490,6 +498,7 @@ def get_pos_err(self, pars, pars_err):

:return: fraction of P(r) that is positive.
"""
from . import calc
nslice = 51
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand All @@ -505,6 +514,7 @@ def rg(self, pars):
:param pars: c-parameters.
:return: Rg.
"""
from . import calc
nslice = 101
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand All @@ -519,6 +529,7 @@ def iq0(self, pars):
:param pars: c-parameters.
:return: I(q=0)
"""
from . import calc
nslice = 101
pars = np.float64(pars)
pars = np.atleast_1d(pars)
Expand Down Expand Up @@ -550,6 +561,7 @@ def _get_matrix(self, nfunc, nr):

:return: 0
"""
from . import calc
nfunc = int(nfunc)
nr = int(nr)
a_obj = np.zeros([self.npoints + nr, nfunc])
Expand Down
2 changes: 2 additions & 0 deletions src/sas/system/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def config_production(self):
logging.captureWarnings(True)
logger = logging.getLogger(self.name)
logging.getLogger('matplotlib').setLevel(logging.WARN)
logging.getLogger('numba').setLevel(logging.WARN)
return logger

def config_development(self):
Expand All @@ -39,6 +40,7 @@ def config_development(self):
self._update_all_logs_to_debug(logger)
logging.captureWarnings(True)
logging.getLogger('matplotlib').setLevel(logging.WARN)
logging.getLogger('numba').setLevel(logging.WARN)
rozyczko marked this conversation as resolved.
Show resolved Hide resolved
return logger

def _read_config_file(self):
Expand Down