Skip to content

Commit

Permalink
Adds code to support recording custom files in "make_cells"
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPaulSharp committed Apr 18, 2024
1 parent 65cccfe commit bd01b64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
17 changes: 1 addition & 16 deletions RAT/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,6 @@ def make_cells(project: RAT.Project) -> Cells:
data_limits.append([0.0, 0.0])
simulation_limits.append([0.0, 0.0])

# Set wrappers for custom function files
file_list = []
for custom_file in project.custom_files:

if custom_file.language == Languages.Matlab:
wrapper = RAT.wrappers.MatlabWrapper(custom_file.filename)
file = wrapper.getHandle()
elif custom_file.language == Languages.Cpp:
wrapper = RAT.wrappers.DylibWrapper(custom_file.filename, pathlib.PurePath(custom_file.filename).stem)
file = wrapper.getHandle()
else:
file = custom_file.filename

file_list.append(pathlib.PurePath(file).stem)

# Populate the set of cells
cells = Cells()
cells.f1 = [[0, 1]] * len(project.contrasts) # This is marked as "to do" in RAT
Expand All @@ -237,7 +222,7 @@ def make_cells(project: RAT.Project) -> Cells:
cells.f11 = [param.name for param in project.bulk_in]
cells.f12 = [param.name for param in project.bulk_out]
cells.f13 = [param.name for param in project.resolution_parameters]
cells.f14 = file_list
cells.f14 = [pathlib.Path(file.filename).stem for file in project.custom_files]
cells.f15 = [param.type for param in project.backgrounds]
cells.f16 = [param.type for param in project.resolutions]

Expand Down
12 changes: 6 additions & 6 deletions tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def standard_layers_project():
"""Add parameters to the default project for a non polarised calculation."""
test_project = RAT.Project(data=RAT.ClassList([RAT.models.Data(name='Simulation', data=np.array([[1.0, 1.0, 1.0]]))]))
test_project.parameters.append(name='Test SLD')
test_project.custom_files.append(name='Test Custom File')
test_project.custom_files.append(name='Test Custom File', filename='matlab_test.m', language='matlab')
test_project.layers.append(name='Test Layer', SLD='Test SLD')
test_project.contrasts.append(name='Test Contrast', data='Simulation', background='Background 1', bulk_in='SLD Air',
bulk_out='SLD D2O', scalefactor='Scalefactor 1', resolution='Resolution 1',
Expand All @@ -30,7 +30,7 @@ def domains_project():
test_project = RAT.Project(calculation=RAT.utils.enums.Calculations.Domains,
data=RAT.ClassList([RAT.models.Data(name='Simulation', data=np.array([[1.0, 1.0, 1.0]]))]))
test_project.parameters.append(name='Test SLD')
test_project.custom_files.append(name='Test Custom File')
test_project.custom_files.append(name='Test Custom File', filename='matlab_test.m', language='matlab')
test_project.layers.append(name='Test Layer', SLD='Test SLD')
test_project.domain_contrasts.append(name='up', model=['Test Layer'])
test_project.domain_contrasts.append(name='down', model=['Test Layer'])
Expand All @@ -45,7 +45,7 @@ def custom_xy_project():
"""Add parameters to the default project for a non polarised calculation and use the custom xy model."""
test_project = RAT.Project(model=RAT.utils.enums.Models.CustomXY)
test_project.parameters.append(name='Test SLD')
test_project.custom_files.append(name='Test Custom File')
test_project.custom_files.append(name='Test Custom File', filename='matlab_test.m', language='matlab')
test_project.contrasts.append(name='Test Contrast', data='Simulation', background='Background 1', bulk_in='SLD Air',
bulk_out='SLD D2O', scalefactor='Scalefactor 1', resolution='Resolution 1',
model=['Test Custom File'])
Expand Down Expand Up @@ -189,7 +189,7 @@ def standard_layers_cells():
cells.f11 = ['SLD Air']
cells.f12 = ['SLD D2O']
cells.f13 = ['Resolution Param 1']
cells.f14 = ['']
cells.f14 = ['matlab_test']
cells.f15 = [RAT.models.Types.Constant]
cells.f16 = [RAT.models.Types.Constant]
cells.f17 = [[0.0, 0.0, 0.0]]
Expand Down Expand Up @@ -217,7 +217,7 @@ def domains_cells():
cells.f11 = ['SLD Air']
cells.f12 = ['SLD D2O']
cells.f13 = ['Resolution Param 1']
cells.f14 = ['']
cells.f14 = ['matlab_test']
cells.f15 = [RAT.models.Types.Constant]
cells.f16 = [RAT.models.Types.Constant]
cells.f17 = [[0.0, 0.0, 0.0]]
Expand Down Expand Up @@ -245,7 +245,7 @@ def custom_xy_cells():
cells.f11 = ['SLD Air']
cells.f12 = ['SLD D2O']
cells.f13 = ['Resolution Param 1']
cells.f14 = ['']
cells.f14 = ['matlab_test']
cells.f15 = [RAT.models.Types.Constant]
cells.f16 = [RAT.models.Types.Constant]
cells.f17 = [[0.0, 0.0, 0.0]]
Expand Down

0 comments on commit bd01b64

Please sign in to comment.