|
| 1 | +Migration Guide |
| 2 | +=============== |
| 3 | + |
| 4 | +Herbie v2 introduces several architectural improvements and API changes. |
| 5 | +Most workflows remain similar, but a few key parameters and patterns have changed. |
| 6 | + |
| 7 | +This guide highlights the most common changes and how to update existing code. |
| 8 | + |
| 9 | +---- |
| 10 | + |
| 11 | +Key API Changes |
| 12 | +--------------- |
| 13 | + |
| 14 | +.. list-table:: |
| 15 | + :header-rows: 1 |
| 16 | + :widths: 30 35 35 |
| 17 | + |
| 18 | + * - Change |
| 19 | + - v1 |
| 20 | + - v2 |
| 21 | + * - Forecast lead time parameter |
| 22 | + - ``fxx`` |
| 23 | + - ``step`` |
| 24 | + * - Default data directory |
| 25 | + - ``~/data/`` or user specified |
| 26 | + - ``~/herbie-data/`` |
| 27 | + * - DataFrame library |
| 28 | + - Pandas |
| 29 | + - Polars |
| 30 | + * - Model access |
| 31 | + - ``Herbie(model='hrrr')`` |
| 32 | + - ``Herbie.HRRR()`` |
| 33 | + * - Notebook display |
| 34 | + - Plain text repr |
| 35 | + - Rich HTML display |
| 36 | + * - Inventory filtering |
| 37 | + - Search string |
| 38 | + - Search string *or* Polars expressions |
| 39 | + * - Multi-hypercube datasets |
| 40 | + - Flattened |
| 41 | + - ``xarray.DataTree`` |
| 42 | + |
| 43 | +---- |
| 44 | + |
| 45 | +Common Workflows |
| 46 | +---------------- |
| 47 | + |
| 48 | +Create a Herbie Object |
| 49 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 50 | + |
| 51 | +.. grid:: 2 |
| 52 | + |
| 53 | + .. grid-item-card:: v1 |
| 54 | + |
| 55 | + .. code-block:: python |
| 56 | +
|
| 57 | + from herbie import Herbie |
| 58 | +
|
| 59 | + H = Herbie( |
| 60 | + "2025-01-01", |
| 61 | + model="hrrr", |
| 62 | + fxx=12 |
| 63 | + ) |
| 64 | +
|
| 65 | + .. grid-item-card:: v2 |
| 66 | + |
| 67 | + .. code-block:: python |
| 68 | +
|
| 69 | + from herbie.v2 import HRRR |
| 70 | +
|
| 71 | + H = HRRR( |
| 72 | + "2025-01-01", |
| 73 | + step=12 |
| 74 | + ) |
| 75 | +
|
| 76 | +Or via the namespace: |
| 77 | + |
| 78 | +.. code-block:: python |
| 79 | +
|
| 80 | + from herbie.v2 import Herbie |
| 81 | +
|
| 82 | + H = Herbie.HRRR("2025-01-01", step=12) |
| 83 | +
|
| 84 | +---- |
| 85 | + |
| 86 | +Forecast Lead Time |
| 87 | +------------------ |
| 88 | + |
| 89 | +The ``fxx`` parameter has been renamed to ``step``. |
| 90 | + |
| 91 | +.. grid:: 2 |
| 92 | + |
| 93 | + .. grid-item-card:: v1 |
| 94 | + |
| 95 | + .. code-block:: python |
| 96 | +
|
| 97 | + H = Herbie("2025-01-01", model="hrrr", fxx=6) |
| 98 | +
|
| 99 | + .. grid-item-card:: v2 |
| 100 | + |
| 101 | + .. code-block:: python |
| 102 | +
|
| 103 | + H = HRRR("2025-01-01", step=6) |
| 104 | +
|
| 105 | +You can also use a ``timedelta``: |
| 106 | + |
| 107 | +.. code-block:: python |
| 108 | +
|
| 109 | + from datetime import timedelta |
| 110 | +
|
| 111 | + H = HRRR("2025-01-01", step=timedelta(hours=6)) |
| 112 | +
|
| 113 | +---- |
| 114 | + |
| 115 | +Inventory |
| 116 | +--------- |
| 117 | + |
| 118 | +Inventories are now **Polars DataFrames**, which support fast expression-based filtering. |
| 119 | + |
| 120 | +.. grid:: 2 |
| 121 | + |
| 122 | + .. grid-item-card:: v1 |
| 123 | + |
| 124 | + .. code-block:: python |
| 125 | +
|
| 126 | + H.inventory("TMP:2 m") |
| 127 | +
|
| 128 | + .. grid-item-card:: v2 |
| 129 | + |
| 130 | + .. code-block:: python |
| 131 | +
|
| 132 | + inv = H.inventory() |
| 133 | +
|
| 134 | + inv.filter( |
| 135 | + pl.col("variable") == "TMP" |
| 136 | + ) |
| 137 | +
|
| 138 | +Benefits: |
| 139 | + |
| 140 | +- Faster performance |
| 141 | +- Flexible filtering |
| 142 | +- Access to source metadata |
| 143 | + |
| 144 | +---- |
| 145 | + |
| 146 | +Download Fields |
| 147 | +--------------- |
| 148 | + |
| 149 | +.. grid:: 2 |
| 150 | + |
| 151 | + .. grid-item-card:: v1 |
| 152 | + |
| 153 | + .. code-block:: python |
| 154 | +
|
| 155 | + H.download("TMP:2 m") |
| 156 | +
|
| 157 | + .. grid-item-card:: v2 |
| 158 | + |
| 159 | + .. code-block:: python |
| 160 | +
|
| 161 | + H.download("TMP:2 m") |
| 162 | +
|
| 163 | +The basic workflow is unchanged, but downloads now: |
| 164 | + |
| 165 | +- Run subsets in **parallel threads** |
| 166 | +- Display **Rich progress bars** |
| 167 | +- Preserve the **remote file path structure** |
| 168 | + |
| 169 | +---- |
| 170 | + |
| 171 | +Load Data with xarray |
| 172 | +--------------------- |
| 173 | + |
| 174 | +.. grid:: 2 |
| 175 | + |
| 176 | + .. grid-item-card:: v1 |
| 177 | + |
| 178 | + .. code-block:: python |
| 179 | +
|
| 180 | + ds = H.xarray("TMP:2 m") |
| 181 | +
|
| 182 | + .. grid-item-card:: v2 |
| 183 | + |
| 184 | + .. code-block:: python |
| 185 | +
|
| 186 | + ds = H.xarray("TMP:2 m") |
| 187 | +
|
| 188 | +If multiple hypercubes are present, v2 returns an **xarray DataTree** rather |
| 189 | +than flattening them. |
| 190 | + |
| 191 | +---- |
| 192 | + |
| 193 | +Checking Data Availability |
| 194 | +-------------------------- |
| 195 | + |
| 196 | +.. grid:: 2 |
| 197 | + |
| 198 | + .. grid-item-card:: v1 |
| 199 | + |
| 200 | + Source checking was mostly implicit. |
| 201 | + |
| 202 | + .. grid-item-card:: v2 |
| 203 | + |
| 204 | + You can explicitly resolve sources: |
| 205 | + |
| 206 | + .. code-block:: python |
| 207 | +
|
| 208 | + # Default resolution |
| 209 | + H.resolve() |
| 210 | +
|
| 211 | + # Check a specific source |
| 212 | + H.resolve("google") |
| 213 | +
|
| 214 | + # Check all sources |
| 215 | + H.resolve("all") |
| 216 | +
|
| 217 | +---- |
| 218 | + |
| 219 | +FastHerbie Changes |
| 220 | +------------------ |
| 221 | + |
| 222 | +``FastHerbie`` has been redesigned. |
| 223 | + |
| 224 | +.. grid:: 2 |
| 225 | + |
| 226 | + .. grid-item-card:: v1 |
| 227 | + |
| 228 | + Focused primarily on downloading many files quickly. |
| 229 | + |
| 230 | + .. grid-item-card:: v2 |
| 231 | + |
| 232 | + Now enables **building custom GRIB files from multiple model runs**. |
| 233 | + |
| 234 | + Example use cases: |
| 235 | + |
| 236 | + - Combine all ``TMP:2 m`` forecasts for a day |
| 237 | + - Combine all ``GRD:10 m`` forecasts initialized at one cycle |
| 238 | + |
| 239 | + This allows users to generate **custom GRIB datasets tailored to |
| 240 | + their workflow**. |
| 241 | + |
| 242 | +---- |
| 243 | + |
| 244 | +Configuration |
| 245 | +------------- |
| 246 | + |
| 247 | +Herbie v2 introduces a **configuration file** that lets you set preferences |
| 248 | +without modifying Python code: |
| 249 | + |
| 250 | +- Default data directory |
| 251 | +- Preferred sources |
| 252 | +- Authentication settings |
| 253 | + |
| 254 | +---- |
| 255 | + |
| 256 | +Notebook Experience |
| 257 | +------------------- |
| 258 | + |
| 259 | +When displayed in a Jupyter notebook, a Herbie object now shows a |
| 260 | +**rich HTML summary** that includes: |
| 261 | + |
| 262 | +- Model configuration |
| 263 | +- Forecast step |
| 264 | +- Available sources |
| 265 | +- Data availability |
| 266 | + |
| 267 | +This makes exploratory analysis much easier. |
| 268 | + |
| 269 | +---- |
| 270 | + |
| 271 | +Summary |
| 272 | +------- |
| 273 | + |
| 274 | +Most workflows require **minimal code changes**, but the following updates |
| 275 | +are recommended: |
| 276 | + |
| 277 | +1. Replace ``fxx`` with ``step`` |
| 278 | +2. Import models from ``herbie.v2`` |
| 279 | +3. Update inventory workflows to use **Polars expressions** |
| 280 | +4. Be aware that multi-hypercube datasets now return **DataTree objects** |
| 281 | + |
| 282 | +These changes provide faster performance, improved data handling, better |
| 283 | +extensibility, and a more modern Python API. |
0 commit comments