davidanthoff / PyRhodium.jl
1 1
module PyRhodium
2

3
using PyCall
4
using PyPlot
5
using IterableTables
6
using Distributions
7
using DataFrames
8
using DataStructures
9

10
export Model, Parameter, Response, Lever, RealLever, IntegerLever, CategoricalLever,
11
    PermutationLever, SubsetLever, Constraint, Brush, DataSet, pandas_dataframe,
12
    named_tuple, named_tuples, optimize, scatter2d, scatter3d, pairs,
13
    parallel_coordinates, apply, evaluate, sample_lhs, set_parameters!,
14
    set_levers!, set_responses!, set_constraints!, set_uncertainties!,
15
    Prim, PrimBox, find_box, find_all, show_tradeoff, stats, limits,
16
    Cart, show_tree, print_tree, save, save_pdf, save_png,
17
    Sensitivity, SAResult, sa, oat, plot, plot_sobol, find
18

19
const rhodium = PyNULL()
20
const prim = PyNULL()
21
const pd = PyNULL()
22
const seaborn = PyNULL()
23

24
function __init__()
25 2
    copy!(rhodium, pyimport("rhodium"))
26 2
    copy!(prim, pyimport("prim"))
27 2
    copy!(pd, pyimport("pandas"))
28 2
    copy!(seaborn, pyimport("seaborn"))
29

30
    # TBD: see if it works to simply call __init__(function) without storing the julia function
31 1
    py"""
32
    from rhodium import *
33
    class JuliaModel(Model):
34
        
35
        def __init__(self, function, **kwargs):
36
            super(JuliaModel, self).__init__(self._evaluate)
37
            self.j_function = function
38
            
39
        def _evaluate(self, **kwargs):
40
            result = self.j_function(**kwargs)
41
            return result
42
    """
43

44
    # Create a Python class that can store the SAResult (a subclass of dict) in 
45
    # an instance var so we can access it without conversion. Otherwise, PyCall 
46
    # converts it to a Dict and we can't use it as an argument to the plot routines
47
    # that are methods of rhodium.SARsult.
48 2
    py"""
49
    import rhodium
50

51
    class SAResultContainer(object):
52
        def __init__(self, sa_result):
53
            self.sa_result = sa_result
54

55
    def my_sa(*args, **kwargs):
56
        sa_result = rhodium.sa(*args, **kwargs)
57
        return SAResultContainer(sa_result)
58
    """    
59
end
60

61
include("core.jl")
62
include("prim.jl")
63
include("cart.jl")
64
include("sa.jl")
65

66
end # module

Read our documentation on viewing source code .

Loading