Public
Edited
Jan 4, 2023
Paused
Insert cell
Insert cell
Insert cell
bcSiteLocs = _.uniqBy(metadata, ({ lat, long }) => lat)
Insert cell
Insert cell
Insert cell
metadata
Insert cell
date = new Date(metadata[0].year, metadata[0].month - 1, metadata[0].day)
Insert cell
Insert cell
Insert cell
Insert cell
speciesTotals = {
const out = [];
d3.rollups(
joinedData,
v => d3.sum(v, d => d.Value),
d => d.site,
d => d.date.toString(),
d => d.species
).forEach(d => {
out.push({ site: d[0], data: d[1].flat() });
});
return out;
}
Insert cell
sp = d3.rollups(
joinedData,
v => d3.sum(v, d => d.Value),
d => d.site,
d => d.date.toString(),
d => d.species
)
Insert cell
flatData = {
const out = [];
sp.forEach(d => {
d[1].forEach(dd => {
dd[1].forEach(s => {
out.push({
site: d[0],
date: new Date(dd[0]),
mmyy: new Date(dd[0]).toLocaleString("en", {
month: "2-digit",
year: 'numeric'
}),
monthly: d3.timeMonth(new Date(dd[0])),
mm: new Date(dd[0]).toLocaleString("en", {
month: "2-digit"
}),
species: s[0],
class: joinedData.filter(d => d.species === s[0])[0].class,
value: s[1]
});
});
});
});
return out;
}
Insert cell
mutable debug = undefined
Insert cell
allsite = [...new Set(dataCleaned.map(d => d.site))]
Insert cell
allspecies = [...new Set(dataCleaned.map(d => d.species))]
Insert cell
filled = {
const out = [];
allsite.map(s => {
uniqDates.forEach(dd => {
let siteByDate = dataRolled.filter(d => d.site === s && +d.date === dd);
if (siteByDate.length === 0) {
allspecies.forEach(sp => {
out.push({
site: s,
date: new Date(dd),
species: sp,
total: 0,
group: familyGroupings.filter(
d => d["Common Name"].toLowerCase() === sp.toLowerCase()
)[0].Group
});
});
}
});
});

return out.concat(dataRolled); //combined filled and real data
}
Insert cell
Insert cell
Insert cell
dataCleaned = {
let out = [];
joinedData.forEach((row) => {
Object.keys(row).forEach(function (colname) {
// Ignore 'State' and 'Value' columns
if (
colname == "Sample" ||
colname == "lat" ||
colname == "lon" ||
colname == "year" ||
colname == "month" ||
colname == "day" ||
colname == "site" ||
colname == "monthly" ||
colname == "date"
) {
return;
}
let result = familyGroupings.filter(function (f) {
return f["Common Name"].toLowerCase() === colname.toLowerCase();
});
mutable debug = colname;
// mutable debug = colname;
// row.date = new Date(row.year, row.month - 1, row.day);
out.push({
species: colname,
group: result[0].Group,
value: row[colname],
lat: row.lat,
lon: row.lon,
site: row.site,
date: row.date,
monthly: row.monthly
});
});
});

return out;
}
Insert cell
dataRolled.filter(d => d.site === "Victoria" && d.species === "Pink salmon")
Insert cell
metadata.filter(function (sample) {
// console.log(sample.Sample_ID);
return sample.Sample_ID.toLowerCase() === "ICOE0002".toLowerCase();
})
Insert cell
realData.filter(function (sample) {
return sample.Sample === "ICOE0002";
})
Insert cell
realData
Insert cell
joinedData = {
let c = _.cloneDeep(realData);
c.forEach(function (individual) {
// console.log(individual);
var result = metadata.filter(function (sample) {
// console.log(sample);
return sample.Sample_ID.toLowerCase() === individual.Sample.toLowerCase();
});
// console.log(result, individual);
individual.lat = result[0] !== undefined ? Number(result[0].lat) : null;
individual.lon = result[0] !== undefined ? Number(result[0].long) : null;
individual.month = result[0] !== undefined ? Number(result[0].month) : null;
individual.day = result[0] !== undefined ? Number(result[0].day) : null;
individual.year = result[0] !== undefined ? Number(result[0].year) : null;
individual.date = new Date(
result[0].year,
result[0].month - 1,
result[0].day
);
individual.monthly = d3.timeMonth(new Date(individual.date));

individual.site = result[0] !== undefined ? result[0].site : null;
});

return c;
}
Insert cell
uniqClass = [...new Set(familyGroupings.map(d => d.Group))]
Insert cell
uniqClassOld = [...new Set(flatData.map(d => d.class))]
Insert cell
Insert cell
Insert cell
dataCleaned[0].date
Insert cell
groupedTallData = tidy(
dataCleaned,
mutate({
month: d => +d3.timeMonth(new Date(d.date))
}),
groupBy(
['site', 'month', 'species'],
[summarize({ total: sum('value') })],
groupBy.entriesObject({ single: true })
)
)
Insert cell
uniqDates = {
const out = [];
groupedTallData.forEach(d => {
d.values.forEach(v => {
// console.log(new Date(v.key));
out.push(new Date(v.key));

// const date = [...new Set(groupedTallData.map(v => v.values[0].key))];
// return date.map(d => new Date(d));
});
});
return [...new Set(out.map(d => +d))];
}
Insert cell
Insert cell
dataRolled = {
let newDat = [];
groupedTallData.forEach((d) => {
//add dates here

d.values.forEach((v) => {
// console.log(new Date(v.key));
v.values.forEach((vv) => {
let result = familyGroupings.filter(function (f) {
return f["Common Name"].toLowerCase() === vv.key.toLowerCase();
});

vv.values.total > 0 ? (d.count = 1) : (d.count = 0);

newDat.push({
site: d.key,
date: new Date(v.key),
// monthly: d3.timeMonth(new Date(v.key)),
species: vv.key,
group: result[0].Group,
total: vv.values.total,
count: d.count
});
});
});
});
return newDat;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
realData = d3.tsvParse(
await FileAttachment("OccurenceTable_Dec2022_transposed@1.txt").text(),
d3.autoType
)
Insert cell
d3.tsvParse(
await FileAttachment("OccurenceTable_Plates1-7 (1)@1.txt").text(),
d3.autoType
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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