Skip to content

Commit

Permalink
ADD: Gridding with fasr-barnes-py #55 from syedhamidali/gridding-test
Browse files Browse the repository at this point in the history
ADD: Gridding and AWS tools
  • Loading branch information
syedhamidali authored Dec 6, 2024
2 parents e9827a4 + 618708d commit c36839e
Show file tree
Hide file tree
Showing 26 changed files with 2,759 additions and 6 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ repos:
hooks:
- id: black
- id: black-jupyter
args: ["--line-length", "88"]
5 changes: 4 additions & 1 deletion ci/notebooktests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies:
- notebook
- numpy
- open-radar-data>=0.3.0
- pip
- pyproj
- pytest
- pytest-cov
Expand All @@ -36,3 +35,7 @@ dependencies:
- zarr
- nbval
- pooch
- itables
- pip
- pip:
- git+https://github.com/MeteoSwiss/fast-barnes-py.git
7 changes: 6 additions & 1 deletion ci/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies:
- netCDF4
- numpy
- open-radar-data>=0.3.0
- pip
- pyproj
- pytest
- pytest-cov
Expand All @@ -27,3 +26,9 @@ dependencies:
- xradar
- xmltodict
- pooch
- cartopy
- arm_pyart
- boto3
- pip
- pip:
- git+https://github.com/MeteoSwiss/fast-barnes-py.git
3 changes: 3 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# History

## 0.2.1 (Unreleased)
- **ADD:** Added fast-barnes-py gridding for radar. ({issue}`51`,`52`,`53`) and ({pull}`55`) by [@syedhamidali](https://github.com/syedhamidali)

## 0.2.0 (2024-11-18)
This is the first version which uses DataTree from xarray. Thus, xarray is pinned to version >=2024.10.0.
- **REL:** Version Release 0.2.0. ({issue}`45`), ({pull}`46`) by [@syedhamidali](https://github.com/syedhamidali)
Expand Down
10 changes: 10 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ import radarx
:caption: Examples
notebooks/IMD_Radar_Data
notebooks/Grid_Radar
notebooks/aws_data
```

```{toctree}
:maxdepth: 2
:caption: Gridding Rates
notebooks/gridding_rate_part1
notebooks/gridding_rate_part2
```
17 changes: 15 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ channels:
- conda-forge
- nodefaults
dependencies:
- python >=3.9,<3.12
- python >=3.9
- pydata-sphinx-theme
- pip
- myst-parser
- sphinx
- sphinx-copybutton
Expand All @@ -17,6 +16,8 @@ dependencies:
- lat_lon_parser
- netCDF4
- open-radar-data>=0.1.0
- proj
- proj-data
- pyproj
- xarray>=2024.10.0
- xmltodict
Expand All @@ -31,3 +32,15 @@ dependencies:
- zarr
- pooch
- xradar
- fsspec
- wradlib
- arm_pyart
- hvplot
- bokeh
- holoviews
- geoviews
- nbclassic
- itables
- pip
- pip:
- git+https://github.com/MeteoSwiss/fast-barnes-py.git
180 changes: 180 additions & 0 deletions examples/notebooks/Grid_Radar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Grid Radar -> Plot Max-CAPPI"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We are using [fast-barnes-py](https://github.com/MeteoSwiss/fast-barnes-py.git) to grid the radar data. Please cite if you use it in your research."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import fsspec\n",
"import radarx as rx\n",
"import xradar as xd\n",
"import cmweather # noqa\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"file = \"s3://noaa-nexrad-level2/2022/03/30/KGWX/KGWX20220330_234639_V06\"\n",
"local_file = fsspec.open_local(\n",
" f\"simplecache::s3://{file}\",\n",
" s3={\"anon\": True},\n",
" filecache={\"cache_storage\": \".\"},\n",
")\n",
"dtree = xd.io.open_nexradlevel2_datatree(local_file)\n",
"dtree = rx.combine_nexrad_sweeps(dtree)\n",
"dtree = dtree.xradar.georeference()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dtree.groups"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def filter_radar(ds):\n",
" ds = ds.where((ds.DBZH > -10) & (ds.DBZH < 75))\n",
" return ds"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dtree = dtree.xradar.map_over_sweeps(filter_radar)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a figure and axis\n",
"fig, ax = plt.subplots(figsize=(7, 5))\n",
"dtree[\"sweep_2\"][\"DBZH\"].plot.contourf(\n",
" x=\"x\",\n",
" y=\"y\",\n",
" levels=range(-10, 75),\n",
" cmap=\"NWSRef\",\n",
" ylim=(-200e3, 300e3), # Adjust y-axis limits\n",
" xlim=(-200e3, 300e3), # Adjust x-axis limits\n",
" ax=ax, # Use the created axis\n",
")\n",
"# Set the title\n",
"ax.set_title(\n",
" f\"{dtree.attrs['instrument_name']} {dtree['sweep_0']['time'].min().values}\"\n",
")\n",
"# Show the plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"ds = dtree.radarx.to_grid(\n",
" data_vars=[\"DBZH\"],\n",
" pseudo_cappi=True,\n",
" x_lim=(-100000.0, 100000.0),\n",
" y_lim=(-100000.0, 100000.0),\n",
" z_lim=(0, 10000.0),\n",
" x_step=1000,\n",
" y_step=1000,\n",
" z_step=250,\n",
" x_smth=0.2,\n",
" y_smth=0.2,\n",
" z_smth=1,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds.radarx.plot_max_cappi(\"DBZH\", cmap=\"ChaseSpectral\", add_slogan=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"ds2 = dtree.radarx.to_grid(\n",
" data_vars=[\"DBZH\"],\n",
" pseudo_cappi=False,\n",
" x_lim=(-200000.0, 200000.0),\n",
" y_lim=(-200000.0, 200000.0),\n",
" z_lim=(0, 15000.0),\n",
" x_step=1000,\n",
" y_step=1000,\n",
" z_step=250,\n",
" x_smth=0.2,\n",
" y_smth=0.2,\n",
" z_smth=1,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds2.radarx.plot_max_cappi(\"DBZH\", cmap=\"ChaseSpectral\", add_slogan=True)"
]
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit c36839e

Please sign in to comment.