{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Examples of applying filters and categorising tracks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import essential libraries" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "from octant.core import TrackRun" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the common data directory" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sample_dir = Path(\".\") / \"sample_data\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Data are usually organised in hierarchical directory structure. Here, the relevant parameters are defined." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "dataset = \"era5\"\n", "period = \"test\"\n", "run_id = 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Construct the full path" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "track_res_dir = sample_dir / dataset / f\"run{run_id:03d}\" / period" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now load the cyclone tracks themselves" ] }, { "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", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Number of tracks671
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr = TrackRun(track_res_dir)\n", "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Classify the tracks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, to label each of the tracks within `tr` according to a set of filters or criteria, `classify()` method should be used.\n", "\n", "It has an alias: `categorise()`.\n", "\n", "Below are two examples: a simple one and a more advanced using a function with multiple arguments." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Simple functions as filters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As its argument, `classify()` takes a list of tuples in the form of\n", "```\n", "[\n", "(, [, , ..., ]),\n", "(, [, , ..., ]),\n", "...\n", "(, [, , ..., ]),\n", "],\n", "```\n", "\n", "where `labelA` is assigned to a track if the track satisfies **all** the conditions given by `[, , ..., ]`, which is a list of 1 or more functions.\n", "These functions expect 1 and only 1 argument - `OctantTrack`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example, it is possible to classify tracks by their lifetime, maximum vorticity, and distance travelled:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "conditions = [\n", " (\"long_lived\", [lambda ot: ot.lifetime_h >= 6]),\n", " (\n", " \"far_travelled_and_very_long_lived\",\n", " [lambda ot: ot.lifetime_h >= 36, lambda ot: ot.gen_lys_dist_km > 300.0],\n", " ),\n", " (\"strong\", [lambda x: x.max_vort > 1e-3]),\n", "]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "tr.classify(conditions)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(True, False)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr.is_categorised, tr.is_cat_inclusive" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which247long_lived
of which18far_travelled_and_very_long_lived
of which5strong
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**NB** By default, the categories are **NOT** \"inclusive\", so all categories are independent." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this case, \"long_lived\" do not include the 18 tracks, of which 15 are \"far_travelled_and_very_long_lived\" plus 5 are \"strong\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is how the numbers change if the categorisation is inclusive, so the \"long_lived\" subset includes tracks are \"far_travelled_and_very_long_lived\", and they both include the \"strong\" subset." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "tr.classify(conditions, inclusive=True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(True, True)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr.is_categorised, tr.is_cat_inclusive" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which247long_lived
of which18far_travelled_and_very_long_lived|long_lived
of which3strong|far_travelled_and_very_long_lived|long_lived
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that it automatically appends `|` to the category labels." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Select one or multiple categories" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Selection of tracks within a category can be done as following." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "tr.classify(conditions)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which247long_lived
of which18far_travelled_and_very_long_lived
of which5strong
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* one category" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
lonlatvotimeareavortex_type
track_idxrow_idx
9301.575.00.0004182011-01-04 02:00:0055228.769531
13.675.30.0004032011-01-04 03:00:0059789.968751
26.675.90.0004032011-01-04 04:00:0058341.808591
37.575.90.0004212011-01-04 05:00:0064806.839843
44.874.70.0004312011-01-04 06:00:0060390.078121
55.774.70.0004492011-01-04 07:00:0056248.261721
64.274.10.0004442011-01-04 08:00:0054530.765621
73.973.80.0004362011-01-04 09:00:0051079.367191
813.575.90.0004702011-01-04 10:00:0063191.570311
914.776.50.0004842011-01-04 11:00:0064762.199221
1015.676.50.0005162011-01-04 12:00:0017545.869141
1116.276.50.0005282011-01-04 13:00:0019758.556641
1218.377.10.0005242011-01-04 14:00:003609.310301
1318.377.10.0007492011-01-04 15:00:0023973.103521
1418.677.10.0009352011-01-04 16:00:0023797.587891
1518.977.10.0010162011-01-04 17:00:0029484.755863
1619.277.10.0009532011-01-04 18:00:0031794.384773
1719.577.10.0008892011-01-04 19:00:0036683.437503
1820.177.10.0008152011-01-04 20:00:0037243.855473
1921.077.10.0007242011-01-04 21:00:0020711.820313
2023.477.10.0007252011-01-04 22:00:0038624.171883
2124.377.10.0008152011-01-04 23:00:0034974.031250
2225.277.10.0008752011-01-05 00:00:0028838.160160
2325.877.10.0008532011-01-05 01:00:0029850.998050
2427.077.40.0007632011-01-05 02:00:0032273.253910
2527.977.40.0007952011-01-05 03:00:0032486.572270
2628.577.40.0007762011-01-05 04:00:0033306.078120
2729.777.70.0007272011-01-05 05:00:0031798.091800
2830.077.70.0007662011-01-05 06:00:0032786.722660
2931.278.00.0007112011-01-05 07:00:0032779.285160
........................
5695736.373.80.0008652011-01-30 10:00:0053348.921880
5836.973.50.0008672011-01-30 11:00:0052527.417970
5937.273.50.0008252011-01-30 12:00:0054444.710940
6037.873.20.0007682011-01-30 13:00:0083394.437500
6138.772.90.0007282011-01-30 14:00:0083738.906250
6239.372.60.0006862011-01-30 15:00:0088395.617190
6340.272.30.0006212011-01-30 16:00:0061690.128910
6442.072.30.0006022011-01-30 17:00:0091611.585940
6542.672.00.0006262011-01-30 18:00:0040642.468750
6643.572.00.0006522011-01-30 19:00:0042448.890620
6744.171.70.0006582011-01-30 20:00:0062467.359380
6844.771.70.0006622011-01-30 21:00:0039607.703120
6945.371.70.0006222011-01-30 22:00:0051207.281250
7045.371.70.0006002011-01-30 23:00:0053267.828120
7145.971.40.0005542011-01-31 00:00:0052988.437500
7246.271.40.0005322011-01-31 01:00:0053947.320310
7345.671.10.0004952011-01-31 02:00:0051971.468750
7446.571.10.0004792011-01-31 03:00:0056551.718750
7546.570.80.0004352011-01-31 04:00:0056018.835940
7648.070.20.0004292011-01-31 05:00:0056886.234380
7748.069.90.0004532011-01-31 06:00:0051720.191410
7848.069.60.0004972011-01-31 07:00:0043837.632810
7949.269.90.0005082011-01-31 08:00:0041850.425780
8049.569.60.0004752011-01-31 09:00:0037235.421880
8150.169.60.0004852011-01-31 10:00:0034360.566410
8250.169.60.0003542011-01-31 11:00:0015396.193360
8350.168.70.0004592011-01-31 12:00:0022106.046880
631036.673.50.0003712011-01-30 06:00:004751.187500
137.873.50.0003102011-01-30 07:00:003506.607910
235.474.10.0010012011-01-30 08:00:0040545.027340
\n", "

214 rows × 6 columns

\n", "
" ], "text/plain": [ " lon lat vo time area \\\n", "track_idx row_idx \n", "93 0 1.5 75.0 0.000418 2011-01-04 02:00:00 55228.76953 \n", " 1 3.6 75.3 0.000403 2011-01-04 03:00:00 59789.96875 \n", " 2 6.6 75.9 0.000403 2011-01-04 04:00:00 58341.80859 \n", " 3 7.5 75.9 0.000421 2011-01-04 05:00:00 64806.83984 \n", " 4 4.8 74.7 0.000431 2011-01-04 06:00:00 60390.07812 \n", " 5 5.7 74.7 0.000449 2011-01-04 07:00:00 56248.26172 \n", " 6 4.2 74.1 0.000444 2011-01-04 08:00:00 54530.76562 \n", " 7 3.9 73.8 0.000436 2011-01-04 09:00:00 51079.36719 \n", " 8 13.5 75.9 0.000470 2011-01-04 10:00:00 63191.57031 \n", " 9 14.7 76.5 0.000484 2011-01-04 11:00:00 64762.19922 \n", " 10 15.6 76.5 0.000516 2011-01-04 12:00:00 17545.86914 \n", " 11 16.2 76.5 0.000528 2011-01-04 13:00:00 19758.55664 \n", " 12 18.3 77.1 0.000524 2011-01-04 14:00:00 3609.31030 \n", " 13 18.3 77.1 0.000749 2011-01-04 15:00:00 23973.10352 \n", " 14 18.6 77.1 0.000935 2011-01-04 16:00:00 23797.58789 \n", " 15 18.9 77.1 0.001016 2011-01-04 17:00:00 29484.75586 \n", " 16 19.2 77.1 0.000953 2011-01-04 18:00:00 31794.38477 \n", " 17 19.5 77.1 0.000889 2011-01-04 19:00:00 36683.43750 \n", " 18 20.1 77.1 0.000815 2011-01-04 20:00:00 37243.85547 \n", " 19 21.0 77.1 0.000724 2011-01-04 21:00:00 20711.82031 \n", " 20 23.4 77.1 0.000725 2011-01-04 22:00:00 38624.17188 \n", " 21 24.3 77.1 0.000815 2011-01-04 23:00:00 34974.03125 \n", " 22 25.2 77.1 0.000875 2011-01-05 00:00:00 28838.16016 \n", " 23 25.8 77.1 0.000853 2011-01-05 01:00:00 29850.99805 \n", " 24 27.0 77.4 0.000763 2011-01-05 02:00:00 32273.25391 \n", " 25 27.9 77.4 0.000795 2011-01-05 03:00:00 32486.57227 \n", " 26 28.5 77.4 0.000776 2011-01-05 04:00:00 33306.07812 \n", " 27 29.7 77.7 0.000727 2011-01-05 05:00:00 31798.09180 \n", " 28 30.0 77.7 0.000766 2011-01-05 06:00:00 32786.72266 \n", " 29 31.2 78.0 0.000711 2011-01-05 07:00:00 32779.28516 \n", "... ... ... ... ... ... \n", "569 57 36.3 73.8 0.000865 2011-01-30 10:00:00 53348.92188 \n", " 58 36.9 73.5 0.000867 2011-01-30 11:00:00 52527.41797 \n", " 59 37.2 73.5 0.000825 2011-01-30 12:00:00 54444.71094 \n", " 60 37.8 73.2 0.000768 2011-01-30 13:00:00 83394.43750 \n", " 61 38.7 72.9 0.000728 2011-01-30 14:00:00 83738.90625 \n", " 62 39.3 72.6 0.000686 2011-01-30 15:00:00 88395.61719 \n", " 63 40.2 72.3 0.000621 2011-01-30 16:00:00 61690.12891 \n", " 64 42.0 72.3 0.000602 2011-01-30 17:00:00 91611.58594 \n", " 65 42.6 72.0 0.000626 2011-01-30 18:00:00 40642.46875 \n", " 66 43.5 72.0 0.000652 2011-01-30 19:00:00 42448.89062 \n", " 67 44.1 71.7 0.000658 2011-01-30 20:00:00 62467.35938 \n", " 68 44.7 71.7 0.000662 2011-01-30 21:00:00 39607.70312 \n", " 69 45.3 71.7 0.000622 2011-01-30 22:00:00 51207.28125 \n", " 70 45.3 71.7 0.000600 2011-01-30 23:00:00 53267.82812 \n", " 71 45.9 71.4 0.000554 2011-01-31 00:00:00 52988.43750 \n", " 72 46.2 71.4 0.000532 2011-01-31 01:00:00 53947.32031 \n", " 73 45.6 71.1 0.000495 2011-01-31 02:00:00 51971.46875 \n", " 74 46.5 71.1 0.000479 2011-01-31 03:00:00 56551.71875 \n", " 75 46.5 70.8 0.000435 2011-01-31 04:00:00 56018.83594 \n", " 76 48.0 70.2 0.000429 2011-01-31 05:00:00 56886.23438 \n", " 77 48.0 69.9 0.000453 2011-01-31 06:00:00 51720.19141 \n", " 78 48.0 69.6 0.000497 2011-01-31 07:00:00 43837.63281 \n", " 79 49.2 69.9 0.000508 2011-01-31 08:00:00 41850.42578 \n", " 80 49.5 69.6 0.000475 2011-01-31 09:00:00 37235.42188 \n", " 81 50.1 69.6 0.000485 2011-01-31 10:00:00 34360.56641 \n", " 82 50.1 69.6 0.000354 2011-01-31 11:00:00 15396.19336 \n", " 83 50.1 68.7 0.000459 2011-01-31 12:00:00 22106.04688 \n", "631 0 36.6 73.5 0.000371 2011-01-30 06:00:00 4751.18750 \n", " 1 37.8 73.5 0.000310 2011-01-30 07:00:00 3506.60791 \n", " 2 35.4 74.1 0.001001 2011-01-30 08:00:00 40545.02734 \n", "\n", " vortex_type \n", "track_idx row_idx \n", "93 0 1 \n", " 1 1 \n", " 2 1 \n", " 3 3 \n", " 4 1 \n", " 5 1 \n", " 6 1 \n", " 7 1 \n", " 8 1 \n", " 9 1 \n", " 10 1 \n", " 11 1 \n", " 12 1 \n", " 13 1 \n", " 14 1 \n", " 15 3 \n", " 16 3 \n", " 17 3 \n", " 18 3 \n", " 19 3 \n", " 20 3 \n", " 21 0 \n", " 22 0 \n", " 23 0 \n", " 24 0 \n", " 25 0 \n", " 26 0 \n", " 27 0 \n", " 28 0 \n", " 29 0 \n", "... ... \n", "569 57 0 \n", " 58 0 \n", " 59 0 \n", " 60 0 \n", " 61 0 \n", " 62 0 \n", " 63 0 \n", " 64 0 \n", " 65 0 \n", " 66 0 \n", " 67 0 \n", " 68 0 \n", " 69 0 \n", " 70 0 \n", " 71 0 \n", " 72 0 \n", " 73 0 \n", " 74 0 \n", " 75 0 \n", " 76 0 \n", " 77 0 \n", " 78 0 \n", " 79 0 \n", " 80 0 \n", " 81 0 \n", " 82 0 \n", " 83 0 \n", "631 0 0 \n", " 1 0 \n", " 2 0 \n", "\n", "[214 rows x 6 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr[\"strong\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* several categories (AND operator)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
lonlatvotimeareavortex_type
track_idxrow_idx
9301.575.00.0004182011-01-04 02:00:0055228.769531
13.675.30.0004032011-01-04 03:00:0059789.968751
26.675.90.0004032011-01-04 04:00:0058341.808591
37.575.90.0004212011-01-04 05:00:0064806.839843
44.874.70.0004312011-01-04 06:00:0060390.078121
55.774.70.0004492011-01-04 07:00:0056248.261721
64.274.10.0004442011-01-04 08:00:0054530.765621
73.973.80.0004362011-01-04 09:00:0051079.367191
813.575.90.0004702011-01-04 10:00:0063191.570311
914.776.50.0004842011-01-04 11:00:0064762.199221
1015.676.50.0005162011-01-04 12:00:0017545.869141
1116.276.50.0005282011-01-04 13:00:0019758.556641
1218.377.10.0005242011-01-04 14:00:003609.310301
1318.377.10.0007492011-01-04 15:00:0023973.103521
1418.677.10.0009352011-01-04 16:00:0023797.587891
1518.977.10.0010162011-01-04 17:00:0029484.755863
1619.277.10.0009532011-01-04 18:00:0031794.384773
1719.577.10.0008892011-01-04 19:00:0036683.437503
1820.177.10.0008152011-01-04 20:00:0037243.855473
1921.077.10.0007242011-01-04 21:00:0020711.820313
2023.477.10.0007252011-01-04 22:00:0038624.171883
2124.377.10.0008152011-01-04 23:00:0034974.031250
2225.277.10.0008752011-01-05 00:00:0028838.160160
2325.877.10.0008532011-01-05 01:00:0029850.998050
2427.077.40.0007632011-01-05 02:00:0032273.253910
2527.977.40.0007952011-01-05 03:00:0032486.572270
2628.577.40.0007762011-01-05 04:00:0033306.078120
2729.777.70.0007272011-01-05 05:00:0031798.091800
2830.077.70.0007662011-01-05 06:00:0032786.722660
2931.278.00.0007112011-01-05 07:00:0032779.285160
........................
5695435.774.40.0010752011-01-30 07:00:0037938.289060
5535.474.10.0010012011-01-30 08:00:0040545.027340
5636.374.10.0009752011-01-30 09:00:0043897.417970
5736.373.80.0008652011-01-30 10:00:0053348.921880
5836.973.50.0008672011-01-30 11:00:0052527.417970
5937.273.50.0008252011-01-30 12:00:0054444.710940
6037.873.20.0007682011-01-30 13:00:0083394.437500
6138.772.90.0007282011-01-30 14:00:0083738.906250
6239.372.60.0006862011-01-30 15:00:0088395.617190
6340.272.30.0006212011-01-30 16:00:0061690.128910
6442.072.30.0006022011-01-30 17:00:0091611.585940
6542.672.00.0006262011-01-30 18:00:0040642.468750
6643.572.00.0006522011-01-30 19:00:0042448.890620
6744.171.70.0006582011-01-30 20:00:0062467.359380
6844.771.70.0006622011-01-30 21:00:0039607.703120
6945.371.70.0006222011-01-30 22:00:0051207.281250
7045.371.70.0006002011-01-30 23:00:0053267.828120
7145.971.40.0005542011-01-31 00:00:0052988.437500
7246.271.40.0005322011-01-31 01:00:0053947.320310
7345.671.10.0004952011-01-31 02:00:0051971.468750
7446.571.10.0004792011-01-31 03:00:0056551.718750
7546.570.80.0004352011-01-31 04:00:0056018.835940
7648.070.20.0004292011-01-31 05:00:0056886.234380
7748.069.90.0004532011-01-31 06:00:0051720.191410
7848.069.60.0004972011-01-31 07:00:0043837.632810
7949.269.90.0005082011-01-31 08:00:0041850.425780
8049.569.60.0004752011-01-31 09:00:0037235.421880
8150.169.60.0004852011-01-31 10:00:0034360.566410
8250.169.60.0003542011-01-31 11:00:0015396.193360
8350.168.70.0004592011-01-31 12:00:0022106.046880
\n", "

211 rows × 6 columns

\n", "
" ], "text/plain": [ " lon lat vo time area \\\n", "track_idx row_idx \n", "93 0 1.5 75.0 0.000418 2011-01-04 02:00:00 55228.76953 \n", " 1 3.6 75.3 0.000403 2011-01-04 03:00:00 59789.96875 \n", " 2 6.6 75.9 0.000403 2011-01-04 04:00:00 58341.80859 \n", " 3 7.5 75.9 0.000421 2011-01-04 05:00:00 64806.83984 \n", " 4 4.8 74.7 0.000431 2011-01-04 06:00:00 60390.07812 \n", " 5 5.7 74.7 0.000449 2011-01-04 07:00:00 56248.26172 \n", " 6 4.2 74.1 0.000444 2011-01-04 08:00:00 54530.76562 \n", " 7 3.9 73.8 0.000436 2011-01-04 09:00:00 51079.36719 \n", " 8 13.5 75.9 0.000470 2011-01-04 10:00:00 63191.57031 \n", " 9 14.7 76.5 0.000484 2011-01-04 11:00:00 64762.19922 \n", " 10 15.6 76.5 0.000516 2011-01-04 12:00:00 17545.86914 \n", " 11 16.2 76.5 0.000528 2011-01-04 13:00:00 19758.55664 \n", " 12 18.3 77.1 0.000524 2011-01-04 14:00:00 3609.31030 \n", " 13 18.3 77.1 0.000749 2011-01-04 15:00:00 23973.10352 \n", " 14 18.6 77.1 0.000935 2011-01-04 16:00:00 23797.58789 \n", " 15 18.9 77.1 0.001016 2011-01-04 17:00:00 29484.75586 \n", " 16 19.2 77.1 0.000953 2011-01-04 18:00:00 31794.38477 \n", " 17 19.5 77.1 0.000889 2011-01-04 19:00:00 36683.43750 \n", " 18 20.1 77.1 0.000815 2011-01-04 20:00:00 37243.85547 \n", " 19 21.0 77.1 0.000724 2011-01-04 21:00:00 20711.82031 \n", " 20 23.4 77.1 0.000725 2011-01-04 22:00:00 38624.17188 \n", " 21 24.3 77.1 0.000815 2011-01-04 23:00:00 34974.03125 \n", " 22 25.2 77.1 0.000875 2011-01-05 00:00:00 28838.16016 \n", " 23 25.8 77.1 0.000853 2011-01-05 01:00:00 29850.99805 \n", " 24 27.0 77.4 0.000763 2011-01-05 02:00:00 32273.25391 \n", " 25 27.9 77.4 0.000795 2011-01-05 03:00:00 32486.57227 \n", " 26 28.5 77.4 0.000776 2011-01-05 04:00:00 33306.07812 \n", " 27 29.7 77.7 0.000727 2011-01-05 05:00:00 31798.09180 \n", " 28 30.0 77.7 0.000766 2011-01-05 06:00:00 32786.72266 \n", " 29 31.2 78.0 0.000711 2011-01-05 07:00:00 32779.28516 \n", "... ... ... ... ... ... \n", "569 54 35.7 74.4 0.001075 2011-01-30 07:00:00 37938.28906 \n", " 55 35.4 74.1 0.001001 2011-01-30 08:00:00 40545.02734 \n", " 56 36.3 74.1 0.000975 2011-01-30 09:00:00 43897.41797 \n", " 57 36.3 73.8 0.000865 2011-01-30 10:00:00 53348.92188 \n", " 58 36.9 73.5 0.000867 2011-01-30 11:00:00 52527.41797 \n", " 59 37.2 73.5 0.000825 2011-01-30 12:00:00 54444.71094 \n", " 60 37.8 73.2 0.000768 2011-01-30 13:00:00 83394.43750 \n", " 61 38.7 72.9 0.000728 2011-01-30 14:00:00 83738.90625 \n", " 62 39.3 72.6 0.000686 2011-01-30 15:00:00 88395.61719 \n", " 63 40.2 72.3 0.000621 2011-01-30 16:00:00 61690.12891 \n", " 64 42.0 72.3 0.000602 2011-01-30 17:00:00 91611.58594 \n", " 65 42.6 72.0 0.000626 2011-01-30 18:00:00 40642.46875 \n", " 66 43.5 72.0 0.000652 2011-01-30 19:00:00 42448.89062 \n", " 67 44.1 71.7 0.000658 2011-01-30 20:00:00 62467.35938 \n", " 68 44.7 71.7 0.000662 2011-01-30 21:00:00 39607.70312 \n", " 69 45.3 71.7 0.000622 2011-01-30 22:00:00 51207.28125 \n", " 70 45.3 71.7 0.000600 2011-01-30 23:00:00 53267.82812 \n", " 71 45.9 71.4 0.000554 2011-01-31 00:00:00 52988.43750 \n", " 72 46.2 71.4 0.000532 2011-01-31 01:00:00 53947.32031 \n", " 73 45.6 71.1 0.000495 2011-01-31 02:00:00 51971.46875 \n", " 74 46.5 71.1 0.000479 2011-01-31 03:00:00 56551.71875 \n", " 75 46.5 70.8 0.000435 2011-01-31 04:00:00 56018.83594 \n", " 76 48.0 70.2 0.000429 2011-01-31 05:00:00 56886.23438 \n", " 77 48.0 69.9 0.000453 2011-01-31 06:00:00 51720.19141 \n", " 78 48.0 69.6 0.000497 2011-01-31 07:00:00 43837.63281 \n", " 79 49.2 69.9 0.000508 2011-01-31 08:00:00 41850.42578 \n", " 80 49.5 69.6 0.000475 2011-01-31 09:00:00 37235.42188 \n", " 81 50.1 69.6 0.000485 2011-01-31 10:00:00 34360.56641 \n", " 82 50.1 69.6 0.000354 2011-01-31 11:00:00 15396.19336 \n", " 83 50.1 68.7 0.000459 2011-01-31 12:00:00 22106.04688 \n", "\n", " vortex_type \n", "track_idx row_idx \n", "93 0 1 \n", " 1 1 \n", " 2 1 \n", " 3 3 \n", " 4 1 \n", " 5 1 \n", " 6 1 \n", " 7 1 \n", " 8 1 \n", " 9 1 \n", " 10 1 \n", " 11 1 \n", " 12 1 \n", " 13 1 \n", " 14 1 \n", " 15 3 \n", " 16 3 \n", " 17 3 \n", " 18 3 \n", " 19 3 \n", " 20 3 \n", " 21 0 \n", " 22 0 \n", " 23 0 \n", " 24 0 \n", " 25 0 \n", " 26 0 \n", " 27 0 \n", " 28 0 \n", " 29 0 \n", "... ... \n", "569 54 0 \n", " 55 0 \n", " 56 0 \n", " 57 0 \n", " 58 0 \n", " 59 0 \n", " 60 0 \n", " 61 0 \n", " 62 0 \n", " 63 0 \n", " 64 0 \n", " 65 0 \n", " 66 0 \n", " 67 0 \n", " 68 0 \n", " 69 0 \n", " 70 0 \n", " 71 0 \n", " 72 0 \n", " 73 0 \n", " 74 0 \n", " 75 0 \n", " 76 0 \n", " 77 0 \n", " 78 0 \n", " 79 0 \n", " 80 0 \n", " 81 0 \n", " 82 0 \n", " 83 0 \n", "\n", "[211 rows x 6 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr[[\"strong\", \"long_lived\"]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the same fashion, the size of each subset can be checked." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr.size(\"strong\")" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr.size([\"long_lived\", \"strong\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Group-by operation can also be used to iterate over tracks within a subset." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr[\"strong\"].gb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Where is the categorisation data stored?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After categorisation is applied to `TrackRun`, the attribute `TrackRun.cats` is assigned to a `pandas.DataFrame` with boolean values containing the True/False flags for each track and category." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
long_livedfar_travelled_and_very_long_livedstrong
track_idx
0FalseFalseFalse
1TrueFalseFalse
2FalseFalseFalse
3FalseFalseFalse
4TrueFalseFalse
5FalseFalseFalse
6TrueFalseFalse
7TrueFalseFalse
8FalseFalseFalse
9FalseFalseFalse
\n", "
" ], "text/plain": [ " long_lived far_travelled_and_very_long_lived strong\n", "track_idx \n", "0 False False False\n", "1 True False False\n", "2 False False False\n", "3 False False False\n", "4 True False False\n", "5 False False False\n", "6 True False False\n", "7 True False False\n", "8 False False False\n", "9 False False False" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr.cats.head(10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note** by default, `classify()` clears previous categories. To preserve them, use `clear=False` keyword." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A shortcut to view the available categories is" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['long_lived', 'far_travelled_and_very_long_lived', 'strong']" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr.cat_labels" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### More complex functions as filters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is possible to categorise tracks by their proximity to the coast (land) or other masked points in an array with geographical coordinates.\n", "For convenience, `octant.misc` module contains `check_by_mask()` function that checks if a cyclone track stays close to land points or domain boundaries for a long enough time. This function is essentially a wrapper around `octant.utils.mask_tracks()` function." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "\n", "from octant.misc import check_by_mask" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, reload the `TrackRun` just in case." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "tr = TrackRun(track_res_dir)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load land-sea mask array from ERA5 dataset:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "lsm = xr.open_dataarray(sample_dir / dataset / \"lsm.nc\")\n", "lsm = lsm.squeeze() # remove singular time dimension" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Importantly, the `classify()` method expects functions that only take 1 argument of type `OctantTrack`, so to use the function above, we need to construct a partial function using `functools` from the standard library." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "from functools import partial" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "land_mask_fun = partial(check_by_mask, trackrun=tr, lsm=lsm, dist=75.) # and leave other parameters default" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This new function has been supplied with all the additional arguments, and can take only `OctantTrack`, which is exactly what `classify()` needs.\n", "It is then passed as a second filtering function to the list of conditions:" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "new_conditions = [\n", " (\"good_candidates\", [lambda ot: ot.lifetime_h >= 6, land_mask_fun]),\n", " (\n", " \"pmc\",\n", " [\n", " lambda ot: ((ot.vortex_type != 0).sum() / ot.shape[0] < 0.2)\n", " and (ot.gen_lys_dist_km > 300.0)\n", " ],\n", " ),\n", "]" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 22 s, sys: 8 ms, total: 22 s\n", "Wall time: 22 s\n" ] } ], "source": [ "%%time\n", "tr.classify(new_conditions, inclusive=True)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which101good_candidates
of which36pmc|good_candidates
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Categorise by percentile" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`TrackRun` also has a method to select a subset of tracks depending on a statistic.\n", "\n", "For example, to select tracks with maximum vorticity in the top 20% (greater than) you can do:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "tr.categorise_by_percentile(by=\"max_vort\", subset=\"pmc|good_candidates\", perc=80, oper=\"gt\")" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which101good_candidates
of which36pmc|good_candidates
of which7max_vort__gt__80pc|pmc|good_candidates
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "... or to find the weakest 5% of \"good candidates\":" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "tr.categorise_by_percentile(\"max_vort\", subset=\"good_candidates\", perc=5, oper=\"le\")" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which101good_candidates
of which36pmc|good_candidates
of which7max_vort__gt__80pc|pmc|good_candidates
of which6max_vort__le__5pc|good_candidates
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Percentile selection with a custom function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Apart from available reducers of `OctantTrack`, e.g. `max_vort`, `lifetime_h`, `total_dist_km`, it is possible to construct a custom one and use it to select tracks above a certain percentile.\n", "\n", "This is achieved by passing a tuple of `(label, function)` as `by=` argument. In this case the function will be applied to each of the tracks within `TrackRun` and it should return only one value.\n", "\n", "For example:" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which101good_candidates
of which36pmc|good_candidates
of which7max_vort__gt__80pc|pmc|good_candidates
of which6max_vort__le__5pc|good_candidates
of which11easternmost__le__10pc|good_candidates
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "def fun(track):\n", " \"\"\"Find easternmost point of the track.\"\"\"\n", " return np.nanmin(track.lon.values)\n", "\n", "tr.categorise_by_percentile(by=(\"easternmost\", fun), subset=\"good_candidates\", perc=10, oper=\"le\")\n", "\n", "tr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Clear categories" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Categories can be removed one by one or all together. It is also possible to \"overwrite\" the inclusivity within this function." ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "tr.clear_categories(subset=\"good_candidates\", inclusive=False)" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Categories
671in total
of which36pmc|good_candidates
of which7max_vort__gt__80pc|pmc|good_candidates
of which6max_vort__le__5pc|good_candidates
of which11easternmost__le__10pc|good_candidates
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "tr.clear_categories()" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
Cyclone tracking results
Number of tracks671
Data columnslon, lat, vo, time, area, vortex_type
Sources
sample_data/era5/run000/test
\n", " " ], "text/plain": [ " [671 tracks]" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tr" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:test_env]", "language": "python", "name": "conda-env-test_env-py" }, "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.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }