Skip to content

Commit 2b28520

Browse files
authored
Merge branch 'main' into add-plotting-docs
2 parents 62f9031 + 802218b commit 2b28520

7 files changed

Lines changed: 105 additions & 33 deletions

File tree

.github/workflows/docs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
paths:
88
- 'docs/**'
99
- 'mkdocs.yml'
10+
- '.github/workflows/docs.yml'
1011

1112
jobs:
1213
deploy:
@@ -24,7 +25,8 @@ jobs:
2425
- name: Install MkDocs and dependencies
2526
run: |
2627
python -m pip install --upgrade pip
27-
pip install mkdocs mkdocs-macros-plugin requests
28+
pip install -r pyproject.toml --extra docs
29+
2830
2931
- name: Build docs
3032
run: mkdocs build

cdippy/ncstats.py

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44

55

66
class NcStats(StnData):
7-
"""For a given station, produces data availability.
7+
"""Produces data availability statistics for a given station.
88
9-
There are methods to return counts for the entire station record to be
10-
used diretly by a web app, and there are methods to save to disk availabililty
11-
counts (e.g. xyz counts) for individual nc files. In that case updates
12-
to totals would be calculated by re-summarizing any files that have changed
13-
and adding up all the files to produce new totals.
9+
This class provides methods to:
10+
* Return counts for the entire station record, intended for use by web applications.
11+
* Save availability counts (e.g., xyz counts) for individual NetCDF files.
12+
Updates to totals are calculated by re-summarizing any files that have changed
13+
and aggregating all files to produce new totals.
1414
"""
1515

1616
QC_flags = ["waveFlagPrimary", "sstFlagPrimary", "gpsStatusFlags"]
1717

1818
def __init__(self, stn: str, data_dir: str = None):
19-
"""
20-
PARAMETERS: See StnData
21-
"""
19+
"""Initializes an NcStats instance.
2220
21+
Args:
22+
stn (str): Station identifier.
23+
data_dir (str, optional): Path to the data directory. Defaults to None.
24+
"""
2325
StnData.__init__(self, stn, data_dir)
2426

2527
self.date_modifieds = {}
@@ -28,14 +30,26 @@ def __init__(self, stn: str, data_dir: str = None):
2830
self.pub_set = "all"
2931

3032
def make_stats(self) -> dict:
31-
"""Returns various statistics off the given station."""
33+
"""Computes station-level statistics.
34+
35+
Returns:
36+
dict: A dictionary containing:
37+
- "flag_counts" (dict): Flag count summaries for the station.
38+
- "deployments" (dict): Deployment summary statistics.
39+
"""
3240
result = {}
3341
result["flag_counts"] = self.flag_counts()
3442
result["deployments"] = self.deployment_summary()
3543
return result
3644

3745
def deployment_summary(self) -> dict:
38-
"""Returns deployment summary statistics."""
46+
"""Generates deployment summary statistics.
47+
48+
Returns:
49+
dict: A dictionary containing:
50+
- Deployment IDs as keys, with values containing start and end coverage times.
51+
- "number_of_deployments" (int): The number of deployments.
52+
"""
3953
self.load_nc_files()
4054
result = {}
4155
dep_cnt = 0
@@ -54,11 +68,26 @@ def deployment_summary(self) -> dict:
5468
return result
5569

5670
def load_nc_files(self, types: list = ["realtime", "historic", "archive"]) -> dict:
57-
"""Returns netCDF4 objects of a station's netcdf files"""
71+
"""Loads NetCDF files for the station.
72+
73+
Args:
74+
types (list, optional): List of file categories to load. Defaults to
75+
["realtime", "historic", "archive"].
76+
77+
Returns:
78+
dict: Dictionary of NetCDF file objects keyed by filename.
79+
"""
5880
self.nc_files = self.get_nc_files(types)
5981

6082
def load_file(self, nc_filename: str):
61-
"""Sets self.nc for a given nc_filename"""
83+
"""Loads a specific NetCDF file into the instance.
84+
85+
Args:
86+
nc_filename (str): Filename of the NetCDF file.
87+
88+
Sets:
89+
self.nc: Loaded NetCDF file object.
90+
"""
6291
if nc_filename in self.nc_files:
6392
self.nc = self.nc_files[nc_filename]
6493
else:
@@ -78,7 +107,15 @@ def nc_file_summaries(self) -> dict:
78107
return result
79108

80109
def nc_file_summary(self, nc_filename: str) -> dict:
81-
"""Returns statistical summaries given an nc file name."""
110+
"""Computes a summary for a given NetCDF file.
111+
112+
Args:
113+
nc_filename (str): Name of the NetCDF file.
114+
115+
Returns:
116+
dict: Summary statistics for the file, including:
117+
- "flag_counts" (dict): Flag count statistics.
118+
"""
82119
if self.nc is None:
83120
self.load_file(nc_filename)
84121
result = {}
@@ -87,7 +124,17 @@ def nc_file_summary(self, nc_filename: str) -> dict:
87124
return result
88125

