Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop (added tests) to main_v3.0 #416

Open
wants to merge 8 commits into
base: main_v3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .coveragerc

This file was deleted.

23 changes: 3 additions & 20 deletions .github/workflows/trigger_metplus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- develop
- 'main_v[0-9]+.[0-9]+'
paths-ignore:
- 'docs/**'
- '.github/pull_request_template.md'
Expand All @@ -16,24 +17,6 @@ jobs:
name: Trigger METplus testing workflow
runs-on: ubuntu-latest
steps:
- name: Print GitHub values for reference
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/github-script@v7
- uses: dtcenter/metplus-action-trigger-use-cases@v1
with:
github-token: ${{ secrets.METPLUS_BOT_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'dtcenter',
repo: 'METplus',
workflow_id: 'testing.yml',
ref: 'develop',
inputs: {
repository: '${{ github.repository }}',
ref: '${{ github.ref }}',
actor: '${{ github.actor }}',
sha: '${{ github.sha }}',
pusher_email: '${{ github.event.pusher.email }}'
},
});
token: ${{ secrets.METPLUS_BOT_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ For information about the support provided for releases, see our [Release Suppor
Instructions for installing the metcalcpy package locally
---------------------------------------------------------
- activate your conda environment (i.e. 'conda activate your-conda-env-name')
- from within your active conda environment, cd to the METcalcpy/ directory, where you will see the setup.py script
- from within your active conda environment, cd to the METcalcpy/ directory, where you will see the file pyproject.toml
- from this directory, run the following on the command line: pip install -e .
- the -e option stands for editable, which is useful in that you can update your METcalcpy/metcalcpy source without reinstalling it
- the . indicates that you should search the current directory for the setup.py script
- the . indicates that you should search the current directory for the pyproject.toml file.

- use metcalcpy package via import statement:
- Examples:
Expand Down
2 changes: 1 addition & 1 deletion docs/Users_Guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ METcalcpy source code, e.g. `/User/someuser/METcalcpy`. From this directory, ru

`pip install -e .`

This instructs pip to install the package based on instructios in the setup.py file located in the current directory
This instructs pip to install the package based on instructions in the pyproject.toml file located in the current directory
(as indicated by the '.'). The `-e` directs pip to install the package in edit mode, so if one wishes to make changes
bikegeek marked this conversation as resolved.
Show resolved Hide resolved
to this source code, the changes are automatically applied without the need to re-install the package.

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
copyright = '2024, NCAR'
author = 'UCAR/NCAR, NOAA, CSU/CIRA, and CU/CIRES'
author_list = 'Fisher, H., C. Kalb, D. Adriaansen, D. Fillmore, M. Win-Gildenmeister, T. Burek, M. Smith, and T. Jensen'
version = '3.0.0-rc1'
version = '3.0.0-dev'
verinfo = version
release = f'{version}'
release_year = '2024'
Expand Down
2 changes: 1 addition & 1 deletion docs/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="3.0.0-rc1"
3.0.0-beta1-dev
104 changes: 52 additions & 52 deletions metcalcpy/agg_stat_bootstrap.py

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions metcalcpy/pre_processing/directional_means.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# ============================*



import numpy as np
import xarray as xr


def zonal_mean(dat,dimvar='longitude'):
Expand Down Expand Up @@ -52,10 +50,8 @@ def meridional_mean(dat, lat1, lat2, dimvar='latitude'):
"""

# Check inputs
if lat1 > lat2:
raise ValueError('lat1 is greater than lat2, but it must be less than lat2')
elif lat1 == lat2:
raise ValueError('lat1 is equal to lat2, but it must be less than lat2')
if lat1 >= lat2:
raise ValueError('lat1 is greater than or equal to lat2, but it must be less than lat2')

wgts = np.cos(np.deg2rad(dat[dimvar].where((dat[dimvar] >= lat1) & (dat[dimvar] <= lat2),drop=True)))

Expand Down
1 change: 1 addition & 0 deletions metcalcpy/util/write_mpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import numpy as np

from metcalcpy.util.safe_log import safe_log

def write_mpr_file(data_fcst,data_obs,lats_in,lons_in,fcst_lead,fcst_valid,obs_lead,obs_valid,mod_name,desc,fcst_var,fcst_unit,fcst_lev,obs_var,obs_unit,obs_lev,maskname,obsslev,outdir,outfile_prefix, logger=None):

Expand Down
62 changes: 62 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[build-system]
requires = [
"setuptools",
"wheel",
"setuptools-git-versioning>=2.0,<3",
]
build-backend = "setuptools.build_meta"

[project]
name = "metcalcpy"
dynamic = ["version", "dependencies"]
description = "statistics and util package for METplus"
authors = [
{name = "METplus"},
]
requires-python = ">=3.10.4"
readme = "README.md"
license = {text = "MIT"}
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
]

[project.urls]
Homepage = "https://github.com/dtcenter/METcalcpy"

[tool.setuptools.packages]
find = {include = ["metcalcpy*"]}

[tool.setuptools.package-data]
metplus = [
"docs/version"
]

[tool.setuptools.exclude-package-data]
metplus = ["README", "__pycache__", "*~"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.setuptools-git-versioning]
enabled = true
version_file = "docs/version"

[tool.pytest.ini_options]
testpaths = ["test"]

[tool.coverage.run]
source = ["metcalcpy"]
omit = [
"config.py",
"config-3.py",
"metcalcpy/contributed/*",
]
relative_files = true

[tool.coverage.report]
exclude_also = [
"def __repr__",
"if __name__ == .__main__.:",
]
29 changes: 0 additions & 29 deletions setup.py

This file was deleted.

96 changes: 0 additions & 96 deletions test/logs/log_agg_eclv.txt

This file was deleted.

15 changes: 15 additions & 0 deletions test/test_agg_stat_bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import metcalcpy.agg_stat_bootstrap as asb
from test.utils import AGG_STAT_AND_BOOT_DATA


DEFAULT_CONF = {
"log_filename": "tmp.log",
"log_level": "DEBUG",
"agg_stat_input": AGG_STAT_AND_BOOT_DATA,
}


def test_smoke(tmp_path):
"""Basic test to check object instantiation"""
DEFAULT_CONF["log_dir"] = tmp_path
asb.AggStatBootstrap(DEFAULT_CONF)
46 changes: 46 additions & 0 deletions test/test_preprocessing_directional_means.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
import xarray as xr
import numpy as np
from metcalcpy.pre_processing import directional_means as dm

TEST_DATA = xr.Dataset(
{
"variable": xr.DataArray(
[
[1.1, 2.2, 3.3],
[2.2, 3.3, 4.4],
[4.4, 5.5, 6.6],
],
coords={
"latitude": [-10.25, -11.25, -12.25],
"longitude": [112.25, 113.25, 114.25],
},
dims=["latitude", "longitude"],
),
},
attrs={},
)


def test_zonal_mean():
actual = dm.zonal_mean(TEST_DATA)
np.testing.assert_almost_equal(actual.variable.values, np.array([2.2, 3.3, 5.5]))

actual = dm.zonal_mean(TEST_DATA, "latitude")
np.testing.assert_almost_equal(actual.variable.values, np.array([2.57, 3.67, 4.77]), 2)


def test_meridional_mean():
actual = dm.meridional_mean(TEST_DATA, -12.25, -10.25)
np.testing.assert_almost_equal(actual.variable.values, np.array([2.562829, 3.662829, 4.762829]))

actual = dm.meridional_mean(TEST_DATA, 112.25, 114.25, "longitude")
np.testing.assert_almost_equal(actual.variable.values, np.array([2.2297922, 3.3297922, 5.5297922]))


def test_meridional_mean_rasied():
with pytest.raises(ValueError):
dm.meridional_mean(TEST_DATA, -10.25, -10.25)

with pytest.raises(ValueError):
dm.meridional_mean(TEST_DATA, -10.25, -12.25)
8 changes: 8 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pathlib import Path

def abs_path(rel_path):
"""Turn a relative path into abs path"""
return str(Path(str(Path(__file__).parents[2])) / rel_path)

# Datafile access
AGG_STAT_AND_BOOT_DATA = abs_path("METcalcpy/test/data/agg_stat_and_boot_data.data")
Loading