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

Releasing variogram and bug fixes #236

Merged
merged 29 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2aec78d
Use new incomplete field in WSMessage for breaking up large messages
May 14, 2024
bbe9db1
Using new code gen, sending arrays of responses from each handler fun…
May 15, 2024
5611d4d
Merge pull request #225 from pixlise/bugfix/disconnections
pnemere May 15, 2024
9daa363
Revert "Using new code gen, sending arrays of responses from each han…
May 16, 2024
368f1f1
Use latest data-formats
May 21, 2024
92b095c
Merge pull request #226 from pixlise/bugfix/disconnections
pnemere May 22, 2024
d0cd06e
Fixing scan notifications - correctly identifies new vs updates, and …
May 23, 2024
2276395
Add all PMCs to auto-quant requests
May 23, 2024
e83be10
Fixing unit tests for importer (ignore time stamps which vary every run)
May 23, 2024
c4815b3
Fixing unit tests for importer (ignore time stamps which vary every run)
May 23, 2024
ee87c95
Merge pull request #227 from pixlise/bugfix/new-scan-notification
pnemere May 23, 2024
9f48a4b
Adds new variogram state data
RyanStonebraker May 23, 2024
614d024
Preserve title, description, tags for scans when regenerating
May 23, 2024
446b8c6
Merge pull request #228 from pixlise/bugfix/new-scan-notification
pnemere May 23, 2024
d3bccb1
Added message to trigger auto-quant for a scan
May 23, 2024
1ca146c
Merge branch 'development' into bugfix/new-scan-notification
May 23, 2024
3c1fe44
Merge pull request #229 from pixlise/bugfix/new-scan-notification
pnemere May 23, 2024
295ecee
Added message ids for scan trigger auto quant
May 24, 2024
2bec06d
Merge pull request #230 from pixlise/bugfix/new-scan-notification
pnemere May 24, 2024
8678c82
Use latest data formats to include new msg ids
May 24, 2024
c4e5050
Merge pull request #231 from pixlise/bugfix/new-scan-notification
pnemere May 24, 2024
b358a20
Fixing auto quant detector, making test fail error more specific
May 24, 2024
79afcd6
Merge pull request #232 from pixlise/bugfix/new-scan-notification
pnemere May 24, 2024
590d3b4
Set RunTimeSec on auto quants
May 24, 2024
a283c3c
Merge pull request #233 from pixlise/bugfix/new-scan-notification
pnemere May 24, 2024
875d346
Fixing elements sent for auto quant
May 24, 2024
402842c
Merge pull request #234 from pixlise/bugfix/new-scan-notification
pnemere May 24, 2024
0cfd34c
Iron ratio added to auto-quants
May 24, 2024
1f862a6
Merge pull request #235 from pixlise/bugfix/new-scan-notification
pnemere May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/dataimport/for-trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func printArchiveOKLogOutput(logger *logger.StdOutLoggerForTest, db *mongo.Datab
}
// Clear the time stamp so it doesn't change next time we run test
summary.TimestampUnixSec = 0
summary.CompleteTimeStampUnixSec = 0

