# Recipe: the core job

A constellation and ground sites: what sees what, and when. Three forms: catalogue data, your own design, and the same as one program.

## A. Catalogue constellation and ground sites (7 calls)

"What each OneWeb ground site sees above 25 deg in the next 2 hours, then the sky from the busiest site at its busiest minute."

```json
{"verb":"data_find","args":{"query":["operator:OneWeb kind:satellites","OneWeb kind:ground"]}}
```
Each entry in `results` answers its query with `hits`. Take the `ref` of the hit you mean, and note the satellite set's `count` and each hit's `refreshed` and `licence`: you will say them. Free words must appear together in a title or summary, so keep them few. A query with no hit answers `did_you_mean`, single words with their counts; nothing is substituted, so choose and search again.

On Starter the ground-segment catalogues come back `locked: true` (Pro). Say so once, then put the sites the person names with `rows` (form B below); never guess their coordinates.

```json
{"verb":"project_set","args":{"create":{}}}
{"verb":"data_put","args":{"project":"prj_1a2b3c4d5e","items":[
  {"id":"oneweb","ref":{"kind":"satellite-set","id":"<from hit>"}},
  {"id":"gateways","ref":{"kind":"ground","id":"<from hit>"}}]}}
```
Both items are one write and one undo step. The answer gives each layer's `shape`, `rows`, `columns` and `keys_sample` (`time_range` only for data with a time span). Check the satellites' `rows` against the set's `count`. A ground segment's member keys are its `site_id` values, such as `oneweb-sintra-portugal`: take them from answers, never guess them.

Size the visibility before you send it. It stops at 50 million tests, counts included (sites x satellites x instants; `describe {topic:"limits"}`, `access_work`). A ground segment holds the company's sites worldwide. OneWeb's (about 74) with its set (about 650) over 2 h at 60 s (121 instants) is 5.8 million: it fits. Starlink's (about 650 sites) with the Starlink set (about 10,600) is 845 million: read the sites first with `data_read {project, of:"layer:gateways", columns:["site_id","name","kind"], limit:1000}`, then pass the ones you need as `args.site_keys` (38 at most for that set over 2 h at 60 s). One member alone can go as `stations:"gateways/<key>"`; a list of several members is refused.

