AntSimi / py-eddy-tracker

Eddy identification and tracking
https://py-eddy-tracker.readthedocs.io/en/latest/
GNU General Public License v3.0
120 stars 48 forks source link

How to store the eddy tracking results #234

Open thomaseocean opened 4 months ago

thomaseocean commented 4 months ago

I would be so thankful if you could please help me. I have carried out eddy detection and realized eddy tracking through your sample code. How to store the eddy tracking results???l want to get save the path and boundary of each eddy.

AntSimi commented 4 months ago

Use to_netcdf method https://py-eddy-tracker.readthedocs.io/en/latest/_modules/py_eddy_tracker/observations/observation.html#EddiesObservations.to_netcdf

thomaseocean commented 4 months ago

I use the data of aviso to detect the vortex and store it as NC data. It takes ten days. One day, the data is stored in an NC file. But when I track the vortex, the result is wrong. I don't know if there is something wrong with the function I called? Please provide some help,Another problem is how to store the test results of ten days in zarr. I will only store the test results of one day in zarr according to your instance code. I see that the sample data you provided is to store many test results in zarr, and the tracking code also reads the zarr data

import logging
from py_eddy_tracker.gui import GUI
from matplotlib import pyplot as plt
from netCDF4 import Dataset
import os
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
import py_eddy_tracker.observations.observation
from py_eddy_tracker.tracking import Correspondances

py_eddy_tracker.observations.observation._display_check_warning = False

# file_objects = get_remote_demo_sample(
#     "eddies_med_adt_allsat_dt2018/Anticyclonic_2010_2011_2012"
# )[:20]
def get_local_demo_sample(folder_path):

    if not os.path.exists(folder_path):
        raise FileNotFoundError(f"The folder {folder_path} does not exist.")

    nc_files = []
    for filename in os.listdir(folder_path):
        if filename.endswith(".nc"):
            file_path = os.path.join(folder_path, filename)
            # nc_file = nc.Dataset(file_path, 'r')
            nc_files.append(file_path)

    return nc_files

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(-180, 170), ax.set_ylim(-40, 40)
    ax.set_aspect("equal")
    ax.grid()
datapath = 'aviso_reult/Anticyclonic'
file_objects =get_local_demo_sample(datapath)

c = Correspondances(datasets=file_objects, class_method=AreaTracker, virtual=3)
c_first_run = Correspondances(
    datasets=file_objects, class_method=AreaTracker, virtual=10
)

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_eddy(eddies_area_tracker)

plt.show()
thomaseocean commented 4 months ago

24dffb09da1b02addb8fb27f0586e0e

AntSimi commented 4 months ago

Zarr or netcdf is only a storage format and could be use to store identification or tracking. You need to apply a tracking on your identification file to create an atlas. You could also merge all identification result in one collection.