Skip to content

Commit

Permalink
Merge pull request #3 from shenyulu/dev
Browse files Browse the repository at this point in the history
Publish version 2023.12.01
  • Loading branch information
shenyulu committed Dec 10, 2023
2 parents 3b37fcf + 7dde630 commit 88bf44b
Show file tree
Hide file tree
Showing 62 changed files with 1,963 additions and 80 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/AutoPushToPypi.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
name: Push easyclimate to pypi
name: published easyclimate to pypi

on:
release:
types:
- published
push:
branches: [ main ]
tags:
- v*
# - TEST*
# paths:
# - 'rapid_videocr/**'
# - 'docs/doc_whl.md'
# - 'setup.py'
# - '.github/workflows/AutoPushToPypi.yml'
- 'v*'

jobs:
UnitTesting:
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/TEST_AutoPushToPypi.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Workflow for Codecov example-python
name: Workflow for Codecov easyclimate-python
on: [push, pull_request]
jobs:
run:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/.vscode
dist
**/.pytest_cache
.coverage
.coverage
.coverage*
21 changes: 12 additions & 9 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ geocat.viz <= 2023.10.0
cartopy >= 0.20
xeofs >= 1.1.0
matplotlib
pandas
fast-barnes-py
oceans
intel-fortran-rt
Expand All @@ -18,13 +19,15 @@ flox
xarray-datatree
xarray_regrid
gsw_xarray
pooch
tqdm

