Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions Sources/FormatoDM/DM4Experiment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ public nonisolated struct DM4ImageObject: Sendable, Equatable {
public let dataByteCount: Int

package var dataTypeName: String { DM4Experiment.dataTypeName(dataType) }
/// Saturates at `Int.max` rather than trapping on absurd tag dimensions.
package var elementCount: Int {
dimensions.reduce(1) { acc, d in
let (p, o) = acc.multipliedReportingOverflow(by: d)
return o ? Int.max : p
}
}
}

/// A decoded 2D image object.
Expand Down
6 changes: 2 additions & 4 deletions Sources/FormatoEMD/VeloxEMDReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ public nonisolated struct VeloxEMDReader: Sendable {
}

let image = try Self.readScanImage(
file: file, shapes: imageShapes, grid: grid, range: range, preferredDetector: metadata.binaryResultDetector,
cancelled: cancelled)
file: file, shapes: imageShapes, grid: grid, range: range, cancelled: cancelled)
tracker.finish()
return VeloxSpectrumImage(
eventStore: store, scanImage: image, metadata: metadata, version: version.version,
Expand Down Expand Up @@ -707,8 +706,7 @@ public nonisolated struct VeloxEMDReader: Sendable {
/// integer image; summed over the same frame range, clipped to the frames the image has.
private static func readScanImage(
file: VeloxFile, shapes: [(name: String, ny: Int, nx: Int, frames: Int, isInteger: Bool)],
grid: (ny: Int, nx: Int), range: Range<Int>, preferredDetector: String?,
cancelled: @Sendable () -> Bool
grid: (ny: Int, nx: Int), range: Range<Int>, cancelled: @Sendable () -> Bool
) throws -> VeloxScanImage? {
let onGrid = shapes.filter { $0.ny == grid.ny && $0.nx == grid.nx && $0.isInteger }
guard !onGrid.isEmpty else { return nil }
Expand Down
3 changes: 0 additions & 3 deletions Sources/FormatoEMD/VeloxEventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public nonisolated struct VeloxEventStore: Sendable {
/// inside the frame range (prediction P4).
public var totalCounts: Int { counts.reduce(0) { $0 + Int($1) } }
package var distinctEntries: Int { channelIndex.count }
package var storageBytes: Int {
rowOffsets.count * MemoryLayout<Int>.stride + channelIndex.count * 2 + counts.count * 4
}

/// Frames of dose that `pixel` received.
public func framesCovering(pixel: Int) -> Int {
Expand Down
1 change: 0 additions & 1 deletion Sources/FormatoEMD/VeloxMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//

import Foundation
import FormatoCore

// MARK: - Metadata

Expand Down
2 changes: 0 additions & 2 deletions Sources/FormatoEMD/VeloxSpectrumSignals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ public nonisolated struct VeloxSpectrumSignals: Sendable {
}

private nonisolated struct VeloxSpectrumRead {
let path: String
let zone: TimeZone?
let policy: VeloxReadPolicy
let cancelled: @Sendable () -> Bool
let file: VeloxFile
let fileName: String

init(path: String, zone: TimeZone?, policy: VeloxReadPolicy, cancelled: @escaping @Sendable () -> Bool) throws {
self.path = path
self.zone = zone
self.policy = policy
self.cancelled = cancelled
Expand Down
1 change: 0 additions & 1 deletion Sources/FormatoEMD/VeloxTitles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import Foundation
import FormatoCore
import FormatoHDF5

/// The title of each image of a Velox file, and where it came from.
nonisolated struct VeloxTitles: Sendable {
Expand Down
10 changes: 5 additions & 5 deletions Sources/FormatoHDF5/BraggVectorsEMD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ private nonisolated struct EMDWriter {
guard withUnsafePointer(to: &v, { h5.h5awrite(attribute, h5.int64, $0) }) >= 0 else { throw fail("writing attribute \(name)") }
}

/// Creates a scalar dataset, writes `bytes` from memory type `memory`, and tags it with py4DSTEM's `type` attribute.
private func scalarDataset(_ name: String, fileType: hid_t, memory: hid_t, tag: String?, in parent: hid_t,
/// Creates a scalar dataset, lets `write` fill it, and tags it with py4DSTEM's `type` attribute.
private func scalarDataset(_ name: String, fileType: hid_t, tag: String?, in parent: hid_t,
write: (hid_t) -> herr_t) throws {
let space = h5.h5screate(h5Scalar); guard space >= 0 else { throw fail("dataset \(name)") }
defer { _ = h5.h5sclose(space) }
Expand All @@ -488,7 +488,7 @@ private nonisolated struct EMDWriter {

private func doubleDataset(_ name: String, _ value: Double, in parent: hid_t) throws {
var v = value
try scalarDataset(name, fileType: h5.float64, memory: h5.float64, tag: "number", in: parent) { ds in
try scalarDataset(name, fileType: h5.float64, tag: "number", in: parent) { ds in
withUnsafePointer(to: &v) { h5.h5dwrite(ds, h5.float64, h5EntireSpace, h5EntireSpace, h5Default, $0) }
}
}
Expand All @@ -501,15 +501,15 @@ private nonisolated struct EMDWriter {
guard "FALSE".withCString({ h5.h5tenumInsert(type, $0, &f) }) >= 0,
"TRUE".withCString({ h5.h5tenumInsert(type, $0, &t) }) >= 0 else { throw fail("defining the bool type") }
var v: Int8 = value ? 1 : 0
try scalarDataset(name, fileType: type, memory: type, tag: "bool", in: parent) { ds in
try scalarDataset(name, fileType: type, tag: "bool", in: parent) { ds in
withUnsafePointer(to: &v) { h5.h5dwrite(ds, type, h5EntireSpace, h5EntireSpace, h5Default, $0) }
}
}

/// py4DSTEM stores its strings as variable-length ASCII; units and paths stay ASCII-typed for it.
private func stringDataset(_ name: String, _ value: String, type tag: String?, in parent: hid_t) throws {
let type = try stringType(utf8: false); defer { _ = h5.h5tclose(type) }
try scalarDataset(name, fileType: type, memory: type, tag: tag, in: parent) { ds in
try scalarDataset(name, fileType: type, tag: tag, in: parent) { ds in
value.withCString { characters -> herr_t in
var pointer: UnsafePointer<CChar>? = characters
return withUnsafePointer(to: &pointer) { h5.h5dwrite(ds, type, h5EntireSpace, h5EntireSpace, h5Default, $0) }
Expand Down
18 changes: 9 additions & 9 deletions Sources/FormatoHDF5/HDF5AppendWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public nonisolated final class HDF5WriteSession {
/// object anywhere along the path throws `wrongKind`.
public func createGroup(_ path: String) throws {
let parts = try HDF5Ops.components(path)
try open { try makeGroups(parts, $0, path) }
try open { try makeGroups(parts, $0) }
}

/// Writes `array` as a new dataset at `path` (missing groups above it are created), stored in the array's own type and
Expand Down Expand Up @@ -196,15 +196,15 @@ public nonisolated final class HDF5WriteSession {
}
guard shape.count <= HDF5Ops.maximumRank else { throw HDF5FileError.limitExceeded("rank \(shape.count)") }
try open { file in
try checkParents(Array(parts.dropLast()), file, path)
try checkParents(Array(parts.dropLast()), file)
if HDF5Ops.linkExists(h5, file, parts) {
guard replace else { throw HDF5FileError.alreadyExists(path) }
guard HDF5Ops.kind(h5, file, parts) != .group else { throw HDF5FileError.alreadyExists("\(path) (a group; use deleteLink)") }
guard HDF5Ops.absolute(parts).withCString({ h5.h5ldelete(file, $0, 0) }) >= 0 else {
throw HDF5RootAttributes.failure("unlinking \(path)", h5)
}
}
try makeGroups(Array(parts.dropLast()), file, path)
try makeGroups(Array(parts.dropLast()), file)
let dims = shape.map(UInt64.init)
let space = dims.isEmpty ? h5.h5screate(0) : h5.h5screateSimple(Int32(dims.count), dims, nil)
guard space >= 0 else { throw HDF5RootAttributes.failure("making the space of \(path)", h5) }
Expand Down Expand Up @@ -404,7 +404,7 @@ public nonisolated final class HDF5WriteSession {
let other = try HDF5RootAttributes.openForReading(source, h5)
defer { _ = h5.h5fclose(other) }
guard HDF5Ops.linkExists(h5, other, sourceParts) else { throw HDF5FileError.notFound(sourcePath) }
try makeGroups(Array(parts.dropLast()), file, path)
try makeGroups(Array(parts.dropLast()), file)
if HDF5Ops.linkExists(h5, file, parts) {
guard replace else { throw HDF5FileError.alreadyExists(path) }
guard HDF5Ops.absolute(parts).withCString({ h5.h5ldelete(file, $0, 0) }) >= 0 else {
Expand All @@ -421,7 +421,7 @@ public nonisolated final class HDF5WriteSession {
// MARK: Internals (all under open)

/// Throws `wrongKind` when a component of `parts` that exists is not a group.
private func checkParents(_ parts: [String], _ file: hid_t, _ path: String) throws {
private func checkParents(_ parts: [String], _ file: hid_t) throws {
guard !parts.isEmpty else { return }
for count in 1...parts.count {
let prefix = Array(parts.prefix(count))
Expand All @@ -432,9 +432,9 @@ public nonisolated final class HDF5WriteSession {
}
}

private func makeGroups(_ parts: [String], _ file: hid_t, _ path: String) throws {
private func makeGroups(_ parts: [String], _ file: hid_t) throws {
guard !parts.isEmpty else { return }
try checkParents(parts, file, path)
try checkParents(parts, file)
for count in 1...parts.count {
let prefix = Array(parts.prefix(count))
if HDF5Ops.linkExists(h5, file, prefix) { continue }
Expand All @@ -457,15 +457,15 @@ public nonisolated final class HDF5WriteSession {

/// The checks and unlinking shared by the scalar dataset writers (all under `open`).
private func prepareScalar(_ parts: [String], _ file: hid_t, _ path: String, replace: Bool) throws {
try checkParents(Array(parts.dropLast()), file, path)
try checkParents(Array(parts.dropLast()), file)
if HDF5Ops.linkExists(h5, file, parts) {
guard replace else { throw HDF5FileError.alreadyExists(path) }
guard HDF5Ops.kind(h5, file, parts) != .group else { throw HDF5FileError.alreadyExists("\(path) (a group; use deleteLink)") }
guard HDF5Ops.absolute(parts).withCString({ h5.h5ldelete(file, $0, 0) }) >= 0 else {
throw HDF5RootAttributes.failure("unlinking \(path)", h5)
}
}
try makeGroups(Array(parts.dropLast()), file, path)
try makeGroups(Array(parts.dropLast()), file)
}

private func createScalar(_ parts: [String], _ file: hid_t, _ path: String, type: hid_t,
Expand Down
1 change: 0 additions & 1 deletion Tests/FormatoEMDTests/VeloxMetadataBoundTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Testing
import Foundation
import FormatoCore
import FormatoEMD
import FormatoHDF5

extension VeloxEMDSerialized {
/// A Velox file's metadata row count comes out of the file; a corrupt or hostile one must be refused before it is allocated.
Expand Down
1 change: 0 additions & 1 deletion Tests/FormatoEMDTests/VeloxMetadataFieldsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import Foundation
import Testing
import FormatoCore
import FormatoEMD
import FormatoHDF5

extension VeloxEMDSerialized {
@Suite(.serialized) struct VeloxMetadataFieldsTests {
Expand Down
1 change: 0 additions & 1 deletion Tests/FormatoHDF5Tests/WriteLockAfterCloseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Darwin
import Foundation
import Synchronization
import Testing
import FormatoCore
import FormatoHDF5

@Suite struct WriteLockAfterCloseTests {
Expand Down
1 change: 0 additions & 1 deletion Tests/FormatoTIFFTests/TIFFSeriesRefusalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import Foundation
import Testing
import FormatoCore
@testable import FormatoTIFF

@Suite struct TIFFSeriesRefusalTests {
Expand Down
Loading