From 958b6a28fb938237c29daa5c5b0b36f5714d0f05 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 12 Dec 2020 18:16:28 +0200 Subject: [PATCH 1/2] Update windef_settings_yaml.ipynb --- .../notebooks/windef_settings_yaml.ipynb | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 openpiv/examples/notebooks/windef_settings_yaml.ipynb diff --git a/openpiv/examples/notebooks/windef_settings_yaml.ipynb b/openpiv/examples/notebooks/windef_settings_yaml.ipynb new file mode 100644 index 00000000..960ed88b --- /dev/null +++ b/openpiv/examples/notebooks/windef_settings_yaml.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# test of YAML idea" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from openpiv import windef" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "settings = windef.Settings()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "attrs = vars(settings)\n", + "print(', '.join(\"%s: %s \\n\" % item for item in attrs.items()))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:openpiv] *", + "language": "python", + "name": "conda-env-openpiv-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.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From fabb460a8008610adb9b3ad35b6ee76c1f4ea597 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 12 Dec 2020 18:32:15 +0200 Subject: [PATCH 2/2] Update default_settings.yaml and windef_settings_yaml.ipynb --- .../examples/notebooks/default_settings.yaml | 47 +++++ .../notebooks/windef_settings_yaml.ipynb | 180 +++++++++++++++++- 2 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 openpiv/examples/notebooks/default_settings.yaml diff --git a/openpiv/examples/notebooks/default_settings.yaml b/openpiv/examples/notebooks/default_settings.yaml new file mode 100644 index 00000000..e5ca781c --- /dev/null +++ b/openpiv/examples/notebooks/default_settings.yaml @@ -0,0 +1,47 @@ +MinMax_U_disp: &id001 !!python/tuple +- -30 +- 30 +MinMax_V_disp: *id001 +ROI: full +correlation_method: circular +deformation_method: symmetric +do_sig2noise_validation: false +dt: 1 +dynamic_masking_filter_size: 7 +dynamic_masking_method: None +dynamic_masking_threshold: 0.005 +extract_sig2noise: false +filepath_images: . +filter_kernel_size: 2 +filter_method: localmean +frame_pattern_a: exp1_001_a.bmp +frame_pattern_b: exp1_001_b.bmp +interpolation_order: 3 +iterations: 3 +max_filter_iteration: 4 +median_size: 1 +median_threshold: 3 +normalized_correlation: false +overlap: !!python/tuple +- 32 +- 16 +- 8 +replace_vectors: true +save_folder_suffix: Test_4 +save_path: ./res +save_plot: true +scale_plot: 100 +scaling_factor: 1 +show_plot: true +sig2noise_mask: 2 +sig2noise_method: peak2peak +sig2noise_threshold: 1.05 +smoothn: true +smoothn_p: 0.5 +std_threshold: 10 +subpixel_method: gaussian +validation_first_pass: true +windowsizes: !!python/tuple +- 64 +- 32 +- 16 diff --git a/openpiv/examples/notebooks/windef_settings_yaml.ipynb b/openpiv/examples/notebooks/windef_settings_yaml.ipynb index 960ed88b..a76fbc75 100644 --- a/openpiv/examples/notebooks/windef_settings_yaml.ipynb +++ b/openpiv/examples/notebooks/windef_settings_yaml.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -36,6 +36,45 @@ "name": "stdout", "output_type": "stream", "text": [ + "filepath_images: . \n", + ", save_path: ./res \n", + ", save_folder_suffix: Test_4 \n", + ", frame_pattern_a: exp1_001_a.bmp \n", + ", frame_pattern_b: exp1_001_b.bmp \n", + ", ROI: full \n", + ", dynamic_masking_method: None \n", + ", dynamic_masking_threshold: 0.005 \n", + ", dynamic_masking_filter_size: 7 \n", + ", correlation_method: circular \n", + ", normalized_correlation: False \n", + ", windowsizes: (64, 32, 16) \n", + ", overlap: (32, 16, 8) \n", + ", iterations: 3 \n", + ", subpixel_method: gaussian \n", + ", deformation_method: symmetric \n", + ", interpolation_order: 3 \n", + ", scaling_factor: 1 \n", + ", dt: 1 \n", + ", extract_sig2noise: False \n", + ", sig2noise_method: peak2peak \n", + ", sig2noise_mask: 2 \n", + ", validation_first_pass: True \n", + ", MinMax_U_disp: (-30, 30) \n", + ", MinMax_V_disp: (-30, 30) \n", + ", std_threshold: 10 \n", + ", median_threshold: 3 \n", + ", median_size: 1 \n", + ", do_sig2noise_validation: False \n", + ", sig2noise_threshold: 1.05 \n", + ", replace_vectors: True \n", + ", smoothn: True \n", + ", smoothn_p: 0.5 \n", + ", filter_method: localmean \n", + ", max_filter_iteration: 4 \n", + ", filter_kernel_size: 2 \n", + ", save_plot: True \n", + ", show_plot: True \n", + ", scale_plot: 100 \n", "\n" ] } @@ -45,6 +84,145 @@ "print(', '.join(\"%s: %s \\n\" % item for item in attrs.items()))" ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "import yaml" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "with open(r'default_settings.yaml', 'w') as file:\n", + " documents = yaml.dump(attrs, file)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'MinMax_U_disp': (-30, 30), 'MinMax_V_disp': (-30, 30), 'ROI': 'full', 'correlation_method': 'circular', 'deformation_method': 'symmetric', 'do_sig2noise_validation': False, 'dt': 1, 'dynamic_masking_filter_size': 7, 'dynamic_masking_method': 'None', 'dynamic_masking_threshold': 0.005, 'extract_sig2noise': False, 'filepath_images': '.', 'filter_kernel_size': 2, 'filter_method': 'localmean', 'frame_pattern_a': 'exp1_001_a.bmp', 'frame_pattern_b': 'exp1_001_b.bmp', 'interpolation_order': 3, 'iterations': 3, 'max_filter_iteration': 4, 'median_size': 1, 'median_threshold': 3, 'normalized_correlation': False, 'overlap': (32, 16, 8), 'replace_vectors': True, 'save_folder_suffix': 'Test_4', 'save_path': './res', 'save_plot': True, 'scale_plot': 100, 'scaling_factor': 1, 'show_plot': True, 'sig2noise_mask': 2, 'sig2noise_method': 'peak2peak', 'sig2noise_threshold': 1.05, 'smoothn': True, 'smoothn_p': 0.5, 'std_threshold': 10, 'subpixel_method': 'gaussian', 'validation_first_pass': True, 'windowsizes': (64, 32, 16)}\n" + ] + } + ], + "source": [ + "with open(r'default_settings.yaml') as file:\n", + " # The FullLoader parameter handles the conversion from YAML\n", + " # scalar values to Python the dictionary format\n", + " settings1 = yaml.load(file, Loader=yaml.FullLoader)\n", + "\n", + " print(settings1)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "settings2 = windef.Settings()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "for key in settings1:\n", + " setattr(settings2, key, settings1[key])\n", + "# setattr(self, key, dictionary[key])" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pickle\n", + "pickle.dumps(settings) == pickle.dumps(settings2)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "filepath_images: . \n", + ", save_path: ./res \n", + ", save_folder_suffix: Test_4 \n", + ", frame_pattern_a: exp1_001_a.bmp \n", + ", frame_pattern_b: exp1_001_b.bmp \n", + ", ROI: full \n", + ", dynamic_masking_method: None \n", + ", dynamic_masking_threshold: 0.005 \n", + ", dynamic_masking_filter_size: 7 \n", + ", correlation_method: circular \n", + ", normalized_correlation: False \n", + ", windowsizes: (64, 32, 16) \n", + ", overlap: (32, 16, 8) \n", + ", iterations: 3 \n", + ", subpixel_method: gaussian \n", + ", deformation_method: symmetric \n", + ", interpolation_order: 3 \n", + ", scaling_factor: 1 \n", + ", dt: 1 \n", + ", extract_sig2noise: False \n", + ", sig2noise_method: peak2peak \n", + ", sig2noise_mask: 2 \n", + ", validation_first_pass: True \n", + ", MinMax_U_disp: (-30, 30) \n", + ", MinMax_V_disp: (-30, 30) \n", + ", std_threshold: 10 \n", + ", median_threshold: 3 \n", + ", median_size: 1 \n", + ", do_sig2noise_validation: False \n", + ", sig2noise_threshold: 1.05 \n", + ", replace_vectors: True \n", + ", smoothn: True \n", + ", smoothn_p: 0.5 \n", + ", filter_method: localmean \n", + ", max_filter_iteration: 4 \n", + ", filter_kernel_size: 2 \n", + ", save_plot: True \n", + ", show_plot: True \n", + ", scale_plot: 100 \n", + "\n" + ] + } + ], + "source": [ + "attrs2 = vars(settings2)\n", + "print(', '.join(\"%s: %s \\n\" % item for item in attrs2.items()))" + ] + }, { "cell_type": "code", "execution_count": null,