sphinx == 7.2.6
recommonmark
sphinx-markdown-tables
sphinxcontrib-jupyter
sphinx-inline-tabs
sphinx-gallery
sphinx-autoapi
sphinx-copybutton
sphinx-book-theme
sphinx == 6.2.1
recommonmark == 0.7.1
sphinx-markdown-tables == 0.0.17
sphinxcontrib-jupyter == 0.5.10
sphinx-inline-tabs == 2023.4.21
sphinx-gallery == 0.15.0
sphinx-autoapi == 3.0.0
sphinx-copybutton == 0.5.2
sphinx-book-theme == 1.0.1
5 changes: 4 additions & 1 deletion release_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ geocat.viz <= 2023.10.0
cartopy >= 0.20
xeofs >= 1.1.0
matplotlib
pandas
fast-barnes-py
oceans
intel-fortran-rt
Expand All @@ -17,4 +18,6 @@ pymannkendall
flox
xarray-datatree
xarray_regrid
gsw_xarray
gsw_xarray
pooch
tqdm
8 changes: 6 additions & 2 deletions src/easyclimate/core/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def calc_vertical_water_flux(
specific_humidity_data: xr.DataArray,
omega_data: xr.DataArray,
g = 9.8
) -> xr.Dataset:
) -> xr.DataArray:
"""
Calculate vertical water vapor flux.
Expand All @@ -903,7 +903,11 @@ def calc_vertical_water_flux(
omega_data: :py:class:`xarray.DataArray<xarray.DataArray>`.
The vertical velocity data (:math:`\\frac{\\mathrm{d} p}{\\mathrm{d} t}`).
g: :py:class:`float<python.float>`, default: `9.8`.
The acceleration of gravity.
The acceleration of gravity.
Returns
-------
The vertical water flux. (:py:class:`xarray.DataArray <xarray.DataArray>`).
"""
water_flux = -omega_data *specific_humidity_data /g
return water_flux
Expand Down
2 changes: 2 additions & 0 deletions src/easyclimate/core/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _construct_cache_dir(path):
"shum_202201_mon_mean": 4,
"uwnd_202201_mon_mean": 4,
"vwnd_202201_mon_mean": 4,
"omega_202201_mon_mean": 4,
"mini_HadISST_ice": 4,
"PressQFF_202007271200_872": 'csv',
}
Expand Down Expand Up @@ -102,6 +103,7 @@ def open_tutorial_dataset(
* ``"shum_202201_mon_mean"``: Absolute humidity of the NCEP reanalysis subset
* ``"uwnd_202201_mon_mean"``: Zonal wind of the NCEP reanalysis subset
* ``"vwnd_202201_mon_mean"``: Meridional wind of the NCEP reanalysis subset
* ``"omega_202201_mon_mean"``: Vertical velocity of the NCEP reanalysis subset
* ``"mini_HadISST_ice"``: Hadley Centre Sea Ice and Sea Surface Temperature data set (HadISST) subset
* ``"PressQFF_202007271200_872"``: Observational data from European stations (from https://github.com/EXCITED-CO2/xarray-regrid)
Expand Down
2 changes: 1 addition & 1 deletion src/easyclimate/core/variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def calc_climatological_mean(data_input: xr.DataArray, dim = 'time', **kwargs) -
-------
:py:class:`xarray.DataArray<xarray.DataArray>`.
"""
return data_input.mean(dim = dim)
return data_input.mean(dim = dim, **kwargs)

def calc_climatological_seasonal_mean(data_input: xr.DataArray, dim = 'time', **kwargs) -> xr.DataArray:
"""
Expand Down
1 change: 1 addition & 0 deletions test/const_define.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST_DATA_PATH = 'test/data'
Binary file added test/data/test_input_waveletpytest.nc
Binary file not shown.
Binary file added test/data/test_output_calc_absolute_vorticity.nc
Binary file not shown.
Binary file added test/data/test_output_calc_gradient.nc
Binary file not shown.
Binary file added test/data/test_output_calc_helmholtz.nc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/data/test_output_calc_planetary_vorticity.nc
Binary file not shown.
Binary file not shown.
Binary file added test/data/test_output_calc_rossby_wave_source.nc
Binary file not shown.
Binary file not shown.
Binary file added test/data/test_output_calc_wind_speed.nc
Binary file not shown.
Binary file added test/data/test_output_waveletpytest.nc
Binary file not shown.
91 changes: 90 additions & 1 deletion test/test_core_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import xarray as xr
import pandas as pd
from .util import round_sf_np

# Sample Data Declaration
t_data = xr.DataArray(
Expand Down Expand Up @@ -92,6 +91,27 @@
coords = {'lat': np.array([5.0, 2.5, 0.0]), 'lon': np.array([0.0, 2.5, 5.0])}
)

omega_data_sample1 = xr.DataArray(
np.array([ 0.02437097, 0.03512904, 0.04098387, 0.02112902, 0.01658062, 0.02814513, 0.03577418, 0.04062096, 0.03781452, 0.02902419, 0.00769354, -0.01137904]),
dims = "level",
coords = {'level': np.array([1000., 925., 850., 700., 600., 500., 400., 300., 250., 200., 150., 100.])}
)

q_data_sample1 = xr.DataArray(
np.array([17.74024, 13.399196, 9.72387, 5.151291, 3.0942986, 1.7616936 , 1.09875, 0.32160482]),
dims = "level",
coords = {'level': np.array([1000., 925., 850., 700., 600., 500., 400., 300.])}
)

t_data_sample1 = xr.DataArray(
np.array([299.68384, 294.31772, 290.3024 , 283.88385, 277.28384, 269.40726, 259.0016 , 245.04675, 234.3129 , 221.59273, 206.91853, 191.03226, 194.09918, 203.64514, 211.79112, 221.36288, 229.66693]),
dims = "level",
coords = {'level': np.array([1000., 925., 850., 700., 600., 500., 400., 300., 250., 200., 150., 100., 70., 50., 30., 20., 10.])}
)

# -----------------------------------------------------------
# TEST

def test_calc_gradient():
result_data = ecl.calc_gradient(t_data, dim = 'lon').data
refer_data = np.array([[ 0.12 , 0.08 , 0.04 ], [ 0.1 , 0. , -0.1 ], [ 0.025, -0.105, -0.235]])
Expand Down Expand Up @@ -222,6 +242,63 @@ def test_calc_horizontal_water_flux():
assert np.isclose(result_data1, refer_data1).all()
assert np.isclose(result_data2, refer_data2).all()

def test_calc_vertical_water_flux():
result_data = ecl.calc_vertical_water_flux(q_data_sample1, omega_data_sample1).data
refer_data = np.array([-0.04411703, -0.0480307 , -0.04066549, -0.0111063 , -0.00523524, -0.0050595 , -0.00401091, -0.00133305])
assert np.isclose(result_data, refer_data).all()

def test_calc_water_flux_top2surface_integral():
specific_humidity_data_sample = ecl.open_tutorial_dataset('shum_202201_mon_mean').shum.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))
u_data_sample = ecl.open_tutorial_dataset('uwnd_202201_mon_mean').uwnd.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))
v_data_sample = ecl.open_tutorial_dataset('vwnd_202201_mon_mean').vwnd.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))
surface_pressure_data_sample = ecl.open_tutorial_dataset('pressfc_202201_mon_mean').pres.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))

