{ "cells": [ { "cell_type": "markdown", "id": "8c162971-0337-491b-a0a8-2153dc9eb7d5", "metadata": {}, "source": [ "# Creating solid files" ] }, { "cell_type": "markdown", "id": "41ccf894-fa58-4bd9-af94-482e219eae66", "metadata": {}, "source": [ "In some ParFlow runs, the geometry is defined by a solid file. You can read more about solid files in the [ParFlow documentation](https://parflow.readthedocs.io/en/latest/files.html#parflow-solid-files-pfsol).\n", "\n", "There are two modes to create a solid file from a domain mask. In the first case, the only mask needed is for the top of the domain. In the second case, masks for each of the six faces of the domains are required.\n", "\n", "The `write_mask_solid` function can work in both modes, depending on the type of argument. We will see its uses in the next examples, where we will create solid files for a HUC domain in both modes.\n", "\n", "***IMPORTANT NOTE 1***: *The second mode is currently only appropriate for CONUS2 subsets and will throw an error if used for CONUS1 domains.*\n", "\n", "***IMPORTANT NOTE 2***: *The `write_mask_solid` function runs the pfmask-to-pfsol script from ParFlow. For this reason, you need to have ParFlow installed and the `PARFLOW_DIR` environment variable pointing to that installation for the following code to work.*" ] }, { "cell_type": "markdown", "id": "2e537360-95bb-4462-af04-eeb8aad1d878", "metadata": {}, "source": [ "## Create a solid file from the top mask for the domain\n", "\n", "First, we need to obtain a mask for the domain. We'll do this for the HUC 14050002. Then we pass the mask to `write_mask_solid`. `mode` is `\"single-mask\"` by default, so we omit it here:" ] }, { "cell_type": "code", "execution_count": 2, "id": "ae417b84-f4ce-4b54-ad09-6009a9c76733", "metadata": {}, "outputs": [], "source": [ "import subsettools as st\n", "import hf_hydrodata as hf\n", "\n", "hf.register_api_pin(\"your_email\", \"your_pin\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "1ea61281-62c5-4ff0-a9f6-9926dfbe0f5d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bounding box: (1224, 1739, 1345, 1811)\n" ] } ], "source": [ "ij_huc_bounds, mask = st.define_huc_domain(hucs=[\"14050002\"], grid=\"conus2\")\n", "print(f\"bounding box: {ij_huc_bounds}\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "dfc1bae0-7877-493f-a7ae-e9e0db11b0ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Wrote mask.pfb\n", "Wrote solidfile and mask_vtk with total z of 2000 meters\n", "{'mask': '/home/ga6/workspace/temp/mask.pfb', 'mask_vtk': '/home/ga6/workspace/temp/mask_vtk.vtk', 'solid': '/home/ga6/workspace/temp/solidfile.pfsol'}\n" ] } ], "source": [ "# Set the PARFLOW_DIR path to your local installation of ParFlow.\n", "# This is only necessary if this environment variable is not already set.\n", "import os\n", "os.environ[\"PARFLOW_DIR\"] = \"/path/to/your/parflow/installation\"\n", "\n", "file_paths = st.write_mask_solid(mask, grid=\"conus2\", write_dir=\"/path/to/your/write/directory\")\n", "\n", "print(file_paths)" ] }, { "cell_type": "markdown", "id": "06b0a759-3eed-4019-a819-7a99c8be0185", "metadata": {}, "source": [ "## Create a solid file from six masks, representing all sides of the domain\n", "\n", "First, we need to get the mask and bounds for our HUC (we use thesame HUC as before). With the multi-mask mode, we also need to pass the domain bounds to `write_mask_solid`, as it needs to subset side masks for the domain." ] }, { "cell_type": "code", "execution_count": 8, "id": "8863afc5-b15d-41a9-9155-e22e88b78198", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bounding box: (1224, 1739, 1345, 1811)\n" ] } ], "source": [ "ij_huc_bounds, mask = st.define_huc_domain(hucs=[\"14050002\"], grid=\"conus2\")\n", "print(f\"bounding box: {ij_huc_bounds}\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "3729e63f-57a6-467a-b48b-4bb8882e54a9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Wrote mask.pfb\n", "Wrote solidfile and mask_vtk with total z of 2000 meters\n", "{'mask': '/home/ga6/workspace/temp/mask.pfb', 'mask_vtk': '/home/ga6/workspace/temp/mask_vtk.vtk', 'solid': '/home/ga6/workspace/temp/solidfile.pfsol', 'mask_top': '/home/ga6/workspace/temp/mask_top.pfb', 'mask_bottom': '/home/ga6/workspace/temp/mask_bottom.pfb', 'mask_back': '/home/ga6/workspace/temp/mask_back.pfb', 'mask_front': '/home/ga6/workspace/temp/mask_front.pfb', 'mask_left': '/home/ga6/workspace/temp/mask_left.pfb', 'mask_right': '/home/ga6/workspace/temp/mask_right.pfb'}\n" ] } ], "source": [ "file_paths = st.write_mask_solid(mask, grid=\"conus2\", write_dir=\"/path/to/your/write/directory\",\n", " mode='multi-mask', ij_bounds=ij_huc_bounds)\n", "print(file_paths)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 5 }