```json
{"verb":"compute","args":{"project":"prj_1a2b3c4d5e","fn":"visibility",
  "inputs":{"of":"oneweb","stations":"gateways"},
  "args":{"duration":7200,"min_elevation":25}}}
```
The answer waits up to 25 s and carries `summary.stations`, rows identified by `station_id` (the site's key). Each row gives the station's `latitude`, `max_visible`, `mean_visible`, `min_visible` satellites in view, `passes`, `longest_gap_min` and `time_of_max`. Rows come in the layer's order, as many as fit in 4 KB; `summary.total` and `summary.omitted` count the rest (read them with `args.site_keys`). Call r the listed row with the highest `max_visible`.

Read the rest of the answer too:
- `withheld`: over 2,000,000 samples (here 5.8 million) the counts are complete, but `passes` and `pairs` are withheld with the step and window that fit, and each row's `passes` is `null`.
- `pending`: read that output with `data_read {project, of:"output:<id>.visibility", wait_s:25}`; once it lands, its `envelope.summary` has the same `stations` rows. Only a batch computation (coverage, revisit) answers a `run`; read that one with `project_open {project, run}`.
- `errors`: nothing was computed for that computation. Read the message, size the call down, and send it again.

```json
{"verb":"view_set","args":{"project":"prj_1a2b3c4d5e",
  "clock":{"time":"<r.time_of_max>"},
  "camera":{"preset":"sky","target":"gateways/<r.station_id>"}}}
{"verb":"render","args":{"project":"prj_1a2b3c4d5e"}}
{"verb":"show","args":{"project":"prj_1a2b3c4d5e"}}
```
Look at the picture before you write the answer (`check-your-work.md`). Then give the numbers per site, the mask, the window, the data's release, and the `url`.

## B. Your own design and named stations (E1 shape)

"A Walker 1584/72/17 at 550 km and 53 deg; stations at Svalbard (78.23N 15.39E), Inuvik (68.32N 133.54W), Punta Arenas (53.00S 70.85W). Satellites each sees above 10 deg over 24 hours."

```json
{"verb":"project_set","args":{"create":{}}}
{"verb":"compute","args":{"project":"P","fn":"walker",
  "args":{"total":1584,"planes":72,"phasing":17,"altitude":550,"inclination":53}}}
{"verb":"data_put","args":{"project":"P","items":[{"id":"stations","preset":"ground-station","columns":{"id":"site_id"},
  "rows":[{"site_id":"svalbard","name":"Svalbard","latitude":78.23,"longitude":15.39},
          {"site_id":"inuvik","name":"Inuvik","latitude":68.32,"longitude":-133.54},
          {"site_id":"punta_arenas","name":"Punta Arenas","latitude":-53.00,"longitude":-70.85}]}]}}
{"verb":"compute","args":{"project":"P","fn":"visibility",
  "inputs":{"of":"<outputs.elements.layer of the walker answer>","stations":["stations_svalbard","stations_inuvik","stations_punta_arenas"]},
  "args":{"duration":86400,"min_elevation":10}}}
```
- On a new id, up to 200 inline rows with the ground-station preset create individual Ground stations, like Add > Station, without Custom. `site_id` names each row; `items[0].layers` returns `stations_svalbard`, `stations_inuvik`, `stations_punta_arenas`. Pass these ids to compute. If the id already names a ground-station dataset layer, rows replace its whole dataset in place, even with the preset omitted; `items[0].layers` is `[id]`. This replaces all rows, not a single site. Latitude and longitude in degrees, South and West negative; `altitude` in m above sea level (default: 0 m).
- Every answer that makes a layer names it (`outputs.<name>.layer`, `items[].layer`). Pass those ids on; do not guess them.
- Walker defaults to delta: `raan_spread:360` deg. Use `raan_spread:180` (star) for polar or near-polar shells with few planes, or a filing specifying it. Two polar planes then sit at RAAN 0 and 90 deg; 360 gives 0 and 180 deg, the same geometric polar plane in opposite directions. Keep the standard phase offset `F * 360 / total` for both patterns.
- The walker's `epoch` is the project clock unless you give one. A new project's clock runs from now for 24 h, so "the next 24 hours" is `duration:86400` from the clock range's start; give `start` explicitly if the range starts elsewhere. Say so.
- Expect Svalbard at 0, Inuvik at 0 to 1 (it just reaches 10 deg a few times a day) and Punta Arenas around 40: a 53 deg shell at 550 km is seen above 10 deg only up to about 68 deg latitude. That is the right answer, not a bug.
- Size: the counts (max, mean, min) allow up to 50 million station/satellite/instant tests, but passes and the sky view are station and satellite pairs: 3 x 1,584 x 1,441 = 6.8 million, over the 2,000,000 limit. The counts still come; for passes, use a window of 6 h or less at 60 s (3 x 1,584 x 361 = 1.7 million), or one station at a time with a coarser step (120 s fits 24 h). The answer says so itself: `withheld.passes.fits` gives the step and window that fit.
- "Take the analysis back out": `undo {project:"P"}` removes your last write (the visibility) and leaves the walker and the stations. Use `remove {project:"P",ids:["<visibility id>"]}` if other writes came after it.

## C. The same as one program

When the job is a loop (every mask, every candidate site, every shell), send one program instead of many calls (`own-algorithm.md`).

A program reads each input as one layer. Put the candidate sites in one points layer first, without the ground-station preset: `data_put {project:"P", items:[{id:"sites", rows:[{"site_id":"svalbard","latitude":78.23,"longitude":15.39}, ...]}]}`. Form B's typed stations are one layer each. The source is the text of `examples/best_sites.py`, from `describe {topic:"recipes", name:"best_sites.py"}`.

```json
{"verb":"program_run","args":{"project":"P","name":"Highest mask per site",
  "inputs":{"fleet":"<walker layer>","sites":"sites"},
  "source":"<examples/best_sites.py>"}}
```
This saves the program and runs it; the answer names each input's layer, dataset and release, and each output's rows and `assurance`. `check:true` is optional: it only parses the source (syntax, imports, emit slots, parameter defaults, limits), runs nothing and costs a call. A run without it refuses bad source the same way.
