Skip to content

Commit

Permalink
Add pre-commit to manage code style & repo QA (#121)
Browse files Browse the repository at this point in the history
* Add pre-commit to manage code style & repo QA

Introduced `.pre-commit-config.yaml` to configure pre-commit hooks,
including Black for code formatting and other QA checks. Updated
dependencies and environments to include `pre-commit` and `black` for
consistent coding standards.

pre-commit hooks:
* Code formatting by black
* Trim trailing whitespace
* Ensure that files are either empty, or end with one newline
* Confirm that YAML files have parsable syntax
* Confirm that TOML files have parsable syntax
* Prevent files larger than 500 kB from being committed

* Refactor code for consistency & formatting cleanup

Code style gardening by the pre-commit hooks, especially black.
Also fix CRLF line endings.

* Fix mixture of tabs and spaces for indentation

WARNING: This module has many other broken code issues in it. Much debugging
and modernization will be required if you want to use it.
  • Loading branch information
douglatornell authored Jan 4, 2025
1 parent ad92639 commit 44b3bad
Show file tree
Hide file tree
Showing 136 changed files with 17,195 additions and 10,297 deletions.
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Git pre-commit hooks config file
# Only takes effect if you have pre-commit installed in the env,
# and after you run `pre-commit install`
#
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
# Out-of-the-box hooks from the pre-commit org
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-added-large-files
# Code formatting with black
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion I_ForcingFiles/Atmos/AtmosphereGridSelection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion I_ForcingFiles/Atmos/NegativePrecip.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion I_ForcingFiles/Atmos/ProcessPramodArchive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1308,4 +1308,4 @@
"metadata": {}
}
]
}
}
110 changes: 55 additions & 55 deletions I_ForcingFiles/Atmos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ The links below are to static renderings of the notebooks via
Descriptions below the links are from the first cell of the notebooks
(if that cell contains Markdown or raw text).

* ## [GetGrib.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/GetGrib.ipynb)
* ## [GetGrib.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/GetGrib.ipynb)

Notebook to design script to download GRIB2 data from EC webpage

* ## [NegativePrecip.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/NegativePrecip.ipynb)
* ## [InitialGEMCheck.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/InitialGEMCheck.ipynb)
* ## [NegativePrecip.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/NegativePrecip.ipynb)

* ## [InitialGEMCheck.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/InitialGEMCheck.ipynb)

**Initial Check of GEM Products Forcing Data**

This notebook is about initial checks and exploration of the 2.5 km grid GEM products
atmospheric forcing dataset provided by Luc Fillion's group at EC Dorval.

* ## [RebaseCGRF.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/RebaseCGRF.ipynb)
* ## [RebaseCGRF.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/RebaseCGRF.ipynb)

**Rebasing CGRF Atmospheric Forcing Files**

This notebook documents and verifies the algorithm for
rebasing the [CGRF atmospheric forcing dataset][CGRF dataset] files.

[CGRF dataset]: https://salishsea-meopar-docs.readthedocs.org/en/latest/code-notes/salishsea-nemo/nemo-forcing/atmospheric.html#cgrf-dataset

The raw CGRF files contain hourly values that run from 06:00 UTC on the file's date
to 06:00 UTC on the following day.
For hourly forcing,
Expand All @@ -39,102 +39,102 @@ Descriptions below the links are from the first cell of the notebooks
by creating them as netCDF4 files with variable-level compression enabled.
Metadata that conforms to [CF-1.6 and Salish Sea MEOPAR project conventions][netCDF4 conventions] is included
in the new files.

[netCDF4 conventions]: https://salishsea-meopar-docs.readthedocs.org/en/latest/code-notes/salishsea-nemo/nemo-forcing/netcdf4.html#netcdf4-file-conventions

All of that processing is implemented in the [`salishsea get_cgrf`][salishsea get_cgrf] command.
This notebook provides explanation of that code,
and verification that the created files contain wind and precipitation forcing
values that are consistent with observations at Sandheads and YVR.

[salishsea get_cgrf]: https://salishsea-meopar-tools.readthedocs.org/en/latest/SalishSeaCmd/salishsea-cmd.html#get-cgrf-sub-command

* ## [ProcessPramodArchive.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/ProcessPramodArchive.ipynb)
* ## [ProcessPramodArchive.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/ProcessPramodArchive.ipynb)

Notebook to process Pramod's archived grib files to produce our netcdf files

* ## [OriginalVelocities.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/OriginalVelocities.ipynb)
* ## [CheckAltitude.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CheckAltitude.ipynb)
* ## [OriginalVelocities.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/OriginalVelocities.ipynb)

* ## [CheckAltitude.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CheckAltitude.ipynb)

This notebook checks that the altitude.py script generates a files that are reasonable.

