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

Plotting Earthquake Hypocenters as Time Series Data #317

Open
AlexanderJuestel opened this issue Dec 13, 2020 · 1 comment
Open

Plotting Earthquake Hypocenters as Time Series Data #317

AlexanderJuestel opened this issue Dec 13, 2020 · 1 comment

Comments

@AlexanderJuestel
Copy link

Description

Hello,

I would like to plot earthquake data as Time Series with PyVista, ideally having a slider or a sort of "play button" to start adding data. The data used for the slider would be the year the earthquake occured. So while time progresses, more and more events should appear in the plotting window.

Example Data

I have attached the sample data.

What I have accomplished so far is plotting each single event as sphere and adjust its size and color to the magnitude of the event. Is there a way to combine the single spheres like done for the lines in #310 and then somehow plot the data by year by adjusting a slider?

image

data = pd.read_csv(file_path + 'earthquakes_aachen.csv', delimiter=';').dropna()
data = data[data['Magnitude'] != '-']
data = data[data['Tiefe [km]'] != '-']

data['Magnitude'] = pd.to_numeric(data['Magnitude'])
data['Tiefe [km]'] = pd.to_numeric(data['Tiefe [km]'])
data['Date'] = pd.to_datetime(data['Date'])
data['Year'] = pd.DatetimeIndex(data['Date']).year

data['X'] = pd.to_numeric(data['X'])
data['Y'] = pd.to_numeric(data['Y'])
data['Z'] = pd.to_numeric(data['Z'])

spheres = [pv.Sphere(radius=data_df.loc[i]['Magnitude']*200, center=data_df.loc[i][['X', 'Y', 'Z']].tolist()) for i in range(len(data_df))]

for i in range(len(spheres)):
    spheres[i]['Magnitude'] = np.zeros(len(spheres[i].points)) + data_df.loc[i]['Magnitude']
    spheres[i]['Year'] = np.zeros(len(spheres[i].points)) + data_df.loc[i]['Year']

sargs = dict(fmt="%.1f", color='black')

p = pv.Plotter(notebook=False)

for i in spheres:
    p.add_mesh(i,scalars='Magnitude', cmap='Reds', clim=[0,6],scalar_bar_args=sargs)

p.set_background('white')
p.show_grid(color='black')
p.show()

Looking forward to some hints and tipps :)

earthquakes_aachen.txt

@banesullivan
Copy link
Member

This is awesome and I want to provide some help but am lacking time at the moment. Hopefully, these tips help:

Is there a way to combine the single spheres like done for the lines in #310

Yep, you can either merge all the spheres into a single unstructured grid or put them all in a MultiBlock dataset. Since you already have the spheres as a list, you can just pass that to the MultiBlock constructor:

spheres = pv.MultiBlock([pv.Sphere(radius=data_df.loc[i]['Magnitude']*200, center=data_df.loc[i][['X', 'Y', 'Z']].tolist()) for i in range(len(data_df))])

...

# Remove the for loop plotting
p.add_mesh(spheres, scalars='Magnitude', cmap='Reds', clim=[0,6],scalar_bar_args=sargs)

then somehow plot the data by year by adjusting a slider?

See if you can create a multiblock like this for each year. Then track which data to show by having some sort of class that will hold all of that data and have callbacks for updating the data shown in the viewer.

At the moment, we only have slider widgets to control the timestep but we could add this time widget: https://vtk.org/Wiki/File:PlaybackWidget.png

Otherwise, I'd use ipywdigets or a qt interface with BackgroundPlotter

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants