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

add CI and warning to readme #7

Merged
merged 14 commits into from
Jan 24, 2024
Merged
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
153 changes: 153 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: ci
on:
# Trigger the workflow on push to master or develop, except tag creation
push:
branches:
- 'main'
- 'develop'
# Trigger the workflow on pull request
pull_request: ~
# Trigger the workflow manually
workflow_dispatch: ~
# Trigger after public PR approved for CI
pull_request_target:
types: [labeled]
release:
types: [created]
jobs:
qa:
name: qa
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install black flake8 isort
- name: Check isort
run: isort --check .

- name: Check black
run: black --check .

- name: Check flake8
run: flake8 .
setup:
name: setup
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
inputs: ${{ steps.prepare-inputs.outputs.inputs }}
inputs-for-ubuntu: ${{ steps.prepare-inputs.outputs.inputs-for-ubuntu }}
steps:
- name: Set Matrix
id: set-matrix
shell: bash -eux {0}
run: |
MATRIX=$(cat << 'EOS'
name:
- [email protected]
- [email protected]
include:
- name: [email protected]
os: ubuntu-22.04
compiler: gnu-11
compiler_cc: gcc-11
compiler_cxx: g++-11
compiler_fc: gfortran-11
- name: [email protected]
os: ubuntu-22.04
compiler: clang-14
compiler_cc: clang-14
compiler_cxx: clang++-14
compiler_fc: gfortran-11
# Xcode compiler requires empty environment variables, so we pass null (~) here
EOS
)
SKIP_MATRIX_JOBS=$(cat << 'EOS'
${{ inputs.skip_matrix_jobs }}
EOS
)
SELECT_NAME_COND="1 != 1"
SELECT_INCLUDE_COND="1 != 1"
for skip_job in $SKIP_MATRIX_JOBS; do SELECT_NAME_COND="$SELECT_NAME_COND or . == \"$skip_job\""; SELECT_INCLUDE_COND="$SELECT_INCLUDE_COND or .name == \"$skip_job\""; done
echo matrix=$(echo "$MATRIX" | yq eval "del(.name[] | select($SELECT_NAME_COND)) | del(.include[] | select($SELECT_INCLUDE_COND))" --output-format json --indent 0 -) >> $GITHUB_OUTPUT
- name: Prepare build-package Inputs
id: prepare-inputs
shell: bash -eux {0}
run: |
echo inputs=$(echo "${{ inputs.build_package_inputs || '{}' }}" | yq eval '.' --output-format json --indent 0 -) >> $GITHUB_OUTPUT
echo inputs-for-ubuntu=$(echo "${{ inputs.build_package_inputs || '{}' }}" | yq eval '. * {"os":"ubuntu-20.04","compiler":"gnu-10","compiler_cc":"gcc-10","compiler_cxx":"g++-10","compiler_fc":"gfortran-10"}' --output-format json --indent 0 -) >> $GITHUB_OUTPUT
test:
name: test
needs:
- qa
- setup
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pip setuptools wheel
python -m pip install pytest pytest-cov
python -m pip install -r requirements.txt
python -m pip install -r ./tests/requirements_test.txt