It also combines the monthly altitude calculation into one file by averaging.

* ## [VerifyAtmosphericForcing.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/VerifyAtmosphericForcing.ipynb)
* ## [VerifyAtmosphericForcing.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/VerifyAtmosphericForcing.ipynb)

**Verification of Atmospheric Forcing**

* ## [CGridLocations.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CGridLocations.ipynb)
* ## [RadiationCheck.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/RadiationCheck.ipynb)
* ## [CGridLocations.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CGridLocations.ipynb)

* ## [RadiationCheck.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/RadiationCheck.ipynb)

This notebook compares the longwave/shortwave radiation from the GEM2.5 model provided by

1. Pramod converted from grib2 format to netcdf covering all of Dec 2012
2. Kao-Shen at Environment Canada covering 1 hour on Dec 16, 2012

Question: Are the longwave/shortwave radiation variables in Pramod's netcdf files the ones we should be using? There are several radiation flux variables in the grib2 output.

Description of grib2 variables
https://weather.gc.ca/grib/HRDPS_HR/HRDPS_ps2p5km_P000_deterministic_e.html

Plan: Comapre Pramod's radiation variables to Kao Shen's.

* ## [gribTnetcdf.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/gribTnetcdf.ipynb)
* ## [gribTnetcdf.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/gribTnetcdf.ipynb)

Notebook to convert grib2 files to netCDF files that can be used in NEMO
Makes use of wgrib2

* ## [netCDF4weights-CGRF.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/netCDF4weights-CGRF.ipynb)
* ## [netCDF4weights-CGRF.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/netCDF4weights-CGRF.ipynb)

**Convert Atmospheric Forcing Weights to netCDF4**
Transfer the values from the `met_gem_weight.nc`

Transfer the values from the `met_gem_weight.nc`
from the 2-Oct-2013 `WC3_PREP` tarball
into a netCDF4 file with zlib compression on variables
and CF-1.6 conventions conformant attributes.

* ## [ImproveWeightsFile.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/ImproveWeightsFile.ipynb)
* ## [ImproveWeightsFile.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/ImproveWeightsFile.ipynb)

**Improve Atmospheric Forcing Weights File**

Transfer the values from a `met_gem_weight.nc`
created by `NEMO_EastCoast/NEMO_Preparation/4_weights_ATMOS/get_weight_nemo`
into a netCDF4 file with zlib compression on variables
and CF-1.6 conventions conformant attributes.

* ## [CheckGridCoLocation.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CheckGridCoLocation.ipynb)
* ## [CheckGridCoLocation.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CheckGridCoLocation.ipynb)

Are the ugrid, vgrid and temperature at the same points

* ## [NoSnowIce.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/NoSnowIce.ipynb)
* ## [NoSnowIce.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/NoSnowIce.ipynb)

**Create `no_snow_ice.nc` File for NEMO Surface Forcing**

Create a netCDF4 file containing 2 variables named `snow` and `ice`.
The coordinates of the variable are `y` and `x`.
The values of `snow` and `ice` at all points in the domain is floating point zero.

The resulting `no_snow_ice.nc` file can be used as an annual climatology in NEMO atmospheric forcing
that does not require on-the-fly interpolation.
It imposes a no snow, ever condition on the NEMO configuration.
The no ice, ever condition that it provides works in conjunction with the code in `sbcice_if.F90` contributed by Michael Dunphy
to provide a minimal ice-model substitute.
to provide a minimal ice-model substitute.
In Michael's words,
> "The point is to make sure water temperatures don’t go below the local freezing point,
> "The point is to make sure water temperatures don’t go below the local freezing point,
> and there are some limits on heat exchanges as well."
* ## [RotateVelocities.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/RotateVelocities.ipynb)
* ## [RotateVelocities.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/RotateVelocities.ipynb)

Rotate the Wind

* ## [AtmosphereGridSelection.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/AtmosphereGridSelection.ipynb)
* ## [AtmosphereGridSelection.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/AtmosphereGridSelection.ipynb)

Notebook to Look at Atmosphereic Domains and Choose Ours

* ## [CheckRotation.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CheckRotation.ipynb)
* ## [CheckRotation.ipynb](https://nbviewer.org/github/SalishSeaCast/tools/blob/main/I_ForcingFiles/Atmos/CheckRotation.ipynb)


## License

Expand Down
2 changes: 1 addition & 1 deletion I_ForcingFiles/Atmos/RadiationCheck.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -778,4 +778,4 @@
"metadata": {}
}
]
}
}
2 changes: 1 addition & 1 deletion I_ForcingFiles/Atmos/VerifyAtmosphericForcing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1545,4 +1545,4 @@
"metadata": {}
}
]
}
}
Loading

0 comments on commit 44b3bad

Please sign in to comment.