Skip to content

Instantly share code, notes, and snippets.

View TarickWake's full-sized avatar
🐍

Clément T. TarickWake

🐍
View GitHub Profile
@TarickWake
TarickWake / xarray_accessor_peak_detection_and_plotting.md
Last active June 24, 2024 12:38
Xarray Extensions for Peak Detection and Visualization: This Python code snippet extends xarray DataArrays with custom accessors for detecting and plotting positive and negative peaks in 1D signals, enhancing data analysis and visualization capabilities.

Xarray Peak Detection and Visualization 📈

TL;DR

Enhance your data analysis with custom Xarray accessors for detecting and visualizing both positive and negative peaks in 1D signals. This Python code snippet makes it easy to identify and annotate peaks directly on your plots. doc xarray

Features

  • Find Peaks: Utilize the find_peaks accessor to detect peaks in your DataArray.
  • Plot Peaks: With the plot_peaks accessor, visualize positive and negative peaks on your plots, including annotations for peak indices.

Output

@TarickWake
TarickWake / read mat file easy.md
Created June 18, 2024 16:46
Reading .mat Files Using `pymatreader` 📊

Reading .mat Files Using pymatreader 📊

To efficiently read MATLAB .mat files in Python, pymatreader simplifies the process by returning data as a nested dictionary, akin to scipy.io.loadmat style.

Usage Example 🚀

import pymatreader

# Specify the path to your .mat file
@TarickWake
TarickWake / importer_tiff_readme.md
Last active June 19, 2024 12:30
imort into array of array tif image fast ! ["frame", "y_im", "x_im", "rgb"]

📸 TIFF loading FAST !

This Python script is designed to load images from a specified directory using a ThreadPoolExecutor for concurrent execution. It reads all .tif files from the "tif" directory and processes them in parallel, utilizing multiple threads to speed up the image loading process.

Important Note: The order of the images is preserved throughout this process. The executor.map method guarantees that the results are returned in the same order as the input paths, ensuring that the correspondence between the file paths and the loaded images is maintained.

🛠️ Dependencies

  • 🖥️ os (built-in): For interacting with the operating system to list files in a directory.
  • 📷 cv2 (OpenCV, to be installed): For reading image files.
  • 📁 pathlib (built-in): For manipulating filesystem paths in a platform-independent way.
  • 🌐 concurrent.futures.ThreadPoolExecutor (built-in): For managing a pool of threads to execute calls asynchronously.
"""
Author: Clement TIFFON
Date: 14-06-2023
Description: This is a simple GUI for the OpenAI Text-to-Speech API. This is an example of a Streamlit app that uses the OpenAI API to convert text to speech. The app allows users to enter text in a chat input field, which is then converted to speech using the OpenAI API. The app displays the chat history and the corresponding audio files. The app uses the OpenAI Python client library to interact with the OpenAI API. The app also uses the Streamlit chat input and audio components to create a chat interface for the user. The app is a simple example of how to use the OpenAI API with Streamlit to create a text-to-speech application.
to run the app, you need to install the following libraries:
- streamlit
- openai
- numpy
@TarickWake
TarickWake / grab value from notebook.py
Created June 6, 2024 11:07
This function opens a Jupyter notebook file and searches for a specific pattern in the outputs of the code cells. If the pattern is found, it returns the first group of the match as a float.
import codecs
import nbformat
import re
def grab_value_from_notebook(file_path, pattern):
"""
This function opens a Jupyter notebook file and searches for a specific pattern in the outputs of the code cells.
If the pattern is found, it returns the first group of the match as a float.
"""
@TarickWake
TarickWake / draw_loglog_slope.py
Created June 6, 2024 10:58 — forked from w1th0utnam3/draw_loglog_slope.py
A helper function for Matplotlib to draw "convergence triangles" into loglog plots.
import matplotlib as mpl
def draw_loglog_slope(fig, ax, origin, width_inches, slope, inverted=False, color=None, polygon_kwargs=None, label=True, labelcolor=None, label_kwargs=None, zorder=None):
"""
This function draws slopes or "convergence triangles" into loglog plots.
@param fig: The figure
@param ax: The axes object to draw to
@param origin: The 2D origin (usually lower-left corner) coordinate of the triangle
@param width_inches: The width in inches of the triangle