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

new features added #2

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
eeaadc1
implement FA module
lchen23 Aug 22, 2019
3578f16
implement MCR
lchen23 Aug 24, 2019
e12f305
add interactivity to FA components
lchen23 Aug 28, 2019
13d98d5
add pix value reader
lchen23 Aug 30, 2019
53a4e63
fix the crosshair bug in mapconvertwidget
lchen23 Aug 31, 2019
81a544c
show file open, FA calculate message in status bar
lchen23 Sep 9, 2019
1447a50
allow npy format import
lchen23 Sep 10, 2019
005814d
fix open npy bug
lchen23 Sep 11, 2019
f21d5aa
fix bugs in mapconvert and spectraview
lchen23 Sep 13, 2019
b7449d8
implement ROI for sparse image
lchen23 Sep 13, 2019
6caff12
change back from XAS view to maptoH5
lchen23 Sep 14, 2019
1b36818
add 3 initial params to make spectraplot more customizable
lchen23 Sep 15, 2019
1e3c4c2
add a splitter to spectraplot panel, make markselect control all mask
lchen23 Sep 16, 2019
c2275d7
make spectramaproi widget
lchen23 Sep 16, 2019
cb5d497
pull out spectramaproi widget, reformat init file
lchen23 Sep 16, 2019
9d29482
fix datahandler import
lchen23 Sep 23, 2019
c6805ef
add new imageview widget
lchen23 Oct 7, 2019
61bf38f
add slim window widget and toHtml func
lchen23 Oct 7, 2019
303d224
merge Merge branch 'master' of https://github.com/lchen23/Xi-cam.BSISB
lchen23 Oct 7, 2019
852639b
Update MapView with stream arg (see xi-cam.gui #44)
lchen23 Mar 11, 2020
0e6e80e
Replaced yapsy plugin file with entry points
lchen23 Mar 11, 2020
931a632
Remove BSISB yapsy file
lchen23 Mar 11, 2020
7888cb6
Removed tracked files that should be ignored
lchen23 Mar 11, 2020
1a924b3
Ignore egg-info dir
lchen23 Mar 11, 2020
19caf77
adjust cross size and change txt position from fixed to x[0]
lchen23 Apr 5, 2020
bb4e9ed
add lbl_ir install
lchen23 Apr 6, 2020
783025c
bring highlighted curve to front in PCA loadings
lchen23 May 5, 2020
63e5f20
add preprocess stage
lchen23 May 5, 2020
512bcc5
add 'error type' to isbaselineOK msgbox
lchen23 May 5, 2020
2dec52f
hide mapToH5 stage for review
lchen23 May 11, 2020
07fb319
change fonts and button names in FA widget
lchen23 May 26, 2020
bad8f4a
add cleanup func in preprocess
lchen23 May 26, 2020
ea3c18b
add clustering widget
lchen23 May 26, 2020
39b8268
change scatter plot mouseClick to mouseMove
lchen23 May 26, 2020
cbeb8bc
add clearAll func
lchen23 May 27, 2020
bd4f9fb
show all cluster mean spectra and fix clearAll bug
lchen23 May 27, 2020
e44e0c2
change FA to Decomposition
lchen23 May 31, 2020
98d2ae9
change text position
lchen23 May 31, 2020
69f52bc
add PCA and multimap clustering
lchen23 May 31, 2020
f417e01
move buttons out of parameterlist
lchen23 May 31, 2020
73d1f4b
add lbl_ir package
lchen23 Jun 1, 2020
45615ef
add openpyxl dependency
lchen23 Jun 3, 2020
0650e94
add mouseclick to select anchor points
lchen23 Jun 3, 2020
e0f8bea
add mousePosList to cleanup
lchen23 Jun 4, 2020
2c82ccd
clear image window in clean up
lchen23 Jun 4, 2020
3339a10
restore legend
lchen23 Jun 4, 2020
5222464
add installation instructions
lchen23 Jul 3, 2020
ba0423d
update example.png
lchen23 Jul 3, 2020
8368b67
Update README.md
lchen23 Jul 6, 2020
ad8eca7
no need to reposition reset buttons in SlimImageView
lchen23 Jul 27, 2020
b0c86d6
add kohler EMSC method and plots to preprocess
lchen23 Sep 16, 2020
753b214
add EMSC
lchen23 Nov 14, 2020
4a29845
add save button to clustering
lchen23 Aug 2, 2021
512f335
add save cluster file feature
lchen23 Aug 6, 2021
3803650
add save cluster feature
lchen23 Aug 6, 2021
7135ce5
add ROI to clustering
lchen23 Oct 12, 2021
21078d3
Finish clustering ROI with multi-map transition
lchen23 Oct 15, 2021
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
*.tif
build/
dist/
*.egg_info/
*.egg-info/
107 changes: 91 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,109 @@
Bsisb (Xi-cam PluginMaker)
===============================
BSISB (A Xi-cam plugin for FTIR data analysis)
==============================================

version number: 0.1
author: Liang Chen
Version number: 0.1

Overview
--------
Author: Liang Chen

## Installation
---------------------
### Install C++ build tools (Windows OS only):

Download and install "Build Tools for Visual Studio" from [here](https://visualstudio.microsoft.com/downloads/).
See the screenshot below for reference:

Installation / Usage
--------------------
Install Xi-CAM:
![build](images/buildtools.png)

Follow the guide [here](https://xi-cam2.readthedocs.io/en/latest/install.html)
### Install git and python3.7.7:

You will need to ensure that you have both git and python3 installed on your system for Xi-cam installation.

Clone the repo:
**MacOS**

Open the Terminal application (in Applications/Utilities). In the terminal, check to see if git is installed by typing `git --version`. Either a version number will be printed, indicating git is already installed, or a dialog will open asking The “git” command requires the command line developer tools. Would you like to install the tools now? Click the **Install** button to install the developer tools, which will install git for you.

You will also need to install python3.7.7. You can download python3.7.7 at [python.org](https://www.python.org/downloads/mac-osx/). You will want to get the macOS 64-bit installer if you are running any macOS version since Mavericks.

**Windows OS**

Download git [here](https://git-scm.com/download/win) and follow the installer’s instructions. This will install **Git for Windows**, which provides a **Git Bash** command line interface as well as a **Git GUI** graphical interface for git.

You will want to go to the python3.7.7 download page at [python.org](https://www.python.org/downloads/release/python-377/). For modern systems, install the **Windows x86-64 executable installer** at the bottom.

When you run the installer, make sure sure to check the box that says **Add Python 3.x to PATH** to ensure that the interpreter will be placed in your execution path.

### Create and Activate a Virtual Environment:

The latest python3 version comes with the venv module, which can be used to create a virtual environment. A virtual environment is a sequestered space where you can install and uninstall packages without modifying your system’s installed packages.

Create a virtual environment for installing the Xi-cam components and dependencies. You will then want to activate the virtual environment you created so that any packages you install with python’s package manager, **pip**, will be installed into that active virtual environment. In the commands below, create a virtual environment called **venv_xicam** and activate it:

**Linux/macOS**

$ python3 -m venv venv_xicam
$ source venv_xicam/bin/actviate

**Windows OS**

$ python -m venv venv_xicam
$ venv_xicam\Scripts\activate

### Install Xi-CAM:
Before installing Xi-cam, run the following commands:

$ python -m pip install --upgrade pip
$ pip install wheel
$ pip install --upgrade setuptools
$ pip install numcodecs

Then run the following commands to install Xi-cam:

$ pip install xicam

### Install lbl_ir and Xi-cam.BSISB plugin:
Run the following commands to install lbl_ir package and Xi-cam.BSISB plugin:

$ git clone https://github.com/lchen23/Xi-cam.BSISB.git
$ cd Xi-CAM.BSISB
$ cd Xi-cam.BSISB/lbl_ir
$ pip install -e .
$ cd ..
$ cd ..
$ pip install -e .

### Run the Xi-cam.BSISB program:

Run the following command:

$ xicam

### Run the Xi-cam.BSISB GUI from a new terminal:
First, activate the virtual environment, then run xicam:

**Linux/macOS**

$ source venv_xicam/bin/actviate
$ xicam

**Windows OS**

In Git bash:

$ source venv_xicam/Scripts/activate
$ xicam

In Windows CMD:

$ venv_xicam\Scripts\activate
$ xicam

After the Xi-cam GUI program launches, open the
`Xi-cam.BSISB/tests/PC12-NGF-3h.h5` file by double clicking the h5 file
in the file browser as shown below:

![example](images/example.png)

Contributing
------------

TBD

Example
-------

TBD
Binary file added images/buildtools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lbl_ir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
.ipynb_checkpoints/
30 changes: 30 additions & 0 deletions lbl_ir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# README #


This README would normally document whatever steps are necessary to get your application up and running.

### What is this repository for? ###

* Quick summary
* Version
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)

### How do I get set up? ###

* Summary of set up
* Configuration
* Dependencies
* Database configuration
* How to run tests
* Deployment instructions

### Contribution guidelines ###

* Writing tests
* Code review
* Other guidelines

### Who do I talk to? ###

* Repo owner or admin
* Other community or team contact
143 changes: 143 additions & 0 deletions lbl_ir/lbl_ir/GPR/GPR_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import numpy as np
import matplotlib.pyplot as plt
import numba
from scipy.optimize import minimize
from scipy.optimize import basinhopping

@numba.jit(nopython=True) #,cache=True)
def dmat(X1,X2=None):
if X2 is None:
X2 = X1
N1,M1 = X1.shape
N2,M2 = X2.shape

dd = np.zeros( (N2,N1) )
for ii in range(N2):
for jj in range(N1):
tmp = 0
for kk in range(M1):
delta = X2[ii,kk]-X1[jj,kk]
tmp += delta*delta
tmp = np.sqrt( tmp )
dd[ii,jj]=tmp
return dd

@numba.jit(nopython=True) #,cache=True)
def rbf_kern(dmat, variance, length):
result = np.exp( -dmat*dmat/(1e-8+length*length*2.0))*(1e-8+variance)
return result

@numba.jit(nopython=True) #,cache=True)
def d_rbf_kern_FD(X2, X, variance, length, h=1e-4):
dmat_plus = dmat(X,X2+h/2)
dmat_minus= dmat(X,X2-h/2)
Kplus = np.exp( -dmat_plus*dmat_plus/(length*length*2.0) )*variance
Kminus = np.exp( -dmat_minus*dmat_minus/(length*length*2.0) )*variance
result = (Kplus - Kminus)/h
return result

def d_rbf_kern(X2, X, dxx2, Kxx2, variance, length):
# first derivative
result1 = []
for xx in X2.flatten():
result1.append( X.flatten()-xx )
result1 = np.vstack(result1)
result1 = result1*Kxx2

# second derivative
result2 = []
N2,N1 = result1.shape
for ii in range(N2):
xx = X2[ii,:]
dK = result1[ii,:]
K = Kxx2[ii,:]
tmp = -K/(length*length)
tmp2 = (X-xx).flatten()*dK.flatten()/(length*length)
result2.append( tmp.flatten()+tmp2.flatten() )
result2 = np.vstack(result2)
return result1, result2



class GPR_exp_fitter(object):
def __init__(self,sigma,length, mu=0,niter=3):
"""
:param sigma: The sigma
:param length: The length scale
:param mu: The mean value
:param niter: the number of iterations in basin hopping to fit the GPR model
"""

self.sigma = sigma
self.length = length
self.mu = mu

# to compute later
self.dX1X1 = None


def marginal_likelihood(self,hparams):
this_mu = hparams[0]
this_sigma = hparams[1]
this_length= hparams[2]
KX1X1 = rbf_kern( self.dX1X1, this_sigma*this_sigma, this_length )

II = np.diag(self.sY*self.sY)
KX1X1_inv = np.linalg.pinv(KX1X1+II)
tY = self.Y - this_mu
tY = tY.reshape(-1,1)
KiY = KX1X1_inv.dot(tY)
term1 = 0.5*tY.transpose().dot(KiY)
term2 = 0.5*np.linalg.slogdet(KX1X1+II)[1]

result = term1+term2
result = result.flatten()[0]
return result


def fit(self,X,Y,sY):
# first we need to build a distance matrix
self.sY = sY
if type(self.sY) is float:
self.sY = self.Y*0+sY
self.X = X
self.Y = Y
self.dX1X1 = dmat(X.reshape(-1,1))
fitter = basinhopping( func = self.marginal_likelihood,
x0 = np.array([self.mu, self.sigma, self.length]),
niter = 13)
self.mu = fitter.x[0]
self.sigma = abs(fitter.x[1])
self.length = abs(fitter.x[2])


self.tY = (Y - self.mu).reshape(-1,1)
self.KX1X1 = rbf_kern( self.dX1X1, self.sigma**2.0, self.length ) + np.eye( self.dX1X1.shape[0])*self.sY
self.KX1X1_inv = np.linalg.pinv(self.KX1X1)
self.KiY = self.KX1X1_inv.dot(self.tY)



def predict(self,X):
dX1X2 = dmat(self.X.reshape(-1,1), X.reshape(-1,1))
kX1X2 = rbf_kern( dX1X2, self.sigma**2, self.length )
tmp = kX1X2.dot( self.KiY )
return tmp+self.mu




def tst():
x = np.linspace(-10,10,20, True)
xx = np.linspace(-10,10,200,True)
y = np.sin(x) #10 + x*x + x

plt.plot(x,y,'.');plt.show()
obj = GPR_exp_fitter(1,1,1)
obj.fit(x,y,0.01)
yy = obj.predict( xx ).flatten()
plt.plot(x,y,'.'); plt.plot(xx,yy);plt.show()


if __name__ == "__main__":
tst()
Loading