From 2d1d1d43102bafd5561b262616d39dc1687cd8f1 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Thu, 5 Nov 2026 06:18:07 -0800 Subject: [PATCH] rename the xarray export's period dims The dim per is now kper, including the coordinate on a period list's sparse entry dim, and a period array's _period is now _kper. The labels are kper values, 0-based. Names only: to_xarray's return types, its dense default and sparse=True don't change. An export written under the old dims doesn't load back. Co-Authored-By: Claude Opus 5.5 --- docs/examples/period-data.ipynb | 315 ++++++++--------------------- docs/examples/period-data.py | 14 +- flopy4/attrs_xarray.py | 8 +- flopy4/mf6/package.py | 6 +- flopy4/mf6/period_lists.py | 26 +-- test/mf6/test_mf6_component.py | 10 +- test/mf6/test_mf6_period_arrays.py | 16 +- test/mf6/test_mf6_period_lists.py | 21 +- 8 files changed, 135 insertions(+), 281 deletions(-) diff --git a/docs/examples/period-data.ipynb b/docs/examples/period-data.ipynb index 8f638ec93..0e8742f23 100644 --- a/docs/examples/period-data.ipynb +++ b/docs/examples/period-data.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "154b7f09", + "id": "aea001d3", "metadata": {}, "source": [ "# Period data\n", @@ -17,7 +17,7 @@ }, { "cell_type": "markdown", - "id": "35b8fccf", + "id": "d820392b", "metadata": {}, "source": [ "### Imports" @@ -26,15 +26,8 @@ { "cell_type": "code", "execution_count": 1, - "id": "3782bb4e", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:37:58.221443Z", - "iopub.status.busy": "2026-10-19T13:37:58.221223Z", - "iopub.status.idle": "2026-10-19T13:37:58.230186Z", - "shell.execute_reply": "2026-10-19T13:37:58.229494Z" - } - }, + "id": "ad42619b", + "metadata": {}, "outputs": [], "source": [ "from pathlib import Path" @@ -43,15 +36,8 @@ { "cell_type": "code", "execution_count": 2, - "id": "60e9c29c", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:37:58.232257Z", - "iopub.status.busy": "2026-10-19T13:37:58.232096Z", - "iopub.status.idle": "2026-10-19T13:37:58.628555Z", - "shell.execute_reply": "2026-10-19T13:37:58.628175Z" - } - }, + "id": "7ca1bfaa", + "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", @@ -61,15 +47,8 @@ { "cell_type": "code", "execution_count": 3, - "id": "1536d100", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:37:58.629897Z", - "iopub.status.busy": "2026-10-19T13:37:58.629805Z", - "iopub.status.idle": "2026-10-19T13:38:00.322930Z", - "shell.execute_reply": "2026-10-19T13:38:00.322495Z" - } - }, + "id": "8c7d28d1", + "metadata": {}, "outputs": [], "source": [ "from flopy4.mf6.constants import FILL_DNODATA\n", @@ -83,7 +62,7 @@ }, { "cell_type": "markdown", - "id": "a5e21289", + "id": "5c53b8e3", "metadata": {}, "source": [ "### A small model\n", @@ -95,15 +74,8 @@ { "cell_type": "code", "execution_count": 4, - "id": "63ae5c5c", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:38:00.324664Z", - "iopub.status.busy": "2026-10-19T13:38:00.324457Z", - "iopub.status.idle": "2026-10-19T13:38:00.326731Z", - "shell.execute_reply": "2026-10-19T13:38:00.326343Z" - } - }, + "id": "1ac18104", + "metadata": {}, "outputs": [], "source": [ "try:\n", @@ -116,15 +88,8 @@ { "cell_type": "code", "execution_count": 5, - "id": "a22ee461", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:38:00.327775Z", - "iopub.status.busy": "2026-10-19T13:38:00.327694Z", - "iopub.status.idle": "2026-10-19T13:38:00.332709Z", - "shell.execute_reply": "2026-10-19T13:38:00.332369Z" - } - }, + "id": "79404244", + "metadata": {}, "outputs": [], "source": [ "grid = StructuredGrid(\n", @@ -142,7 +107,7 @@ }, { "cell_type": "markdown", - "id": "a25fb155", + "id": "2328f9e2", "metadata": {}, "source": [ "### Rows\n", @@ -159,15 +124,8 @@ { "cell_type": "code", "execution_count": 6, - "id": "05c7baf5", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:38:00.333832Z", - "iopub.status.busy": "2026-10-19T13:38:00.333768Z", - "iopub.status.idle": "2026-10-19T13:38:00.337101Z", - "shell.execute_reply": "2026-10-19T13:38:00.336828Z" - } - }, + "id": "31204486", + "metadata": {}, "outputs": [], "source": [ "pumping = Ts.from_series(pd.Series([-1.0, -3.0], index=[0.0, 3.0], name=\"pumping\"))" @@ -175,7 +133,7 @@ }, { "cell_type": "markdown", - "id": "46c4c5cf", + "id": "f51f34aa", "metadata": {}, "source": [ "Periods fill forward: a period without a block repeats the last one, and an\n", @@ -186,15 +144,8 @@ { "cell_type": "code", "execution_count": 7, - "id": "971730ed", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:38:00.338345Z", - "iopub.status.busy": "2026-10-19T13:38:00.338283Z", - "iopub.status.idle": "2026-10-19T13:38:00.341287Z", - "shell.execute_reply": "2026-10-19T13:38:00.340940Z" - } - }, + "id": "ea26eedc", + "metadata": {}, "outputs": [], "source": [ "wel = Wel(\n", @@ -217,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "747a750a", + "id": "824dbac9", "metadata": {}, "source": [ "Rows come back as `Wel.PeriodData` objects, which can also be built\n", @@ -227,15 +178,8 @@ { "cell_type": "code", "execution_count": 8, - "id": "c6544763", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:38:00.342306Z", - "iopub.status.busy": "2026-10-19T13:38:00.342235Z", - "iopub.status.idle": "2026-10-19T13:38:00.344572Z", - "shell.execute_reply": "2026-10-19T13:38:00.344224Z" - } - }, + "id": "65385eb1", + "metadata": {}, "outputs": [ { "name": "stdout", @@ -256,12 +200,12 @@ }, { "cell_type": "markdown", - "id": "d59310e9", + "id": "baaf753b", "metadata": {}, "source": [ "### The array view\n", "\n", - "`to_xarray()` gives a variable per value column on `(per, layer, row, col)`,\n", + "`to_xarray()` gives a variable per value column on `(kper, layer, row, col)`,\n", "with every period filled forward. Empty cells hold `FILL_DNODATA` (3e30).\n", "\n", "* Each auxiliary variable is its own variable (`conc`).\n", @@ -274,15 +218,8 @@ { "cell_type": "code", "execution_count": 9, - "id": "0cbac9bc", - "metadata": { - "execution": { - "iopub.execute_input": "2026-10-19T13:38:00.345605Z", - "iopub.status.busy": "2026-10-19T13:38:00.345546Z", - "iopub.status.idle": "2026-10-19T13:38:00.353995Z", - "shell.execute_reply": "2026-10-19T13:38:00.353647Z" - } - }, + "id": "88443c8c", + "metadata": {}, "outputs": [ { "data": { @@ -766,14 +703,14 @@ " stroke-width: 0.8px;\n", "}\n", "
<xarray.Dataset> Size: 1kB\n",
-       "Dimensions:    (per: 3, layer: 1, row: 3, col: 4)\n",
+       "Dimensions:    (kper: 3, layer: 1, row: 3, col: 4)\n",
        "Coordinates:\n",
-       "    q_ts       (per, layer, row, col) object 288B nan nan nan ... nan nan nan\n",
-       "    boundname  (per, layer, row, col) object 288B 'north' nan nan ... nan nan\n",
-       "Dimensions without coordinates: per, layer, row, col\n",
+       "    q_ts       (kper, layer, row, col) object 288B nan nan nan ... nan nan nan\n",
+       "    boundname  (kper, layer, row, col) object 288B 'north' nan nan ... nan nan\n",
+       "Dimensions without coordinates: kper, layer, row, col\n",
        "Data variables:\n",
-       "    q          (per, layer, row, col) float64 288B -1.0 3e+30 ... 3e+30 3e+30\n",
-       "    conc       (per, layer, row, col) float64 288B 5.0 3e+30 ... 3e+30 3e+30