Commit e975ddc9 authored by vertighel's avatar vertighel
Browse files

Fase 2 templates: unificati observation.py e snapshot.py



- observation.py cancellato: era divergente da snapshot.py (mancava
  "imagetyp" in fih_params, binning solo scalare, nessun guard
  _NO_FILTER_CAMERAS -- avrebbe pilotato una filter wheel inesistente
  su cam3/echelle, logica di dome-slew nel loop di esposizione).
  Unificato su snapshot.py, che ha gia' tutti e 4 i fix.
- bias.py, box.py, flat.py, skyflat.py: importano ora Template as
  Snapshot da .snapshot invece che da .observation.
- defaults/observation.json: campo "template" ripuntato da
  "observation" a "snapshot" (il preset resta, era l'unico altro
  chiamante rimasto, un modulo da caricare dinamicamente via
  importlib in sequencer.py -- se non lo si ripunta va in
  ModuleNotFoundError a runtime).
- Trovato in corso di confronto: il default camera di observation.py
  era "cam", inesistente in devices.ini (solo cam1/cam2/cam3) --
  avrebbe sollevato un AttributeError non gestito (il try cattura solo
  KeyError). Il default "cam1" di snapshot.py e' quello corretto ed e'
  quello rimasto. Confermato nessun chiamante vivo imposta mai
  domeslewing=True (l'unica route API che lo faceva vive solo in
  noctua/api/camera.py~, backup dell'editor gitignored, non sorgente
  reale) -- eliminare quel blocco morto insieme al resto di
  observation.py non cambia il comportamento di nessun chiamante
  attuale.
- Trovato en passant (non risolto qui, solo loggato in PLAN.md):
  box.py/focus.py/focus2.py/testpause.py fanno tutti `from ..devices
  import cam`, che non esiste in devices.ini (solo cam1/cam2/cam3) --
  ImportError oggi. focus.py/focus2.py restano in scope per questa
  fase, box.py/testpause.py deferred.
- PLAN.md: checklist Fase 2 aggiornata, scope di questo pass limitato
  a snapshot/observation/fillheader/focus (deciso con l'utente), resto
  marcato deferred ma non perso.

Co-Authored-By: default avatarClaude Sonnet 5 <noreply@anthropic.com>
parent 28c9a278
Loading
Loading
Loading
Loading
+68 −27
Original line number Diff line number Diff line
@@ -64,6 +64,17 @@ just style)
  focus.py, or discard focus2.py.
- **`testsonoff.py`** (templates): entire file commented out, imports
  a device (`sof`) that doesn't exist. Delete.
- **`box.py`/`focus.py`/`focus2.py`/`testpause.py` import a `cam` that
  doesn't exist** (templates, found post-Phase-0 while resolving
  `observation.py`/`snapshot.py`): all four do `from ..devices import
  cam`, but `devices.ini` only defines `cam1`/`cam2`/`cam3` sections
  (`noctua/devices/__init__.py`'s `dynamic_import` sets each device as
  an attribute named after its `devices.ini` section, so the module
  only ever gets `cam1`/`cam2`/`cam3`, never a bare `cam`) — importing
  any of these four files raises `ImportError` today. `focus.py`/
  `focus2.py` are in scope for this phase-2 pass (see below) and need
  this fixed as part of resolving which one to keep; `box.py`/
  `testpause.py` are deferred along with the rest of their files.
- **`domotics.py`** (devices): `get()`/`put()` (lines 25-26, 58-59)
  start with a bare `return` before any body — every property built on
  them is silently non-functional. Currently not instantiated
@@ -175,40 +186,70 @@ during the devices phase (no hardware needed); CCD-TEMP is still open.

### 2. Templates

