Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions RATapi/examples/non_polarised/backgroundFunction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import numpy as np


def backgroundFunction(xdata, params):
# Split up the params array
Ao = params[0]
k = params[1]
back_const = params[2]

# Make an exponential decay background
background = np.zeros(len(xdata))
for i in range(0, len(xdata)):
background[i] = Ao * np.exp(-k * xdata[i]) + back_const

return background
14 changes: 9 additions & 5 deletions RATapi/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition:
data_limits = []
simulation_limits = []
contrast_resolution_params = []
contrast_resolution_types = []

# set data, background and resolution for each contrast
for contrast in project.contrasts:
Expand Down Expand Up @@ -278,11 +279,12 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition:
all_data.append(np.column_stack((data, np.zeros((data.shape[0], 6 - data.shape[1])))))

# Set resolution parameters, with -1 used to indicate a data resolution
contrast_resolution_param = []
resolution = project.resolutions[contrast.resolution]
if resolution.type == TypeOptions.Data:
contrast_resolution_params.append(-1)
else:
contrast_resolution_params.append(project.resolution_parameters.index(resolution.source, True))
contrast_resolution_types.append(resolution.type)
if resolution.source:
contrast_resolution_param.append(project.resolution_parameters.index(resolution.source, True))
contrast_resolution_params.append(contrast_resolution_param)

problem = ProblemDefinition()

Expand All @@ -306,7 +308,10 @@ def make_problem(project: RATapi.Project, checks: Checks) -> ProblemDefinition:
]
problem.contrastBulkIns = [project.bulk_in.index(contrast.bulk_in, True) for contrast in project.contrasts]
problem.contrastBulkOuts = [project.bulk_out.index(contrast.bulk_out, True) for contrast in project.contrasts]

problem.contrastResolutionParams = contrast_resolution_params
problem.contrastResolutionTypes = contrast_resolution_types

problem.backgroundParams = [param.value for param in project.background_parameters]
problem.qzshifts = [0.0]
problem.scalefactors = [param.value for param in project.scalefactors]
Expand Down Expand Up @@ -429,7 +434,6 @@ def check_indices(problem: ProblemDefinition) -> None:
"scalefactors": "contrastScalefactors",
"bulkIns": "contrastBulkIns",
"bulkOuts": "contrastBulkOuts",
"resolutionParams": "contrastResolutionParams",
"domainRatios": "contrastDomainRatios",
}

Expand Down
2 changes: 0 additions & 2 deletions RATapi/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class ContrastParams(RATResult):
scalefactors: np.ndarray
bulkIn: np.ndarray
bulkOut: np.ndarray
resolutionParams: np.ndarray
subRoughs: np.ndarray
resample: np.ndarray

Expand Down Expand Up @@ -178,7 +177,6 @@ def make_results(
scalefactors=output_results.contrastParams.scalefactors,
bulkIn=output_results.contrastParams.bulkIn,
bulkOut=output_results.contrastParams.bulkOut,
resolutionParams=output_results.contrastParams.resolutionParams,
subRoughs=output_results.contrastParams.subRoughs,
resample=output_results.contrastParams.resample,
)
Expand Down
35 changes: 15 additions & 20 deletions RATapi/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,24 @@ def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], tup

"""

def handle(params, bulk_in, bulk_out, contrast, domain=-1):
if domain == -1:
output, sub_rough = getattr(self.engine, self.function_name)(
np.array(params, "float"),
np.array(bulk_in, "float"),
np.array(bulk_out, "float"),
float(contrast + 1),
nargout=2,
def handle(*args):
if len(args) == 2:
output = getattr(self.engine, self.function_name)(
np.array(args[0], "float"), # xdata
np.array(args[1], "float"), # params
nargout=1,
)
return np.array(output, "float").tolist()
else:
output, sub_rough = getattr(self.engine, self.function_name)(
np.array(params, "float"),
np.array(bulk_in, "float"),
np.array(bulk_out, "float"),
float(contrast + 1),
float(domain + 1),
np.array(args[0], "float"), # params
np.array(args[1], "float"), # bulk in
np.array(args[2], "float"), # bulk out
float(args[3] + 1), # contrast
float(-1 if len(args) < 5 else args[4] + 1), # domain
nargout=2,
)
return output, sub_rough
return np.array(output, "float").tolist(), float(sub_rough)

return handle

Expand Down Expand Up @@ -105,11 +104,7 @@ def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], tup

"""

