Skip to content

Commit

Permalink
Merge pull request #30 from ecmwf/develop
Browse files Browse the repository at this point in the history
Small changes in GitHub Actions and version
  • Loading branch information
corentincarton authored Jul 23, 2024
2 parents 682336a + 5c47b9d commit 57b177e
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 48 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/hpc-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: hpc-module

on:
workflow_dispatch:
inputs:
module-name:
description: 'Module name'
required: true
type: string
module-tag:
description: 'Module tag'
required: false
default: 'NOT_DEFINED'
type: string
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
jobs:
install_module:
runs-on: [hpc]
steps:
- uses: ecmwf-actions/reusable-workflows/ci-hpc-generic@v2
with:
troika_user: ${{ secrets.HPC_CI_SSH_USER }}
template: |
MODULE_VERSION=${{ github.event_name == 'workflow_dispatch' && inputs.module-name || github.ref_name }}
MODULE_TAG=${{ github.event_name == 'workflow_dispatch' && inputs.module-tag || 'default'}}
HAT_BRANCH=${{ github.ref_name }}
PREFIX=/usr/local/apps/hat/${MODULE_VERSION}
rm -rf $PREFIX
mkdir -p $PREFIX
# Load the default python module
module load python3
PYTHONUSERBASE=$PREFIX pip3 install --user git+https://github.com/ecmwf/hat.git@${HAT_BRANCH}
module unload python3
software-sync -s local -p hat
module load modulemgr
modulemgr -f -m all sync hat
if [ $MODULE_TAG != 'NOT_DEFINED' ]
then
modulemgr -f -m all tag -o hat $MODULE_VERSION $MODULE_TAG
fi
sbatch_options: |
#SBATCH --job-name=cd_hat
#SBATCH --time=00:10:00
#SBATCH --qos=deploy
2 changes: 1 addition & 1 deletion .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
tags:
- "*"
- "[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Added by Sam Murphy
# project specific
.DS_Store
*.png
*.nc
Expand All @@ -11,7 +11,7 @@
notebooks/untracked/*
**/data/
.vscode/launch.json

hat/_version.py

# GENERIC PYTHON GITIGNORE FROM GIT HUB
#
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies:
- tqdm
- typer
- humanize
- typer
- ipyleaflet
- ipywidgets
- pip
Expand Down
8 changes: 8 additions & 0 deletions hat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
# from hat.config import read_config
# from hat.extract_simulations import extract_simulations
# from hat.read_observations import read_observations

