## Hinode/XRT Level-0 Image Visualization

Hinode X-Ray Telescope (XRT) Level-0 data are raw CCD images of the solar corona in soft X-rays (2006–present).
The dataset page is at [DARTS](https://darts.isas.jaxa.jp/datasets/darts:hinode-xrt-level0/).

---

### Data Files

Files are organized by observation time under:

```
https://data.darts.isas.jaxa.jp/pub/hinode/xrt/level0/{YYYY}/{MM}/{DD}/H{NNNN}/
```

where `H{NNNN}` is the hour-block directory (e.g., `H0000`, `H0100`, …).
Each FITS file covers one image and is named:

```
XRT{YYYYMMDD}_{HHMMSS}.{decimal}.fits
```

Quick-look PNG images are also available at:

```
https://data.darts.isas.jaxa.jp/pub/hinode/darts/ql/xrt/level0/{YYYY}/{MM}/{DD}/
```

#### Key FITS header keywords

| Keyword    | Example value          | Description |
|------------|------------------------|-------------|
| `DATE_OBS` | `2017-10-12T09:02:20.111` | Observation start time (UTC) |
| `EXPTIME`  | `0.008156`             | Exposure time (seconds) |
| `EC_FW1_`  | `Al_poly`              | Filter wheel 1 setting |
| `EC_FW2_`  | `Open`                 | Filter wheel 2 setting |
| `CDELT1/2` | `8.2288`               | Pixel scale (arcsec/pixel) |
| `CRVAL1/2` | `-216.5`, `-6.9`       | FOV center in helioprojective arcsec |
| `CCD_TMPC` | `-66.3`                | CCD temperature (°C) |
| `DATA_LEV` | `0`                    | Processing level |

---

### Visualization with Python

#### Requirements

```
pip install "sunpy[map]" astropy matplotlib numpy requests
```

#### Helper functions

```python
import re
import requests
import numpy as np
import matplotlib.pyplot as plt
import sunpy.map
from astropy.utils.data import download_file

BASE = "https://data.darts.isas.jaxa.jp/pub/hinode/xrt/level0"

def list_xrt_files(year, month, day):
    """List all FITS files for a given date."""
    date_url = f"{BASE}/{year:04d}/{month:02d}/{day:02d}/"
    resp = requests.get(date_url, timeout=30)
    if resp.status_code != 200:
        return []
    hblocks = re.findall(r'href="(H\d{4}/)"', resp.text)
    files = []
    for hb in hblocks:
        resp2 = requests.get(date_url + hb, timeout=30)
        names = re.findall(r'href="(XRT\w+\.fits)"', resp2.text)
        files.extend([date_url + hb + n for n in names])
    return files
```

#### Example 1: Display a single image with sunpy

sunpy automatically applies the `hinodexrt` colormap and an appropriate intensity normalization.

```python
url = list_xrt_files(2017, 10, 12)[0]
local = download_file(url, cache=True)

xmap = sunpy.map.Map(local)
print(f"Date: {xmap.date}")
print(f"Filter: {xmap.meta['EC_FW1_']} / {xmap.meta['EC_FW2_']}")
print(f"Exposure: {xmap.meta['EXPTIME']:.4f} s")
print(f"Scale: {xmap.scale[0]:.2f}/pix")

fig = plt.figure(figsize=(7, 7))
ax = fig.add_subplot(projection=xmap)
xmap.plot(axes=ax)
xmap.draw_limb(axes=ax)
xmap.draw_grid(axes=ax)
plt.title(f"Hinode/XRT  {xmap.date}  [{xmap.meta['EC_FW1_']} / {xmap.meta['EC_FW2_']}]")
plt.tight_layout()
plt.savefig("hinode_xrt_single.png", dpi=150, bbox_inches="tight")
plt.close()
```

#### Example 2: Browse multiple images in a day as a thumbnail grid

```python
urls = list_xrt_files(2017, 10, 12)
print(f"{len(urls)} files found")

step = max(1, len(urls) // 9)
selected = urls[::step][:9]

fig, axes = plt.subplots(3, 3, figsize=(12, 12))
for ax, url in zip(axes.flat, selected):
    local = download_file(url, cache=True)
    xmap = sunpy.map.Map(local)
    xmap.plot(axes=ax, annotate=False)
    ax.set_title(xmap.date.strftime("%H:%M:%S"), fontsize=8)
    ax.set_axis_off()

fig.suptitle("Hinode/XRT 2017-10-12 (sample)")
plt.tight_layout()
plt.savefig("hinode_xrt_grid.png", dpi=150, bbox_inches="tight")
plt.close()
```

#### Example 3: Simple display without sunpy

```python
from astropy.io import fits
import matplotlib.colors as colors

local = download_file(list_xrt_files(2017, 10, 12)[0], cache=True)

with fits.open(local) as hdul:
    image = hdul[0].data.astype(float)
    header = hdul[0].header

# Level-0 images are in raw DN; clip to positive values before log scaling
vmin = np.percentile(image, 1)
image_clipped = np.clip(image, max(vmin, 1), None)

fig, ax = plt.subplots(figsize=(7, 7))
im = ax.imshow(image_clipped, origin="lower", cmap="hot",
               norm=colors.LogNorm())
fig.colorbar(im, ax=ax, label="Intensity (DN)")
ax.set_title(f"Hinode/XRT  {header['DATE_OBS']}\n"
             f"{header['EC_FW1_']} / {header['EC_FW2_']}  "
             f"exp={header['EXPTIME']:.4f} s")
plt.tight_layout()
plt.savefig("hinode_xrt_simple.png", dpi=150, bbox_inches="tight")
plt.close()
```

---

### Notes

- Level-0 data are not corrected for dark current, vignetting, or CCD artifacts. For science use, calibrated data processed with `xrt_prep.pro` in SSW/IDL is recommended.
- The two filter wheel settings (`EC_FW1_`, `EC_FW2_`) determine the temperature response of each image. Different combinations give sensitivity to different coronal temperatures (typically 6.0–8.0 in log T).
- The pixel scale is 8.2288 arcsec/pixel for full-resolution images (2048×2048), but many observations use CCD summing (e.g., this example is 256×256 due to `CHIP_SUM = 8`).

---

### Acknowledgement

When using this data in publications, please follow the [Hinode data use guidelines](https://darts.isas.jaxa.jp/missions/hinode/guidelines.html) and cite:

- Kosugi, T. et al. (2007), Sol. Phys., 243, 3. [doi:10.1007/s11207-007-9014-6](https://doi.org/10.1007/s11207-007-9014-6) — Hinode mission
- Golub, L. et al. (2007), Sol. Phys., 243, 223. [doi:10.1007/s11207-007-0182-1](https://doi.org/10.1007/s11207-007-0182-1) — XRT instrument