89126
def flag_counts(self, QC_flags: list = None) -> dict:
90-
"""Returns pandas dataframe of counts of flag variables for the entire station record."""
127+
"""Computes counts of flag variables for the entire station record.
128+
129+
Args:
130+
QC_flags (list, optional): List of quality-control flag variable names.
131+
Defaults to `self.QC_flags`.
132+
133+
Returns:
134+
dict: A dictionary containing:
135+
- "totals" (dict[str, pandas.DataFrame]): Total counts per flag.
136+
- "by_month" (dict[str, pandas.DataFrame]): Monthly counts per flag.
137+
"""
91138
result = {"totals": {}, "by_month": {}}
92139
if not QC_flags:
93140
QC_flags = self.QC_flags
@@ -100,11 +147,26 @@ def flag_counts(self, QC_flags: list = None) -> dict:
100147
return result
101148

102149
def total_count(self, cat_var) -> pd.DataFrame:
103-
"""Returns count totals for a given flag variable."""
150+
"""Counts totals for a given categorical flag variable.
151+
152+
Args:
153+
cat_var (pandas.Categorical): Categorical flag variable.
154+
155+
Returns:
156+
pandas.DataFrame: DataFrame with counts grouped by category.
157+
"""
104158
return pd.DataFrame({"cnt": cat_var}).groupby(cat_var).count()
105159

106160
def by_month_count(self, cat_var, dim: str) -> pd.DataFrame:
107-
"""Returns pandas dataframe of Counts by month for a given flag variable."""
161+
"""Counts observations by month for a given flag variable.
162+
163+
Args:
164+
cat_var (pandas.Categorical): Categorical flag variable.
165+
dim (str): Dimension name prefix for the time variable.
166+
167+
Returns:
168+
pandas.DataFrame: DataFrame with counts grouped by month and flag value.
169+
"""
108170
df = pd.DataFrame(
109171
{"cnt": cat_var}, index=pd.to_datetime(self.data[dim + "Time"], unit="s")
110172
)

