Skip to content

Commit

Permalink
Fixed outport bug, add tomography module and update to latest VTTools
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'upstream/master'
  • Loading branch information
celiafish committed Dec 11, 2014
2 parents 24c89a5 + 35f5695 commit 55f157c
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 46 deletions.
4 changes: 4 additions & 0 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

$PYTHON setup.py install
cp -r vt_config/NSLS-II $SP_DIR/vistrails/packages/
33 changes: 33 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package:
name: vttools
version: {{ environ['GIT_DESCRIBE_TAG'] }}.post{{ environ['GIT_DESCRIBE_NUMBER'] }}

source:
git_url: ../


build:
number: 0
string: {{ environ.get('GIT_BUILD_STR', '') }}_np{{ np }}py{{ py }}

requirements:
build:
- python
- setuptools
- vistrails
run:
- python
- vistrails
- numpy
- scikit-xray
- pyyaml
- numpydoc
- tifffile
- bubblegum

test:
imports:
- vttools

about:
license: 3-Clause BSD
22 changes: 3 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
#!/usr/bin/env python

import setuptools
from distutils.core import setup, Extension

import numpy as np
import os
import shutil
from subprocess import call
import sys
from distutils.core import setup

setup(
name='vttools',
version='0.0.x',
author='Brookhaven National Lab',
packages=["vttools",
'vttools.vtmods',
'vttools.vtmods.import_lists'
'vttools.vtmods.import_lists',
'vttools.to_wrap'
],
include_dirs=[np.get_include()],
package_data = {'vttools.vtmods.import_lists': ['*.yaml']}
)


src = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'vt_config',
'NSLS-II')
dst = os.path.join(os.path.expanduser('~'), '.vistrails', 'userpackages',
'NSLS-II')

from vttools.utils import make_symlink
make_symlink(dst=dst, src=src)
2 changes: 1 addition & 1 deletion vt_config/NSLS-II/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Created on Apr 29, 2014
'''
from __future__ import (absolute_import, division, print_function,
unicode_literals)
)
import six
import logging
import sys
Expand Down
2 changes: 1 addition & 1 deletion vttools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
########################################################################

from __future__ import (absolute_import, division, print_function,
unicode_literals)
)

import six
import logging
Expand Down
2 changes: 1 addition & 1 deletion vttools/func_wrap_smoketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
This module is for spectroscopy specific tools (spectrum fitting etc).
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
)

import six
from six.moves import zip
Expand Down
33 changes: 31 additions & 2 deletions vttools/tests/test_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# POSSIBILITY OF SUCH DAMAGE. #
########################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)
)

import numpy as np
import six
Expand All @@ -43,7 +43,7 @@
from skxray.testing.decorators import known_fail_if
from vttools.to_wrap.fitting import (gaussian_model, lorentzian_model,
lorentzian2_model, quadratic_model,
fit_engine)
fit_engine, fit_engine_list, expression_model)
from nose.tools import (assert_equal, assert_true, raises)


Expand Down Expand Up @@ -114,6 +114,7 @@ def test_lorentzian2_fit():
fitted_val = (out['area'], out['center'], out['sigma'])
assert_array_almost_equal(true_val, fitted_val)


def test_quadratic_fit():
x = np.arange(-1, 1, .01)
a = 1
Expand All @@ -133,3 +134,31 @@ def test_quadratic_fit():
out = result.values
fitted_val = (out['a'], out['b'], out['c'])
assert_array_almost_equal(true_val, fitted_val)


def test_fit_engine_list():
a = 1
b = 2
c = 3
m = quadratic_model('',
a, 'free', [-1, 1],
b, 'free', [-1, 1],
c, 'free', [-1, 1])
x = np.arange(-1, 1, 0.01)
y = x**2 + 1

datav = [(x, y), (x, y+2)]
out = fit_engine_list(m, datav)
assert_equal(len(out), 2)


def test_expression_model():

inputv = 'exp(-a*x)'

x = np.arange(-1, 1, 0.01)
y = np.exp(-x)

mod = expression_model(inputv)
out = mod.fit(y, x=x, a=0.1)
assert_equal(1, out.values['a'])
2 changes: 1 addition & 1 deletion vttools/tests/test_wrap_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
########################################################################

from __future__ import (absolute_import, division, print_function,
unicode_literals)
)

import six
import logging
Expand Down
27 changes: 20 additions & 7 deletions vttools/to_wrap/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
########################################################################
import sys
from skxray.fitting.api import (QuadraticModel, GaussianModel,
LorentzianModel, Lorentzian2Model)
LorentzianModel, Lorentzian2Model,
ExpressionModel)

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -150,6 +151,24 @@ def fit_engine_list(g, data):
return result_list


def expression_model(model_exp):
"""
This function creates a Model from a user-supplied expression.
Parameters
----------
model_exp : str
expression of the model
Returns
-------
mod : array_like
object of fitting results
"""
mod = ExpressionModel(model_exp)
return mod


def set_range(model_name,
parameter_name, parameter_value,
parameter_vary, parameter_range):
Expand Down Expand Up @@ -265,9 +284,3 @@ def inner(prefix, amplitude, amplitude_vary, amplitude_range,
func_name.amplitude_vary = ['fixed', 'free', 'bounded']
func_name.center_vary = ['fixed', 'free', 'bounded']
func_name.sigma_vary = ['fixed', 'free', 'bounded']


function_list = [fit_engine, fit_engine_list, quadratic_model]

for func_name in function_list:
setattr(mod, func_name.__name__, func_name)
2 changes: 1 addition & 1 deletion vttools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
########################################################################

from __future__ import (absolute_import, division,
print_function, unicode_literals)
print_function, )
import six
import os
import shutil
Expand Down
2 changes: 1 addition & 1 deletion vttools/vtmods/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Created on Apr 29, 2014
'''
from __future__ import (absolute_import, division, print_function,
unicode_literals)
)
import six
from PyQt4 import QtCore, QtGui
from vistrails.core.modules.vistrails_module import Module, ModuleSettings
Expand Down
2 changes: 1 addition & 1 deletion vttools/vtmods/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
########################################################################

