Published
Edited
Feb 15, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
// number of particles
n = 100
Insert cell
settings = ({
particleCount: 100,
maxParticleAge: 50,
animate: true,
frameRate: 20,
velocityScale: 0.03, //0.02
fadeFillStyle: "rgba(57,61,71, 0.92)"
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Object.keys(data)
Insert cell
Insert cell
Insert cell
projection
Insert cell
Insert cell
Insert cell
particles = []
Insert cell
generate_particles(particles, n)
Insert cell
NearestLonLat(-2492094, 1570000)
Insert cell
generate_particles = function (particles, n) {
// Create particles
let lonlatitude,
xinit,
yinit,
x0,
y0,
x1,
y1,
loninit,
latinit,
lon0,
lat0,
lat1,
lon1,
visible,
age;

for (let i = 0; i < n; i++) {
loninit = longitude[Math.floor(Math.random() * longitude.length)];
lonlatitude = Object.keys(data[loninit]).map((i) => Number(i));
latinit = lonlatitude[Math.floor(Math.random() * lonlatitude.length)];

age = rand(10, settings.maxParticleAge);
particles.push({
xinit: Math.round(projection([loninit, latinit])[0]),
yinit: Math.round(projection([loninit, latinit])[1]),
loninit: loninit,
latinit: latinit,
x0: Math.round(projection([loninit, latinit])[0]),
y0: Math.round(projection([loninit, latinit])[1]),
lon0: loninit,
lat0: latinit,
x1: Math.round(projection([loninit, latinit])[0]),
y1: Math.round(projection([loninit, latinit])[1]),
lon1: loninit,
lat1: latinit,
visible: 1,
age: age
});
}
return particles;
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
projection = createProjection(bbox[0], bbox[1], bbox[2], bbox[3])
Insert cell
Insert cell
projectiontemp = d3.geoIdentity().reflectY(true)
Insert cell
// bouding box of the Layer Lat/Lon at 4500m resolution :-2800225,-2802275,2802275,2800225
bbox = [-2802275, -2800225, 2800225, 2802275]
Insert cell
Insert cell
Insert cell
// get the longitude values in the dataset
//longitude = Object.keys(data).map((i) => Number(i))
longitude = [...new Set(Object.values(raw_data.data).map((i) => i["lon"]))]
Insert cell
//longitude = d3.range(bbox[0], bbox[2], resolution)
Insert cell
//latitude = d3.range(bbox[1], bbox[3], resolution)
Insert cell
// get the latitude values and remote duplicates: uniq = [...new Set(array)]
latitude = [...new Set(Object.values(raw_data.data).map((i) => i["lat"]))]
Insert cell
Insert cell
Object.values(raw_data.data)
Insert cell
Insert cell
Insert cell
Insert cell
antarctica_json = FileAttachment("antarctica_light.json").json()
Insert cell
Insert cell
Insert cell
raw_data = FileAttachment("antarctic_ice_vel_notnull_9.json").json()
Insert cell
Insert cell
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
R = require("ramda@0.25")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more