Skip to content

Commit

Permalink
Merge branch 'feature/xarray_dims_to_sizes' into xarray_dims_to_sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfromearth authored Jul 10, 2024
2 parents 62bc7e3 + 21f43db commit a1aab98
Show file tree
Hide file tree
Showing 13 changed files with 852 additions and 764 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ updates:
directory: "/"
schedule:
interval: "monthly"
groups:
pip-dependencies:
patterns:
- "*"
# Raise pull requests for version updates
# to pip against the `develop` branch
target-branch: "develop"
Expand All @@ -17,6 +21,10 @@ updates:
schedule:
# Check for updates to GitHub Actions every week
interval: "monthly"
groups:
gha-dependencies:
patterns:
- "*"
# Raise pull requests for version updates
# to pip against the `develop` branch
target-branch: "develop"
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.16.0
hooks:
- id: pyupgrade
args: [ "--py39-plus" ]
Expand All @@ -24,7 +24,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.4.6'
rev: 'v0.5.1'
hooks:
- id: ruff
args: [ "--fix" ]
Expand All @@ -36,7 +36,7 @@ repos:
- id: black-jupyter

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.10.1
hooks:
- id: mypy

Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [unreleased]
### Added
- [Issue #229](https://github.com/nasa/ncompare/issues/229): Added Journal of Open Source Software (JOSS) info to README and CITATION docs.
- [Issue #42](https://github.com/nasa/ncompare/issues/42): Made available via conda and added `conda`/`mamba` installation instructions to README.md
### Changed
- [Issue #233](https://github.com/nasa/ncompare/issues/233): Group dependabot updates into fewer PRs.
- [Issue #246](https://github.com/nasa/ncompare/issues/246): Changed xarray Dataset.dims reference to Dataset.sizes due to FutureWarning
### Deprecated
### Removed
- [Issue #231](https://github.com/nasa/ncompare/issues/231): Removed upper bounds from dependencies
### Fixed
- [Pull #230](https://github.com/nasa/ncompare/pull/230): Fixed help text for second NetCDF file passed on command line
### Security

## [1.9.0]
### Added
Expand Down
53 changes: 32 additions & 21 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
cff-version: 1.2.0

message: |
Please cite this software using these metadata.
Authors are listed in alphabetical order.
title: "ncompare"
abstract: "Compare the structure of two NetCDF files at the command line."
cff-version: "1.2.0"
authors:
- family-names: Kaufman
given-names: Daniel E.
orcid: "https://orcid.org/0000-0002-1487-7298"
- family-names: Baskin
given-names: Walter E.
orcid: "https://orcid.org/0000-0002-2241-3266"
doi: 10.5281/zenodo.11448464
message: If you use this software, please cite our article in the
Journal of Open Source Software.
preferred-citation:
authors:
- family-names: Kaufman
given-names: Daniel E.
orcid: "https://orcid.org/0000-0002-1487-7298"
- family-names: Baskin
given-names: Walter E.
orcid: "https://orcid.org/0000-0002-2241-3266"
date-published: 2024-06-06
doi: 10.21105/joss.06490
issn: 2475-9066
issue: 98
journal: Journal of Open Source Software
publisher:
name: Open Journals
start: 6490
title: "ncompare: A Python package for comparing netCDF structures"
type: article
url: "https://joss.theoj.org/papers/10.21105/joss.06490"
volume: 9
title: "ncompare: A Python package for comparing netCDF structures"

contact:
- name: "The NASA ncompare issues page"
Expand All @@ -14,18 +38,5 @@ keywords:
- "netcdf"
- "data comparison"
- "hierarchical data"

url: "https://ncompare.readthedocs.io"
repository-code: "https://github.com/nasa/ncompare"

version: 1.9.0
date-released: 2024-05-29

authors:
- family-names: "Baskin"
given-names: "Walter"
orcid: "https://orcid.org/0000-0002-2241-3266"
- family-names: "Kaufman"
given-names: "Daniel E"
orcid: "https://orcid.org/0000-0002-1487-7298"
website: "https://github.com/danielfromearth"
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,35 @@ _____
<a href="https://github.com/pyOpenSci/software-review/issues/146" target="_blank">
<img src="https://tinyurl.com/y22nb8up?" alt="pyOpenSci">
</a>
<a style="border-width:0" href="https://doi.org/10.21105/joss.06490">
<img src="https://joss.theoj.org/papers/10.21105/joss.06490/status.svg" alt="DOI badge" >
</a>

Compare the structure of two NetCDF files at the command line.
`ncompare` generates a view of the matching and non-matching groups and variables between two NetCDF datasets.


## Installing

Install the latest version of the package from the Python Package Index (PyPI):
```console
pip install ncompare
The latest release of `ncompare` can be installed with `mamba`, `conda` or `pip`.

#### Using `mamba`

```bash
mamba install -c conda-forge ncompare
```

#### Using `conda`

```bash
conda install -c conda-forge ncompare
```

#### Using `pip`

```bash
pip install ncompare
```

## Usage

Expand Down
8 changes: 5 additions & 3 deletions ncompare/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import importlib.metadata
import sys
import traceback
from collections.abc import Sequence
from typing import Optional

from ncompare.core import compare

__version__ = importlib.metadata.version('ncompare')


def _cli(args) -> argparse.Namespace:
def _cli(args: Optional[Sequence[str]]) -> argparse.Namespace:
"""Parse input arguments from the command line.
Parameters
Expand All @@ -47,7 +49,7 @@ def _cli(args) -> argparse.Namespace:
description="Compare the variables contained within two different NetCDF datasets"
)
parser.add_argument("nc_a", help="First NetCDF file")
parser.add_argument("nc_b", help="First NetCDF file")
parser.add_argument("nc_b", help="Second NetCDF file")
parser.add_argument("-v", "--comparison_var_name", help="Comparison variable name")
parser.add_argument("-g", "--comparison_var_group", help="Comparison variable group")
parser.add_argument(
Expand Down Expand Up @@ -97,7 +99,7 @@ def _cli(args) -> argparse.Namespace:
return parser.parse_args(args)


def main(): # pragma: no cover
def main() -> None: # pragma: no cover
"""Run from the command line."""
args = _cli(None)

Expand Down
42 changes: 16 additions & 26 deletions ncompare/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,16 @@


def ensure_valid_path_exists(should_be_path: Union[str, Path]) -> Path:
"""Convert input to a pathlib.Path and check that the resulting filepath exists."""
fails_to_exist_msg = "Expected file does not exist: "
wrong_type_msg = "Unexpected type for something that should be convertable to a Path: "

if isinstance(should_be_path, str):
# Convert to a Path object
path_obj = Path(should_be_path)
if path_obj.exists():
return path_obj
raise FileNotFoundError(fails_to_exist_msg + str(should_be_path))

if isinstance(should_be_path, Path):
if should_be_path.exists():
return should_be_path
raise FileNotFoundError(fails_to_exist_msg + str(should_be_path))

raise TypeError(wrong_type_msg + str(type(should_be_path)))
"""Coerce input to a pathlib.Path and check that the resulting filepath exists."""
path_obj = _coerce_str_or_path_to_path(should_be_path)
if path_obj.exists():
return path_obj
raise FileNotFoundError("Expected file does not exist: " + str(should_be_path))


def ensure_valid_path_with_suffix(should_be_path: Union[str, Path], suffix: str) -> Path:
"""Coerce input to a pathlib.Path with given suffix."""
wrong_type_msg = "Unexpected type for something that should be convertable to a Path: "

if isinstance(should_be_path, str):
path_obj = Path(should_be_path)
elif isinstance(should_be_path, Path):
path_obj = should_be_path
else:
raise TypeError(wrong_type_msg + str(type(should_be_path)))

path_obj = _coerce_str_or_path_to_path(should_be_path)
return path_obj.with_suffix(suffix)


Expand All @@ -72,3 +52,13 @@ def coerce_to_str(some_object: Union[str, int, tuple]):
return str(some_object)

raise TypeError(f"Unable to coerce value to str. Unexpected type <{type(some_object)}>.")


def _coerce_str_or_path_to_path(should_be_path: Union[Path, str]) -> Path:
wrong_type_msg = "Unexpected type for something that should be convertable to a Path: "
if isinstance(should_be_path, str):
return Path(should_be_path)
elif isinstance(should_be_path, Path):
return should_be_path
else:
raise TypeError(wrong_type_msg + str(type(should_be_path)))
Loading

0 comments on commit a1aab98

Please sign in to comment.