diff --git a/notebooks/MetPy_Advanced/Isentropic Analysis.ipynb b/notebooks/MetPy_Advanced/Isentropic Analysis.ipynb index c0c260f7..c753ed04 100644 --- a/notebooks/MetPy_Advanced/Isentropic Analysis.ipynb +++ b/notebooks/MetPy_Advanced/Isentropic Analysis.ipynb @@ -193,7 +193,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let's parse out the metadata for the isobaric temperature and get the projection information." + "Let's parse out the metadata for the isobaric temperature and get the projection information. We also index with 0 to get the first, and only, time:" ] }, { @@ -206,7 +206,8 @@ }, "outputs": [], "source": [ - "dat = ds.metpy.parse_cf('Temperature_isobaric')" + "ds = ds.metpy.parse_cf()\n", + "temperature = ds['Temperature_isobaric'][0]" ] }, { @@ -219,14 +220,14 @@ }, "outputs": [], "source": [ - "data_proj = dat.metpy.cartopy_crs" + "data_proj = temperature.metpy.cartopy_crs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Let's pull out the grids out into some shorter variable names. We also index with 0 to get the first, and only, time:" + "Let's pull out the grids out into some shorter variable names." ] }, { @@ -239,27 +240,38 @@ }, "outputs": [], "source": [ - "lat = dat.metpy.y\n", - "lon = dat.metpy.x\n", - "press = ds.metpy.parse_cf('isobaric')\n", - "temperature = ds.metpy.parse_cf('Temperature_isobaric')[0]\n", + "lat = temperature.metpy.y\n", + "lon = temperature.metpy.x\n", "\n", "# Need to adjust units on humidity because '%' causes problems\n", "ds['Relative_humidity_isobaric'].attrs['units'] = 'percent'\n", "\n", - "rh = ds.metpy.parse_cf('Relative_humidity_isobaric')[0]\n", - "height = ds.metpy.parse_cf('Geopotential_height_isobaric')[0]\n", - "u = ds.metpy.parse_cf('u-component_of_wind_isobaric')[0]\n", - "v = ds.metpy.parse_cf('v-component_of_wind_isobaric')[0]\n", + "rh = ds['Relative_humidity_isobaric'][0]\n", + "height = ds['Geopotential_height_isobaric'][0]\n", + "u = ds['u-component_of_wind_isobaric'][0]\n", + "v = ds['v-component_of_wind_isobaric'][0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "pycharm": { + "is_executing": false + } + }, + "outputs": [], + "source": [ + "# Can have different vertical levels for wind and thermodynamic variables\n", + "# Find and select the common levels\n", + "press = temperature.metpy.vertical\n", + "common_levels = np.intersect1d(press, u.metpy.vertical)\n", + "temperature = temperature.metpy.sel(vertical=common_levels)\n", + "u = u.metpy.sel(vertical=common_levels)\n", + "v = v.metpy.sel(vertical=common_levels)\n", "\n", - "# Due to a different number of vertical levels find where they are common\n", - "lev_hght = temperature.coords['isobaric4'] * units.Pa\n", - "lev_uwnd = u.coords['isobaric'] * units.Pa\n", - "_, _, common_ind = np.intersect1d(lev_uwnd, lev_hght, return_indices=True)\n", - "temperature = temperature[common_ind, :, :]\n", - "# Reassign units to variables\n", - "temperature.attrs['units'] = 'kelvin'\n", - "lev_uwnd.attrs['units'] = 'Pa'" + "# Get common pressure levels as a data array\n", + "press = press.metpy.sel(vertical=common_levels)" ] }, { @@ -280,7 +292,7 @@ "outputs": [], "source": [ "isen_level = np.array([320]) * units.kelvin\n", - "isen_press, isen_u, isen_v = mpcalc.isentropic_interpolation(isen_level, lev_uwnd,\n", + "isen_press, isen_u, isen_v = mpcalc.isentropic_interpolation(isen_level, press,\n", " temperature, u, v)" ] }, @@ -451,15 +463,6 @@ "Since calculating this involves taking derivatives, first let's smooth the input fields using a gaussian_filter." ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "isen_press.units, isen_u.units, isen_v.units" - ] - }, { "cell_type": "code", "execution_count": null, @@ -471,15 +474,6 @@ "isen_v = mpcalc.smooth_gaussian(isen_v.squeeze(), 9)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "isen_press.units" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -560,7 +554,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:unidata]", + "display_name": "unidata", "language": "python", "name": "conda-env-unidata-py" }, @@ -587,5 +581,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }