Skip to content

Commit

Permalink
test telescope creation with RowData
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeyers314 committed May 16, 2024
1 parent 56fb6ac commit 4e41779
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions tests/test_table_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def create_table():
table["shift"] = np.array(
[(0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5)], dtype=shift_dtype
)
table["shift"].unit = u.m
table["shift"].unit = u.mm
# Some more values for setting up a telescope
table["camera"] = ["LsstCam", "LsstCam", "LsstComCamSim", "LsstComCamSim"]
table["focusZ"] = [-1.0, -0.5, 0.0, 0.5] * u.mm

table.pprint_all()
return table
Expand Down Expand Up @@ -146,7 +149,7 @@ def check_row_data(config, idx):
# Read the str column
s, safe = RowData({"field": "str"}, config, str)
assert safe == True
assert s == chr(ord("a") + idx)
assert s == "abcd"[idx]

# Can't specify to_unit for str
with np.testing.assert_raises(ValueError):
Expand Down Expand Up @@ -183,9 +186,9 @@ def check_row_data(config, idx):
shift, safe = RowData({"field": "shift", "to_unit": "cm"}, config, list)
assert safe == True
assert len(shift) == 3
np.testing.assert_allclose(shift[0], idx * 100, rtol=0, atol=1e-15)
np.testing.assert_allclose(shift[1], (idx + 1) * 100, rtol=0, atol=1e-15)
np.testing.assert_allclose(shift[2], (idx + 2) * 100, rtol=0, atol=1e-15)
np.testing.assert_allclose(shift[0], idx / 10, rtol=0, atol=1e-15)
np.testing.assert_allclose(shift[1], (idx + 1) / 10, rtol=0, atol=1e-15)
np.testing.assert_allclose(shift[2], (idx + 2) / 10, rtol=0, atol=1e-15)


def test_table_row():
Expand Down Expand Up @@ -227,6 +230,36 @@ def test_table_row():
idx = idx0 * 2 + idx1
check_row_data(config, idx)

# Try loading a telescope using row_data for just one idx
config["input"]["telescope"] = {
"file_name": "LSST_r.yaml",
"perturbations": {
"LSSTCamera": {
"shift": {
"type":"RowData",
"field": "shift",
"to_unit": "m"
},
"rotX": {
"type": "RowData",
"field": "tilt",
"subfield": "rx",
}
}
},
"rotTelPos": {
"type": "RowData",
"field": "angle1",
},
}
galsim.config.ProcessInput(config)
telescope = galsim.config.GetInputObj(
'telescope',
config['input']['telescope'],
config,
'telescope'
)


if __name__ == "__main__":
testfns = [v for k, v in vars().items() if k[:5] == 'test_' and callable(v)]
Expand Down

0 comments on commit 4e41779

Please sign in to comment.