def handle(params, bulk_in, bulk_out, contrast, domain=-1):
if domain == -1:
output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast)
else:
output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast, domain)
return output, sub_rough
def handle(*args):
return self.engine.invoke(*args)

return handle
2 changes: 1 addition & 1 deletion cpp/RAT
Submodule RAT updated 94 files
+61 −45 RATMain.cpp
+40 −38 RATMain_internal_types.h
+27 −6 RATMain_rtwutil.cpp
+8 −6 RATMain_rtwutil.h
+38 −32 RATMain_types.h
+2 −2 adaptive.cpp
+3 −3 adaptive.h
+1 −1 allocateLayersForContrast.cpp
+2 −2 allocateLayersForContrast.h
+1 −1 allocateParamsToLayers.cpp
+3 −3 allocateParamsToLayers.h
+2 −2 applyBackgroundCorrection.cpp
+5 −18 backSort.cpp
+5 −7 backSort.h
+3 −3 boundaryHandling.cpp
+171 −79 callCppFunction.cpp
+14 −9 callCppFunction.h
+43 −105 callReflectivity.cpp
+8 −7 callReflectivity.h
+4 −2 classHandle.hpp
+125 −25 constructBackground.cpp
+10 −8 constructBackground.h
+124 −0 constructResolution.cpp
+33 −0 constructResolution.h
+8 −6 coreLayersCalculation.cpp
+4 −3 coreLayersCalculation.h
+291 −210 customLayers.cpp
+31 −28 customLayers.h
+289 −211 customLayers1.cpp
+31 −31 customLayers1.h
+207 −152 customXY.cpp
+17 −15 customXY.h
+266 −205 customXY1.cpp
+19 −17 customXY1.h
+0 −71 dataResolutionPolly.cpp
+0 −30 dataResolutionPolly.h
+4 −4 deopt.cpp
+1 −1 drawMCMC.cpp
+13 −17 extractProblemParams.cpp
+14 −13 extractProblemParams.h
+1 −1 fMinSearch.cpp
+10 −10 getFitNames.cpp
+11 −11 getFitNames.h
+5 −5 getFittedPriors.cpp
+3 −3 getFittedPriors.h
+9 −9 groupLayersMod.cpp
+1 −1 groupLayersMod.h
+9 −9 groupLayersModImaginary.cpp
+1 −1 groupLayersModImaginary.h
+1 −1 isRATStopped.cpp
+3 −3 makeCell.cpp
+4 −4 makeCell.h
+26 −26 makeEmptyBayesResultsStruct.cpp
+5 −5 makeEmptyBayesResultsStruct.h
+1 −1 nestedSampler.cpp
+8 −0 nsIntraFun.cpp
+1 −1 packParams.cpp
+2 −2 packParams.h
+19 −34 processCustomFunction.cpp
+4 −4 processCustomFunction.h
+6 −20 processCustomFunction1.cpp
+4 −4 processCustomFunction1.h
+29 −56 processCustomFunction2.cpp
+4 −4 processCustomFunction2.h
+7 −33 processCustomFunction3.cpp
+4 −4 processCustomFunction3.h
+3 −3 ratDREAM.cpp
+8 −8 refPercentileConfidenceIntervals.cpp
+5 −5 refPercentileConfidenceIntervals.h
+72 −100 reflectivityCalculation.cpp
+2 −2 resampleLayers.cpp
+1 −1 resampleLayersReIm.cpp
+14 −25 resolutionPolly.cpp
+3 −2 resolutionPolly.h
+2 −2 runDE.cpp
+1 −1 runDREAM.cpp
+4 −4 runNestedSampler.cpp
+2 −2 runNestedSampler.h
+5 −5 runSimplex.cpp
+2 −2 splitEllipsoid.cpp
+287 −202 standardLayers.cpp
+30 −28 standardLayers.h
+300 −217 standardLayers1.cpp
+30 −30 standardLayers1.h
+122 −93 strcmp.cpp
+8 −7 strcmp.h
+2 −2 strjoin.cpp
+3 −3 strjoin.h
+1 −1 strlength.cpp
+2 −2 strlength.h
+3 −3 structConstructorHelper.cpp
+6 −6 structConstructorHelper.h
+9 −9 triggerEvent.cpp
+2 −2 triggerEvent.h
Loading
Loading