Skip to content

Commit

Permalink
Merge pull request #90 from GReD-Clermont/5_19_0
Browse files Browse the repository at this point in the history
5.19.0
  • Loading branch information
ppouchin authored Sep 20, 2024
2 parents 6779455 + 0a7d031 commit d69345f
Show file tree
Hide file tree
Showing 16 changed files with 391 additions and 177 deletions.
23 changes: 23 additions & 0 deletions src/main/java/fr/igred/omero/AnnotatableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,29 @@ public Map<String, String> getKeyValuePairs(Client client)
}


/**
* Gets the List of Key-Value pairs associated to an object.
*
* @param client The client handling the connection.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*
* @deprecated This method will be renamed to {@link #getKeyValuePairs(Client)} ()} in a future version.
*/
@Deprecated
public List<Map.Entry<String, String>> getKeyValuePairsAsList(Client client)
throws ServiceException, AccessException, ExecutionException {
return getMapAnnotations(client).stream()
.map(MapAnnotationWrapper::getContentAsEntryList)
.flatMap(List::stream)
.collect(toList());
}


/**
* Gets the value from a Key-Value pair associated to the object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ private static NamedValue toNamedValue(Entry<String, String> entry) {
* Gets the List of NamedValue contained in the map annotation.
*
* @return MapAnnotationData content.
*
* @deprecated This method will be removed in a future version.
*/
@Deprecated
@SuppressWarnings("unchecked")
public List<NamedValue> getContent() {
return (List<NamedValue>) data.getContent();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/fr/igred/omero/annotations/TableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -516,7 +517,7 @@ private void createColumn(int column, String columnName, Class<?> type) {
*/
private Collection<Integer> getEmptyStringColumns() {
Collection<Integer> emptyColumns = new ArrayList<>(0);
for (int j = 0; j < columns.length; j++) {
for (int j = columns.length - 1; j >= 0; j--) {
TableDataColumn column = columns[j];
if (column.getType().equals(String.class)) {
boolean empty = true;
Expand Down Expand Up @@ -881,7 +882,8 @@ public TableData createTable() {
truncateRow();
}

Collection<Integer> emptyColumns = getEmptyStringColumns();
List<Integer> emptyColumns = new ArrayList<>(getEmptyStringColumns());
emptyColumns.sort(Collections.reverseOrder());
emptyColumns.forEach(this::removeColumn);

return new TableData(columns, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ public interface ThrowingFunction<T, R, E extends Throwable> {
@FunctionalInterface
public interface OMEROFunction<T, R> extends ThrowingFunction<T, R, Exception> {

@Override
R apply(T t) throws DSOutOfServiceException, DSAccessException, ServerError;

}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import static java.lang.Double.NaN;
import static ome.formats.model.UnitsFactory.convertTime;
import static ome.units.UNITS.MICROMETER;
import static ome.units.UNITS.SECOND;


Expand Down Expand Up @@ -152,6 +153,28 @@ public static Length getMinPosition(Collection<? extends PlaneInfoWrapper> plane
}


/**
* Retrieves the min value for the specified getter in a PlaneInfoWrapper collection.
*
* @param planesInfo A collection of PlaneInfoWrappers.
* @param getter The getter function to use.
*
* @return See above.
*/
public static Length getMinPosition(Collection<? extends PlaneInfoWrapper> planesInfo,
Function<? super PlaneInfoWrapper, ? extends Length> getter) {
Unit<ome.units.quantity.Length> unit;
unit = planesInfo.stream()
.map(getter)
.map(UnitsFactory::convertLength)
.filter(Objects::nonNull)
.map(ome.units.quantity.Length::unit)
.findFirst()
.orElse(MICROMETER);
return getMinPosition(planesInfo, getter, unit);
}


/**
* @return See above.
*
Expand Down
73 changes: 70 additions & 3 deletions src/main/java/fr/igred/omero/repository/ImageWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,26 @@ private static void setCalibration(PixelsWrapper pixels, Calibration calibration
calibration.setXUnit(positionX.getSymbol());
calibration.setYUnit(positionY.getSymbol());
calibration.setZUnit(positionZ.getSymbol());
calibration.xOrigin = positionX.getValue();
calibration.yOrigin = positionY.getValue();
calibration.zOrigin = positionZ.getValue();
calibration.xOrigin = -positionX.getValue();
calibration.yOrigin = -positionY.getValue();
calibration.zOrigin = -positionZ.getValue();
if (spacingX != null) {
calibration.setXUnit(spacingX.getSymbol());
calibration.pixelWidth = spacingX.getValue();
// positionX and spacingX should use the same unit
calibration.xOrigin /= calibration.pixelWidth;
}
if (spacingY != null) {
calibration.setYUnit(spacingY.getSymbol());
calibration.pixelHeight = spacingY.getValue();
// positionY and spacingY should use the same unit
calibration.yOrigin /= calibration.pixelHeight;
}
if (spacingZ != null) {
calibration.setZUnit(spacingZ.getSymbol());
calibration.pixelDepth = spacingZ.getValue();
// positionZ and spacingZ should use the same unit
calibration.zOrigin /= calibration.pixelDepth;
}
if (!Double.isNaN(stepT.getValue())) {
calibration.setTimeUnit(stepT.getSymbol());
Expand Down Expand Up @@ -254,6 +263,16 @@ public String getFormat() {
}


/**
* Returns the series.
*
* @return See above.
*/
public int getSeries() {
return data.getSeries();
}


/**
* Returns the type of annotation link for this object.
*
Expand Down Expand Up @@ -737,6 +756,9 @@ public ImagePlus toImagePlus(Client client,

Calibration calibration = imp.getCalibration();
setCalibration(pixels, calibration);
calibration.xOrigin -= startX;
calibration.yOrigin -= startY;
calibration.zOrigin -= startZ;
imp.setCalibration(calibration);

boolean isFloat = FormatTools.isFloatingPoint(pixelType);
Expand Down Expand Up @@ -794,6 +816,11 @@ public ImagePlus toImagePlus(Client client,
imp.setPosition(1);
if (IJ.getVersion().compareTo("1.53a") >= 0) {
imp.setProp(IJ_ID_PROPERTY, getId());
imp.setProp("IMAGE_POS_X", startX);
imp.setProp("IMAGE_POS_Y", startY);
imp.setProp("IMAGE_POS_C", startC);
imp.setProp("IMAGE_POS_Z", startZ);
imp.setProp("IMAGE_POS_T", startT);
}
return imp;
}
Expand Down Expand Up @@ -970,6 +997,46 @@ public BufferedImage getThumbnail(Client client, int size)
}


/**
* Returns the original file paths where the image was imported from.
*
* @param client The client handling the connection.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*/
public List<String> getOriginalPaths(Client client)
throws ExecutionException, AccessException, ServiceException {
String error = "Cannot get original paths for " + this;
return call(client.getMetadata(),
m -> m.getOriginalPaths(client.getCtx(), data),
error);
}


/**
* Returns the file paths of the image in the managed repository.
*
* @param client The client handling the connection.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ExecutionException A Facility can't be retrieved or instantiated.
*/
public List<String> getManagedRepositoriesPaths(Client client)
throws ExecutionException, AccessException, ServiceException {
String error = "Cannot get managed repositories paths for " + this;
return call(client.getMetadata(),
m -> m.getManagedRepositoriesPaths(client.getCtx(), data),
error);
}


/**
* Downloads the original files from the server.
*
Expand Down
54 changes: 38 additions & 16 deletions src/main/java/fr/igred/omero/repository/PixelsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import omero.gateway.model.PlaneInfoData;
import omero.gateway.rnd.Plane2D;
import omero.model.Length;
import omero.model.LengthI;
import omero.model.Time;

import java.util.ArrayList;
Expand All @@ -39,8 +40,8 @@
import java.util.concurrent.ExecutionException;

import static fr.igred.omero.exception.ExceptionHandler.call;
import static fr.igred.omero.meta.PlaneInfoWrapper.getMinPosition;
import static ome.formats.model.UnitsFactory.convertLength;
import static ome.units.UNITS.MICROMETER;


/**
Expand Down Expand Up @@ -238,50 +239,71 @@ public Time getMeanExposureTime(int channel) {


/**
* Retrieves the X stage position.
* Retrieves the X stage position, using the same unit as {@link #getPixelSizeX()} if possible.
* <p>Planes information needs to be {@link #loadPlanesInfo(Client) loaded} first.</p>
*
* @return See above.
*/
public Length getPositionX() {
Length x = getMinPosition(planesInfo, PlaneInfoWrapper::getPositionX);

ome.units.quantity.Length pixSizeX = convertLength(getPixelSizeX());
ome.units.quantity.Length posX = convertLength(x);

if (pixSizeX != null) {
Unit<ome.units.quantity.Length> unit = pixSizeX.unit();
if (posX.value(unit) != null) {
x = new LengthI(posX.value(unit).doubleValue(), unit);
}
}

Unit<ome.units.quantity.Length> unit = pixSizeX == null ? MICROMETER : pixSizeX.unit();
return PlaneInfoWrapper.getMinPosition(planesInfo,
PlaneInfoWrapper::getPositionX,
unit);
return x;
}


/**
* Retrieves the Y stage position.
* Retrieves the Y stage position, using the same unit as {@link #getPixelSizeY()} if possible.
* <p>Planes information needs to be {@link #loadPlanesInfo(Client) loaded} first.</p>
*
* @return See above.
*/
public Length getPositionY() {
Length y = getMinPosition(planesInfo, PlaneInfoWrapper::getPositionY);

ome.units.quantity.Length pixSizeY = convertLength(getPixelSizeY());
ome.units.quantity.Length posY = convertLength(y);

if (pixSizeY != null) {
Unit<ome.units.quantity.Length> unit = pixSizeY.unit();
if (posY.value(unit) != null) {
y = new LengthI(posY.value(unit).doubleValue(), unit);
}
}

Unit<ome.units.quantity.Length> unit = pixSizeY == null ? MICROMETER : pixSizeY.unit();
return PlaneInfoWrapper.getMinPosition(planesInfo,
PlaneInfoWrapper::getPositionY,
unit);
return y;
}


/**
* Retrieves the Z stage position.
* Retrieves the Z stage position, using the same unit as {@link #getPixelSizeZ()} if possible.
* <p>Planes information needs to be {@link #loadPlanesInfo(Client) loaded} first.</p>
*
* @return See above.
*/
public Length getPositionZ() {
Length z = getMinPosition(planesInfo, PlaneInfoWrapper::getPositionZ);

ome.units.quantity.Length pixSizeZ = convertLength(getPixelSizeZ());
ome.units.quantity.Length posZ = convertLength(z);

if (pixSizeZ != null) {
Unit<ome.units.quantity.Length> unit = pixSizeZ.unit();
if (posZ.value(unit) != null) {
z = new LengthI(posZ.value(unit).doubleValue(), unit);
}
}

Unit<ome.units.quantity.Length> unit = pixSizeZ == null ? MICROMETER : pixSizeZ.unit();
return PlaneInfoWrapper.getMinPosition(planesInfo,
PlaneInfoWrapper::getPositionZ,
unit);
return z;
}


Expand Down
2 changes: 2 additions & 0 deletions src/test/java/fr/igred/omero/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void testRootConnection() throws ServiceException {
try {
testRoot.disconnect();
} catch (RuntimeException ignored) {
// IGNORED
}
assertEquals(0L, id);
assertEquals(GROUP1.id, groupId);
Expand All @@ -81,6 +82,7 @@ void testUserConnection() throws ServiceException {
try {
testUser.disconnect();
} catch (RuntimeException ignored) {
// IGNORED
}
assertEquals(USER1.id, id);
assertEquals(GROUP1.id, groupId);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/fr/igred/omero/SudoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void testSudoTag() throws Exception {
test.disconnect();
root.disconnect();
} catch (RuntimeException ignored) {
// IGNORED
}

assertNotEquals(0, images.size());
Expand Down
Loading

0 comments on commit d69345f

Please sign in to comment.