Skip to content

Commit

Permalink
Merge pull request #5 from cedadev/CF1.12
Browse files Browse the repository at this point in the history
Version 2024.8.9 - CF-1.12 updates
  • Loading branch information
dwest77a authored Aug 13, 2024
2 parents 508cb71 + 364d25d commit 59d5ed9
Show file tree
Hide file tree
Showing 68 changed files with 1,657 additions and 3,510 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Automatic Test
# Specify which GitHub events will trigger a CI build

on: push
# Define a single job, build

jobs:
build:
# Specify an OS for the runner
runs-on: ubuntu-latest

#Define steps
steps:

# Firstly, checkout repo
- name: Checkout repository
uses: actions/checkout@v2
# Set up Python env
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.11
# Install dependencies
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
pip3 install -e .
# Test with pytest
- name: Run pytest
run: |
pytest
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ cf_repos
xarray_repos
notes
*.pyc
*ipynb_checkpoints*
*ipynb_checkpoints*
CFAPyX/__pycache__/*.pyc
CFAPyX.egg-info/
.vscode/
testing/
14 changes: 0 additions & 14 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion CFAPyX/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .backendentrypoint import CFANetCDFBackendEntrypoint
from .backend import CFANetCDFBackendEntrypoint
Binary file removed CFAPyX/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed CFAPyX/__pycache__/backendentrypoint.cpython-311.pyc
Binary file not shown.
Binary file removed CFAPyX/__pycache__/datastore.cpython-311.pyc
Binary file not shown.
Binary file removed CFAPyX/__pycache__/decoder.cpython-311.pyc
Binary file not shown.
Binary file removed CFAPyX/__pycache__/fragmentarray.cpython-311.pyc
Binary file not shown.
Binary file removed CFAPyX/__pycache__/utils.cpython-311.pyc
Binary file not shown.
30 changes: 0 additions & 30 deletions CFAPyX/active.py

This file was deleted.

29 changes: 23 additions & 6 deletions CFAPyX/backendentrypoint.py → CFAPyX/backend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__author__ = "Daniel Westwood"
__contact__ = "daniel.westwood@stfc.ac.uk"
__copyright__ = "Copyright 2023 United Kingdom Research and Innovation"

from xarray.backends import StoreBackendEntrypoint, BackendEntrypoint
from xarray.backends.common import AbstractDataStore
Expand All @@ -7,7 +10,6 @@
from CFAPyX.datastore import CFADataStore

from importlib.metadata import entry_points
#engine = entry_points(group='xarray.backends')

def open_cfa_dataset(
filename_or_obj,
Expand All @@ -19,6 +21,7 @@ def open_cfa_dataset(
use_cftime=None,
decode_timedelta=None,
cfa_options={},
active_options={},
group=None,
):
"""
Expand Down Expand Up @@ -46,7 +49,8 @@ def open_cfa_dataset(
store = CFADataStore.open(filename_or_obj, group=group)

# Expands cfa_options into individual kwargs for the store.
store.cfa_options = cfa_options
store.cfa_options = cfa_options
store.active_options = active_options

# Xarray makes use of StoreBackendEntrypoints to provide the Dataset 'ds'
store_entrypoint = CFAStoreBackendEntrypoint()
Expand All @@ -59,6 +63,7 @@ def open_cfa_dataset(
drop_variables=drop_variables,
use_cftime=use_cftime,
decode_timedelta=decode_timedelta,
use_active=store.use_active
)

return ds
Expand All @@ -80,6 +85,7 @@ def open_dataset(
use_cftime=None,
decode_timedelta=None,
cfa_options={},
active_options={},
group=None,
# backend specific keyword arguments
# do not use 'chunks' or 'cache' here
Expand All @@ -99,12 +105,12 @@ def open_dataset(
use_cftime=use_cftime,
decode_timedelta=decode_timedelta,
cfa_options=cfa_options,
active_options=active_options,
group=group)


class CFAStoreBackendEntrypoint(StoreBackendEntrypoint):
description = "Open CFA-based Abstract Data Store"
url = "https://docs.xarray.dev/en/stable/generated/xarray.backends.StoreBackendEntrypoint.html"
url = "https://cedadev.github.io/CFAPyX/"

def open_dataset(
self,
Expand All @@ -117,6 +123,7 @@ def open_dataset(
drop_variables=None,
use_cftime=None,
decode_timedelta=None,
use_active=False,
) -> Dataset:
"""
Takes cfa_xarray_store of type AbstractDataStore and creates an xarray.Dataset object.
Expand All @@ -128,7 +135,6 @@ def open_dataset(
:returns: An xarray.Dataset object composed of xarray.DataArray objects representing the different
NetCDF variables and dimensions. CFA aggregated variables are decoded unless the ``decode_cfa``
parameter in ``cfa_options`` is false.
"""
assert isinstance(cfa_xarray_store, AbstractDataStore)
Expand All @@ -151,7 +157,18 @@ def open_dataset(
)

# Create the xarray.Dataset object here.
ds = Dataset(vars, attrs=attrs)
if use_active:
try:
from XarrayActive import ActiveDataset

ds = ActiveDataset(vars, attrs=attrs)
except ImportError:
raise ImportError(
'"ActiveDataset" from XarrayActive failed to import - please ensure you have the XarrayActive package installed.'
)
else:
ds = Dataset(vars, attrs=attrs)

ds = ds.set_coords(coord_names.intersection(vars))
ds.set_close(cfa_xarray_store.close)
ds.encoding = encoding
Expand Down
Loading

0 comments on commit 59d5ed9

Please sign in to comment.