Skip to content

Commit

Permalink
7.7.28 for bug fix in 7.7.27
Browse files Browse the repository at this point in the history
  • Loading branch information
SHDShim committed Feb 19, 2020
1 parent 2992ee1 commit 3e497e1
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 63 deletions.
8 changes: 5 additions & 3 deletions peakpo/control/basepatterncontroller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from PyQt5 import QtWidgets
from utils import get_sorted_filelist, find_from_filelist, readchi, \
make_filename, writechi
make_filename, writechi, get_directory
from utils import undo_button_press
from .mplcontroller import MplController
from .cakecontroller import CakeController
Expand Down Expand Up @@ -68,7 +68,8 @@ def _load_a_new_pattern(self, new_filename):
# '1D Pattern: ' + self.model.get_base_ptn_filename())
self.widget.lineEdit_DiffractionPatternFileName.setText(
str(self.model.get_base_ptn_filename()))
temp_dir = os.path.join(self.model.chi_path, 'temporary_pkpo')

temp_dir = get_directory(self.model.get_base_ptn_filename(), '-param')
if self.widget.checkBox_UseTempBGSub.isChecked():
if os.path.exists(temp_dir):
success = self.model.base_ptn.read_bg_from_tempfile(
Expand Down Expand Up @@ -121,7 +122,8 @@ def _update_bgsub_from_current_values(self):
[self.widget.spinBox_BGParam0.value(),
self.widget.spinBox_BGParam1.value(),
self.widget.spinBox_BGParam2.value()], yshift=0)
self.model.base_ptn.write_temporary_bgfiles()
temp_dir = get_directory(self.model.get_base_ptn_filename(), '-param')
self.model.base_ptn.write_temporary_bgfiles(temp_dir)

def apply_changes_to_graph(self):
self.plot_ctrl.update()
Expand Down
4 changes: 2 additions & 2 deletions peakpo/control/cakecontroller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from PyQt5 import QtWidgets
import numpy as np
from utils import dialog_savefile, writechi
from utils import dialog_savefile, writechi, get_directory
from .mplcontroller import MplController
from .cakemakecontroller import CakemakeController

Expand Down Expand Up @@ -35,7 +35,7 @@ def connect_channel(self):
def update_cake(self):
if self.model.poni_exist():
self.produce_cake()
temp_dir = os.path.join(self.model.chi_path, 'temporary_pkpo')
temp_dir = get_directory(self.model.get_base_ptn_filename(), '-param')
self.model.diff_img.write_temp_cakefiles(temp_dir=temp_dir)
self._apply_changes_to_graph()

Expand Down
72 changes: 49 additions & 23 deletions peakpo/control/maincontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .cakeazicontroller import CakeAziController
from utils import dialog_savefile, writechi, extract_extension, \
convert_wl_to_energy, get_sorted_filelist, find_from_filelist, \
make_filename
make_filename, get_directory
# do not change the module structure for ds_jcpds and ds_powdiff for
# retro compatibility
from ds_jcpds import UnitCell
Expand Down Expand Up @@ -217,8 +217,9 @@ def del_temp_chi(self):
if reply == QtWidgets.QMessageBox.No:
return
if self._temporary_pkpo_exists():
temp_chi = os.path.join(self.model.chi_path, 'temporary_pkpo',
'*.chi')
temp_dir = get_directory(self.model.get_base_ptn_filename(),
'-param')
temp_chi = os.path.join(temp_dir, '*.chi')
for f in glob.glob(temp_chi):
os.remove(f)

Expand All @@ -231,13 +232,14 @@ def del_temp_cake(self):
if reply == QtWidgets.QMessageBox.No:
return
if self._temporary_pkpo_exists():
temp_cake = os.path.join(self.model.chi_path, 'temporary_pkpo',
'*.npy')
temp_dir = get_directory(self.model.get_base_ptn_filename(),
'-param')
temp_cake = os.path.join(temp_dir, '*.npy')
for f in glob.glob(temp_cake):
os.remove(f)

