Created
October 12, 2023 09:25
-
-
Save samarlyka/82b7b9a899236da725dfa58e882a40a5 to your computer and use it in GitHub Desktop.
OOMMF Conversion of Micrographs into MP4 File (Aug 24, 2023)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Converts an array of images into an MP4 video | |
| # SOURCE: https://askubuntu.com/a/610945 | |
| base="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/magick-export" | |
| fps=60 | |
| output_path="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/dist/" | |
| ffmpeg -framerate $fps -i $base/overlaid-micrograph-%07d.png -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p $output_path/ffmpeg-output-$fps"fps".mp4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Bulk-overlay converted OMF micrograph files | |
| # Predetermined paths | |
| file_background="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/assets/background.png" | |
| folder_export="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/magick-export" | |
| folder_source_micrograph="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-8/png-files" | |
| folder_source_plot="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/matplotlib-output" | |
| list_energy_demag="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/data/energy-demag.txt" | |
| list_energy_total="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/data/energy-total.txt" | |
| list_energy_ue="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/data/energy-uniform-exchange.txt" | |
| list_micrograph="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/data/micrographs-list.txt" | |
| list_time="/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/data/simulation-time.txt" | |
| # Predetermined variables | |
| export_filename_extension=".png" | |
| export_filename_prefix="overlaid-micrograph-" | |
| source_filename_extension=".png" | |
| source_filename_prefix="GSnanowire-Oxs_TimeDriver-Magnetization-00-" | |
| plot_filename_extension=".png" | |
| plot_filename_prefix="matplotlib-" | |
| # Dealing with and processing 10000 micrograph files | |
| start=1 | |
| end=10000 | |
| for i in $(eval echo {$start..$end}); do | |
| j=$(echo $(( $i-1 ))) | |
| k=$(cat $list_time | sed "$i"'!d') | |
| l=$(cat $list_micrograph | sed "$i"'!d') | |
| m=$(cat $list_energy_demag | sed "$i"'!d') | |
| n=$(cat $list_energy_total | sed "$i"'!d') | |
| o=$(cat $list_energy_ue | sed "$i"'!d') | |
| magick $file_background \ | |
| -font Montserrat-Bold -weight 100 -pointsize 22 -fill Black -annotate +465+175 $j \ | |
| -font Montserrat-Bold -weight 100 -pointsize 22 -fill Black -annotate +465+203 $k \ | |
| -font Montserrat-Bold -weight 100 -pointsize 22 -fill Black -annotate +465+230 $n \ | |
| -font Montserrat-Bold -weight 100 -pointsize 22 -fill Black -annotate +465+258 $o \ | |
| -font Montserrat-Bold -weight 100 -pointsize 22 -fill Black -annotate +465+285 $m \ | |
| \( \ | |
| $folder_source_micrograph/$source_filename_prefix$l$source_filename_extension \ | |
| -geometry +667+62 -resize 60% \ | |
| \) -composite \ | |
| \( \ | |
| $folder_source_plot/$plot_filename_prefix$l$plot_filename_extension \ | |
| -geometry +70+325 -resize 60% \ | |
| \) -composite \ | |
| $folder_export/$export_filename_prefix$l$export_filename_extension | |
| echo step: $j, time: $k, energy demag: $m, energy total: $n, energy ue: $o | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python | |
| # Bulk-export energy graph of the 100nm model into image files from 0 nanosecond to 5.76 nanosecond | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| # The working directory | |
| wd = '/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10' | |
| # The micrograph list file input | |
| mgl_fi = '/ssynthesia/ghostcity/git-local/02306.00013-neptunal-ix-oommf-nanoparticle/ix-meh-10/data/micrographs-list.txt' | |
| # Reading the source file containing energy data | |
| src = f'{wd}/data-matplotlib/source.csv' | |
| df = pd.read_csv(src) | |
| # Preparing the column data and obtaining the values | |
| # 'c1' --> energy-total | |
| # 'c2' --> energy-uniform-exchange | |
| # 'c3' --> energy-demag | |
| # 't' --> time | |
| c1 = df['energy-total'].values | |
| c2 = df['energy-uniform-exchange'].values | |
| c3 = df['energy-demag'].values | |
| t = df['time'].values | |
| # Reading the list of microgaphs, for file output naming | |
| # The range should not exceed 1800 numbers, otherwise matplotlib cache | |
| # will consume Monked's precious 4 GiB of RAM from the inside :"( | |
| with open(mgl_fi, 'r') as mgl: | |
| rl = mgl.readlines() # --- 'rl' stands for 'read lines' | |
| # Iterating through every micrograph's energy data | |
| # for i in range(len(rl)): | |
| for i in range(8999, len(rl)): | |
| # Preamble | |
| print(f'Plotting the micrograph number {i}. Please wait ...') | |
| # Preparing and configuring the graph figure | |
| plt.figure(dpi=150.0) | |
| plt.xlabel('time (nanosecond)') | |
| plt.ylabel('energy (attojoule)') | |
| # Plotting the data | |
| plt.plot(t[:(i)], c1[:(i)], label='energy-total') | |
| plt.plot(t[:(i)], c2[:(i)], label='energy-uniform-exchange') | |
| plt.plot(t[:(i)], c3[:(i)], label='energy-demag') | |
| # Drawing the legend | |
| plt.legend(fontsize='medium') | |
| # Setting the plot image name and saving the figure | |
| ext = '.png' | |
| pin = 'matplotlib-' + rl[i].strip() + ext # --- 'pin' stands for 'plot image name | |
| plt.savefig(f'{wd}/matplotlib-output/{pin}', bbox_inches='tight') | |
| # Clearing the figure for the next iteration's plotting | |
| plt.close() | |
| # Continuing the iteration | |
| continue | |
| # Good bye | |
| exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment