{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# 🧭 CRS with MetPy\n", "\n", "What if you need to manually attach coordinate reference system because metpy can't detect it?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from herbie import Herbie\n", "import metpy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "✅ Found ┊ model=hrrr ┊ \u001b[3mproduct=sfc\u001b[0m ┊ \u001b[38;2;41;130;13m2021-Jan-25 06:00 UTC\u001b[92m F00\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mGRIB2 @ aws\u001b[0m ┊ \u001b[38;2;255;153;0m\u001b[3mIDX @ aws\u001b[0m\n" ] } ], "source": [ "H = Herbie(\"2021-01-25 06:00\", model=\"hrrr\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "👨🏻‍🏭 Created directory: [C:\\Users\\blaylock\\data\\hrrr\\20210125]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\blaylock\\_GITHUB\\Herbie\\herbie\\archive.py:1041: UserWarning: sorry, on windows I couldn't remove the file.\n", " warnings.warn(\"sorry, on windows I couldn't remove the file.\")\n" ] } ], "source": [ "ds = H.xarray(\"TMP:2 m\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:              (y: 1059, x: 1799)\n",
       "Coordinates:\n",
       "    time                 datetime64[ns] 2021-01-25T06:00:00\n",
       "    step                 timedelta64[ns] 00:00:00\n",
       "    heightAboveGround    float64 2.0\n",
       "    latitude             (y, x) float64 21.14 21.15 21.15 ... 47.86 47.85 47.84\n",
       "    longitude            (y, x) float64 237.3 237.3 237.3 ... 299.0 299.0 299.1\n",
       "    valid_time           datetime64[ns] 2021-01-25T06:00:00\n",
       "Dimensions without coordinates: y, x\n",
       "Data variables:\n",
       "    t2m                  (y, x) float32 292.3 292.3 292.3 ... 272.9 272.9 273.0\n",
       "    gribfile_projection  object None\n",
       "Attributes:\n",
       "    GRIB_edition:            2\n",
       "    GRIB_centre:             kwbc\n",
       "    GRIB_centreDescription:  US National Weather Service - NCEP\n",
       "    GRIB_subCentre:          0\n",
       "    Conventions:             CF-1.7\n",
       "    institution:             US National Weather Service - NCEP\n",
       "    model:                   hrrr\n",
       "    product:                 sfc\n",
       "    description:             High-Resolution Rapid Refresh - CONUS\n",
       "    remote_grib:             https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr....\n",
       "    local_grib:              C:\\Users\\blaylock\\data\\hrrr\\20210125\\subset_f7ef...\n",
       "    searchString:            TMP:2 m
" ], "text/plain": [ "\n", "Dimensions: (y: 1059, x: 1799)\n", "Coordinates:\n", " time datetime64[ns] 2021-01-25T06:00:00\n", " step timedelta64[ns] 00:00:00\n", " heightAboveGround float64 2.0\n", " latitude (y, x) float64 21.14 21.15 21.15 ... 47.86 47.85 47.84\n", " longitude (y, x) float64 237.3 237.3 237.3 ... 299.0 299.0 299.1\n", " valid_time datetime64[ns] 2021-01-25T06:00:00\n", "Dimensions without coordinates: y, x\n", "Data variables:\n", " t2m (y, x) float32 292.3 292.3 292.3 ... 272.9 272.9 273.0\n", " gribfile_projection object None\n", "Attributes:\n", " GRIB_edition: 2\n", " GRIB_centre: kwbc\n", " GRIB_centreDescription: US National Weather Service - NCEP\n", " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: US National Weather Service - NCEP\n", " model: hrrr\n", " product: sfc\n", " description: High-Resolution Rapid Refresh - CONUS\n", " remote_grib: https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr....\n", " local_grib: C:\\Users\\blaylock\\data\\hrrr\\20210125\\subset_f7ef...\n", " searchString: TMP:2 m" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:              (y: 1059, x: 1799)\n",
       "Coordinates:\n",
       "    time                 datetime64[ns] 2021-01-25T06:00:00\n",
       "    step                 timedelta64[ns] 00:00:00\n",
       "    heightAboveGround    float64 2.0\n",
       "    latitude             (y, x) float64 21.14 21.15 21.15 ... 47.86 47.85 47.84\n",
       "    longitude            (y, x) float64 237.3 237.3 237.3 ... 299.0 299.0 299.1\n",
       "    valid_time           datetime64[ns] 2021-01-25T06:00:00\n",
       "    metpy_crs            object Projection: lambert_conformal_conic\n",
       "Dimensions without coordinates: y, x\n",
       "Data variables:\n",
       "    t2m                  (y, x) float32 292.3 292.3 292.3 ... 272.9 272.9 273.0\n",
       "    gribfile_projection  object None\n",
       "Attributes:\n",
       "    GRIB_edition:            2\n",
       "    GRIB_centre:             kwbc\n",
       "    GRIB_centreDescription:  US National Weather Service - NCEP\n",
       "    GRIB_subCentre:          0\n",
       "    Conventions:             CF-1.7\n",
       "    institution:             US National Weather Service - NCEP\n",
       "    model:                   hrrr\n",
       "    product:                 sfc\n",
       "    description:             High-Resolution Rapid Refresh - CONUS\n",
       "    remote_grib:             https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr....\n",
       "    local_grib:              C:\\Users\\blaylock\\data\\hrrr\\20210125\\subset_f7ef...\n",
       "    searchString:            TMP:2 m
" ], "text/plain": [ "\n", "Dimensions: (y: 1059, x: 1799)\n", "Coordinates:\n", " time datetime64[ns] 2021-01-25T06:00:00\n", " step timedelta64[ns] 00:00:00\n", " heightAboveGround float64 2.0\n", " latitude (y, x) float64 21.14 21.15 21.15 ... 47.86 47.85 47.84\n", " longitude (y, x) float64 237.3 237.3 237.3 ... 299.0 299.0 299.1\n", " valid_time datetime64[ns] 2021-01-25T06:00:00\n", " metpy_crs object Projection: lambert_conformal_conic\n", "Dimensions without coordinates: y, x\n", "Data variables:\n", " t2m (y, x) float32 292.3 292.3 292.3 ... 272.9 272.9 273.0\n", " gribfile_projection object None\n", "Attributes:\n", " GRIB_edition: 2\n", " GRIB_centre: kwbc\n", " GRIB_centreDescription: US National Weather Service - NCEP\n", " GRIB_subCentre: 0\n", " Conventions: CF-1.7\n", " institution: US National Weather Service - NCEP\n", " model: hrrr\n", " product: sfc\n", " description: High-Resolution Rapid Refresh - CONUS\n", " remote_grib: https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr....\n", " local_grib: C:\\Users\\blaylock\\data\\hrrr\\20210125\\subset_f7ef...\n", " searchString: TMP:2 m" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.metpy.assign_crs(\n", " dict(\n", " grid_mapping_name=\"lambert_conformal_conic\",\n", " standard_parallel=(38.5, 38.5),\n", " latitude_of_projection_origin=38.5,\n", " longitude_of_central_meridian=262.5,\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.DataArray 'gribfile_projection' ()>\n",
       "array(None, dtype=object)\n",
       "Coordinates:\n",
       "    time               datetime64[ns] 2021-01-25T06:00:00\n",
       "    step               timedelta64[ns] 00:00:00\n",
       "    heightAboveGround  float64 2.0\n",
       "    valid_time         datetime64[ns] 2021-01-25T06:00:00\n",
       "Attributes: (12/17)\n",
       "    crs_wkt:                        PROJCRS["unknown",BASEGEOGCRS["unknown",D...\n",
       "    semi_major_axis:                6371229.0\n",
       "    semi_minor_axis:                6371229.0\n",
       "    inverse_flattening:             0.0\n",
       "    reference_ellipsoid_name:       unknown\n",
       "    longitude_of_prime_meridian:    0.0\n",
       "    ...                             ...\n",
       "    standard_parallel:              (38.5, 38.5)\n",
       "    latitude_of_projection_origin:  38.5\n",
       "    longitude_of_central_meridian:  262.5\n",
       "    false_easting:                  0.0\n",
       "    false_northing:                 0.0\n",
       "    long_name:                      HRRR model grid projection
" ], "text/plain": [ "\n", "array(None, dtype=object)\n", "Coordinates:\n", " time datetime64[ns] 2021-01-25T06:00:00\n", " step timedelta64[ns] 00:00:00\n", " heightAboveGround float64 2.0\n", " valid_time datetime64[ns] 2021-01-25T06:00:00\n", "Attributes: (12/17)\n", " crs_wkt: PROJCRS[\"unknown\",BASEGEOGCRS[\"unknown\",D...\n", " semi_major_axis: 6371229.0\n", " semi_minor_axis: 6371229.0\n", " inverse_flattening: 0.0\n", " reference_ellipsoid_name: unknown\n", " longitude_of_prime_meridian: 0.0\n", " ... ...\n", " standard_parallel: (38.5, 38.5)\n", " latitude_of_projection_origin: 38.5\n", " longitude_of_central_meridian: 262.5\n", " false_easting: 0.0\n", " false_northing: 0.0\n", " long_name: HRRR model grid projection" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds.gribfile_projection" ] } ], "metadata": { "kernelspec": { "display_name": "herbie-dev", "language": "python", "name": "python3" }, "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.10.8" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "ac511961bc6976a3d289cde8fc247e6b0e9298cf513cb762aa0a7df646d192ed" } } }, "nbformat": 4, "nbformat_minor": 2 }