# Chapter refresh record: `orientation`

Ops checklist for **Task 139** — valence flip + `homosex` coding expand, Unity refit, figure regen for [`book/orientation.md`](../../../book/orientation.md).

**Planning doc:** [`book/orientation_plan.md`](../../../book/orientation_plan.md)  
**Data inventory:** [`inventories/orientation_inventory.md`](../../inventories/orientation_inventory.md)  
**Metadata locked:** 2026-09-11 in [`notebooks/utils.py`](../../utils.py) (`SELECTED_VALUES`, y-labels).

---

## Locked coding (2026-09-11)

| Variable | y=1 codes | Action |
|----------|-----------|--------|
| `homosex` | `[1, 2, 3]` | **Expand** (keep wrongness valence) |
| `spkhomo` | `[1]` | Flip → allowed to speak |
| `colhomo` | `[4]` | Flip → allowed to teach |
| `libhomo` | `[2]` | Flip → keep book in library |
| `marsame` / `marsame1` / `marsamey` | `[1, 2]` | Flip → agree / strongly agree |
| `VCF0232` | `51–97` | Flip → warm thermometer |
| `VCF0876` / `VCF0876a` | `[1]` / `[1, 2]` | Flip → favor protection |
| `VCF0877` / `VCF0877a` | `[1]` / `[1, 2]` | Flip → should serve |
| `VCF0878` | `[1]` | Flip → yes, permit adoption |

Chapter embeds only `homosex`, `marsame`, civil-lib trio (composed), ANES battery (composed), `VCF0232`. Strength variants (`VCF0876a`, `VCF0877a`) updated in metadata for consistency; not in Unity lists unless needed later.

---

## Unity refit (Task 94)

**Requires force-refit** — delete stale `.nc` for these variables on Unity (or `FORCE_RUN=1`) because y=1 definition changed.

### 1. Push from local

```bash
cd /home/downey/CultureWar
scripts/unity_rsync.sh push
```

### 2. GSS main battery (2 vars)

```bash
# on Unity, from repo root
N=$(grep -cvE '^\s*(#|$)' slurm/variables_orientation_gss.txt)
sbatch --array=0-$((N-1))%4 slurm/survey_pipeline_array.sh slurm/variables_orientation_gss.txt gss
```

### 3. GSS civil liberties (3 vars)

```bash
N=$(grep -cvE '^\s*(#|$)' slurm/variables_orientation_gss_civil_lib.txt)
sbatch --array=0-$((N-1))%4 slurm/survey_pipeline_array.sh slurm/variables_orientation_gss_civil_lib.txt gss
```

### 4. ANES battery (4 vars)

```bash
N=$(grep -cvE '^\s*(#|$)' slurm/variables_orientation_anes.txt)
sbatch --array=0-$((N-1))%2 slurm/survey_pipeline_array.sh slurm/variables_orientation_anes.txt anes
```

### 5. Pull artifacts

```bash
scripts/unity_rsync.sh pull
```

Record job IDs and completion in this file when submitted.

---

## Local figure regen (after pull)

```bash
conda activate CultureWar
cd /home/downey/CultureWar

# Per-variable (if not already produced on Unity) — Task 149: --extract, not --data-source
for v in homosex marsame; do
  python scripts/run_time_model.py --extract gss_extract_2024_r3a.hdf --variable "$v"
  python scripts/run_cohort_trajectories.py --extract gss_extract_2024_r3a.hdf --variable "$v"
done
ANES=anes_extract_anes_timeseries_cdf_stata_20260205.hdf
for v in VCF0232 VCF0876 VCF0877 VCF0878; do
  python scripts/run_time_model.py --extract "$ANES" --variable "$v"
  python scripts/run_cohort_trajectories.py --extract "$ANES" --variable "$v"
done

# Composed clusters → figs/_composed/composed_{gss_gay_civil_liberties,anes_gay_rights_policy}_*.png
python scripts/run_gss_gay_civil_liberties_cluster_figures.py
python scripts/run_anes_gay_rights_policy_cluster_figures.py

# Task 124 excerpt (VCF0876) + social PNGs
python scripts/run_time_model.py --extract "$ANES" --variable VCF0876 --save-social
python scripts/run_cohort_trajectories.py --extract "$ANES" --variable VCF0876 --save-social
```