b, err := protojson.Marshal(summary)
if err != nil {
Expand Down Expand Up @@ -390,6 +391,7 @@ func printManualOKLogOutput(log *logger.StdOutLoggerForTest, db *mongo.Database,
} else {
// Clear the time stamp so it doesn't change next time we run test
summary.TimestampUnixSec = 0
summary.CompleteTimeStampUnixSec = 0
}

b, err := protojson.Marshal(summary)
Expand Down
9 changes: 8 additions & 1 deletion api/dataimport/internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pixlise/core/v4/core/fileaccess"
"github.com/pixlise/core/v4/core/gdsfilename"
"github.com/pixlise/core/v4/core/logger"
"github.com/pixlise/core/v4/core/scan"
"github.com/pixlise/core/v4/core/utils"
protos "github.com/pixlise/core/v4/generated-protos"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -361,7 +362,13 @@ func (s *PIXLISEDataSaver) Save(
return fmt.Errorf("Failed to get dataset file size for: %v", outFilePath)
}

summaryData := makeSummaryFileContent(&exp, data.DatasetID, data.Instrument, data.Meta, int(fi.Size()), creationUnixTimeSec, data.CreatorUserId)
var prevSavedScan *protos.ScanItem
if prevSavedScan, err = scan.ReadScanItem(data.DatasetID, db); err != nil {
// NOTE: this is largely paranoia, in case ReadScanItem changes and returns errors even on read
prevSavedScan = nil
}

summaryData := makeSummaryFileContent(&exp, prevSavedScan, data.DatasetID, data.Instrument, data.Meta /*int(fi.Size()),*/, creationUnixTimeSec, data.CreatorUserId)

jobLog.Infof("Writing summary to DB for %v...", summaryData.Id)

Expand Down
59 changes: 48 additions & 11 deletions api/dataimport/internal/output/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import (

func makeSummaryFileContent(
exp *protos.Experiment,
prevSavedScan *protos.ScanItem,
datasetID string,
sourceInstrument protos.ScanInstrument,
meta dataConvertModels.FileMetaData,
fileSize int,
//fileSize int,
creationUnixTimeSec int64,
creatorUserId string) *protos.ScanItem {
contextImgCount := len(exp.AlignedContextImages) + len(exp.UnalignedContextImages) + len(exp.MatchedAlignedContextImages)
Expand Down Expand Up @@ -93,16 +94,52 @@ func makeSummaryFileContent(
// what it's displaying

s := &protos.ScanItem{
Id: datasetID,
Title: meta.Title,
Description: "",
DataTypes: dataTypes,
Instrument: sourceInstrument,
InstrumentConfig: exp.DetectorConfig,
TimestampUnixSec: uint32(creationUnixTimeSec),
Meta: saveMeta,
ContentCounts: contentCounts,
CreatorUserId: creatorUserId,
Id: datasetID,
Title: meta.Title,
Description: "",
DataTypes: dataTypes,
Instrument: sourceInstrument,
InstrumentConfig: exp.DetectorConfig,
TimestampUnixSec: uint32(creationUnixTimeSec),
Meta: saveMeta,
ContentCounts: contentCounts,
CreatorUserId: creatorUserId,
PreviousImportTimesUnixSec: []uint32{},
}

// If we've got a previously stored ScanItem, we are updating it, so read its time stamp into the array of previous time stamps
isComplete := exp.NormalSpectra == exp.PseudoIntensities*2

if prevSavedScan != nil {
// Build the list of previous import times
// Preserve the previous list...
s.PreviousImportTimesUnixSec = append(s.PreviousImportTimesUnixSec, prevSavedScan.PreviousImportTimesUnixSec...)

// Add new time at the end
s.PreviousImportTimesUnixSec = append(s.PreviousImportTimesUnixSec, prevSavedScan.TimestampUnixSec)
}

// Save a time stamp for completion
if isComplete {
// If previous scan was also complete, DON'T update the time stamp, just preserve it
if prevSavedScan != nil && prevSavedScan.CompleteTimeStampUnixSec > 0 {
s.CompleteTimeStampUnixSec = prevSavedScan.CompleteTimeStampUnixSec
} else {
// We must've just completed now, so save the time
s.CompleteTimeStampUnixSec = uint32(creationUnixTimeSec)
}
}

// Preserve user-editable fields
if prevSavedScan != nil {
s.Tags = prevSavedScan.Tags
s.Description = prevSavedScan.Description

if len(prevSavedScan.Description) > 0 {
// User has entered a description so perserve the title too
s.Title = prevSavedScan.Title
}
}

return s
}
39 changes: 32 additions & 7 deletions api/quantification/autoQuantification.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package quantification
import (
"context"
"fmt"
"strconv"

"github.com/pixlise/core/v4/api/dbCollections"
"github.com/pixlise/core/v4/api/services"
"github.com/pixlise/core/v4/api/specialUserIds"
"github.com/pixlise/core/v4/api/ws/wsHelpers"
protos "github.com/pixlise/core/v4/generated-protos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -23,11 +25,14 @@ func RunAutoQuantifications(scanId string, svcs *services.APIServices) {
quantNames := []string{"AutoQuant-PDS", "AutoQuant-PIXL"}
quantModes := []string{quantModeCombinedAB, quantModeSeparateAB}
quantElements := [][]string{
// PDS
[]string{"Na2O", "MgO", "Al2O3", "SiO2", "P2O5", "SO3", "Cl", "K2O", "CaO", "TiO2", "Cr2O3", "MnO", "FeO-T", "NiO", "ZnO", "Br"},
[]string{"Na2O", "MgO", "Al2O3", "SiO2", "P2O5", "SO3", "Cl", "K2O", "CaO", "TiO2", "Cr2O3", "MnO", "FeO-T", "NiO", "ZnO", "GeO", "Br", "Rb2O", "SrO", "Y2O3", "ZrO2"},
// PDS: intended "Na2O", "MgO", "Al2O3", "SiO2", "P2O5", "SO3", "Cl", "K2O", "CaO", "TiO2", "Cr2O3", "MnO", "FeO-T", "NiO", "ZnO", "Br"
// But we must specify elements only! Expecting PIQUANT to determine the oxide states to write
[]string{"Na", "Mg", "Al", "Si", "P", "S", "Cl", "K", "Ca", "Ti", "Cr", "Mn", "Fe", "Ni", "Zn", "Br"},
// PIXL: intended "Na2O", "MgO", "Al2O3", "SiO2", "P2O5", "SO3", "Cl", "K2O", "CaO", "TiO2", "Cr2O3", "MnO", "FeO-T", "NiO", "ZnO", "GeO", "Br", "Rb2O", "SrO", "Y2O3", "ZrO2"
// But we must specify elements only! Expecting PIQUANT to determine the oxide states to write
[]string{"Na", "Mg", "Al", "Si", "P", "S", "Cl", "K", "Ca", "Ti", "Cr", "Mn", "Fe", "Ni", "Zn", "Ge", "Br", "Rb", "Sr", "Y", "Zr"},
}
detector := "PIXL/v7"
detector := "PIXL/PiquantConfigs/v7"

allNames := []string{}
for _, name := range quantNames {
Expand All @@ -52,18 +57,38 @@ func RunAutoQuantifications(scanId string, svcs *services.APIServices) {
return
}

exprPB, err := wsHelpers.ReadDatasetFile(scanId, svcs)
if err != nil {
svcs.Log.Errorf("AutoQuant failed to read scan %v to determine PMC list: %v", scanId, err)
return
}

pmcs := []int32{}
for _, loc := range exprPB.Locations {
pmc, err := strconv.Atoi(loc.Id)
if err != nil {
svcs.Log.Errorf("AutoQuant: Failed to read PMC %v from scan %v. Skipping...", loc.Id, scanId)
continue
}

if len(loc.PseudoIntensities) > 0 && len(loc.PseudoIntensities[0].ElementIntensities) > 0 {
// We have quantifiable data for this
pmcs = append(pmcs, int32(pmc))
}
}

// Start all the quants
for c, name := range quantNames {
for _, m := range quantModes {
params := &protos.QuantCreateParams{
Command: "map",
Name: makeAutoQuantName(name, m),
ScanId: scanId,
Pmcs: []int32{},
Pmcs: pmcs,
Elements: quantElements[c],
DetectorConfig: detector,
Parameters: "",
RunTimeSec: 0,
Parameters: "-Fe,1",
RunTimeSec: 300,
QuantMode: m,
RoiIDs: []string{},
IncludeDwells: false,
Expand Down
11 changes: 11 additions & 0 deletions api/ws/handlers/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pixlise/core/v4/api/dbCollections"
"github.com/pixlise/core/v4/api/filepaths"
"github.com/pixlise/core/v4/api/job"
"github.com/pixlise/core/v4/api/quantification"
"github.com/pixlise/core/v4/api/services"
"github.com/pixlise/core/v4/api/ws/wsHelpers"
"github.com/pixlise/core/v4/core/errorwithstatus"
Expand Down Expand Up @@ -708,3 +709,13 @@ func HandleScanAutoShareWriteReq(req *protos.ScanAutoShareWriteReq, hctx wsHelpe

return &protos.ScanAutoShareWriteResp{}, nil
}

func HandleScanTriggerAutoQuantReq(req *protos.ScanTriggerAutoQuantReq, hctx wsHelpers.HandlerContext) (*protos.ScanTriggerAutoQuantResp, error) {
if err := wsHelpers.CheckStringField(&req.ScanId, "ScanId", 1, wsHelpers.IdFieldMaxLength); err != nil {
return nil, err
}

quantification.RunAutoQuantifications(req.ScanId, hctx.Svcs)

return &protos.ScanTriggerAutoQuantResp{}, nil
}
2 changes: 1 addition & 1 deletion api/ws/handlers/selection-entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func writeSelection(id string, idxs *protos.ScanEntryRange, db *mongo.Database,
}

// Modified and Upsert counts will be 0 if the selection hasn't changed, so we just check matched
if dbResult.MatchedCount != 1 {
if dbResult.MatchedCount != 1 && dbResult.UpsertedCount != 1 {
logger.Errorf("writeSelection (%v) UpdateByID result had unexpected counts %+v", id, dbResult)
}

Expand Down
4 changes: 2 additions & 2 deletions generated-protos/detector-config-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/detector-config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/diffraction-data.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/diffraction-detected-peak-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/diffraction-manual-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/diffraction-status-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/diffraction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/doi-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/doi.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/element-set-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/element-set.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/experiment.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/export-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/export.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/expression-group-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/expression-group.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated-protos/expression-msgs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading