Skip to content

Commit fa74529

Browse files
authored
Fix issues with R1 conversion (#94)
* fixed custom xy label and layer index names * added additional test cases
1 parent 21c5c1a commit fa74529

File tree

8 files changed

+1957
-8
lines changed

8 files changed

+1957
-8
lines changed

RATapi/utils/convert.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def r1_to_project_class(filename: str) -> Project:
3737

3838
# R1 uses a different name for custom xy layer model
3939
layer_model = mat_module["type"]
40-
if layer_model == "custom XY profile":
40+
if layer_model.lower() == "custom xy profile":
4141
layer_model = LayerModels.CustomXY
4242
layer_model = LayerModels(layer_model)
4343

@@ -105,7 +105,9 @@ def read_param(names, constrs, values, fits):
105105
f"Background parameter {i}" for i in range(1, mat_project["numberOfBacks"] + 1)
106106
]
107107

108-
if mat_project["numberOfResolutions"] == 1:
108+
# sometimes numberOfResolutions isn't defined: in all these cases there's only one resolution
109+
# maybe from before multiple resolutions were possible?
110+
if getattr(mat_project, "numberOfResolutions", 1) == 1:
109111
mat_project["res_param_names"] = "Resolution parameter 1"
110112
else:
111113
mat_project["res_param_names"] = [
@@ -208,10 +210,11 @@ def read_param(names, constrs, values, fits):
208210
[
209211
Layer(
210212
name=name,
211-
thickness=params[thickness - 1].name,
212-
SLD=params[sld - 1].name,
213-
roughness=params[roughness - 1].name,
214-
hydration=params[hydration - 1].name,
213+
thickness=params[int(thickness) - 1].name,
214+
SLD=params[int(sld) - 1].name,
215+
roughness=params[int(roughness) - 1].name,
216+
# if hydration is not set, it is an empty numpy array, else it is a string representing a number
217+
hydration=params[int(hydration) - 1].name if getattr(hydration, "size", 1) > 0 else "",
215218
hydrate_with=hydrate_with,
216219
)
217220
# R1 layers are 6-item arrays, unpack into a Layer object
@@ -224,7 +227,8 @@ def read_param(names, constrs, values, fits):
224227
if (
225228
isinstance(mat_project["contrastsNumberOfLayers"], int)
226229
and mat_project["contrastsNumberOfLayers"] == 0
227-
or mat_project["contrastsNumberOfLayers"][i] == 0
230+
or isinstance(mat_project["contrastsNumberOfLayers"], list)
231+
and mat_project["contrastsNumberOfLayers"][i] == 0
228232
):
229233
continue
230234
# contrastLayers is not an array, but rather a string with commas between entries
@@ -412,7 +416,7 @@ def convert_parameters(
412416
project.parameters.index(layer.thickness, True),
413417
project.parameters.index(layer.SLD, True),
414418
project.parameters.index(layer.roughness, True),
415-
project.parameters.index(layer.hydration, True),
419+
project.parameters.index(layer.hydration, True) if layer.hydration else empty(shape=(0, 0)),
416420
layer.name,
417421
str(layer.hydrate_with),
418422
]

0 commit comments

Comments
 (0)