Skip to content

Commit

Permalink
Add last_exposure_no to status reply (#50)
Browse files Browse the repository at this point in the history
* Add last_exposure_no to status reply

* Add specific test for when data was not fetched

* Update changelog
  • Loading branch information
albireox authored Jul 15, 2024
1 parent 2c95cf5 commit 921534f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Dropped support for Python 3.9.

### 🚀 New

* [#50](https://github.com/sdss/archon/pull/50) Added `last_exposure_no` to the output of the `status` command.

### ⚙️ Engineering

* Lint and format using `ruff`.
Expand Down
2 changes: 2 additions & 0 deletions archon/actor/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def status(
"controller": controller.name,
"status": controller.status.value,
"status_names": [flag.name for flag in controller.status.get_flags()],
"last_exposure_no": command.actor.exposure_delegate.last_exposure_no,
}
)
return True
Expand All @@ -57,6 +58,7 @@ async def status(
"controller": controller.name,
"status": controller.status.value,
"status_names": [flag.name for flag in controller.status.get_flags()],
"last_exposure_no": command.actor.exposure_delegate.last_exposure_no,
**status,
}
)
Expand Down
8 changes: 8 additions & 0 deletions archon/actor/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def __init__(self, actor: Actor_co):

self.expose_data: ExposeData | None = None

self.last_exposure_no: int = -1

self.use_shutter: bool = True
self.is_writing: bool = False

Expand Down Expand Up @@ -350,6 +352,10 @@ async def readout(
except Exception as err:
return self.fail(f"Failed reading out: {err}")

if len(c_fdata) == 0:
self.command.error("No data was fetched.")
return False

self.command.debug(f"Readout completed in {time()-t0:.1f} seconds.")

if write is False:
Expand Down Expand Up @@ -389,6 +395,8 @@ async def readout(
for fd in fdata
]

self.last_exposure_no = fdata[0]["exposure_no"]

# Prepare checksum information.
write_checksum: bool = self.config["checksum.write"]
checksum_mode: str = self.config.get("checksum.mode", "md5")
Expand Down
3 changes: 2 additions & 1 deletion archon/etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"properties": {
"controller": { "type": "string" },
"status": { "type": "integer" },
"status_names": { "type": "array", "items": { "type": "string" } }
"status_names": { "type": "array", "items": { "type": "string" } },
"last_exposure_no": { "type": "integer" }
},
"additionalProperties": true,
"required": ["controller", "status", "status_names"]
Expand Down
6 changes: 6 additions & 0 deletions tests/actor/test_command_expose.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ async def test_expose_set_window(delegate, actor: ArchonActor):
hdu = fits.open(filename)
assert hdu[0].data.shape == (200, 200) # type: ignore

command_status = await actor.invoke_mock_command("status -s")
await command_status

assert command_status.status.did_succeed
assert command_status.replies[-2].body["status"]["last_exposure_no"] != -1


async def test_expose_with_dark(delegate, actor: ArchonActor, mocker):
expose_mock = mocker.patch.object(delegate, "expose", return_value=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/actor/test_command_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ async def test_status(actor: ArchonActor):
assert command.status.did_succeed
assert len(command.replies) == 3

assert "last_exposure_no" in command.replies[1].body["status"]
assert command.replies[1].body["status"]["last_exposure_no"] == -1


async def test_status_fail_controller(actor: ArchonActor):
await actor.controllers["sp1"].stop()
Expand Down
19 changes: 19 additions & 0 deletions tests/actor/test_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,25 @@ async def test_delegate_shutter_fails(delegate: ExposureDelegate, mocker):
assert result is False


async def test_delegate_readout_no_fetch_data(delegate: ExposureDelegate):
command = Command("", actor=delegate.actor)
result = await delegate.expose(
command,
[delegate.actor.controllers["sp1"]],
flavour="object",
exposure_time=0.01,
readout=False,
)
assert result is True

assert delegate.expose_data
delegate.expose_data.controllers = []

result = await delegate.readout(command)
assert result is False
assert delegate.command.replies[-1].body["error"] == "No data was fetched."


@pytest.mark.parametrize("window_mode", ["test_mode", "default"])
async def test_delegate_expose_window_mode(delegate: ExposureDelegate, window_mode):
command = Command("", actor=delegate.actor)
Expand Down

0 comments on commit 921534f

Please sign in to comment.