Skip to content

Commit

Permalink
add GHA to convert CDL <-> NC
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Apr 25, 2024
1 parent b1f4890 commit 1b7250d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/keeping-your-actions-up-to-date-with-dependabot

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
labels:
- "Bot"
26 changes: 26 additions & 0 deletions .github/workflows/convert_cdl_nc_cdl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Full Tests

on:
pull_request:
push:
branches: [main]

jobs:
run:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Micromamba Python
uses: mamba-org/setup-micromamba@v1
with:
environment-name: GHA
init-shell: bash
create-args: >-
python=3 netcdf4 --channel conda-forge
- name: Convert NC files to CDL and back
shell: bash -l {0}
run: |
python convert_nc_cdl.py
30 changes: 30 additions & 0 deletions convert_nc_cdl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from netCDF4 import Dataset


def convert_nc_to_cdl(nc_fname):
cdl_fname = nc_fname.with_suffix(".cdl")
if cdl_fname.exists():
print(f"The {cdl_fname} file already exists, not overwriting it.")
return
with Dataset(nc_fname) as nc:
print(f"Converting {nc_fname} to {cdl_fname}.")
nc.tocdl(coordvars=True, data=True, outfile=cdl_fname)

def convert_cdl_to_nc(cdl_name):
nc_fname = cdl_fname.with_suffix(".nc")
if nc_fname.exists():
print(f"The {nc_fname} file already exists, not overwriting it.")
return
print(f"Converting {cdl_fname} to {nc_fname}.")
Dataset.fromcdl(cdl_fname)


if __name__ == "__main__":
from pathlib import Path

datasets_path = Path("datasets")
for nc_fname in datasets_path.glob("*.nc"):
convert_nc_to_cdl(nc_fname)

for cdl_fname in datasets_path.glob("*.cdl"):
convert_cdl_to_nc(cdl_fname)

0 comments on commit 1b7250d

Please sign in to comment.