.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_basic_usage.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_basic_usage.py: Basic Tracking Example ====================== This example demonstrates how to use the `soft` package to detect and track features in synthetic data. .. GENERATED FROM PYTHON SOURCE LINES 7-92 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_basic_usage_001.png :alt: Frame 0 :srcset: /auto_examples/images/sphx_glr_plot_basic_usage_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_basic_usage_002.png :alt: Frame 4 :srcset: /auto_examples/images/sphx_glr_plot_basic_usage_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Running tracking... Number of cores used: 1 Cleaning up Detecting features... Assigning unique IDs... 0it [00:00, ?it/s] 0it [00:00, ?it/s] Total number of unique IDs: 1 Feature detection step ended Associating features... Starting the first round of association No associated files found. Cleaning up Starting tabulation No association or source files found for tabulation. No dataframe found. | .. code-block:: Python import numpy as np import matplotlib.pyplot as plt import soft.soft import os import shutil import astropy.io.fits # Create a temporary directory for data data_dir = "temp_data" os.makedirs(data_dir, exist_ok=True) os.makedirs(os.path.join(data_dir, "00-data"), exist_ok=True) os.makedirs(os.path.join(data_dir, "01-mask"), exist_ok=True) os.makedirs(os.path.join(data_dir, "02-id"), exist_ok=True) os.makedirs(os.path.join(data_dir, "03-assoc"), exist_ok=True) # Generate synthetic frames # We'll create a moving Gaussian blob nx, ny = 100, 100 n_frames = 5 x, y = np.meshgrid(np.arange(nx), np.arange(ny)) for t in range(n_frames): # Blob moves along x=y cx, cy = 20 + t * 5, 20 + t * 5 sigma = 5 blob = 100 * np.exp(-((x - cx)**2 + (y - cy)**2) / (2 * sigma**2)) # Add some noise noise = np.random.normal(0, 5, (ny, nx)) frame = blob + noise filename = os.path.join(data_dir, "00-data", f"{t:04d}.fits") astropy.io.fits.writeto(filename, frame, overwrite=True) # Plot the first and last frame for visualization if t == 0 or t == n_frames - 1: plt.figure() plt.title(f"Frame {t}") plt.imshow(frame, origin='lower', cmap='gray') plt.colorbar() plt.show() # Set tracking parameters l_thr = 20 # Low threshold h_thr = 50 # High threshold min_size = 10 min_distance = 5 dx = 1.0 dt = 1.0 sign = "both" separation = True verbose = True cores = 1 # Run tracking print("Running tracking...") soft.soft.track_all(data_dir, cores, min_distance, l_thr, h_thr, min_size, dx, dt, sign, separation, verbose) # Check results # Read the resulting dataframe import pandas as pd df_path = os.path.join(data_dir, "dataframe.json") if os.path.exists(df_path): df = pd.read_json(df_path) print("Tracking results:") print(df.head()) # Plot trajectory plt.figure() plt.title("Tracked Trajectory") for label in df['label'].unique(): subset = df[df['label'] == label] plt.plot(subset['X'], subset['Y'], 'o-', label=f'Label {label}') plt.legend() plt.xlabel("X pixel") plt.ylabel("Y pixel") plt.show() else: print("No dataframe found.") # Cleanup # shutil.rmtree(data_dir) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.611 seconds) .. _sphx_glr_download_auto_examples_plot_basic_usage.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_basic_usage.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_basic_usage.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_basic_usage.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_