diff --git a/.github/workflows/hsp2-pip-install-test.yml b/.github/workflows/hsp2-pip-install-test.yml index 16f7db1c..92eda6d9 100644 --- a/.github/workflows/hsp2-pip-install-test.yml +++ b/.github/workflows/hsp2-pip-install-test.yml @@ -1,87 +1,94 @@ +--- name: Python application -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master", "develop", "develop-specact" ] +on: # yamllint disable-line rule:truthy + push: + branches: [master] + pull_request: + branches: [master, develop, develop-specact] permissions: - contents: read + contents: read jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" - cache: "pip" - - name: Install dependencies - run: | - pip install flake8 - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 --show-source --statistics --exclude=build/* - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - test-pytest: - runs-on: ubuntu-latest - continue-on-error: true - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] - pandas-version: [""] - include: - - python-version: "3.11" - pandas-version: "pandas>2.0" - coverage: true - - python-version: "3.11" - pandas-version: "pandas>1.5,<2.0" - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - cache: "pip" - - name: Install hsp2 - run: | - # install the hsp2 executable - pip install .[dev] - - if: ${{ matrix.pandas-version }} - run: pip install "${{ matrix.pandas-version }}" - - if: ${{ matrix.coverage }} - run: | - # python coverage - NUMBA_DISABLE_JIT=1 pytest --cov --cov-branch --cov-report term-missing - - if: ${{ ! matrix.coverage }} - run: pytest - - test-cmd: - runs-on: ubuntu-latest - continue-on-error: true - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - cache: "pip" - - name: Install hsp2 - run: | - # install the hsp2 executable - pip install . - - name: Run hsp2 - run: | - # TODO: find much shorter test case. - hsp2 import_uci ./tests/test10/HSP2results/test10.uci _temp_test10.h5 - hsp2 run _temp_test10.h5 - + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: pip + - name: Install dependencies + run: | + pip install flake8 + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or + # undefined names + flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 \ + --show-source --statistics --exclude=build/* + # exit-zero treats all errors as warnings. + # The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 \ + --max-line-length=127 --statistics + + test-pytest: + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + python-version: ['3.9', '3.10', '3.11', '3.12'] + pandas-version: [''] + include: + - python-version: '3.11' + pandas-version: pandas>2.0 + coverage: true + - python-version: '3.11' + pandas-version: pandas>1.5,<2.0 + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: pip + - name: Install hsp2 + run: | + # install the hsp2 executable + pip install .[dev] + - if: ${{ matrix.pandas-version }} + run: pip install "${{ matrix.pandas-version }}" + - if: ${{ matrix.coverage }} + run: | + # python coverage + NUMBA_DISABLE_JIT=1 pytest --cov --cov-branch --cov-report \ + term-missing + - if: ${{ ! matrix.coverage }} + run: pytest + + test-cmd: + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + python-version: ['3.9', '3.10', '3.11', '3.12'] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: pip + - name: Install hsp2 + run: | + # install the hsp2 executable + pip install . + - name: Run hsp2 + run: | + # TODO: find much shorter test case. + hsp2 import_uci \ + ./tests/test10/HSP2results/test10.uci \ + _temp_test10.h5 + hsp2 run _temp_test10.h5 diff --git a/.gitignore b/.gitignore index 8cad0c9b..7a22225a 100644 --- a/.gitignore +++ b/.gitignore @@ -68,7 +68,7 @@ tests/GLWACSO/HSP2results/hspp007.uci tests/test_report_conversion.html # Omit big files -tests/**/*.h5 +tests/**/**/*.h5 tests/testcbp/HSP2results/*.csv # R files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..bdc42a59 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,96 @@ +--- +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +exclude: | + (?x)^( + .*\.hbn| + .*\.wdm| + .*\.hdf5| + .*\.h5 + )$ + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-case-conflict + - id: check-docstring-first + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-toml + - id: check-xml + - id: end-of-file-fixer + exclude: notebooks/tstoolbox_plot_bash.sh + - id: fix-encoding-pragma + args: [--remove] + - id: mixed-line-ending + - id: trailing-whitespace + exclude: notebooks/tstoolbox_plot_bash.sh + + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.5.5 + hooks: + # Run the linter. + # Uncomment the following lines to enable the linter. + # Right now way to many things fail. + # - id: ruff + # types_or: [python, pyi, jupyter] + # args: [--fix] + + # Run the linter sort imports. + - id: ruff + types_or: [python, pyi, jupyter] + args: [--select, I, --fix] + + # Run the formatter. + - id: ruff-format + types_or: [python, pyi, jupyter] + + - repo: https://github.com/pappasam/toml-sort + rev: v0.23.1 + hooks: + - id: toml-sort-fix + args: [--in-place, --spaces-indent-inline-array, '4'] + + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.35.1 + hooks: + - id: yamllint + args: [--format, parsable, --strict] + + - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt + rev: 0.2.3 + hooks: + - id: yamlfmt + + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shellcheck + args: [-s, bash] + + - repo: https://github.com/lovesegfault/beautysh + rev: v6.2.1 + hooks: + - id: beautysh + args: [--indent-size, '4'] + + - repo: https://github.com/asottile/blacken-docs + rev: 1.18.0 + hooks: + - id: blacken-docs + + - repo: https://github.com/asottile/pyupgrade + rev: v3.16.0 + hooks: + - id: pyupgrade + + - repo: https://github.com/commitizen-tools/commitizen + rev: v3.28.0 + hooks: + - id: commitizen + stages: [commit-msg] diff --git a/HSP2_Driver.py b/HSP2_Driver.py index c91b8963..262699e8 100644 --- a/HSP2_Driver.py +++ b/HSP2_Driver.py @@ -1,4 +1,5 @@ -import os, sys +import os +import sys # print('in HSP2_Driver') command_line = "" @@ -6,25 +7,29 @@ if len(sys.argv) >= 2: # see if anything on command line command_line = sys.argv[1] - print('command line' + command_line) + print("command line" + command_line) # if given UCI, import to h5 file # if given WDM, import to h5 file # if given h5, run HSP2 -from PyQt5.QtWidgets import QFileDialog, QApplication +from PyQt5.QtWidgets import QApplication, QFileDialog application = QApplication(sys.argv) -if command_line == '': - file_filter = "Run HDF5 (*.h5) Full Output;;" \ - "Run HDF5 (*.h5) Light Output;;" \ - "Import UCI to HDF5 (*.uci);;" \ - "Import WDM to HDF5 (*.wdm)" - filename, filetype = QFileDialog.getOpenFileName(None, 'HSP2 Open File...', '', file_filter) +if command_line == "": + file_filter = ( + "Run HDF5 (*.h5) Full Output;;" + "Run HDF5 (*.h5) Light Output;;" + "Import UCI to HDF5 (*.uci);;" + "Import WDM to HDF5 (*.wdm)" + ) + filename, filetype = QFileDialog.getOpenFileName( + None, "HSP2 Open File...", "", file_filter + ) else: filename = command_line - filetype = '' + filetype = "" file_ext = filename[-3:] dir_name = os.path.dirname(filename) @@ -33,12 +38,14 @@ if file_ext.upper() == "UCI": h5_name = filename[:-3] + "h5" from hsp2.hsp2tools.readUCI import readUCI + readUCI(filename, h5_name) # readUCI('HSPF.uci', 'test.h5') if file_ext.upper() == "WDM": h5_name = filename[:-3] + "h5" from hsp2.hsp2tools.readWDM import readWDM + readWDM(filename, h5_name) # readWDM('GRICM.wdm', 'test.h5') # readWDM('ZUMBROSCEN.WDM', 'test.h5') @@ -52,11 +59,7 @@ io_manager = IOManager(hdf5_instance) SaveLevel = True - if 'Light' in filetype: + if "Light" in filetype: SaveLevel = False main(io_manager, saveall=SaveLevel, jupyterlab=False) # main('test.h5', saveall=True) - - - - diff --git a/README.rst b/README.rst index 179d43a9..e4003f95 100644 --- a/README.rst +++ b/README.rst @@ -44,7 +44,7 @@ Source Code Directories future automation and model coupling. - NOTE: With v0.10 the I/O abstraction classes provide an alternate approach to running HSP2. Our plan is to migrate solely using the I/O abstracted methods, but we will maintain both approaches - for for several more releases for backward compatibility. + for for several more releases for backward compatibility. - **docs** contains relevant reference documentation. @@ -65,13 +65,13 @@ We recommend getting started by: HSP2 Installation ================= -We **recommend Python 3.10**. +We **recommend Python 3.10**. Install From Pre-built Packages ------------------------------- Python Package Index (PyPI) +++++++++++++++++++++++++++ -Starting with version 0.11.0a1 we provide a PyPI wheel package for HSP2 which +Starting with version 0.11.0a1 we provide `a PyPI wheel package for HSP2`_ which should work on any supported platform for Python 3.10, 3.11, and 3.12. .. code-block:: console @@ -113,13 +113,17 @@ Option 1: Install using "conda" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Follow these steps to install using the conda_ package manager. -1. Install the Anaconda Python Distribution +1. Install Miniconda or Anaconda Python Distribution ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Install the `latest release`_ of the Anaconda Distribution, which includes the -conda package manager, a complete Python (and R) data science stack, and the -Anaconda Navigator GUI. Follow `Anaconda Installation`_ documentation. +We recommend installing the light-weight Miniconda_ that includes Python, the +conda_ environment and package management system, and their dependencies. + +NOTE: Follow conda defaults to install in your local user directory. DO NOT +install for all users, to avoid substantial headaches with permissions. + +If you have already installed the Anaconda Distribution, you can use it to +complete the next steps, but you may need to update to the `latest release`_. -A lighter-weight alternative is to install Miniconda_. 2. Create a Conda Environment for HSP2 Modeling (optional) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +135,7 @@ Use the following `conda create`_ command in your terminal or console: .. code-block:: console - conda create -c conda-forge -n hsp2_310 python=3.10 + conda create -c conda-forge -n hsp2_310 python=3.10 Install the necessary and optional packages for HSP2 in the new environment: @@ -147,13 +151,21 @@ Install the necessary and optional packages for HSP2 in the new environment: cd /path/to/module/hsp2 pip install . # or "pip install -e ." to install in editable mode +**Alternately**, you can replace all of the create and install steps above by +creating the new environment from the included `environment.yml` file +from this single line of code: + +.. code-block:: console + + conda env create --file=environment.yml --solver=libmamba + You should now be able to run the Tutorials and create your own Jupyter Notebooks! Option 2: Install From Source Code Using `pip` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Installing HSP2 using `pip`, the `Package Installer for Python`_ -is an alternative method to installing with `conda`. +is an alternative method to installing with `conda`. 1. Install Python ^^^^^^^^^^^^^^^^^ @@ -170,7 +182,7 @@ activate a new environment for running HSP2. python -m venv hsp2_env /path/to/python/virtual/environments/hsp2_env -3. PIP install HSP2 +3. PIP install HSP2 ^^^^^^^^^^^^^^^^^^^ Navigate to your copy of the HSPsquared folder (for these instructions /path/to/module/hsp2) on your computer in the command @@ -221,8 +233,9 @@ The HSP2 API is designed to be used in Python scripts and Jupyter notebooks. .. _`HSPF Conversion Project`: https://github.com/respec/HSPsquared/blob/archivePy2/Why%20HSP2%20(EAA).pdf .. _`Introduction to HSP2 by Jason Love (RESPEC)`: https://www.youtube.com/watch?v=aeLScKsP1Wk .. _`initial release`: https://github.com/respec/HSPsquared/releases/tag/0.7.7 -.. _`GNU Affero General Public License (AGPL), copyrighted 2017 by RESPEC`: https://github.com/respec/HSPsquared/blob/master/LICENSE +.. _`GNU Affero General Public License (AGPL), copyrighted 2017 by RESPEC`: https://github.com/respec/HSPsquared/blob/master/LICENSE .. _JupyterLab: https://jupyterlab.readthedocs.io/en/stable/ +.. _`a PyPI wheel package for HSP2`: https://pypi.org/project/hsp2/ .. _conda: https://docs.conda.io/en/latest/ .. _`latest release`: https://docs.anaconda.com/anaconda/reference/release-notes/ .. _`Anaconda Installation`: https://docs.anaconda.com/anaconda/install/ diff --git a/_version.py b/_version.py deleted file mode 100644 index 2fb6788e..00000000 --- a/_version.py +++ /dev/null @@ -1,4 +0,0 @@ -import os - -with open(os.path.join(os.path.dirname(__file__), "VERSION"), encoding="ascii") as version_file: - __version__ = version_file.read().strip() diff --git a/compare_case.json b/compare_case.json index 5cd4e8c3..cb746076 100644 --- a/compare_case.json +++ b/compare_case.json @@ -17,4 +17,3 @@ } } } - diff --git a/environment.yml b/environment.yml index 807dd2c7..026de50e 100644 --- a/environment.yml +++ b/environment.yml @@ -1,45 +1,49 @@ -name: hsp2_py38 +--- +name: hsp2 channels: - conda-forge + - nodefaults # Speeds solving env, by limiting the number of options dependencies: - # Aligned with Anaconda 2021.05 (May 13, 2021) - # package management - - conda - - conda-build - - pip + - python >=3.10 # Running HSP2 - - python =3.8* - - scipy # Scipy also installs numpy - - pandas ==1.2.* # Pandas installs most scientific Python modules, such as Numpy, etc. - - numba ==0.53.1 - - numpy ==1.20.* # for compatibility with numba version <0.53 - - hdf5 ==1.10.6 # latest compatible with both versions of PyTables & h5py below - doesn't work with setup.py - - pytables ==3.6.1 - - h5py >=3.1 + - scipy # Scipy also installs numpy + # Pandas installs most scientific Python modules, such as Numpy, etc. + - pandas <3.0.0 + - numba + - numpy + - hdf5 + - pytables + - h5py - hdf5plugin # HDF5 compression filters for h5py & jupyterlab_hdf - - mando # for Python CLI app in HSP2tools/HSP2_CLI.py; hasn't been updated since 2017 and doesn't support Python 3.9: https://github.com/rubik/mando + - cltoolbox - # Interactivity & Visualization via Jupyter Notebooks (optional, but required for tutorials) - - jupyterlab ==3.0.* # also installs classic Jupyter notbook - - ipympl # jupyter-matplotlib, https://github.com/matplotlib/ipympl - - nodejs # required for many JupyterLab extensions - - nb_conda # Conda environment & package access extension from within Jupyter - # HoloViz, https://holoviz.org + # Operational Model (om) + - pyparsing + + # Interactivity via Jupyter Notebooks (optional, but required for tutorials) + - jupyterlab # also installs classic Jupyter notbook + - nodejs # required for many JupyterLab extensions + + # Visualization (optional) - hvplot # hvPlot installs most HoloViz libs, including matplotlib + - ipympl # jupyter-matplotlib, https://github.com/matplotlib/ipympl - ipywidgets # Required for HoloViz interactivity in Jupyter notebooks + - ipywidgets_bokeh + - jupyter_bokeh # Renders Holviz / Bokeh objects in Jupyter + - pyviz_comms # bidirectional communication between Python & JavaScript for Jupyter # Dev tools (optional) - - python-language-server - - jupyter-lsp-python # Includes both the server extension (jupyter-lsp) and pyls third-party server (python-language-server) - - jupyterlab-lsp # Docs at https://github.com/krassowski/jupyterlab-lsp - + # Language Server Protocol (LSP) extension for Python (pylsp) + - python-lsp-server + - jupyterlab-lsp # Provides both server extension and lab extension + # Environment and package management + - conda + - conda-libmamba-solver + - pip # PIP install requirements only if it is not possible with conda # https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment - pip: - # Optional, but recommended for tutorials - # - lckr-jupyterlab-variableinspector # https://github.com/lckr/jupyterlab-variableInspector - # - jupyterlab_hdf # Explore HDF5 files in JupyterLab. Requires an additional step to install. - # Installation instructions: https://github.com/jupyterlab/jupyterlab-hdf5#installation + - hsp2 diff --git a/environment_dev.yml b/environment_dev.yml index 2bf310a7..78bfc5a9 100644 --- a/environment_dev.yml +++ b/environment_dev.yml @@ -1,40 +1,45 @@ +--- name: hsp2_py311_dev channels: - conda-forge - - nodefaults # Speeds solving env, by limiting the number of options + - nodefaults # Speeds solving env, by limiting the number of options dependencies: - # Python 3.11 is supported by Anaconda since 2023.03-0 (Mar 20, 2023) - # https://docs.anaconda.com/free/anaconda/release-notes/#anaconda-2023-03-0-mar-20-2023 - # package management - - conda - - conda-build - - conda-libmamba-solver - - pip + # Python 3.11 was default for Anaconda 2023.07-0 (Jul 11, 2023) + # https://docs.anaconda.com/anaconda/release-notes/#anaconda-2023-07-0-jul-11-2023 + - python =3.11 # Running HSP2 - - python =3.11 - - scipy # Scipy also installs numpy - - pandas >=2.0 # Pandas installs most scientific Python modules, such as Numpy, etc. - - numba - - numpy + - scipy # Scipy also installs numpy + # Pandas installs most scientific Python modules, such as Numpy, etc. + - pandas >=2.0 + - numba + - numpy - hdf5 - - pytables - - h5py + - pytables + - h5py - hdf5plugin # HDF5 compression filters for h5py & jupyterlab_hdf # - dask # for future performance enhancements - - mando # for Python CLI app in HSP2tools/HSP2_CLI.py; hasn't been updated since 2017 and doesn't support Python 3.9: https://github.com/rubik/mando + - cltoolbox - # Interactivity & Visualization via Jupyter Notebooks (optional, but required for tutorials) - - jupyterlab # also installs classic Jupyter notbook - - ipympl # jupyter-matplotlib, https://github.com/matplotlib/ipympl - - nodejs # required for many JupyterLab extensions - # HoloViz, https://holoviz.org + # Operational Model (om) + - pyparsing + + # Interactivity via Jupyter Notebooks (optional, but required for tutorials) + - jupyterlab # also installs classic Jupyter notbook + - nodejs # required for many JupyterLab extensions + + # Visualization (optional) - hvplot # hvPlot installs most HoloViz libs, including matplotlib + - ipympl # jupyter-matplotlib, https://github.com/matplotlib/ipympl - ipywidgets # Required for HoloViz interactivity in Jupyter notebooks + - ipywidgets_bokeh + - jupyter_bokeh # Renders Holviz / Bokeh objects in Jupyter + - pyviz_comms # bidirectional communication between Python & JavaScript for Jupyter # Dev tools (optional) - - python-lsp-server # Language Server Protocol (LSP) extension for Python (pylsp) + # Language Server Protocol (LSP) extension for Python (pylsp) + - python-lsp-server # Rope for Completions and renaming # Pyflakes linter to detect various errors # McCabe linter for complexity checking @@ -46,7 +51,12 @@ dependencies: # pylint for code linting (disabled by default) - jupyterlab-lsp # Provides both server extension and lab extension - + # Environment and package management + - conda + - conda-build + - conda-libmamba-solver + - pip # PIP install requirements only if it is not possible with conda # https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment - - pip: \ No newline at end of file + - pip: + # For developing HPS2, we recommend using the `conda build` command to "install" diff --git a/examples/1_Intro_to_HSP2.ipynb b/examples/1_Intro_to_HSP2.ipynb index 0e15e45b..1c3ee74c 100644 --- a/examples/1_Intro_to_HSP2.ipynb +++ b/examples/1_Intro_to_HSP2.ipynb @@ -34,56 +34,168 @@ "source": [ "# Installation and Setup\n", "\n", - "## Install HSP2\n", - "\n", - "Carefully follow our **[Installation Instructions](https://github.com/respec/HSPsquared#installation)**, especially including:\n", - "- Creating a virtual environment for HSP2 (step 3)\n", - "- Adding HSPsquared to your Python path (step 4)" + "This notebook is designed to be run from: \n", + "- a cloned or copied version of the [HSPsquared](https://github.com/respec/HSPsquared) respository and \n", + "- a custom virtual environment as described in our **[HSP2 Installation](https://github.com/respec/HSPsquared#hsp2-installation) Instructions**, especially including:\n", + " - Creating a virtual environment for HSP2 (step 3)\n", + " - Adding HSP2 to your Python path (step 4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Python Imports" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### General Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from pathlib import Path\n", + "\n", + "import tables" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Import HSP2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'hsp2_py38'" + "'default311'" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Confirm that your active environment for this notebook is the one you created for HSP2.\n", - "import os\n", - "\n", "os.environ[\"CONDA_DEFAULT_ENV\"]" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# Install HSP2, HSP2 Tools, and HSP2 IO Utillties\n", + "from hsp2 import hsp2, hsp2tools, hsp2io" + ] + }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Import Python Dependencies\n", - "- Most dependancies get installed when you import the `HSP2` and `HSP2tools` modules. " + "### If you get `ModuleNotFoundError`\n", + "\n", + "If you get `ModuleNotFoundError`, you need to install hsp2 into your environment, either using \n", + "- `pip` (see [HSP2 Installation](https://github.com/respec/HSPsquared#hsp2-installation) Instructions) for normal use, or using\n", + "- [`conda develop`](https://docs.conda.io/projects/conda-build/en/latest/resources/commands/conda-develop.html) if you want to develop HSP2.\n", + "\n", + "If using the development environment, the following steps will install in develop mode:\n", + "1. Run the [`conda develop`](https://docs.conda.io/projects/conda-build/en/latest/resources/commands/conda-develop.html) command in your terminal with your local absolute path to the `src` directory of this repo.\n", + "2. Restart the kernel.\n", + "3. Rerun the import statements above." ] }, { "cell_type": "code", - "execution_count": 2, - "metadata": { - "execution": { - "iopub.execute_input": "2024-05-21T17:40:19.613424Z", - "iopub.status.busy": "2024-05-21T17:40:19.613169Z", - "iopub.status.idle": "2024-05-21T17:40:19.737150Z", - "shell.execute_reply": "2024-05-21T17:40:19.736693Z", - "shell.execute_reply.started": "2024-05-21T17:40:19.613404Z" + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "PosixPath('/var/home/timcera/programming/HSP_old/HSPsquared')" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" } - }, + ], + "source": [ + "# Find project directory (i.e. the parent to `/examples` directory for this notebook)\n", + "project_path = Path.cwd().parent\n", + "project_path" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "PosixPath('/var/home/timcera/programming/HSP_old/HSPsquared/src')" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your source directory should be: \n", + "src_path = project_path / 'src' \n", + "src_path" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### To install in developer mode:\n", + "- Copy from the output of `src_path` from the cell above, and \n", + "- Paste it after `!conda develop` in the cell below (replacing the previous user's path). \n", + " - NOTE 1: If your path has any blank spaces, you must enclose the path with quotes.\n", + " - NOTE 2: The Jupyter `!` magic command runs a the follwoing terminal command from this notebook." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + " # !conda develop '/Users/aaufdenkampe/Documents/Python/respec.HSPsquared/src'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You now need to **restart the Python kernel** for this notebook, if the path didn't already exist." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, "outputs": [ { "data": { @@ -116,11 +228,11 @@ "
\n", "| \n", - " | Start | \n", - "Stop | \n", - "Freq | \n", - "Length | \n", - "TSTYPE | \n", - "TFILL | \n", - "STAID | \n", - "STNAM | \n", - "
|---|---|---|---|---|---|---|---|---|
| TS039 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1H | \n", - "8784 | \n", - "PREC | \n", - "-999.0 | \n", - "HOURLY PREC | \n", - "PRECIP TRAER IOWA | \n", - "
| TS041 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "EVAP | \n", - "-999.0 | \n", - "DAILY EVAP | \n", - "FARMERS COOP WEATHER STN | \n", - "
| TS042 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "WIND | \n", - "-999.0 | \n", - "DAILY WIND | \n", - "FARMERS COOP WEATHER STN | \n", - "
| TS046 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "2H | \n", - "4392 | \n", - "SOLR | \n", - "-999.0 | \n", - "2 HOUR RAD | \n", - "FARMERS WEATHER STN | \n", - "
| TS113 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "FLOW | \n", - "-999.0 | \n", - "DAILY FLOW | \n", - "IOWA RIVER MARSHALLTOWN | \n", - "
| TS119 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "FLOW | \n", - "-999.0 | \n", - "DAILY FLOW | \n", - "IOWA RIVER MARENGO | \n", - "
| TS121 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "2H | \n", - "4392 | \n", - "ATMP | \n", - "-999.0 | \n", - "2 HOUR AIR TEMP | \n", - "CEDAR RAPIDS IOWA | \n", - "
| TS122 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "2H | \n", - "4392 | \n", - "ATMP | \n", - "-999.0 | \n", - "2 HOUR AIR TEMP | \n", - "IOWA FALLS IOWA | \n", - "
| TS123 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "2H | \n", - "4392 | \n", - "ATMP | \n", - "-999.0 | \n", - "2 HOUR AIR TEMP | \n", - "MARSHALLTOWN IOWA | \n", - "
| TS124 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "DEWP | \n", - "-999.0 | \n", - "DAILY DEW PT | \n", - "CEDAR RAPIDS IOWA | \n", - "
| TS125 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "DEWP | \n", - "-999.0 | \n", - "DAILY DEW PT | \n", - "IOWA FALLS IOWA | \n", - "
| TS126 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "DEWP | \n", - "-999.0 | \n", - "DAILY DEW PT | \n", - "MARSHALLTOWN IOWA | \n", - "
| TS127 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "SEDM | \n", - "-999.0 | \n", - "SEDIMENT CONC | \n", - "IOWA RIVER MARENGO | \n", - "
| TS131 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1H | \n", - "8784 | \n", - "PREC | \n", - "-999.0 | \n", - "HOURLY PREC | \n", - "PRECIP IOWA FALLS | \n", - "
| TS132 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1H | \n", - "8784 | \n", - "PREC | \n", - "-999.0 | \n", - "HOURLY PREC | \n", - "PRECIP SHEFFIELD | \n", - "
| TS134 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "WTMP | \n", - "-999.0 | \n", - "WATER TEMP | \n", - "IOWA RIVER (ESTIMATED) | \n", - "
| TS135 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "CLDC | \n", - "-999.0 | \n", - "CLOUD COVER | \n", - "WATERLOO (TENTHS) | \n", - "
| TS136 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "FLOW | \n", - "-999.0 | \n", - "DAILY FLOW | \n", - "IOWA RIVER ROWAN | \n", - "
| TS140 | \n", - "1976-01-01 00:00:00 | \n", - "1977-01-01 00:00:00 | \n", - "1D | \n", - "366 | \n", - "CLND | \n", - "-999.0 | \n", - "COLIND | \n", - "COLUMN INDICATOR MEIER POND SUMMER-WINTER OUTLET | \n", - "
8784 rows × 10 columns
\n", + "8784 rows × 15 columns
\n", "" ], "text/plain": [ - " DEP IVOL PRSUPY RO ROVOL SAREA \\\n", - "1976-01-01 01:00:00 0.822988 1.747608 0.0 7.371986 0.304628 2.052829 \n", - "1976-01-01 02:00:00 0.754730 0.428585 0.0 6.350832 0.567059 2.003019 \n", - "1976-01-01 03:00:00 0.604331 0.150780 0.0 4.385298 0.443642 1.893593 \n", - "1976-01-01 04:00:00 0.474719 0.066827 0.0 3.010308 0.305604 1.799683 \n", - "1976-01-01 05:00:00 0.376407 0.034621 0.0 2.013996 0.207616 1.728451 \n", - "... ... ... ... ... ... ... \n", - "1976-12-31 20:00:00 0.000000 0.000000 0.0 0.000000 0.000000 0.000000 \n", - "1976-12-31 21:00:00 0.000000 0.000000 0.0 0.000000 0.000000 0.000000 \n", - "1976-12-31 22:00:00 0.000000 0.000000 0.0 0.000000 0.000000 0.000000 \n", - "1976-12-31 23:00:00 0.000000 0.000000 0.0 0.000000 0.000000 0.000000 \n", - "1977-01-01 00:00:00 0.000000 0.000000 0.0 0.000000 0.000000 0.000000 \n", + " AVDEP AVVEL DEP HRAD IVOL \\\n", + "1976-01-01 01:00:00 0.702923 1.857768 0.822988 0.562775 1.747608 \n", + "1976-01-01 02:00:00 0.651220 1.770455 0.754730 0.526685 0.428585 \n", + "1976-01-01 03:00:00 0.534142 1.576605 0.604331 0.443217 0.150780 \n", + "1976-01-01 04:00:00 0.429286 1.416886 0.474719 0.365824 0.066827 \n", + "1976-01-01 05:00:00 0.346840 1.221629 0.376407 0.302669 0.034621 \n", + "... ... ... ... ... ... \n", + "1976-12-31 20:00:00 0.000000 0.000000 0.000000 0.000000 0.000000 \n", + "1976-12-31 21:00:00 0.000000 0.000000 0.000000 0.000000 0.000000 \n", + "1976-12-31 22:00:00 0.000000 0.000000 0.000000 0.000000 0.000000 \n", + "1976-12-31 23:00:00 0.000000 0.000000 0.000000 0.000000 0.000000 \n", + "1977-01-01 00:00:00 0.000000 0.000000 0.000000 0.000000 0.000000 \n", "\n", - " TAU USTAR VOL VOLEV \n", - "1976-01-01 01:00:00 0.088680 0.213918 1.442980 0.000000 \n", - "1976-01-01 02:00:00 0.082993 0.206945 1.304407 0.000100 \n", - "1976-01-01 03:00:00 0.069840 0.189840 1.011448 0.000097 \n", - "1976-01-01 04:00:00 0.057645 0.172471 0.772579 0.000092 \n", - "1976-01-01 05:00:00 0.047693 0.156879 0.599497 0.000087 \n", + " POTEV PRSUPY RO ROVOL SAREA TAU \\\n", + "1976-01-01 01:00:00 0.000583 0.0 7.371986 0.304628 2.052829 0.088680 \n", + "1976-01-01 02:00:00 0.000583 0.0 6.350832 0.567059 2.003019 0.082993 \n", + "1976-01-01 03:00:00 0.000583 0.0 4.385298 0.443642 1.893593 0.069840 \n", + "1976-01-01 04:00:00 0.000583 0.0 3.010308 0.305604 1.799683 0.057645 \n", + "1976-01-01 05:00:00 0.000583 0.0 2.013996 0.207616 1.728451 0.047693 \n", + "... ... ... ... ... ... ... \n", + "1976-12-31 20:00:00 0.000583 0.0 0.000000 0.000000 0.000000 0.000000 \n", + "1976-12-31 21:00:00 0.000583 0.0 0.000000 0.000000 0.000000 0.000000 \n", + "1976-12-31 22:00:00 0.000583 0.0 0.000000 0.000000 0.000000 0.000000 \n", + "1976-12-31 23:00:00 0.000583 0.0 0.000000 0.000000 0.000000 0.000000 \n", + "1977-01-01 00:00:00 0.000583 0.0 0.000000 0.000000 0.000000 0.000000 \n", + "\n", + " TWID USTAR VOL VOLEV \n", + "1976-01-01 01:00:00 5.645279 0.213918 1.442980 0.000000 \n", + "1976-01-01 02:00:00 5.508303 0.206945 1.304407 0.000100 \n", + "1976-01-01 03:00:00 5.207382 0.189840 1.011448 0.000097 \n", + "1976-01-01 04:00:00 4.949128 0.172471 0.772579 0.000092 \n", + "1976-01-01 05:00:00 4.753240 0.156879 0.599497 0.000087 \n", "... ... ... ... ... \n", "1976-12-31 20:00:00 0.000000 0.000000 0.000000 0.000000 \n", "1976-12-31 21:00:00 0.000000 0.000000 0.000000 0.000000 \n", @@ -786,7 +871,7 @@ "1976-12-31 23:00:00 0.000000 0.000000 0.000000 0.000000 \n", "1977-01-01 00:00:00 0.000000 0.000000 0.000000 0.000000 \n", "\n", - "[8784 rows x 10 columns]" + "[8784 rows x 15 columns]" ] }, "execution_count": 9, @@ -825,13 +910,18 @@ " \n", "