from __future__ import (absolute_import, division, print_function,
unicode_literals)
)
import six
from vistrails.core.modules.vistrails_module import Module, ModuleSettings
from vistrails.core.modules.config import IPort, OPort
Expand Down
2 changes: 1 addition & 1 deletion vttools/vtmods/import_lists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
########################################################################

from __future__ import (absolute_import, division, print_function,
unicode_literals)
)
import six
import os
import yaml
Expand Down
3 changes: 3 additions & 0 deletions vttools/vtmods/import_lists/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ autowrap_func:
- func_name: fit_engine_list
module_path: vttools.to_wrap.fitting
namespace: fitting
- func_name: expression_model
module_path: vttools.to_wrap.fitting
namespace: fitting
# CALIBRATION
- func_name: refine_center
module_path: skxray.calibration
Expand Down
15 changes: 14 additions & 1 deletion vttools/vtmods/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# POSSIBILITY OF SUCH DAMAGE. #
########################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)
)
import six
from bubblegum.qt_widgets import query_widget
from logging import Handler
Expand All @@ -44,6 +44,8 @@
from .broker import search
import numpy as np
from metadataStore.utilities.utility import get_data_keys
import enaml
from enaml.qt.qt_application import QtApplication
import logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -153,6 +155,13 @@ def search_databroker(search_dict):
# unique_id_func=gen_unique_id)


from bubblegum.xrf.model.xrf_model import XRF
with enaml.imports():
from bubblegum.xrf.view.xrf_view import XrfGui

xrf_view = XrfGui()
xrf_view.xrf_model = XRF()

def setup_bnl_menu():
"""
Creates and hooks up a BNL specific menu in the main window
Expand All @@ -162,10 +171,14 @@ def setup_bnl_menu():
menu_bar = bw.menuBar()

bnl_menu = menu_bar.addMenu("BNL")
print('\n\n\n\n\n\nBNL Menu Added\n\n\n\n\n\n\n\n\n')

def foo():
print('menu bar clicked!')
# query_window.show()
xrf_view.show()


bnl_menu.addAction("demo", foo)


Expand Down
2 changes: 1 addition & 1 deletion vttools/vtmods/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Created on Apr 29, 2014
'''
from __future__ import (absolute_import, division, print_function,
unicode_literals)
)
import six
from PyQt4 import QtCore, QtGui
from vistrails.core.modules.vistrails_module import (Module, ModuleSettings,
Expand Down
16 changes: 8 additions & 8 deletions vttools/wrap_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
########################################################################

from __future__ import (absolute_import, division,
print_function, unicode_literals)
print_function)
import six
import inspect
import importlib
Expand Down Expand Up @@ -487,11 +487,11 @@ def define_input_ports(docstring, func):
port_is_enum = is_enum
port_enum_list = enum_list
# start with the easy ones
pdict = {'name': port_name,
'label': short_description,
pdict = {'name': str(port_name),
'label': str(short_description),
'optional': is_optional,
'signature': pytype_to_vtsig(param_type=port_type,
param_name=port_name)}
'signature': str(pytype_to_vtsig(param_type=port_type,
param_name=port_name))}

# deal with if the function as an enum attribute
if hasattr(func, port_name):
Expand All @@ -518,8 +518,8 @@ def define_input_ports(docstring, func):
port_enum_list = f_enums
port_is_enum = True
if port_is_enum:
pdict['entry_type'] = 'enum'
pdict['values'] = port_enum_list
pdict['entry_type'] = str('enum')
pdict['values'] = [str(x) for x in port_enum_list]

logger.debug('port_param_dict: {0}'.format(pdict))
input_ports.append(IPort(**pdict))
Expand Down Expand Up @@ -576,7 +576,7 @@ def define_output_ports(docstring):
if the_type == '':
continue
the_type = _check_alt_types(the_type)
output_ports.append(OPort(name=the_name,
output_ports.append(OPort(name=str(the_name),
signature=pytype_to_vtsig(
param_type=the_type,
param_name=the_name)))
Expand Down

0 comments on commit 55f157c

Please sign in to comment.