Skip to content

Commit

Permalink
Merge pull request #22 from CJ-Wright/0911_XPD
Browse files Browse the repository at this point in the history
0911 xpd
  • Loading branch information
chiahaoliu authored Sep 16, 2017
2 parents a622d5f + 352179f commit 68bbadd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ install:
script:
# - coverage run run_tests.py
# - coverage report -m
- flake8 xpdview
# - flake8 xpdview
- true

#after_success:
# - codecov
# - coveralls
# - coveralls
35 changes: 22 additions & 13 deletions xpdview/Chi_File_Finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
##############################################################################

"""
This class will handle reading in .chi files from the directory so that XPD view can show
the 1-D integration patterns extracted from the .chi files. You should only put this option back in if you are
working on a Windows computer with .chi files. This is because all azimuthal integration software that has been found
so far has had no windows equivalent and no windows configuration files.
This class will handle reading in .chi files from the directory so that XPD
view can show the 1-D integration patterns extracted from the .chi files.
You should only put this option back in if you are working on a Windows
computer with .chi files. This is because all azimuthal integration
software that has been found so far has had no windows equivalent and no
windows configuration files.
"""

import numpy as np
Expand Down Expand Up @@ -61,8 +63,8 @@ def __init__(self):

def get_file_list(self):
"""
This method gets all of the chi files from the directory and organizes them according to the time they were
made
This method gets all of the chi files from the directory and organizes
them according to the time they were made
Parameters
----------
Expand All @@ -78,13 +80,16 @@ def get_file_list(self):
if self._directory_name[-1] != '/' or '\\':
self._directory_name += '/'
self.dir_fil = os.listdir(self._directory_name)
self.dir_fil.sort(key=lambda x: os.path.getmtime(self._directory_name + x))
self.file_list = [file for file in self.dir_fil if file.endswith('.chi')]
self.dir_fil.sort(key=lambda x: os.path.getmtime(self._directory_name
+ x))
self.file_list = [file for file in self.dir_fil if
file.endswith('.chi')]
self.get_data_lists()

def get_data_lists(self):
"""
This method reads in the data from the files and then splits it up into the x and y data
This method reads in the data from the files and then splits it up
into the x and y data
Parameters
----------
Expand Down Expand Up @@ -117,8 +122,10 @@ def get_new_files(self):
"""
self.dir_fil = os.listdir(self._directory_name)
self.dir_fil.sort(key=lambda x: os.path.getmtime(self._directory_name + x))
new_file_list = [file for file in self.dir_fil if file.endswith('.chi')]
self.dir_fil.sort(key=lambda x: os.path.getmtime(
self._directory_name + x))
new_file_list = [file for file in self.dir_fil if file.endswith(
'.chi')]
need_read_files = []
for i in new_file_list:
add = True
Expand All @@ -133,12 +140,14 @@ def get_new_files(self):

def get_new_data(self, temp_file_list):
"""
This method gets the new data from the files that get_new_files determined had not been read in yet
This method gets the new data from the files that get_new_files
determined had not been read in yet
Parameters
----------
temp_file_list : list of strings
a list of strings that correspond to all of the new files that need to be read in
a list of strings that correspond to all of the new files that
need to be read in
Returns
-------
Expand Down
5 changes: 3 additions & 2 deletions xpdview/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ class LiveWaterfall(BrokerCallbackBase):
The units for the x and y axes
"""

def __init__(self, x_name, y_name, db=None, units=None):
def __init__(self, x_name, y_name, db=None, units=None,
window_title=None):
super().__init__((x_name, y_name,), db=db)
self.db = db
self.x_name = x_name
self.y_name = y_name
self.units = units

self.fig = plt.figure()
self.fig = plt.figure(window_title)

self.wf = Waterfall(fig=self.fig, unit=self.units)
self.i = 0
Expand Down
15 changes: 9 additions & 6 deletions xpdview/cross_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from matplotlib.widgets import Slider
import numpy as np


def auto_redraw(func):
def inner(self, *args, **kwargs):
if self._fig.canvas is None:
Expand Down Expand Up @@ -60,6 +61,7 @@ class CrossSection(object):
Interpolation method to use. List of valid options can be found in
CrossSection2DView.interpolation
"""

def __init__(self, fig, cmap=None, norm=None,
limit_func=None, auto_redraw=True, interpolation=None):

Expand Down Expand Up @@ -116,7 +118,7 @@ def __init__(self, fig, cmap=None, norm=None,
self._im_ax.yaxis.set_major_locator(NullLocator())
self._imdata = None
self._im = self._im_ax.imshow([[]], cmap=self._cmap, norm=self._norm,
interpolation=self._interpolation,
interpolation=self._interpolation,
aspect='equal', vmin=0,
vmax=1)

Expand Down Expand Up @@ -462,14 +464,15 @@ class to hold multiple 2d images and provide a slider to navigate
img_data_list : list, optional
a list of 2D numpy arrays, default to None
"""

def __init__(self, viewer, key_list=None, img_data_list=None):
self.viewer = viewer
self.key_list = key_list
self.img_data_list = img_data_list
self.fig = self.viewer._fig
# create slider
if not key_list:
self.data_length = None # init
self.data_length = None # init
else:
self.data_length = len(key_list)
self.slider_ax = self.fig.add_axes([0.15, 0.01, 0.7, 0.02])
Expand Down Expand Up @@ -500,9 +503,9 @@ def update(self, key_list, img_data_list, refresh=False):
refresh: bool, optional
option of refreshing or not
"""
#TODO: figure out origin of this weird flipping logic
# TODO: figure out origin of this weird flipping logic
img_data_list = list(map(lambda x: np.flipud(x), img_data_list))
update_ind = self.slider.val+1
update_ind = self.slider.val + 1
if refresh:
self.key_list = []
self.img_data_list = []
Expand All @@ -517,15 +520,15 @@ def update(self, key_list, img_data_list, refresh=False):
def no_image_plot(self):
"""method to call when no valid image files are found"""
# give a default array
default_array = np.zeros((200,200))
default_array = np.zeros((200, 200))
self.viewer.update_image(default_array)

def configure_slider(self):
"""method to update upper and lower limit of slider"""
if not self.data_length:
max_val = 0
else:
max_val = self.data_length-1
max_val = self.data_length - 1
self.slider_ax.cla()
self.slider = Slider(self.slider_ax, 'image ind.', 0, max_val, 0,
valfmt='%d/{}'.format(max_val))
Expand Down
2 changes: 1 addition & 1 deletion xpdview/waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update(self, key_list=None, int_data_list=None, refresh=False):
self.int_data_list = []
self.key_list.extend(key_list)
self.int_data_list.extend(int_data_list)
self._adapt_data_list(int_data_list)
self._adapt_data_list(self.int_data_list)
# generate plot
self.halt = False
self._update_plot() # use current value of x,y offset
Expand Down

0 comments on commit 68bbadd

Please sign in to comment.