19
19
import java .nio .file .Path ;
20
20
import java .nio .file .Paths ;
21
21
import java .util .ArrayList ;
22
- import java .util .Collections ;
23
22
import java .util .Comparator ;
24
23
import java .util .HashMap ;
25
24
import java .util .List ;
56
55
import loci .formats .ome .OMEXMLMetadata ;
57
56
import loci .formats .services .OMEXMLService ;
58
57
import loci .formats .services .OMEXMLServiceImpl ;
58
+ import ome .units .quantity .Quantity ;
59
59
import ome .xml .meta .OMEXMLMetadataRoot ;
60
60
import ome .xml .model .enums .DimensionOrder ;
61
61
import ome .xml .model .enums .EnumerationException ;
@@ -1506,33 +1506,63 @@ private void setSeriesLevelMetadata(int series, int resolutions)
1506
1506
multiscale .put ("metadata" , metadata );
1507
1507
multiscale .put ("version" , nested ? "0.2" : "0.1" );
1508
1508
multiscales .add (multiscale );
1509
- List <Map <String , String >> datasets = new ArrayList <Map <String , String >>();
1509
+
1510
+ IFormatReader v = null ;
1511
+ IMetadata meta = null ;
1512
+ String axisOrder = null ;
1513
+ try {
1514
+ v = readers .take ();
1515
+ meta = (IMetadata ) v .getMetadataStore ();
1516
+
1517
+ if (dimensionOrder != null ) {
1518
+ axisOrder = dimensionOrder .toString ();
1519
+ }
1520
+ else {
1521
+ axisOrder = v .getDimensionOrder ();
1522
+ }
1523
+ }
1524
+ finally {
1525
+ readers .put (v );
1526
+ }
1527
+
1528
+ List <Map <String , Object >> datasets = new ArrayList <Map <String , Object >>();
1510
1529
for (int r = 0 ; r < resolutions ; r ++) {
1511
1530
resolutionString = String .format (
1512
1531
scaleFormatString , getScaleFormatStringArgs (series , r ));
1513
1532
String lastPath = resolutionString .substring (
1514
1533
resolutionString .lastIndexOf ('/' ) + 1 );
1515
- datasets .add (Collections .singletonMap ("path" , lastPath ));
1516
- }
1517
- multiscale .put ("datasets" , datasets );
1518
1534
1519
- String axisOrder = null ;
1520
- if (dimensionOrder != null ) {
1521
- axisOrder = dimensionOrder .toString ();
1522
- }
1523
- else {
1524
- IFormatReader reader = readers .take ();
1525
- try {
1526
- axisOrder = reader .getDimensionOrder ();
1527
- }
1528
- finally {
1529
- readers .put (reader );
1535
+ List <Map <String , Object >> transforms =
1536
+ new ArrayList <Map <String , Object >>();
1537
+ Map <String , Object > scale = new HashMap <String , Object >();
1538
+ scale .put ("type" , "scale" );
1539
+ List <Double > axisValues = new ArrayList <Double >();
1540
+ List <Integer > axisIndices = new ArrayList <Integer >();
1541
+ for (int i =axisOrder .length ()-1 ; i >=0 ; i --) {
1542
+ Quantity axisScale = getScale (meta , series , axisOrder , i );
1543
+ if (axisScale != null ) {
1544
+ // TODO: does this need to be recalculated for r > 0?
1545
+ axisValues .add (axisScale .value ().doubleValue ());
1546
+ axisIndices .add (axisOrder .length () - i - 1 );
1547
+ }
1530
1548
}
1549
+ scale .put ("scale" , axisValues );
1550
+ scale .put ("axisIndices" , axisIndices );
1551
+
1552
+ transforms .add (scale );
1553
+
1554
+ Map <String , Object > dataset = new HashMap <String , Object >();
1555
+ dataset .put ("path" , lastPath );
1556
+ dataset .put ("transformations" , transforms );
1557
+ datasets .add (dataset );
1531
1558
}
1559
+ multiscale .put ("datasets" , datasets );
1560
+
1532
1561
List <Map <String , String >> axes = new ArrayList <Map <String , String >>();
1533
1562
for (int i =axisOrder .length ()-1 ; i >=0 ; i --) {
1534
1563
String axis = axisOrder .substring (i , i + 1 ).toLowerCase ();
1535
1564
String type = "space" ;
1565
+ Quantity scale = getScale (meta , series , axisOrder , i );
1536
1566
if (axis .equals ("t" )) {
1537
1567
type = "time" ;
1538
1568
}
@@ -1542,6 +1572,9 @@ else if (axis.equals("c")) {
1542
1572
Map <String , String > thisAxis = new HashMap <String , String >();
1543
1573
thisAxis .put ("name" , axis );
1544
1574
thisAxis .put ("type" , type );
1575
+ if (scale != null ) {
1576
+ thisAxis .put ("unit" , scale .unit ().getSymbol ());
1577
+ }
1545
1578
axes .add (thisAxis );
1546
1579
}
1547
1580
multiscale .put ("axes" , axes );
@@ -1555,6 +1588,33 @@ else if (axis.equals("c")) {
1555
1588
LOGGER .debug (" finished writing subgroup attributes" );
1556
1589
}
1557
1590
1591
+ private Quantity getScale (
1592
+ IMetadata meta , int series , String axisOrder , int axis )
1593
+ {
1594
+ if (meta == null ) {
1595
+ return null ;
1596
+ }
1597
+ int seriesIndex = seriesList .indexOf (series );
1598
+
1599
+ if (seriesIndex < 0 || seriesIndex >= meta .getImageCount ()) {
1600
+ return null ;
1601
+ }
1602
+
1603
+ String axisChar = axisOrder .substring (axis , axis + 1 ).toLowerCase ();
1604
+ switch (axisChar .charAt (0 )) {
1605
+ case 'x' :
1606
+ return meta .getPixelsPhysicalSizeX (seriesIndex );
1607
+ case 'y' :
1608
+ return meta .getPixelsPhysicalSizeY (seriesIndex );
1609
+ case 'z' :
1610
+ return meta .getPixelsPhysicalSizeZ (seriesIndex );
1611
+ case 't' :
1612
+ return meta .getPixelsTimeIncrement (seriesIndex );
1613
+ default :
1614
+ return null ;
1615
+ }
1616
+ }
1617
+
1558
1618
/**
1559
1619
* Takes exception from asynchronous execution and re-throw known exception
1560
1620
* types. If the end is reached with no known exception detected, either the
0 commit comments