- [ ] Resolve `observation.py` vs `snapshot.py` (see above).
- [ ] Resolve `focus.py` vs `focus2.py` (see above).
- [ ] Delete `testsonoff.py`.
- [ ] Unify error handling: most templates use
**Scope decision (this pass):** only `snapshot.py`, `observation.py`,
`fillheader.py`, `focus.py`/`focus2.py` are touched in this phase 2
pass. Everything else audited below is a real, still-open finding —
not dropped — but explicitly deferred to a later templates pass so it
isn't lost. Don't pick up a deferred item opportunistically just
because a file is open for another reason; re-scope explicitly first.

- [x] Resolve `observation.py` vs `snapshot.py` (see above). In scope.
      Unified on `snapshot.py`: `observation.py` deleted, its 4
      callers (`bias.py`/`box.py`/`flat.py`/`skyflat.py`) now import
      `Template as Snapshot` from `.snapshot`, `defaults/observation.
      json`'s `"template"` field repointed from `"observation"` to
      `"snapshot"` (that JSON preset itself is kept — it's a real,
      distinct full-frame/no-filter default, just was pointing at the
      module being deleted). Also found and fixed in passing while
      comparing the two files: `observation.py`'s default camera name
      was `"cam"`, which doesn't exist in `devices.ini` (only
      `cam1`/`cam2`/`cam3`) — would have raised an uncaught
      `AttributeError` (the `try` only catches `KeyError`); `snapshot.
      py`'s default of `"cam1"` is correct and is what's kept.
      Confirmed no live caller ever sets `domeslewing=True` (the one
      API route that did lives only in `noctua/api/camera.py~`, a
      gitignored editor backup, not real source) so dropping that dead
      block with the rest of `observation.py` is not a behavior change
      for any current caller.
- [ ] Resolve `focus.py` vs `focus2.py` (see above). In scope.
- [ ] `fillheader.py:212-217` swallows FITS-writing errors silently
      (logs only, no `self.error`, no `return`, falls through to save
      anyway) — align with the standard error pattern. In scope.
- [ ] Add docstrings to `fillheader.py`, `focus.py`, `observation.py`/
      `snapshot.py` (the in-scope subset of the fuller list below). In
      scope.
- [ ] Remove dead/commented-out blocks: `fillheader.py` (large
      commented WCS block), `observation.py:28-33` (the in-scope
      subset of the fuller list below). In scope.
- [ ] *(deferred)* Delete `testsonoff.py`.
- [ ] *(deferred)* Unify error handling: most templates use
      `except KeyError: log.error(...)` without `self.error.append()`
      or a `return` afterward (real bug — execution falls through
      using possibly-missing params) — `acquisition.py`, `bias.py`,
      `flat.py`, `skyflat.py`, `box.py` all need this fixed to match
      the `snapshot.py`/`observation.py` pattern (`self.error.append`
      + `return`).
- [ ] `lampsoff.py`, `testoutput.py`, `testpause.py` set `self.name =
      __name__` (produces `"noctua.templates.lampsoff"`) instead of a
      short string — inconsistent with every other template and with
      what `sequencer.py`'s log messages expect.
- [ ] `testoutput.py`'s description string is copy-pasted from
      `lampsoff.py` and wrong for what the file does — fix.
- [ ] `flat.py:62-76` — the telescope-move wait loop doesn't call
      `check_pause_or_abort()`, so an abort mid-slew isn't honored.
- [ ] `fillheader.py:212-217` swallows FITS-writing errors silently
      (logs only, no `self.error`, no `return`, falls through to save
      anyway) — align with the standard error pattern.
- [ ] Add docstrings to the templates that have none (`bias.py`,
      `box.py`, `fillheader.py`, `focus.py`, `observation.py`/
      `snapshot.py`, `testlamp.py`, `testpause.py`).
- [ ] Remove dead/commented-out blocks: `fillheader.py` (large
      commented WCS block), `observation.py:28-33`,
- [ ] *(deferred)* `lampsoff.py`, `testoutput.py`, `testpause.py` set
      `self.name = __name__` (produces `"noctua.templates.lampsoff"`)
      instead of a short string — inconsistent with every other
      template and with what `sequencer.py`'s log messages expect.