result_data = ecl.calc_water_flux_top2surface_integral(
specific_humidity_data_sample,
u_data_sample,
v_data_sample,
surface_pressure_data_sample,
surface_pressure_data_units = 'hPa',
vertical_dim = 'level',
vertical_dim_units = 'hPa',
)

result_data1 = result_data['qu'].data.flatten()
result_data2 = result_data['qv'].data.flatten()
refer_data1 = np.array([ -61719.65 , -53384.867, -46633.44 , -94774.73 , -84097.77 , -68822.93 , -127009.766, -119459.65 , -109226.625])
refer_data2 = np.array([ 1478.0461, 4159.2134, -2113.73 , 19404.598 , 21102.201 ,16411.918 , 31748.395 , 31434.625 , 23815.54 ])

assert np.isclose(result_data1, refer_data1).all()
assert np.isclose(result_data2, refer_data2).all()

def test_calc_divergence_watervaporflux():
result_data = ecl.calc_divergence_watervaporflux(
q_data_500hpa,
u_data_500hpa,
v_data_500hpa,
specific_humidity_units = 'g/kg',
).data.flatten()
refer_data = np.array([ 4.63115041e-10, 3.28054031e-10, 6.85267982e-11, -3.62682915e-10, -2.54289074e-10, -2.22359484e-10, -6.92384309e-10, -5.19564327e-10, -3.74825155e-10])
assert np.isclose(result_data, refer_data).all()

def test_calc_divergence_watervaporflux_top2surface_integral():
specific_humidity_data_sample = ecl.open_tutorial_dataset('shum_202201_mon_mean').shum.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))
u_data_sample = ecl.open_tutorial_dataset('uwnd_202201_mon_mean').uwnd.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))
v_data_sample = ecl.open_tutorial_dataset('vwnd_202201_mon_mean').vwnd.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))
surface_pressure_data_sample = ecl.open_tutorial_dataset('pressfc_202201_mon_mean').pres.isel(time = 0).sel(lat = slice(5, 0), lon = slice(0, 5))

result_data = ecl.calc_divergence_watervaporflux_top2surface_integral(
specific_humidity_data_sample,
u_data_sample,
v_data_sample,
surface_pressure_data_sample,
vertical_dim = 'level',
specific_humidity_units = 'g/kg',
surface_pressure_data_units = 'hPa',
vertical_dim_units = 'hPa',
).data.flatten()
refer_data = np.array([-3.16235016e-08, -5.25733773e-08, -6.11471233e-08, -1.84145484e-08, 3.67623974e-10, 1.46561626e-08, -1.93079642e-08, 1.67279636e-08, 3.28154620e-08])
assert np.isclose(result_data, refer_data).all()

def test_calc_u_advection():
result_data = ecl.calc_u_advection(u_data_500hpa, t_data).data.flatten()
Expand All @@ -235,4 +312,16 @@ def test_calc_v_advection():
refer_data = np.array([ 1.33300385e-07, -9.17452042e-08, -9.71419810e-08, -5.18270458e-07,
-4.12133849e-07, -6.69200313e-08, -3.96483196e-07, -1.24665542e-07,
2.81711745e-07])
assert np.isclose(result_data, refer_data).all()

def test_calc_p_advection():
result_data = ecl.calc_p_advection(
omega_data_sample1,
t_data_sample1,
vertical_dim = 'level',
vertical_dim_units = 'hPa'
)
refer_data = np.array([-1.96316937e-05, -2.19707321e-05, -1.90053499e-05, -1.10027766e-05,
-1.20015419e-05, -2.57278011e-05, -4.35738635e-05, -6.68585797e-05,
-8.86902508e-05, -7.95099400e-05, -2.35118198e-05, 1.82339871e-05])
assert np.isclose(result_data, refer_data).all()
Loading

0 comments on commit 88bf44b

Please sign in to comment.