Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML for windef settings #178

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions openpiv/examples/notebooks/default_settings.yaml
Original file line number Diff line number Diff line change
@@ -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
255 changes: 255 additions & 0 deletions openpiv/examples/notebooks/windef_settings_yaml.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"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": [
"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": [
"attrs = vars(settings)\n",
"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,
"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
}