Skip to content
New issue

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

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

Already on GitHub? # to your account

Provide function to create animated gif #67

Open
jgieseler opened this issue Nov 22, 2024 · 1 comment
Open

Provide function to create animated gif #67

jgieseler opened this issue Nov 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jgieseler
Copy link
Owner

jgieseler commented Nov 22, 2024

Based on 7.1 Loop over multiple datetimes (plots) in https://github.com/jgieseler/solarmach/blob/main/examples/example.ipynb, provide a function that creates an animated gif. The current code in the Notebook is the following:

body_list = ['Earth', 'STEREO A', 'Solar Orbiter', 'PSP', 'BepiColombo']
vsw_list = len(body_list) * [350]
for i in range(2,19,1):    
    j = str(i).rjust(2, '0')
    date = f'2022-6-{j} 12:00:00'
    filename = f'animate_{date[:-9]}.png'        # define filename of output figure
    sm7 = SolarMACH(date, body_list, vsw_list, coord_sys='Stoneyhurst')
    sm7.plot(plot_sun_body_line=False, transparent=False, markers='numbers', outfile=filename)
import glob
files = sorted(glob.glob(filename.replace(f'{i}', '*')))
import imageio
images_data = []
for filename in files:
    data = imageio.v2.imread(filename)
    images_data.append(data)

# write to animated gif; duration (in ms) defines how fast the animation is.
imageio.mimwrite('solarmach.gif', images_data, format= '.gif', duration=100, loop=0)
@jgieseler
Copy link
Owner Author

Ideally, in another step, the call of SolarMACH(date, body_list, vsw_list) should be modified so that date accepts next to a single datetime a list of them, similar to the get_horizons_coord() call in https://docs.sunpy.org/en/stable/generated/gallery/units_and_coordinates/ParkerSolarProbe_trajectory.html This should increase the speed significantly because there will be only one call to JPL Horizon per spacecraft.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant