Skip to content

Commit 33656e4

Browse files
authored
Merge pull request #131 from rcjackson/io_fix
FIX: Grid attrs and pre-commit hooks
2 parents d5dec7a + 828a3b2 commit 33656e4

File tree

14 files changed

+244
-450
lines changed

14 files changed

+244
-450
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/psf/black
9-
rev: 22.10.0
9+
rev: 24.8.0
1010
hooks:
1111
- id: black
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
1313
# Ruff version.
14-
rev: v0.0.286
14+
rev: v0.6.4
1515
hooks:
16+
# Run the linter.
1617
- id: ruff
18+
# Run the formatter.
19+
- id: ruff-format

continuous_integration/environment-actions.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ dependencies:
2121
- cmweather
2222
- jax
2323
- jaxopt
24-
- tensorflow>=2.6
25-
- tensorflow-probability
26-
- xarray-datatree

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381

382382

383383
# Example configuration for intersphinx: refer to the Python standard library.
384-
intersphinx_mapping = {"https://docs.python.org/": None}
384+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
385385

386386
# ----------------------------------------------------------------------------
387387
# Numpydoc extension

notebooks/ERA5_cdsapi.ipynb

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"import xarray as xr\n",
122122
"import os\n",
123123
"import warnings\n",
124+
"\n",
124125
"warnings.filterwarnings(action=\"ignore\", category=UserWarning)"
125126
]
126127
},
@@ -133,8 +134,8 @@
133134
"source": [
134135
"grid1_path = pydda.tests.EXAMPLE_RADAR0\n",
135136
"grid2_path = pydda.tests.EXAMPLE_RADAR1\n",
136-
"Grid1 = pyart.io.read_grid(grid1_path)\n",
137-
"Grid2 = pyart.io.read_grid(grid2_path)"
137+
"Grid1 = pydda.io.read_grid(grid1_path)\n",
138+
"Grid2 = pydda.io.read_grid(grid2_path)"
138139
]
139140
},
140141
{
@@ -172,9 +173,9 @@
172173
}
173174
],
174175
"source": [
175-
"if any(field_name in Grid1.fields for field_name in ['u', 'v', 'w']):\n",
176+
"if any(field_name in Grid1.fields for field_name in [\"u\", \"v\", \"w\"]):\n",
176177
" # If any of 'u', 'v', or 'w' exists in Grid1.fields, remove them\n",
177-
" fields_to_remove = ['u', 'v', 'w']\n",
178+
" fields_to_remove = [\"u\", \"v\", \"w\"]\n",
178179
" for field_name in fields_to_remove:\n",
179180
" if field_name in Grid1.fields:\n",
180181
" del Grid1.fields[field_name]\n",
@@ -257,8 +258,10 @@
257258
],
258259
"source": [
259260
"Grid1 = pydda.initialization.make_initialization_from_era5(\n",
260-
" Grid1, vel_field='corrected_velocity',\n",
261-
" dest_era_file=f'./data/ERA_{str(xg1.time.dt.strftime(\"%Y%m%d_%H%M%S\").values[0])}.nc')"
261+
" Grid1,\n",
262+
" vel_field=\"corrected_velocity\",\n",
263+
" dest_era_file=f'./data/ERA_{str(xg1.time.dt.strftime(\"%Y%m%d_%H%M%S\").values[0])}.nc',\n",
264+
")"
262265
]
263266
},
264267
{
@@ -289,9 +292,9 @@
289292
"metadata": {},
290293
"outputs": [],
291294
"source": [
292-
"u = Grid1.fields['u']['data']\n",
293-
"v = Grid1.fields['v']['data']\n",
294-
"w = Grid1.fields['w']['data']"
295+
"u = Grid1.fields[\"u\"][\"data\"]\n",
296+
"v = Grid1.fields[\"v\"][\"data\"]\n",
297+
"w = Grid1.fields[\"w\"][\"data\"]"
295298
]
296299
},
297300
{
@@ -440,16 +443,22 @@
440443
" u_init=u,\n",
441444
" v_init=v,\n",
442445
" w_init=w,\n",
443-
" Cx=2, Cy=2, Cz=2,\n",
444-
"# filter_window=5,\n",
445-
"# filter_order=3,\n",
446-
" Co=1e-1, Cm=10, frz=3900.0, Cb=0,\n",
446+
" Cx=2,\n",
447+
" Cy=2,\n",
448+
" Cz=2,\n",
449+
" # filter_window=5,\n",
450+
" # filter_order=3,\n",
451+
" Co=1e-1,\n",
452+
" Cm=10,\n",
453+
" frz=3900.0,\n",
454+
" Cb=0,\n",
447455
" mask_outside_opt=False,\n",
448456
" wind_tol=0.1,\n",
449457
" max_iterations=200,\n",
450458
" engine=\"scipy\",\n",
451-
" refl_field='reflectivity',\n",
452-
" vel_name='corrected_velocity')"
459+
" refl_field=\"reflectivity\",\n",
460+
" vel_name=\"corrected_velocity\",\n",
461+
")"
453462
]
454463
},
455464
{
@@ -493,6 +502,7 @@
493502
],
494503
"source": [
495504
"import matplotlib.pyplot as plt\n",
505+
"\n",
496506
"# Plot a horizontal cross section\n",
497507
"plt.figure(figsize=(6, 5))\n",
498508
"pydda.vis.plot_horiz_xsection_barbs(\n",
@@ -502,7 +512,9 @@
502512
" w_vel_contours=[5, 10, 15],\n",
503513
" barb_spacing_x_km=5.0,\n",
504514
" barb_spacing_y_km=15.0,\n",
505-
" colorbar_flag=True, cmap='pyart_ChaseSpectral')\n",
515+
" colorbar_flag=True,\n",
516+
" cmap=\"pyart_ChaseSpectral\",\n",
517+
")\n",
506518
"plt.show()\n",
507519
"# Plot a vertical X-Z cross section\n",
508520
"plt.figure(figsize=(6, 5))\n",
@@ -513,8 +525,10 @@
513525
" w_vel_contours=[5, 10, 15],\n",
514526
" barb_spacing_x_km=10.0,\n",
515527
" barb_spacing_z_km=2.0,\n",
516-
" colorbar_flag=True, cmap='pyart_ChaseSpectral',\n",
517-
" wind_vel_contours=[5, 10])\n",
528+
" colorbar_flag=True,\n",
529+
" cmap=\"pyart_ChaseSpectral\",\n",
530+
" wind_vel_contours=[5, 10],\n",
531+
")\n",
518532
"plt.show()\n",
519533
"\n",
520534
"# Plot a vertical Y-Z cross section\n",
@@ -525,7 +539,10 @@
525539
" level=70,\n",
526540
" barb_spacing_y_km=10.0,\n",
527541
" barb_spacing_z_km=2.0,\n",
528-
" colorbar_flag=True, cmap='pyart_ChaseSpectral', wind_vel_contours=[5, 10])\n",
542+
" colorbar_flag=True,\n",
543+
" cmap=\"pyart_ChaseSpectral\",\n",
544+
" wind_vel_contours=[5, 10],\n",
545+
")\n",
529546
"plt.show()"
530547
]
531548
},
@@ -546,10 +563,12 @@
546563
},
547564
"outputs": [],
548565
"source": [
549-
"Grid1 = pydda.constraints.make_constraint_from_era5(Grid1,\n",
550-
" vel_field='corrected_velocity',\n",
551-
" file_name=\"./data/ERA_20060120_004008.nc\")\n",
552-
"Grid1 = pydda.initialization.make_constant_wind_field(Grid1, (0.0, 0.0, 0.0), vel_field='corrected_velocity')"
566+
"Grid1 = pydda.constraints.make_constraint_from_era5(\n",
567+
" Grid1, vel_field=\"corrected_velocity\", file_name=\"./data/ERA_20060120_004008.nc\"\n",
568+
")\n",
569+
"Grid1 = pydda.initialization.make_constant_wind_field(\n",
570+
" Grid1, (0.0, 0.0, 0.0), vel_field=\"corrected_velocity\"\n",
571+
")"
553572
]
554573
},
555574
{
@@ -668,15 +687,21 @@
668687
"new_grids, _ = pydda.retrieval.get_dd_wind_field(\n",
669688
" [Grid1, Grid2],\n",
670689
" Cmod=0,\n",
671-
" Cx=2, Cy=2, Cz=2,\n",
672-
" Co=1e-1, Cm=10, frz=3900.0, Cb=0,\n",
690+
" Cx=2,\n",
691+
" Cy=2,\n",
692+
" Cz=2,\n",
693+
" Co=1e-1,\n",
694+
" Cm=10,\n",
695+
" frz=3900.0,\n",
696+
" Cb=0,\n",
673697
" wind_tol=0.1,\n",
674698
" max_iterations=100,\n",
675699
" mask_outside_opt=True,\n",
676700
" engine=\"scipy\",\n",
677-
" refl_field='reflectivity',\n",
678-
" vel_name='corrected_velocity',\n",
679-
" model_fields=[\"era5\"],)"
701+
" refl_field=\"reflectivity\",\n",
702+
" vel_name=\"corrected_velocity\",\n",
703+
" model_fields=[\"era5\"],\n",
704+
")"
680705
]
681706
},
682707
{
@@ -730,6 +755,7 @@
730755
],
731756
"source": [
732757
"import matplotlib.pyplot as plt\n",
758+
"\n",
733759
"# Plot a horizontal cross section\n",
734760
"plt.figure(figsize=(6, 5))\n",
735761
"pydda.vis.plot_horiz_xsection_barbs(\n",
@@ -739,7 +765,8 @@
739765
" w_vel_contours=[5, 10, 15],\n",
740766
" barb_spacing_x_km=5.0,\n",
741767
" barb_spacing_y_km=15.0,\n",
742-
" cmap='pyart_ChaseSpectral')\n",
768+
" cmap=\"pyart_ChaseSpectral\",\n",
769+
")\n",
743770
"\n",
744771
"plt.show()\n",
745772
"# Plot a vertical X-Z cross section\n",
@@ -751,7 +778,8 @@
751778
" w_vel_contours=[5, 10, 15],\n",
752779
" barb_spacing_x_km=10.0,\n",
753780
" barb_spacing_z_km=2.0,\n",
754-
" cmap='pyart_ChaseSpectral')\n",
781+
" cmap=\"pyart_ChaseSpectral\",\n",
782+
")\n",
755783
"plt.show()\n",
756784
"\n",
757785
"# Plot a vertical Y-Z cross section\n",
@@ -762,7 +790,8 @@
762790
" level=70,\n",
763791
" barb_spacing_y_km=10.0,\n",
764792
" barb_spacing_z_km=2.0,\n",
765-
" cmap='pyart_ChaseSpectral')"
793+
" cmap=\"pyart_ChaseSpectral\",\n",
794+
")"
766795
]
767796
},
768797
{
@@ -805,10 +834,10 @@
805834
"source": [
806835
"xg = new_grids[0].to_xarray().isel(time=0, z=1).sel(x=slice(0, 20e3), y=slice(-20e3, 0))\n",
807836
"fig, ax = plt.subplots(figsize=[6, 5], dpi=100)\n",
808-
"xg['reflectivity'].plot(cmap='pyart_ChaseSpectral', ax=ax)\n",
837+
"xg[\"reflectivity\"].plot(cmap=\"pyart_ChaseSpectral\", ax=ax)\n",
809838
"stride = 2 # Adjust the stride value to control the density of arrows\n",
810839
"xg_downsampled = xg.isel(x=slice(None, None, stride), y=slice(None, None, stride))\n",
811-
"xg_downsampled.plot.quiver(x='x', y='y', u='u', v='v', ax=ax, pivot='mid')"
840+
"xg_downsampled.plot.quiver(x=\"x\", y=\"y\", u=\"u\", v=\"v\", ax=ax, pivot=\"mid\")"
812841
]
813842
},
814843
{
@@ -841,10 +870,10 @@
841870
"source": [
842871
"xg = new_grids[0].to_xarray().isel(time=0).sel(x=slice(-20e3, 20e3), y=-10e3)\n",
843872
"fig, ax = plt.subplots(figsize=[6, 5], dpi=100)\n",
844-
"xg['reflectivity'].plot(cmap='pyart_ChaseSpectral', ax=ax)\n",
873+
"xg[\"reflectivity\"].plot(cmap=\"pyart_ChaseSpectral\", ax=ax)\n",
845874
"stride = 5 # Adjust the stride value to control the density of arrows\n",
846875
"xg_downsampled = xg.isel(x=slice(None, None, stride), z=slice(None, None, stride))\n",
847-
"xg_downsampled.plot.quiver(x='x', y='z', u='u', v='v', ax=ax, pivot='mid')"
876+
"xg_downsampled.plot.quiver(x=\"x\", y=\"z\", u=\"u\", v=\"v\", ax=ax, pivot=\"mid\")"
848877
]
849878
},
850879
{

0 commit comments

Comments
 (0)