def _temporary_pkpo_exists(self):
temp_dir = os.path.join(self.model.chi_path, 'temporary_pkpo')
temp_dir = get_directory(self.model.get_base_ptn_filename(), '-param')
return os.path.exists(temp_dir)

def check_for_peakfit(self, i):
Expand Down Expand Up @@ -516,7 +518,7 @@ def update_bgsub(self):
bg_roi[1] = self.model.base_ptn.x_raw.max()
self.widget.doubleSpinBox_Background_ROI_max.setValue(bg_roi[1])
self.model.base_ptn.subtract_bg(bg_roi, bg_params, yshift=0)
temp_dir = os.path.join(self.model.chi_path, 'temporary_pkpo')
temp_dir = get_directory(self.model.get_base_ptn_filename(), '-param')
self.model.base_ptn.write_temporary_bgfiles(temp_dir=temp_dir)
if self.model.waterfall_exist():
for pattern in self.model.waterfall_ptn:
Expand Down Expand Up @@ -801,23 +803,47 @@ def _goto_dpp_next_file(self, move):
else:
# pre-existing dpp
# question if overwrite or not
reply = QtWidgets.QMessageBox.question(
self.widget, 'Message',
"The next pattern already has a dpp.\n" +
"If you want to overwrite the existing one based" +
" on the dpp of the last pattern, choose YES.\n" +
"If you want to keep and open the existing dpp, choose NO.",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
self.base_ptn_ctrl._load_a_new_pattern(new_filename_chi)
self.session_ctrl.save_dpp(quiet=True)
if self.widget.checkBox_AutoGenDPP.isChecked():
reply = QtWidgets.QMessageBox.question(
self.widget, 'Message',
"The next pattern already has a dpp.\n" +
"If you want to overwrite the existing one based" +
" on the dpp of the last pattern, choose YES.\n" +
"If you want to keep and open the existing dpp, choose NO.",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
self.base_ptn_ctrl._load_a_new_pattern(new_filename_chi)
self.session_ctrl.save_dpp(quiet=True)
else:
# load the existing dpp
# QtWidgets.QMessageBox.warning(
# self.widget, "Warning", "The existing dpp will be open.")
success = self.session_ctrl._load_dpp(new_filename_dpp)
if success:
if self.model.exist_in_waterfall(self.model.base_ptn.fname):
self.widget.pushButton_AddBasePtn.setChecked(True)
else:
self.widget.pushButton_AddBasePtn.setChecked(False)
self.plot_ctrl.zoom_out_graph()
self.session_ctrl.update_inputs()
else:
QtWidgets.QMessageBox.warning(
self.widget, "Warning", "DPP loading was not successful.")
self.plot_ctrl.update()
else:
# load the existing dpp
# QtWidgets.QMessageBox.warning(
# self.widget, "Warning", "The existing dpp will be open.")
self.session_ctrl._load_dpp(new_filename_dpp)
self.plot_ctrl.update()
success = self.session_ctrl._load_dpp(new_filename_dpp)
if success:
if self.model.exist_in_waterfall(self.model.base_ptn.fname):
self.widget.pushButton_AddBasePtn.setChecked(True)
else:
self.widget.pushButton_AddBasePtn.setChecked(False)
self.plot_ctrl.zoom_out_graph()
self.session_ctrl.update_inputs()
else:
QtWidgets.QMessageBox.warning(
self.widget, "Warning", "DPP loading was not successful.")
self.plot_ctrl.update()
return

# QtWidgets.QMessageBox.warning(self.widget, "Warning",
Expand Down
5 changes: 3 additions & 2 deletions peakpo/control/waterfallcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from PyQt5 import QtGui
from .mplcontroller import MplController
from .waterfalltablecontroller import WaterfallTableController
from utils import convert_wl_to_energy
from utils import convert_wl_to_energy, get_directory


class WaterfallController(object):
Expand Down Expand Up @@ -147,7 +147,8 @@ def _add_patterns(self, files):
self.widget.spinBox_BGParam1.value(),
self.widget.spinBox_BGParam2.value()]
if self.widget.checkBox_UseTempBGSub.isChecked():
temp_dir = os.path.join(self.model.chi_path, 'temporary_pkpo')
temp_dir = get_directory(self.model.get_base_ptn_filename(),
'-param')
else:
temp_dir = None
self.model.append_a_waterfall_ptn(
Expand Down
2 changes: 1 addition & 1 deletion peakpo/ds_cake/DiffractionImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def make_temp_filenames(self, temp_dir=None):
temp_dir=temp_dir)
return tth_filen, azi_filen, int_filen

def write_temp_cakefiles(self, temp_dir='temporary_pkpo'):
def write_temp_cakefiles(self, temp_dir):
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
tth_filen, azi_filen, int_filen = self.make_temp_filenames(
Expand Down
2 changes: 1 addition & 1 deletion peakpo/ds_powdiff/DiffractionPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def temp_files_exist(self, temp_dir=None):
else:
return False

def write_temporary_bgfiles(self, temp_dir='temporary_pkpo'):
def write_temporary_bgfiles(self, temp_dir):
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
bgsub_filen, bg_filen = self.make_temp_filenames(temp_dir=temp_dir)
Expand Down
40 changes: 20 additions & 20 deletions peakpo/mplstyle/day.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ text.usetex : False # use latex for all text handling. The following fo
# If another font is desired which can loaded using the
# LaTeX \usepackage command, please inquire at the
# matplotlib mailing list
text.latex.unicode : False # use "ucs" and "inputenc" LaTeX packages for handling
# text.latex.unicode : False # use "ucs" and "inputenc" LaTeX packages for handling
# unicode strings.
text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURES
# AND IS THEREFORE UNSUPPORTED. PLEASE DO NOT ASK FOR HELP
Expand All @@ -124,7 +124,7 @@ text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURE
# may also be loaded, depending on your font settings
text.latex.preview : False

text.dvipnghack : None # some versions of dvipng don't handle alpha
# text.dvipnghack : None # some versions of dvipng don't handle alpha
# channel properly. Use True to correct
# and flush ~/.matplotlib/tex.cache
# before testing and False to force
Expand Down Expand Up @@ -429,10 +429,10 @@ savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight'
savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter.
savefig.transparent : False # setting that controls whether figures are saved with a
# transparent background by default
savefig.frameon : True
#savefig.frameon : True
savefig.orientation : portrait

nbagg.transparent: True
# nbagg.transparent: True

# ps backend params
ps.papersize : letter # auto, letter, legal, ledger, A0-A10, B0-B10
Expand All @@ -452,7 +452,7 @@ pdf.inheritcolor : False
pdf.use14corefonts : False

# pgf backend params
pgf.debug : False
# pgf.debug : False
pgf.texsystem : xelatex
pgf.rcfonts : True
pgf.preamble :
Expand Down Expand Up @@ -483,8 +483,8 @@ svg.fonttype : path # How to handle SVG fonts:
#
# You can access the verbose instance in your code
# from matplotlib import verbose.
verbose.level : silent # one of silent, helpful, debug, debug-annoying
verbose.fileo : sys.stdout # a log filename, sys.stdout or sys.stderr
# verbose.level : silent # one of silent, helpful, debug, debug-annoying
# verbose.fileo : sys.stdout # a log filename, sys.stdout or sys.stderr

# Event keys to interact with figures/plots via keyboard.
# Customize these settings according to your needs.
Expand All @@ -504,25 +504,25 @@ keymap.xscale : k, L # toggle scaling of x-axes ('log'/'linear')
keymap.all_axes : a # enable all axes

###ANIMATION settings
animation.writer : ffmpeg # MovieWriter 'backend' to use
animation.codec : mpeg4 # Codec to use for writing movie
animation.bitrate: -1 # Controls size/quality tradeoff for movie.
#animation.writer : ffmpeg # MovieWriter 'backend' to use
#animation.codec : mpeg4 # Codec to use for writing movie
#animation.bitrate: -1 # Controls size/quality tradeoff for movie.
# -1 implies let utility auto-determine
animation.frame_format: png # Controls frame format used by temp files
animation.ffmpeg_path: ffmpeg # Path to ffmpeg binary. Without full path
#animation.frame_format: png # Controls frame format used by temp files
#animation.ffmpeg_path: ffmpeg # Path to ffmpeg binary. Without full path
# $PATH is searched
animation.ffmpeg_args: # Additional arguments to pass to ffmpeg
animation.avconv_path: avconv # Path to avconv binary. Without full path
#animation.ffmpeg_args: # Additional arguments to pass to ffmpeg
#animation.avconv_path: avconv # Path to avconv binary. Without full path
# $PATH is searched
animation.avconv_args: # Additional arguments to pass to avconv
animation.mencoder_path: mencoder
#animation.avconv_args: # Additional arguments to pass to avconv
#animation.mencoder_path: mencoder
# Path to mencoder binary. Without full path
# $PATH is searched
animation.mencoder_args: # Additional arguments to pass to mencoder
animation.convert_path: convert # Path to ImageMagick's convert binary.
#animation.mencoder_args: # Additional arguments to pass to mencoder
#animation.convert_path: convert # Path to ImageMagick's convert binary.
# On Windows use the full path since convert
# is also the name of a system tool.
animation.convert_args:
animation.html: none
#animation.convert_args:
#animation.html: none

_internal.classic_mode: True
12 changes: 8 additions & 4 deletions peakpo/peakpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ def excepthook(exc_type, exc_value, traceback_obj):
errorbox.setText(error_message)
errorbox.exec_()

QtCore.QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"

# 2020/02/15 block below does not affect screen resolution
#QtCore.QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
#os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"

app = QtWidgets.QApplication(sys.argv)
app.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
# 2020/02/15 block below does not affect screen resolution
# app.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
sys.excepthook = excepthook
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
# app.setStyleSheet('fusion')
# app.setStyle('osx')
controller = MainController()
controller.show_window()
ret = app.exec_()
Expand Down
2 changes: 1 addition & 1 deletion peakpo/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .pyqtutils import undo_button_press, SpinBoxFixStyle
from .fileutils import samefilename, extract_filename, make_filename, \
get_sorted_filelist, find_from_filelist, writechi, readchi, \
extract_extension, change_file_path
extract_extension, change_file_path, get_directory
from .dialogs import dialog_savefile, ErrorMessageBox, InformationBox
from .excelutils import xls_ucfitlist, xls_jlist
from .physutils import convert_wl_to_energy
6 changes: 5 additions & 1 deletion peakpo/utils/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def extract_filename(filen):
return filen


def get_directory(filen_path, branch):
path, filen, __ = breakdown_filename(filen_path)
return os.path.join(path, filen+branch)


def extract_extension(filen):
"""
extract extension without dot
Expand Down Expand Up @@ -121,5 +126,4 @@ def change_file_path(filename, new_path):
else:
filen_ext = filen_ext1
new_filename = os.path.join(new_path, filen_ext)
print(filename, ':', path, ':', filen_ext, ':', new_path)
return new_filename
3 changes: 2 additions & 1 deletion peakpo/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
Add option to use diffraction file for background subtraction
Better system should be implemented, such as pbr.
"""
__version__ = "7.7.27"
__version__ = "7.7.28"
"""
7.7.28: Bug fix in 7.7.27 for not updating the info when navigated
7.7.27: Add new Navigation choices, dpp vs chi. Also autogenerate dpp.
7.7.26: Add conda environment to the title bar
7.7.25: Add HDPI display support, such as retina display
Expand Down
Loading

0 comments on commit 3e497e1

Please sign in to comment.