-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
258 additions
and
4 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
examples/08_tracking_manipulation/pet_how_to_use_correspondances.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
""" | ||
Correspondances | ||
=============== | ||
Correspondances is a mechanism to intend to continue tracking with new detection | ||
""" | ||
|
||
import logging | ||
|
||
# %% | ||
from matplotlib import pyplot as plt | ||
from netCDF4 import Dataset | ||
|
||
from py_eddy_tracker import start_logger | ||
from py_eddy_tracker.data import get_remote_demo_sample | ||
from py_eddy_tracker.featured_tracking.area_tracker import AreaTracker | ||
|
||
# In order to hide some warning | ||
import py_eddy_tracker.observations.observation | ||
from py_eddy_tracker.tracking import Correspondances | ||
|
||
py_eddy_tracker.observations.observation._display_check_warning = False | ||
|
||
|
||
# %% | ||
def plot_eddy(ed): | ||
fig = plt.figure(figsize=(10, 5)) | ||
ax = fig.add_axes([0.05, 0.03, 0.90, 0.94]) | ||
ed.plot(ax, ref=-10, marker="x") | ||
lc = ed.display_color(ax, field=ed.time, ref=-10, intern=True) | ||
plt.colorbar(lc).set_label("Time in Julian days (from 1950/01/01)") | ||
ax.set_xlim(4.5, 8), ax.set_ylim(36.8, 38.3) | ||
ax.set_aspect("equal") | ||
ax.grid() | ||
|
||
|
||
# %% | ||
# Get remote data, we will keep only 20 first days, | ||
# `get_remote_demo_sample` function is only to get demo dataset, in your own case give a list of identification filename | ||
# and don't mix cyclonic and anticyclonic files. | ||
file_objects = get_remote_demo_sample( | ||
"eddies_med_adt_allsat_dt2018/Anticyclonic_2010_2011_2012" | ||
)[:20] | ||
|
||
# %% | ||
# We run a traking with a tracker which use contour overlap, on 10 first time step | ||
c_first_run = Correspondances( | ||
datasets=file_objects[:10], class_method=AreaTracker, virtual=4 | ||
) | ||
start_logger().setLevel("INFO") | ||
c_first_run.track() | ||
start_logger().setLevel("WARNING") | ||
with Dataset("correspondances.nc", "w") as h: | ||
c_first_run.to_netcdf(h) | ||
# Next step are done only to build atlas and display it | ||
c_first_run.prepare_merging() | ||
|
||
# We have now an eddy object | ||
eddies_area_tracker = c_first_run.merge(raw_data=False) | ||
eddies_area_tracker.virtual[:] = eddies_area_tracker.time == 0 | ||
eddies_area_tracker.filled_by_interpolation(eddies_area_tracker.virtual == 1) | ||
|
||
# %% | ||
# Plot from first ten days | ||
plot_eddy(eddies_area_tracker) | ||
|
||
# %% | ||
# Restart from previous run | ||
# ------------------------- | ||
# We give all filenames, the new one and filename from previous run | ||
c_second_run = Correspondances( | ||
datasets=file_objects[:20], | ||
# This parameter must be identical in each run | ||
class_method=AreaTracker, | ||
virtual=4, | ||
# Previous saved correspondancs | ||
previous_correspondance="correspondances.nc", | ||
) | ||
start_logger().setLevel("INFO") | ||
c_second_run.track() | ||
start_logger().setLevel("WARNING") | ||
c_second_run.prepare_merging() | ||
# We have now another eddy object | ||
eddies_area_tracker_extend = c_second_run.merge(raw_data=False) | ||
eddies_area_tracker_extend.virtual[:] = eddies_area_tracker_extend.time == 0 | ||
eddies_area_tracker_extend.filled_by_interpolation( | ||
eddies_area_tracker_extend.virtual == 1 | ||
) | ||
|
||
|
||
# %% | ||
# Plot with time extension | ||
plot_eddy(eddies_area_tracker_extend) |
155 changes: 155 additions & 0 deletions
155
notebooks/python_module/08_tracking_manipulation/pet_how_to_use_correspondances.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Correspondances\n\nCorrespondances is a mechanism to intend to continue tracking with new detection\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import logging" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from matplotlib import pyplot as plt\nfrom netCDF4 import Dataset\n\nfrom py_eddy_tracker import start_logger\nfrom py_eddy_tracker.data import get_remote_demo_sample\nfrom py_eddy_tracker.featured_tracking.area_tracker import AreaTracker\n\n# In order to hide some warning\nimport py_eddy_tracker.observations.observation\nfrom py_eddy_tracker.tracking import Correspondances\n\npy_eddy_tracker.observations.observation._display_check_warning = False" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"def plot_eddy(ed):\n fig = plt.figure(figsize=(10, 5))\n ax = fig.add_axes([0.05, 0.03, 0.90, 0.94])\n ed.plot(ax, ref=-10, marker=\"x\")\n lc = ed.display_color(ax, field=ed.time, ref=-10, intern=True)\n plt.colorbar(lc).set_label(\"Time in Julian days (from 1950/01/01)\")\n ax.set_xlim(4.5, 8), ax.set_ylim(36.8, 38.3)\n ax.set_aspect(\"equal\")\n ax.grid()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Get remote data, we will keep only 20 first days,\n`get_remote_demo_sample` function is only to get demo dataset, in your own case give a list of identification filename\nand don't mix cyclonic and anticyclonic files.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"file_objects = get_remote_demo_sample(\n \"eddies_med_adt_allsat_dt2018/Anticyclonic_2010_2011_2012\"\n)[:20]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We run a traking with a tracker which use contour overlap, on 10 first time step\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"c_first_run = Correspondances(\n datasets=file_objects[:10], class_method=AreaTracker, virtual=4\n)\nstart_logger().setLevel(\"INFO\")\nc_first_run.track()\nstart_logger().setLevel(\"WARNING\")\nwith Dataset(\"correspondances.nc\", \"w\") as h:\n c_first_run.to_netcdf(h)\n# Next step are done only to build atlas and display it\nc_first_run.prepare_merging()\n\n# We have now an eddy object\neddies_area_tracker = c_first_run.merge(raw_data=False)\neddies_area_tracker.virtual[:] = eddies_area_tracker.time == 0\neddies_area_tracker.filled_by_interpolation(eddies_area_tracker.virtual == 1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Plot from first ten days\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"plot_eddy(eddies_area_tracker)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Restart from previous run\nWe give all filenames, the new one and filename from previous run\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"c_second_run = Correspondances(\n datasets=file_objects[:20],\n # This parameter must be identical in each run\n class_method=AreaTracker,\n virtual=4,\n # Previous saved correspondancs\n previous_correspondance=\"correspondances.nc\",\n)\nstart_logger().setLevel(\"INFO\")\nc_second_run.track()\nstart_logger().setLevel(\"WARNING\")\nc_second_run.prepare_merging()\n# We have now another eddy object\neddies_area_tracker_extend = c_second_run.merge(raw_data=False)\neddies_area_tracker_extend.virtual[:] = eddies_area_tracker_extend.time == 0\neddies_area_tracker_extend.filled_by_interpolation(\n eddies_area_tracker_extend.virtual == 1\n)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Plot with time extension\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"plot_eddy(eddies_area_tracker_extend)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters