{ "cells": [ { "cell_type": "markdown", "id": "7371b5ed", "metadata": {}, "source": [ "# Accessing ROI Pixel Arrays\n", "\n", "A typical `craterpy` workflow defines regions of interest (ROIs) around craters and computes zonal statistics over a raster with `get_stats`. Sometimes you want the *raw* pixel values inside each ROI so you can run your own analysis (custom statistics, histograms, masking, etc.). `get_arrays` returns those underlying values as masked arrays.\n", "\n", "Here we use the sample data files `moon_craters_km.csv` crater list and `moon.tif` image from `craterpy.sample_data`." ] }, { "cell_type": "code", "execution_count": 1, "id": "17b2981a", "metadata": { "execution": { "iopub.execute_input": "2026-06-16T16:19:12.379897Z", "iopub.status.busy": "2026-06-16T16:19:12.379795Z", "iopub.status.idle": "2026-06-16T16:19:13.456544Z", "shell.execute_reply": "2026-06-16T16:19:13.456178Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/cjtu/projects/craterpy/craterpy/helper.py:19: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)\n", " from tqdm.autonotebook import tqdm\n" ] }, { "data": { "text/plain": [ "CraterDatabase of length 786 with attributes lat, lon, rad, center." ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from craterpy import CraterDatabase, sample_data\n", "\n", "craters = sample_data[\"moon_craters_km.csv\"]\n", "moon_tif = sample_data[\"moon.tif\"]\n", "\n", "cdb = CraterDatabase(craters, \"moon\", units=\"km\")\n", "cdb" ] }, { "cell_type": "markdown", "id": "dc29cc56", "metadata": {}, "source": [ "Add a `rim` annulus region (1 to 1.5 crater radii past the rim), then compute zonal statistics over the raster as usual with [`get_stats`](https://craterpy.readthedocs.io/latest/api.html#craterpy.classes.CraterDatabase.get_stats)." ] }, { "cell_type": "code", "execution_count": null, "id": "1e0d181d", "metadata": { "execution": { "iopub.execute_input": "2026-06-16T16:19:13.458141Z", "iopub.status.busy": "2026-06-16T16:19:13.457915Z", "iopub.status.idle": "2026-06-16T16:19:17.686037Z", "shell.execute_reply": "2026-06-16T16:19:17.685706Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "879bc16e45e941e99418ed93c2a4c187", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating polygons: 0%| | 0/786 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a2d5a3251f544f8b9a92ffb3342cc8f1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Computing Zonal Stats: 0%| | 0/1 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
| \n", " | Diameter (km) | \n", "Latitude | \n", "Longitude | \n", "mean_rim | \n", "count_rim | \n", "std_rim | \n", "
|---|---|---|---|---|---|---|
| 0 | \n", "1145.53 | \n", "34.72 | \n", "-14.91 | \n", "63.856143 | \n", "2857 | \n", "16.150758 | \n", "
| 1 | \n", "996.84 | \n", "-47.77 | \n", "91.99 | \n", "83.909259 | \n", "2700 | \n", "29.274694 | \n", "
| 2 | \n", "875.75 | \n", "8.35 | \n", "30.83 | \n", "60.931741 | \n", "1465 | \n", "16.523376 | \n", "
| 3 | \n", "840.35 | \n", "-7.83 | \n", "53.67 | \n", "68.728070 | \n", "1368 | \n", "15.506291 | \n", "
| 4 | \n", "714.50 | \n", "-20.59 | \n", "-17.29 | \n", "64.739488 | \n", "1094 | \n", "19.162319 | \n", "