- name: Verify Source Distribution
shell: bash -eux {0}
run: |
python setup.py sdist
python -m pip install dist/*
- name: Run Tests with Repository Code
env:
LD_LIBRARY_PATH: ${{ steps.install-dependencies.outputs.lib_path }}
shell: bash -eux {0}
run: |
DYLD_LIBRARY_PATH=${{ env.LD_LIBRARY_PATH }} python -m pytest -m "not data" tests --cov=./ --cov-report=xml
python -m coverage report

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: coverage.xml
deploy:
needs: test
if: ${{ github.event_name == 'release' }}
name: Upload to Pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist
twine upload dist/*
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ ECMWF library for encoding and decoding coerageJSON files/objects of meteorlogic

* Encodes and decodes CoverageJSON objects

* CoverageCollection(python dictionary)
* get_coverages()

* Coverage()
* get_axes()
* get_metadata()
* get_ranges()
* get_parameters()


* TimeSeriesCoverage()
* set_axes()
* set_ranges()
* set_parameters()
| :warning: This project is BETA and will be experimental for the foreseeable future. Interfaces and functionality are likely to change. DO NOT use this software in any project/software that is operational. |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
3 changes: 0 additions & 3 deletions eccovjson/Coverage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import json


class Coverage:
def __init__(self, covjson):
if isinstance(covjson, dict):
Expand Down
7 changes: 1 addition & 6 deletions eccovjson/CoverageCollection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import json


class CoverageCollection:
def __init__(self, covjson):
if isinstance(covjson, dict):
Expand All @@ -12,8 +9,6 @@ def __init__(self, covjson):
if self.type == "CoverageCollection":
print("Correct Type")
elif self.type == "Coverage":
raise TypeError(
"CoverageCollection class takes CoverageCollection not Coverage"
)
raise TypeError("CoverageCollection class takes CoverageCollection not Coverage")

self.coverages = self.coverage["coverages"]
8 changes: 4 additions & 4 deletions eccovjson/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import eccovjson.encoder.VerticalProfile
import eccovjson.encoder.TimeSeries
import eccovjson.decoder.VerticalProfile
import eccovjson.decoder.TimeSeries
import eccovjson.api
import eccovjson.decoder.TimeSeries
import eccovjson.decoder.VerticalProfile
import eccovjson.encoder.TimeSeries
import eccovjson.encoder.VerticalProfile
10 changes: 4 additions & 6 deletions eccovjson/api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json

import eccovjson.decoder.BoundingBox
import eccovjson.decoder.Frame
import eccovjson.decoder.TimeSeries
import eccovjson.decoder.VerticalProfile
import eccovjson.encoder.TimeSeries
import eccovjson.encoder.VerticalProfile
import eccovjson.encoder.BoundingBox
import eccovjson.decoder.BoundingBox
import eccovjson.encoder.Frame
import eccovjson.decoder.Frame
import eccovjson.encoder.TimeSeries
import eccovjson.encoder.VerticalProfile

features_encoder = {
"pointseries": eccovjson.encoder.TimeSeries.TimeSeries,
Expand Down
24 changes: 8 additions & 16 deletions eccovjson/decoder/BoundingBox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .decoder import Decoder
import xarray as xr
import datetime as dt

import xarray as xr

from .decoder import Decoder


class BoundingBox(Decoder):
def __init__(self, covjson):
Expand Down Expand Up @@ -74,15 +76,9 @@ def to_xarray(self):
num = [int(coord[0][5]) for coord in coords]
coords_fc = coords[ind]
try:
t = [
dt.datetime.strptime(coord[4], "%Y-%m-%d %H:%M:%S")
for coord in coords_fc
]
t = [dt.datetime.strptime(coord[4], "%Y-%m-%d %H:%M:%S") for coord in coords_fc]
except ValueError:
t = [
dt.datetime.strptime(coord[4], "%Y-%m-%dT%H:%M:%S")
for coord in coords_fc
]
t = [dt.datetime.strptime(coord[4], "%Y-%m-%dT%H:%M:%S") for coord in coords_fc]

param_coords = {"x": xs, "y": ys, "z": zs, "number": num, "t": t}
dataarray = xr.DataArray(
Expand All @@ -93,12 +89,8 @@ def to_xarray(self):
)

dataarray.attrs["type"] = self.get_parameter_metadata(parameter)["type"]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)[
"unit"
]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)[
"description"
]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)["unit"]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)["description"]
dataarraydict[dataarray.attrs["long_name"]] = dataarray

ds = xr.Dataset(dataarraydict)
Expand Down
24 changes: 8 additions & 16 deletions eccovjson/decoder/Frame.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .decoder import Decoder
import xarray as xr
import datetime as dt

import xarray as xr

from .decoder import Decoder


class Frame(Decoder):
def __init__(self, covjson):
Expand Down Expand Up @@ -71,15 +73,9 @@ def to_xarray(self):
num = [int(coord[0][5]) for coord in coords]
coords_fc = coords[ind]
try:
t = [
dt.datetime.strptime(coord[4], "%Y-%m-%d %H:%M:%S")
for coord in coords_fc
]
t = [dt.datetime.strptime(coord[4], "%Y-%m-%d %H:%M:%S") for coord in coords_fc]
except ValueError:
t = [
dt.datetime.strptime(coord[4], "%Y-%m-%dT%H:%M:%S")
for coord in coords_fc
]
t = [dt.datetime.strptime(coord[4], "%Y-%m-%dT%H:%M:%S") for coord in coords_fc]

param_coords = {"x": xs, "y": ys, "z": zs, "number": num, "t": t}
dataarray = xr.DataArray(
Expand All @@ -90,12 +86,8 @@ def to_xarray(self):
)

dataarray.attrs["type"] = self.get_parameter_metadata(parameter)["type"]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)[
"unit"
]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)[
"description"
]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)["unit"]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)["description"]
dataarraydict[dataarray.attrs["long_name"]] = dataarray

ds = xr.Dataset(dataarraydict)
Expand Down
26 changes: 9 additions & 17 deletions eccovjson/decoder/TimeSeries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .decoder import Decoder
import xarray as xr
import datetime as dt

import xarray as xr

from .decoder import Decoder


class TimeSeries(Decoder):
def __init__(self, covjson):
Expand Down Expand Up @@ -75,15 +77,9 @@ def to_xarray(self):
num = [int(coord[0][5]) for coord in coords]
coords_fc = coords[ind]
try:
t = [
dt.datetime.strptime(coord[4], "%Y-%m-%d %H:%M:%S")
for coord in coords_fc
]
t = [dt.datetime.strptime(coord[4], "%Y-%m-%d %H:%M:%S") for coord in coords_fc]
except ValueError:
t = [
dt.datetime.strptime(coord[4], "%Y-%m-%dT%H:%M:%S")
for coord in coords_fc
]
t = [dt.datetime.strptime(coord[4], "%Y-%m-%dT%H:%M:%S") for coord in coords_fc]

param_coords = {"x": x, "y": y, "z": z, "number": num, "t": t}
dataarray = xr.DataArray(
Expand All @@ -94,12 +90,8 @@ def to_xarray(self):
)

dataarray.attrs["type"] = self.get_parameter_metadata(parameter)["type"]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)[
"unit"
]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)[
"description"
]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)["unit"]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)["description"]
dataarraydict[dataarray.attrs["long_name"]] = dataarray

ds = xr.Dataset(dataarraydict)
Expand All @@ -110,7 +102,7 @@ def to_xarray(self):
return ds


"""
"""
def to_xarray(self):
dims = ["x", "y", "z", "fct", "t"]
dataarraydict = {}
Expand Down
11 changes: 4 additions & 7 deletions eccovjson/decoder/VerticalProfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .decoder import Decoder
import xarray as xr

from .decoder import Decoder


class VerticalProfile(Decoder):
def __init__(self, covjson):
Expand Down Expand Up @@ -79,12 +80,8 @@ def to_xarray(self):
name=parameter,
)
dataarray.attrs["type"] = self.get_parameter_metadata(parameter)["type"]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)[
"unit"
]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)[
"description"
]
dataarray.attrs["units"] = self.get_parameter_metadata(parameter)["unit"]["symbol"]
dataarray.attrs["long_name"] = self.get_parameter_metadata(parameter)["description"]
dataarraydict[dataarray.attrs["long_name"]] = dataarray

ds = xr.Dataset(dataarraydict)
Expand Down
Loading
Loading