- [ ] *(deferred)* `testoutput.py`'s description string is
      copy-pasted from `lampsoff.py` and wrong for what the file
      does — fix.
- [ ] *(deferred)* `flat.py:62-76` — the telescope-move wait loop
      doesn't call `check_pause_or_abort()`, so an abort mid-slew
      isn't honored.
- [ ] *(deferred)* Add docstrings to the remaining templates that
      have none: `bias.py`, `box.py`, `testlamp.py`, `testpause.py`.
- [ ] *(deferred)* Remove dead/commented-out blocks in
      `sequencer.py:37-38,218-219,252-259`.
- [ ] Translate remaining Italian comments (`sequencer.py:40,42,47`,
      `skyflat.py:78`).
- [ ] `testpause.py` is the only file using `@check.content_errors`
      an orphaned pattern (its failure mode, `self.paused = True`,
      doesn't match the standard `self.error.append`+`return`) — decide
      whether to adopt it properly or drop it in favor of the standard
      pattern.
- [ ] *(deferred)* Translate remaining Italian comments
      (`sequencer.py:40,42,47`, `skyflat.py:78`).
- [ ] *(deferred)* `testpause.py` is the only file using
      `@check.content_errors`an orphaned pattern (its failure mode,
      `self.paused = True`, doesn't match the standard
      `self.error.append`+`return`) — decide whether to adopt it
      properly or drop it in favor of the standard pattern.

### 3. API

+1 −1
Original line number Diff line number Diff line
    {"template" : "observation",
    {"template" : "snapshot",
     "params": {
         "object": "test object",
         "binning": 1,
+5 −5
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
# Other templates
from ..utils.logger import log
from .basetemplate import BaseTemplate
from .observation import Template as Observation
from .snapshot import Template as Snapshot


class Template(BaseTemplate):
@@ -37,11 +37,11 @@ class Template(BaseTemplate):

        params.update(fixed)

        ###################################
        ##### Calling Observation tpl #####
        ###################################
        ################################
        ##### Calling Snapshot tpl #####
        ################################

        obs = Observation()
        obs = Snapshot()
        obs.run(params)

        return
+7 −7
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
from ..devices import cam
from ..utils.logger import log
from .basetemplate import BaseTemplate
from .observation import Template as Observation
from .snapshot import Template as Snapshot


class Template(BaseTemplate):
@@ -58,12 +58,12 @@ class Template(BaseTemplate):
            f"Camera windows now: xrange {cam.xrange}, yrange {cam.yrange}")
        log.info(f"Which means start xy: {cam.xystart}, end xy: {cam.xyend}")

        ##################################
        ##### Calling Observation tpl ####
        ##################################
        ################################
        ##### Calling Snapshot tpl #####
        ################################

        # Adding Obs xy parameters,
        # otherwise it takes the full frame
        # Adding xy parameters, otherwise snapshot leaves the
        # camera's current windowing untouched.
        obs_params = {
            "xystart": cam.xystart,
            "xyend": cam.xyend
@@ -71,7 +71,7 @@ class Template(BaseTemplate):

        params.update(obs_params)

        obs = Observation()
        obs = Snapshot()
        obs.run(params)

        return
+5 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ from ..config.constants import dome_park_position, telescope_flat_position
from ..devices import dom, tel
from ..utils.logger import log
from .basetemplate import BaseTemplate
from .observation import Template as Observation
from .snapshot import Template as Snapshot


class Template(BaseTemplate):
@@ -100,11 +100,11 @@ class Template(BaseTemplate):

        log.info(f"Dome is moving? {dom.is_moving}")

        ##################################
        ##### Calling Observation tpl ####
        ##################################
        ################################
        ##### Calling Snapshot tpl #####
        ################################

        obs = Observation()
        obs = Snapshot()
        obs.run(params)

        return
Loading