Skip to content

Commit 2499c96

Browse files
committed
Correct CEFAS data for min / max depths
1 parent 0eb96f4 commit 2499c96

7 files changed

Lines changed: 93 additions & 25 deletions

File tree

SedimentDataExplorer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
<div id="everything" style="display: none;"></div>
533533

534534
<header>
535-
<h1>Sediment Data Explorer <small style="font-weight: normal; opacity: 0.8;">v0.20250811</small></h1>
535+
<h1>Sediment Data Explorer <small style="font-weight: normal; opacity: 0.8;">v0.20250919</small></h1>
536536
<div class="header-actions">
537537
<button onclick="updateChart()">(Re)Plot Chart</button>
538538
<button onclick="exportCharts()" class="secondary">Export Chart</button>

SedimentDataExplorer.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,10 @@ fred = df;
11391139
//fred = sampleMeasurements[dateSampled]['Physical Data'].samples[allSamples[0]];
11401140
// if (!sampleMeasurements[dateSampled]['Physical Data'].samples[allSamples[0]]['Total solids (% total sediment)']) {
11411141
// if (sampleMeasurements[dateSampled]['Physical Data'].samples[allSamples[0]]['Total solids (% total sediment)'] === undefined) {
1142-
console.log('New test: No total solids',dateSampled, sheetName);
1142+
console.log('New test: No total solids',dateSampled, sheetName, allSamples[0]);
1143+
//console.log(sampleMeasurements[dateSampled]['Physical Data'].samples[allSamples[0]]);
11431144
// Code that reads Total Solids column into physical data
1144-
if (!('Total solids (% total sediment)' in sampleMeasurements[dateSampled]['Physical Data'].samples[allSamples[0]])) {
1145+
if (!(sampleMeasurements[dateSampled]?.['Physical Data']?.samples?.[allSamples[0]]?.['Total solids (% total sediment)'])) {
11451146
col = startCol + 3;
11461147
row = startRow - 2;
11471148
console.log('col ',col,' row ',row, df[row][col]);
@@ -1173,7 +1174,12 @@ let missingTotalSolids = true;
11731174
}
11741175
if (!missingTotalSolids) {
11751176
for (let sample in ts) {
1176-
if (!(sampleMeasurements[dateSampled]['Physical Data'].samples[sample] === undefined)) {
1177+
// if (!(sampleMeasurements[dateSampled]['Physical Data'].samples[sample] === undefined)) {
1178+
if (!sampleMeasurements[dateSampled]?.['Physical Data']) {
1179+
sampleMeasurements[dateSampled]['Physical Data'] = {};
1180+
sampleMeasurements[dateSampled]['Physical Data'].samples = {};
1181+
}
1182+
if (sampleMeasurements[dateSampled]?.['Physical Data']?.samples[sample]) {
11771183
sampleMeasurements[dateSampled]['Physical Data'].samples[sample]['Total solids (% total sediment)'] = ts[sample];
11781184
if (!(ts[sample] === undefined)) {
11791185
missingTotalSolids = false;

sdeCalcs4Charts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ function dataForTotalScatterCharting(sheetName, chartType) {
477477
y: currentChemical.samples[s],
478478
label: selectedSampleInfo[ds].label + ': ' + selectedSampleInfo[ds].position[s].label,
479479
};
480+
console.log(xValue);
480481
ii += 1;
481482
if (!xValue) {
482483
// reverted to 250502 version of test not sure why? if (!(typeof xValue === "number")) {

sdeCharts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,9 +2641,9 @@ function pcaChart(selectMeas, sheetName, chemicalNames, instanceNo) {
26412641
}
26422642
const setName = parts.length > 1 ? parts[0].trim() : "Unknown Set";
26432643
const sampleName = parts[1];
2644-
console.log(`Sample "${fullSampleName}" parsed as set "${setName}", sample "${sampleName}".`);
2645-
console.log('selectedSampleInfo', selectedSampleInfo[setName].label);
2646-
console.log('selectedSampleInfo position', selectedSampleInfo[setName].position[sampleName].label);
2644+
// console.log(`Sample "${fullSampleName}" parsed as set "${setName}", sample "${sampleName}".`);
2645+
// console.log('selectedSampleInfo', selectedSampleInfo[setName].label);
2646+
// console.log('selectedSampleInfo position', selectedSampleInfo[setName].position[sampleName].label);
26472647
const labelSampleName = selectedSampleInfo[setName].label + ': ' + selectedSampleInfo[setName].position[sampleName].label;
26482648
// const sampleName = parts.length > 2 ? parts.slice(1).join(':').trim() : fullSampleName.trim();
26492649

sdeDredgeData.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ ddLookup.sheet = {'pcb101' : "PCB data" , 'pcb105' : "PCB data" , 'pcb110' : "PC
4747
'pcb66' : "PCB data" , 'acenapth' : "PAH data" , 'acenapthylene' : "PAH data" , 'anthracn' : "PAH data" , 'baa' : "PAH data" , 'bap' : "PAH data" ,
4848
'bbf' : "PAH data" , 'benzghip' : "PAH data" , 'bep' : "PAH data" , 'bkf' : "PAH data" , 'c1n' : "PAH data" , 'c1phen' : "PAH data" , 'c2n' : "PAH data" ,
4949
'c3n' : "PAH data" , 'chrysene' : "PAH data" , 'dibenzah' : "PAH data" , 'flurant' : "PAH data" , 'fluorene' : "PAH data" , 'indypr' : "PAH data" ,
50-
'napth' : "PAH data" , 'perylene' : "PAH data" , 'phenant' : "PAH data" , 'pyrene' : "PAH data" , 'thc' : "PAH data" , 'ahch' : "Organochlorine data" ,
50+
'napth' : "PAH data" , 'perylene' : "PAH data" , 'phenant' : "PAH data" , 'pyrene' : "PAH data" , //'thc' : "PAH data" ,
51+
'ahch' : "Organochlorine data" ,
5152
'bhch' : "Organochlorine data" , 'ghch' : "Organochlorine data" , 'dieldrin' : "Organochlorine data" , 'hcb' : "Organochlorine data" ,
5253
'dde' : "Organochlorine data" , 'ddt' : "Organochlorine data" , 'tde' : "Organochlorine data" , 'bde100' : "BDE data" , 'bde138' : "BDE data" ,
5354
'bde153' : "BDE data" , 'bde154' : "BDE data" , 'bde17' : "BDE data" , 'bde183' : "BDE data" , 'bde28' : "BDE data" , 'bde47' : "BDE data" ,
@@ -234,6 +235,7 @@ function processDDExcelData(data, url, mlaInput) {
234235
// dateAnalysed = extractDataFromSheet();
235236
selectedSampleInfo = sampleInfo;
236237
selectedSampleMeasurements = sampleMeasurements;
238+
postLoadSnapShot();
237239
updateChart();
238240
}
239241

@@ -274,10 +276,14 @@ function extractDataFromSheet(sheetData, mlApplication) {
274276
sampleInfo[dateSampled].position = {};
275277
sampleInfo[dateSampled].label = dateSampled;
276278
uniqueRows.forEach(row => {
279+
let correctedDepth = parseFloat(row[CEFASdepth]);
280+
if (correctedDepth < 0) {
281+
correctedDepth = 0;
282+
}
277283
sampleInfo[dateSampled].position[row[CEFASsamplename]] = {
278-
'Position latitude': row[CEFASlatitude],
279-
'Position longitude': row[CEFASlongitude],
280-
'Sampling depth (m)': row[CEFASdepth],
284+
'Position latitude': parseFloat(row[CEFASlatitude]),
285+
'Position longitude': parseFloat(row[CEFASlongitude]),
286+
'Sampling depth (m)': { minDepth:correctedDepth, maxDepth:correctedDepth},
281287
'label': row[CEFASsamplename],
282288
};
283289
});
@@ -335,7 +341,7 @@ function extractDataFromSheet(sheetData, mlApplication) {
335341
});
336342
for (const sheetName in meas) {
337343
meas[sheetName]['Unit of measurement'] = CEFASMeasurementUnit[sheetName];
338-
// Fill in 0 for missing positions
344+
/*SRG250920 // Fill in 0 for missing positions
339345
// for (const chemical in determinands[sheetName]) {
340346
for (let i = 0; i < determinands[sheetName].length; i++) {
341347
const chemical = determinands[sheetName][i];
@@ -346,8 +352,8 @@ function extractDataFromSheet(sheetData, mlApplication) {
346352
/* if(!(meas[sheetName].chemicals[chemical].samples[sample])) {
347353
meas[sheetName].chemicals[chemical].samples[sample] = 0;
348354
}*/
349-
}
350-
}
355+
// }
356+
// }
351357
}
352358
sampleMeasurements[dateSampled] = meas;
353359
for (const sheetName in meas) {
@@ -388,16 +394,16 @@ function closeCEFASSearch(centreLat,centreLon,radius,startDate,finishDate) {
388394
}
389395
mlas = [];
390396
uniqueRows = CEFASUniqueRows;
391-
//console.log(uniqueRows);
397+
console.log(uniqueRows);
392398
uniqueRows.forEach(row => {
393399
samplingDate = new Date(parseDates(row[CEFASsampledate])[0]);
394400
sampleLat = row[CEFASlatitude];
395401
sampleLon = row[CEFASlongitude];
396402
distance = 1000 * haversineDistance(sampleLat, sampleLon, centreLat, centreLon);
397403
if (distance <= radius) {
398-
//console.log(startDate);
404+
console.log(startDate);
399405
if(startDate.toString() === 'Invalid Date' || finishDate.toString() === 'Invalid Date'){
400-
//console.log('Pushing Invalid Date');
406+
console.log('Pushing Invalid Date');
401407
mlas.push(row[CEFASmla]);
402408
} else {
403409
if (isBetweenDates(startDate,finishDate,samplingDate)){
@@ -406,16 +412,24 @@ function closeCEFASSearch(centreLat,centreLon,radius,startDate,finishDate) {
406412
}
407413
}
408414
});
415+
// let mlaReturn = document.getElementById('mlApplications');
416+
// let mlaInput = mlaReturn.value;
417+
//console.log(mlaInput);
418+
// if (!(mlaInput === undefined || mlaInput === null)) {
419+
// let mlas = mlaInput.trim().split(',').map(mla => mla.trim()); // Split comma-separated URLs
409420
console.log(mlas);
410-
if (mlas.length > 0) {
411-
mlas.forEach(mlApplication => {
421+
if (mlas.length > 0) {
422+
mlas.forEach(mlApplication => {
412423
//console.log(mlApplication);
413424
extractDataFromSheet(CEFASdata, mlApplication);
414425
});
426+
}
427+
//}
415428
selectedSampleInfo = sampleInfo;
416429
selectedSampleMeasurements = sampleMeasurements;
430+
postLoadSnapShot();
417431
updateChart();
418-
}
432+
419433
}
420434

421435
function sedDredgeDataDisplay(noMLAs,noDatasets) {

sdeMaps.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ const openSensorCommunityTiles = L.tileLayer('https://osmc3.maps.sensor.communit
5454

5555
//function createGlobalLayers(selectedSampleMeasurements, selectedSampleInfo) {
5656
function createGlobalLayers() {
57+
console.log('Creating global layers...');
5758
if (allMapData.isReady) {
5859
console.log("Layers already generated. Skipping regeneration.");
5960
return;
6061
}
61-
62+
console.log(selectedSampleMeasurements, selectedSampleInfo);
6263
let allSamples = [];
6364
let sampleNo = -1;
6465

@@ -75,7 +76,7 @@ function createGlobalLayers() {
7576
let colorIndex = 0;
7677
let noSamples = 0;
7778
const datesSampled = Object.keys(selectedSampleInfo);
78-
79+
console.log(datesSampled);
7980
datesSampled.forEach(dateSampled => {
8081
markers[dateSampled] = {};
8182
dateColors[dateSampled] = markerColors[colorIndex];
@@ -85,11 +86,15 @@ function createGlobalLayers() {
8586
dsSamples.forEach(sample => allSamples.push(`${dateSampled}: ${sample}`));
8687
});
8788

89+
if(datesSampled.length > 1) {
8890
datesSampled.sort((a, b) => {
8991
const labelA = selectedSampleInfo[a].label || a;
9092
const labelB = selectedSampleInfo[b].label || b;
9193
return labelA.localeCompare(labelB);
9294
});
95+
}
96+
console.log(datesSampled);
97+
console.log(noSamples, allSamples);
9398

9499
let sampleDepths = {};
95100
let depthStatsGlobal = { min: Infinity, max: -Infinity };
@@ -108,7 +113,7 @@ function createGlobalLayers() {
108113
}
109114
});
110115
});
111-
116+
console.log(sampleDepths, depthStatsGlobal);
112117
function computeContaminationStats(measurements, sampleInfo) {
113118
const statsByChem = {};
114119
Object.keys(measurements).forEach(datasetName => {
@@ -1546,6 +1551,8 @@ function sampleMap(meas) {
15461551
map.fitBounds(bounds);
15471552
}
15481553

1554+
console.log("Map created", noLocations, noSamples);
1555+
15491556
//DUPLICATE from sampleMap
15501557
function applyDynamicStyling(chemicalName) {
15511558
const stats = contaminantStats[chemicalName];

sdeSelections.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,13 @@ console.log('sheetName',sheetName,dataSheetNamesCheckboxes[i]);
467467
}
468468
const checkboxes = document.querySelectorAll('#sampleCheckboxes input[type="checkbox"]');
469469
const checkboxesIn = document.querySelectorAll('input[name="sample"]:checked');
470+
//console.log(checkboxes,checkboxesIn);
471+
//console.log(Object.keys(checkboxes));
472+
let checkboxesNames = [];
473+
for (let i = 0; i < checkboxes.length; i++) {
474+
checkboxesNames[i] = checkboxes[i].value;
475+
}
476+
console.log(checkboxes.value);
470477
if (selectBySheet) {
471478
index = 0;
472479
samplesToKeep = {};
@@ -613,7 +620,7 @@ console.log('sheetName',sheetName,dataSheetNamesCheckboxes[i]);
613620
}
614621
}
615622
// going to find sample with specific measurements
616-
for (const dateSelected in selectedSampleMeasurements) {
623+
/* for (const dateSelected in selectedSampleMeasurements) {
617624
for (const sheetName in selectedSampleMeasurements[dateSelected]) {
618625
const mustChemicalType = document.getElementById((sheetName + 'sample').replace(/\s/g, '').toLowerCase()).checked;
619626
if (mustChemicalType) {
@@ -630,8 +637,41 @@ console.log(dateSelected,sheetName,chemical,sample,conc);
630637
}
631638
}
632639
}
640+
}*/
641+
for (let i = 0; i < dataSheetNames.length; i++) {
642+
sheetName = dataSheetNames[i];
643+
const mustChemicalType = document.getElementById((sheetName + 'sample').replace(/\s/g, '').toLowerCase()).checked;
644+
if(mustChemicalType) {
645+
for (let j = 0; j < checkboxesNames.length; j++) {
646+
let parts = checkboxesNames[j].split(": ");
647+
if (parts.length > 2) parts[1] = parts[1] + ': ' + parts[2];
648+
const dateSampled = parts[0];
649+
const sample = parts[1];
650+
const checkName = `sample_${dateSampled + ': ' + sample}`;
651+
const checkbox = document.getElementById(checkName);
652+
if (!(sheetName in selectedSampleMeasurements[dateSampled])) {
653+
checkbox.checked = false;
654+
} else {
655+
// Assume no chemicals are present for this sample
656+
checkbox.checked = false;
657+
for (const chemical in selectedSampleMeasurements[dateSampled][sheetName].chemicals) {
658+
const conc = selectedSampleMeasurements[dateSampled][sheetName].chemicals[chemical].samples[sample];
659+
// console.log(dateSampled,sheetName,chemical,sample,conc);
660+
/* if (conc === null || conc == undefined) {
661+
const checkName = `sample_${dateSampled + ': ' + sample}`;
662+
const checkbox = document.getElementById(checkName);
663+
checkbox.checked = false;
664+
}*/
665+
// If any chemical has a concentration > 0 then keep the sample
666+
if (conc > 0) {
667+
checkbox.checked = true;
668+
break;
669+
}
670+
}
671+
}
672+
}
673+
}
633674
}
634-
635675
}
636676

637677
function haversineDistance(lat1, lon1, lat2, lon2) {

0 commit comments

Comments
 (0)