Figs land under `notebooks/figs/`; [`book/figs`](../../../book/figs) is a symlink — no copy step. Revise [`book/orientation.md`](../../../book/orientation.md) prose (Phase 4 in prep doc).

---

## Job log

| Date | List | Job ID | Status | Notes |
|------|------|--------|--------|-------|
| 2026-09-11 | `variables_orientation_gss.txt` (2 vars) | **64278029** | **COMPLETED** (2/2 OK) | `homosex` 7:31 / 2.0G; `marsame` 5:15 / 1.5G |
| 2026-09-11 | `variables_orientation_gss_civil_lib.txt` (3 vars) | **64278030** | **COMPLETED** (3/3 OK) | ~6–7 min each / ~1.9G |
| 2026-09-11 | `variables_orientation_anes.txt` (4 vars) | **64278031** | **COMPLETED** (4/4 OK) | 4:22–6:16 / 0.96–1.6G |
| 2026-09-11 | `variables_orientation_anes_vcf0232.txt` | **64279309** | **COMPLETED** (1/1 OK) | `50–97`; 6:58 / 1.1G; tm 7 div; m10 11 div R̂ 1.039 |
| 2026-09-18 | `variables_orientation_gss_parenting.txt` (2 vars) | **64564394** | **FAILED** | NUTS OK; post-write crash: `pd.to_numeric(..., errors="ignore")` invalid under pandas 3; not a data issue |
| 2026-09-18 | `variables_orientation_gss_parenting.txt` (2 vars) | **64564584** | **COMPLETED** (2/2 OK) | ~2:20 / ~0.64G; tm+m10 0 div, R̂≈1.00, ESS>1k; pull 2026-09-18 |

**Pull:** 2026-09-11 local `scripts/unity_rsync.sh pull` — idata under Task **95** paths (`idata/{gss,anes}/{var}/`), figs under `figs/{gss,anes}/{var}/`. Parenting pull 2026-09-18 (`ssfchild` / `ssmchild`).

**Sampling summaries:** `notebooks/tables/orientation_{gss,gss_civil_lib,anes}_unity_sampling_summary.csv`

### Parenting capability follow-on (`ssfchild` / `ssmchild`)

From [`book/orientation_plan.md`](../../../book/orientation_plan.md) follow-on A. Sparse (2 waves) — exploratory fits; expect weak cohort ID.

**Headline (time_model support, agree+strongly):**

| Variable | 2012 | 2022 | Notes |
|----------|------|------|-------|
| `ssfchild` (female couple) | 47.6% | 62.1% | period +12pp; cohort standardized 1923→2004: 29%→73% |
| `ssmchild` (male couple) | 44.3% | 58.9% | similar level/slope; APC shares unstable (2-wave) |

```bash
# local
scripts/unity_rsync.sh push
# on Unity
N=$(grep -cvE '^\s*(#|$)' slurm/variables_orientation_gss_parenting.txt)
CW_TARGET_ACCEPT=0.99 sbatch --array=0-$((N-1))%2 slurm/survey_pipeline_array.sh slurm/variables_orientation_gss_parenting.txt gss
# after COMPLETED
scripts/unity_rsync.sh pull
conda activate CultureWar
python scripts/report_variable_results.py ssfchild --section both
python scripts/report_variable_results.py ssmchild --section both
python scripts/summarize_survey_pipeline_runs.py --list slurm/variables_orientation_gss_parenting.txt --job-id JOBID
```

### VCF0232 refit — neutral + warm (`50–97`)

List: `slurm/variables_orientation_anes_vcf0232.txt`. Force-refit required (coding change from `51–97`).

```bash
scripts/unity_rsync.sh push
N=$(grep -cvE '^\s*(#|$)' slurm/variables_orientation_anes_vcf0232.txt)
sbatch --array=0-$((N-1))%2 slurm/survey_pipeline_array.sh slurm/variables_orientation_anes_vcf0232.txt anes
scripts/unity_rsync.sh pull   # after COMPLETED
```