try:
# NOTE: the `_version.py` file must not be present in the git repository
# as it is generated by setuptools at install time
from ._version import __version__
except ImportError: # pragma: no cover
# Local copy or not installed with setuptools
__version__ = ""
6 changes: 5 additions & 1 deletion hat/extract_simulation_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def extract_timeseries(

# all timeseries (i.e. handle proximal and duplicate stations)
da_stations = assign_stations(
stations, station_mask, da_points, coords, config["station_id_column_name"]
stations,
station_mask,
da_points,
coords,
config["station_id_column_name"],
)

return da_stations
5 changes: 4 additions & 1 deletion hat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

# @st.cache_data
def temporal_filter(
_metadata, _observations: pd.DataFrame, timeperiod, station_id_name="station_id"
_metadata,
_observations: pd.DataFrame,
timeperiod,
station_id_name="station_id",
):
"""
filter station metadata and timeseries by timeperiod
Expand Down
11 changes: 9 additions & 2 deletions hat/interactive/explorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ def __init__(self, config):
self.title_label = ipywidgets.Label(
"Interactive Map Visualisation for Hydrological Model Performance",
layout=ipywidgets.Layout(justify_content="center"),
style={"font_weight": "bold", "font_size": "24px", "font_family": "Arial"},
style={
"font_weight": "bold",
"font_size": "24px",
"font_family": "Arial",
},
)

# Create the interactive widgets
Expand Down Expand Up @@ -302,7 +306,10 @@ def create_frame(self):
width="40%",
)
right_layout = ipywidgets.Layout(
justify_content="center", align_items="center", spacing="2px", width="60%"
justify_content="center",
align_items="center",
spacing="2px",
width="60%",
)

# Frames
Expand Down
8 changes: 6 additions & 2 deletions hat/interactive/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(
basemap=ipyleaflet.basemaps.OpenStreetMap.Mapnik,
):
self.map = ipyleaflet.Map(
basemap=basemap, layout=ipywidgets.Layout(width="100%", height="600px")
basemap=basemap,
layout=ipywidgets.Layout(width="100%", height="600px"),
)
self.legend_widget = ipywidgets.Output()

Expand All @@ -56,7 +57,10 @@ def _set_boundaries(self, stations_metadata, coord_names):
min_lat, max_lat = min(lats), max(lats)
min_lon, max_lon = min(lons), max(lons)

bounds = [(float(min_lat), float(min_lon)), (float(max_lat), float(max_lon))]
bounds = [
(float(min_lat), float(min_lon)),
(float(max_lat), float(max_lon)),
]
self.map.fit_bounds(bounds)

def add_geolayer(self, geodata, colormap, widgets, coord_names=None):
Expand Down
10 changes: 6 additions & 4 deletions hat/interactive/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ def __init__(self, datasets):
height=350,
margin=dict(l=120),
legend=dict(
orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1,
),
xaxis_title="Date",
xaxis_tickformat="%d-%m-%Y",
Expand Down Expand Up @@ -262,9 +266,7 @@ def _update_title(self, metadata):
"""
station_id = metadata["station_id"]
station_name = metadata["StationName"]
updated_title = (
f"<b>Selected station:<br>ID: {station_id}, name: {station_name}</b> "
)
updated_title = f"<b>Selected station:<br>ID: {station_id}, name: {station_name}</b> " # noqa: E501
self.figure.update_layout(
title={
"text": updated_title,
Expand Down
6 changes: 4 additions & 2 deletions hat/mapping/station_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ def save_geo_dataframes(df, out_dir, cell_size):

# Create GeoDataFrames
gdf_station_point = gpd.GeoDataFrame(
df, geometry=[Point(xy) for xy in zip(df["station_lon"], df["station_lat"])]
df,
geometry=[Point(xy) for xy in zip(df["station_lon"], df["station_lat"])],
)
gdf_near_grid_polygon = gpd.GeoDataFrame(
df, geometry=df["near_grid_polygon_wkt"].apply(loads)
Expand All @@ -408,7 +409,8 @@ def save_geo_dataframes(df, out_dir, cell_size):
os.path.join(out_dir, "optimum_grid.geojson"), driver="GeoJSON"
)
gdf_line_optimum.to_file(
os.path.join(out_dir, "stations2grid_optimum_line.geojson"), driver="GeoJSON"
os.path.join(out_dir, "stations2grid_optimum_line.geojson"),
driver="GeoJSON",
)
gdf_station_point.to_csv(os.path.join(out_dir, "stations.csv"))

Expand Down
1 change: 0 additions & 1 deletion hat/version.py

This file was deleted.

102 changes: 100 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,101 @@
# required for isort and black to play nicely

[build-system]
requires = ["setuptools>=65", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "hydro_analysis_toolkit"
requires-python = ">=3.8"
authors = [
{name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "software.support@ecmwf.int"},
]
maintainers = [
{name = "Corentin Carton de Wiart", email = "corentin.carton@ecmwf.int"},
]
description = "ECMWF Hydrological Analysis Tools"
license = {file = "LICENSE"}
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering",
]
dynamic = ["version", "readme"]

dependencies = [
"numpy",
"pandas",
"xarray",
"matplotlib",
"geopandas",
"typer",
"humanize",
"tqdm",
"ipyleaflet",
"ipywidgets",
"earthkit-data",
"cfgrib"
]

[project.urls]
repository = "https://github.com/ecmwf/hat"
documentation = "https://hydro-analysis-toolkit.readthedocs.io"
issues = "https://github.com/ecmwf/hat/issues"

[project.optional-dependencies]
test = [
"pytest",
]
docs = [
"mkdocs",
"mkdocs-material",
"mkdocstrings-python",
"mkdocs-autorefs",
"mkdocs-gen-files",
"pymdown-extensions",
"markdown-exec[ansi]",
]

[project.scripts]
hat-extract-timeseries = "hat.tools.extract_simulation_timeseries_cli:main"
hat-hydrostats = "hat.tools.hydrostats_cli:main"
hat-stations-mapping = "hat.mapping.station_mapping:main"

[tool.isort]
profile = "black"
profile="black"

# Testing
[tool.pytest]
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"
testpaths = [
"tests",
]

# Packaging/setuptools options
[tool.setuptools]
include-package-data = true

[tool.setuptools.dynamic]
readme = {file = ["README.md"], content-type = "text/markdown"}

# [tool.setuptools.package_data]
# hat = ["config_json/*.json"]

[tool.setuptools.packages.find]
where = ["."]
exclude = ["tests"]

[tool.setuptools_scm]
write_to = "hat/_version.py"
write_to_template = '''
# Do not change! Do not track in version control!
__version__ = "{version}"
'''
parentdir_prefix_version='hat-' # get version from GitHub-like tarballs
fallback_version='0.7.1'
27 changes: 0 additions & 27 deletions setup.cfg

This file was deleted.

6 changes: 5 additions & 1 deletion tests/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def test_update(self):
class TestMetaDataWidget:
def test_update(self):
df = pd.DataFrame(
{"col1": [1, 2, 3], "col2": ["a", "b", "c"], "col3": [0.1, 0.2, 0.3]}
{
"col1": [1, 2, 3],
"col2": ["a", "b", "c"],
"col3": [0.1, 0.2, 0.3],
}
)
widget = wd.MetaDataWidget(df, "col2")
assert widget.update("a") is True
Expand Down
7 changes: 6 additions & 1 deletion tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ def test_create_grid_polygon():
lat, lon = 2.5, 2.5
cell_size = 1
polygon = create_grid_polygon(lat, lon, cell_size)
assert polygon.bounds == (2, 2, 3, 3) # Check if the polygon bounds are as expected
assert polygon.bounds == (
2,
2,
3,
3,
) # Check if the polygon bounds are as expected


@pytest.fixture
Expand Down

0 comments on commit 57b177e

Please sign in to comment.