This notebook walks you through some of the high level aspects of the Planetoid API
import pandas as pd
import numpy as np
from matplotlib import colors
from sklearn.datasets import make_blobs
import planetoids as pt
np.random.seed(42)
Using scikit-learn, we will generate some random data that we will use to seed a Planetoid
X, y = make_blobs(n_samples=200,
n_features=2,
centers=3,
cluster_std=1.1,
center_box=(0,10),
random_state=42)
data = pd.DataFrame(X)
data['Cluster'] = y
#plot
data.plot(kind='scatter', x=0, y=1, c='Cluster', cmap='tab10')
<matplotlib.axes._subplots.AxesSubplot at 0x18729c8c400>
blob_planet = pt.Planetoid(data, x=0, y=1, cluster_field='Cluster')
This will generate all of the data needed to terraform and render our blob_planet
but calling fit
and then terraform
.
blob_planet.fit_terraform(planet_name='fit_terraform demo')
HBox(children=(IntProgress(value=0, description='Generating data', max=3, style=ProgressStyle(description_widt…
HBox(children=(IntProgress(value=0, description='Plotting contours', max=3, style=ProgressStyle(description_wi…
HBox(children=(IntProgress(value=0, description='Plotting relief', max=3, style=ProgressStyle(description_widt…
HBox(children=(IntProgress(value=0, description='Plotting highlight', max=3, style=ProgressStyle(description_w…
HBox(children=(IntProgress(value=0, description='Plotting shadows', max=3, style=ProgressStyle(description_wid…
Ecology is one of the simplest changes you can make that produces dramatic difference in the look and feel of a Planetoid. Ecology is considered a key seed element for your planet, as such, you will have to explicitly set it using its own method if you want to change it.
This controls the level of detail in the generated land mass contours. Lower values will produce fewer contours and consequently shallower land masses, higher values will help land masses rise out of the 'ocean'. This can result in fundamental shifts in the generated ecology.
This controls the level of detail in the lighting effect. This is meant to add an additional level of depth to your Planetoid. Terraforming allows you to selectively choose whether or not to show the hillshade and highlight independantly of one another.
This controls the level of detail in the relief. These lines represent the gradient of the generated land mass physical features.
This is the map projection that is used to render the planetoid. The default 'orthographic' will produce a 3D sphere effect. Use an 'equirectangular' projection to show the data in a more traditional euclidean space. Interesting distortion effects using some of the more exotic projections are also possible.
We're going to generate 3 planetoids using a different mix of these elements to illustrate some of the variation possible with the same seed data.
for ix, projection in enumerate(["orthographic", "natural earth", "azimuthal equidistant"]):
ecology = ['gist_earth', 'gnuplot', 'rainbow_r']
topography_levels = int(np.random.choice([x for x in range(10,35,5)],1)[0])
lighting_levels = int(np.random.choice([x for x in range(10,35,5)],1)[0])
relief_density = np.random.randint(1,5)
plot_highlight = np.random.choice([True, False])
plot_hillshade = np.random.choice([True, False])
print("Ecology: {}".format(ecology[ix]))
print("Topography Levels: {}".format(topography_levels))
print("Lighting Levels: {}".format(lighting_levels))
print("Relief Density: {}".format(relief_density))
print("Projection: {}".format(projection))
print("Highlight: {}".format(plot_highlight))
print("Hillshade: {}".format(plot_hillshade))
blob_planet.change_ecology(ecology[ix])
blob_planet.fit_terraform(topography_levels=topography_levels,
lighting_levels=lighting_levels,
relief_density=relief_density,
plot_highlight=plot_highlight,
plot_hillshade=plot_hillshade,
projection=projection,
planet_name=projection)
Ecology: gist_earth Topography Levels: 30 Lighting Levels: 15 Relief Density: 3 Projection: orthographic Highlight: False Hillshade: False
HBox(children=(IntProgress(value=0, description='Generating data', max=3, style=ProgressStyle(description_widt…
HBox(children=(IntProgress(value=0, description='Plotting contours', max=3, style=ProgressStyle(description_wi…
HBox(children=(IntProgress(value=0, description='Plotting relief', max=6, style=ProgressStyle(description_widt…
Ecology: gnuplot Topography Levels: 30 Lighting Levels: 30 Relief Density: 4 Projection: natural earth Highlight: True Hillshade: True
HBox(children=(IntProgress(value=0, description='Generating data', max=3, style=ProgressStyle(description_widt…
HBox(children=(IntProgress(value=0, description='Plotting contours', max=3, style=ProgressStyle(description_wi…
HBox(children=(IntProgress(value=0, description='Plotting relief', max=9, style=ProgressStyle(description_widt…
HBox(children=(IntProgress(value=0, description='Plotting highlight', max=9, style=ProgressStyle(description_w…
HBox(children=(IntProgress(value=0, description='Plotting shadows', max=9, style=ProgressStyle(description_wid…
Ecology: rainbow_r Topography Levels: 25 Lighting Levels: 20 Relief Density: 4 Projection: azimuthal equidistant Highlight: True Hillshade: True
HBox(children=(IntProgress(value=0, description='Generating data', max=3, style=ProgressStyle(description_widt…
HBox(children=(IntProgress(value=0, description='Plotting contours', max=3, style=ProgressStyle(description_wi…
HBox(children=(IntProgress(value=0, description='Plotting relief', max=12, style=ProgressStyle(description_wid…
HBox(children=(IntProgress(value=0, description='Plotting highlight', max=12, style=ProgressStyle(description_…
HBox(children=(IntProgress(value=0, description='Plotting shadows', max=12, style=ProgressStyle(description_wi…