docs/dev_guide/contribute.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Thank you for considering making a contribution to CDIPpy! We welcome all types
99
## Setting up your git workflow
1010
This project uses a fork-and-pull-request workflow. You will need to make your [fork](https://github.com/cdipsw/CDIPpy/fork) of the repository to work in, and submit changes to CDIPpy via pull request. To set up your workflow, follow these instructions:
1111

12-
1. Fork the respository at [https://github.com/cdipsw/CDIPpy/fork](https://github.com/cdipsw/CDIPpy/fork)
13-
2. Clone the repository from your fork `git clone https://github.com/{your_github_username}/CDIPpy.git` - this will add your own fork as your `origin` remote repo. *Note: If you already have the main fork cloned, skip to the next step and follow instuctions to add your fork as another remote.*
12+
1. Fork the repository at [https://github.com/cdipsw/CDIPpy/fork](https://github.com/cdipsw/CDIPpy/fork)
13+
2. Clone the repository from your fork `git clone https://github.com/{your_github_username}/CDIPpy.git` - this will add your own fork as your `origin` remote repo. *Note: If you already have the main fork cloned, skip to the next step and follow instructions to add your fork as another remote.*
1414
3. Add the main fork as another remote (or your fork, if you cloned from the main fork). This will allow you to pull latest code from the main fork, but push your own development to your own fork:
1515
```bash
1616
git add remote cdip https://github.com/cdipsw/CDIPpy.git
@@ -26,21 +26,21 @@ git checkout main # make sure this is cdip/main not your fork
2626
git pull
2727
git checkout -b example-branch
2828
```
29-
This will create a new branch called `example-branch` based on the lastest commit to `main`. Now you can start making your changes.
29+
This will create a new branch called `example-branch` based on the latest commit to `main`. Now you can start making your changes.
3030

3131
Any changes you plan to contribute should be sure to follow the project's style guide, testing structure, and be up-to-date with documentation.
3232

3333
### linting
34-
First you'll need to make sure your code style matches the rest of `cdippy` by using the `flake8` linter to check for adherance to the [PEP8](https://peps.python.org/pep-0008/) style guide:
34+
First you'll need to make sure your code style matches the rest of `cdippy` by using the `flake8` linter to check for adherence to the [PEP8](https://peps.python.org/pep-0008/) style guide:
3535
```bash
3636
flake8 .
3737
```
38-
If this commnad is successful, your style is up to date! Otherwise, the output will indicate where in the project the style is not compliant. You can manually fix these style deviations, or use a tool like [`black`](https://black.readthedocs.io/en/stable/) to autolint:
38+
If this command is successful, your style is up to date! Otherwise, the output will indicate where in the project the style is not compliant. You can manually fix these style deviations, or use a tool like [`black`](https://black.readthedocs.io/en/stable/) to autolint:
3939
```bash
4040
black .
4141
```
4242

43-
This project also provides a [`pre-commit`](https://pre-commit.com/) hook to manage style for you autmatically on every `git commit`. From the porject root:
43+
This project also provides a [`pre-commit`](https://pre-commit.com/) hook to manage style for you automatically on every `git commit`. From the project root:
4444
```bash
4545
pre-commit install
4646
```

docs/dev_guide/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ You'll specifically want to look at configuring credentials with [https](https:/
1515
## Install with dev tools
1616
It is recommended to us [`uv`](https://docs.astral.sh/uv/) to manage you development environment for this project, but other package managers will likely work as well. This documentation provides instructions for using `uv`.
1717

18-
Navigate to the project root dirctory ('CDIPpy/') and run the following:
18+
Navigate to the project root directory ('CDIPpy/') and run the following:
1919
``` bash
20-
>>> pip install uv # install uv pacakge manager
21-
>>> uv sync # create a virtual envionment at CDIPpy/.venv/, install the source code, its runtime dependencies and it's dev dependencies defined in pyproject.toml.
20+
>>> pip install uv # install uv package manager
21+
>>> uv sync # create a virtual environment at CDIPpy/.venv/, install the source code, its runtime dependencies and it's dev dependencies defined in pyproject.toml.
2222
>>> source .venv/bin/activate # activate the environment
2323
```
24-
To exclude the development dpendancies, you can run `uv sync --no-dev`.
24+
To exclude the development dependencies, you can run `uv sync --no-dev`.
2525

2626
### testing
2727
You can check that your dev installation was successful by running unit tests from the root directory: `python -m unittest discover`.
@@ -30,6 +30,6 @@ This runs every test in the library; you should see all successful tests.
3030
Learn more about running specific tests or subsets from the [`unittest` docs](https://docs.python.org/3/library/unittest.html).
3131

3232
### linting
33-
This library uses `flake8` to check for adherance to the [PEP8](https://peps.python.org/pep-0008/) style guide. To check whether your code is compliant with the project style, run `flake8 .` from the project root. You can fix problems manually, or use a tool like [`black`](https://black.readthedocs.io/en/stable/) to autolint: `black .`.
33+
This library uses `flake8` to check for adherence to the [PEP8](https://peps.python.org/pep-0008/) style guide. To check whether your code is compliant with the project style, run `flake8 .` from the project root. You can fix problems manually, or use a tool like [`black`](https://black.readthedocs.io/en/stable/) to autolint: `black .`.
3434

35-
This project also provides a [`pre-commit`](https://pre-commit.com/) hook to manage style for you autmatically on every `git commit`. To install it, run `pre-commit install` from the project root - this will use `black` and `flake` to autolint and check any changes you make for style before committing them to the repository.
35+
This project also provides a [`pre-commit`](https://pre-commit.com/) hook to manage style for you automatically on every `git commit`. To install it, run `pre-commit install` from the project root - this will use `black` and `flake` to autolint and check any changes you make for style before committing them to the repository.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CDIPpy is python library for navigating and accessing products provided by the [
44
A goal of publishing this library as an open source, contributable package is to foster closer collaboration between CDIP and the community of users.
55

66
## Navigating these docs
7-
The CDIP user community spans a brooad expertise and vastly different backgrounds in python development and usage - use the following guidelines to determine where to start in the documentation:
7+
The CDIP user community spans a broad expertise and vastly different backgrounds in python development and usage - use the following guidelines to determine where to start in the documentation:
88

99
* If you are relatively comfortable working with python, visit the [Quickstart Guide](quickstart.md).
1010
* If you would like more explicit, step-by-step instructions for:

docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To view the coverage report:
3939
Contributions are welcome and should be merged via pull request on the `main` branch from a forked repository. Before a PR can be merged, it needs to pass the following checks:
4040

4141
* all tests passed
42-
* coverage >= threshhold
42+
* coverage >= threshold
4343
* passes [`flake8`](https://flake8.pycqa.org/en/latest/) linter
4444
* there must be at least one reviewer approval
4545
* a CLA must be signed by the contributor, if this is their first commit

pyproject.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ requires = ["setuptools>=61.0"]
2929
build-backend = "setuptools.build_meta"
3030

3131
[dependency-groups]
32+
docs = [
33+
"mkdocs",
34+
"mkdocs-jupyter",
35+
"mkdocs-macros-plugin",
36+
"mkdocs-material",
37+
"mkdocstrings[python]",
38+
"mkdocs-material",
39+
]
40+
3241
dev = [
3342
"black",
3443
"coverage",
@@ -39,7 +48,6 @@ dev = [
3948
"mkdocs-material",
4049
"mkdocstrings[python]",
4150
"mkdocs-material",
42-
"mkdocstrings[python]",
4351
"nbval",
4452
"pre-commit",
4553
"pytest",

0 commit comments

Comments
 (0)