Skip to content

Commit

Permalink
Default Unit Values
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Aug 23, 2024
1 parent 2faada1 commit 8c33b44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 16 additions & 2 deletions vcell-core/src/main/java/cbit/vcell/export/server/N5Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public N5Exporter(ExportServiceImpl exportServiceImpl) {
}

private ExportOutput exportToN5(OutputContext outputContext, long jobID, N5Specs n5Specs, ExportSpecs exportSpecs, FileDataContainerManager fileDataContainerManager) throws Exception {
VCUnitDefinition lengthUnit = ModelUnitSystem.createDefaultVCModelUnitSystem().getLengthUnit();
double[] allTimes = dataServer.getDataSetTimes(user, vcDataID);
TimeSpecs timeSpecs = exportSpecs.getTimeSpecs();
String[] variableNames = exportSpecs.getVariableSpecs().getVariableNames();
Expand Down Expand Up @@ -135,7 +134,7 @@ private ExportOutput exportToN5(OutputContext outputContext, long jobID, N5Specs
N5Specs.writeImageJMetaData(jobID, dimensions, blockSize, n5Specs.getCompression(), n5FSWriter,
n5Specs.dataSetName, numVariables, sizeZ, allTimes.length,
exportSpecs.getHumanReadableExportData().subVolume,
lengthPerPixelY, lengthPerPixelX, lengthPerPixelZ, lengthUnit.getSymbol(), channelInfo);
lengthPerPixelY, lengthPerPixelX, lengthPerPixelZ, getLengthUnit(), getTimeUnit(),channelInfo);

int timeLoops = 1;
double progress = 0;
Expand Down Expand Up @@ -192,6 +191,21 @@ private boolean containsPostProcessedVariable(String[] variableNames, OutputCont
return false;
}

private String getTimeUnit(){
VCUnitDefinition timeUnit = ModelUnitSystem.createDefaultVCModelUnitSystem().getTimeUnit();
return timeUnit.getSymbol();
}

private String getSpeciesUnit(){
VCUnitDefinition speciesUnit = ModelUnitSystem.createDefaultVCModelUnitSystem().getVolumeConcentrationUnit();
return speciesUnit.getSymbol();
}

private String getLengthUnit(){
VCUnitDefinition lengthUnit = ModelUnitSystem.createDefaultVCModelUnitSystem().getLengthUnit();
return lengthUnit.getSymbol();
}

public void initalizeDataControllers(User user, DataServerImpl dataServer, VCSimulationDataIdentifier vcSimulationDataIdentifier) throws IOException, DataAccessException {
this.user = user;
this.vcDataID = vcSimulationDataIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public String toString() {

public static void writeImageJMetaData(long jobID,long[] dimensions, int[] blockSize, Compression compression, N5FSWriter n5FSWriter, String datasetName, int numChannels, int zSlices,
int timeLength, HashMap<Integer, String> maskMapping, double pixelHeight,
double pixelWidth, double pixelDepth, String unit, HashMap<Integer, Object> channelInfo) throws MathException, DataAccessException {
double pixelWidth, double pixelDepth, String unit, String timeUnit, HashMap<Integer, Object> channelInfo) throws MathException, DataAccessException {
try {
HashMap<String, String> compresssionMap = new HashMap<>(){{put("type", compression.getType().toLowerCase());}};
ImageJMetaData imageJMetaData = ImageJMetaData.generateDefaultRecord(dimensions, blockSize, compresssionMap, datasetName, numChannels, zSlices, timeLength,
maskMapping, pixelHeight, pixelWidth, pixelDepth, unit, channelInfo);
maskMapping, pixelHeight, pixelWidth, pixelDepth, unit, timeUnit , channelInfo);
Path path = Path.of(n5FSWriter.getURI().getPath(), String.valueOf(jobID), "attributes.json");
Gson gson = n5FSWriter.getGson();
String jsonRepresentation = gson.toJson(imageJMetaData, ImageJMetaData.class);
Expand All @@ -112,7 +112,7 @@ public static void writeImageJMetaData(long jobID,long[] dimensions, int[] block

}

record ImageJMetaData(long[] dimensions ,int[] blockSize, HashMap<String, String> compression, String dataType, String name, double fps, double frameInterval, double pixelWidth,
private record ImageJMetaData(long[] dimensions ,int[] blockSize, HashMap<String, String> compression, String dataType, String name, double fps, double frameInterval, double pixelWidth,
double pixelHeight, double pixelDepth, double xOrigin, double yOrigin, double zOrigin, int numChannels, int numSlices, int numFrames,
int type, String unit, HashMap<Integer, String> maskMapping, HashMap<Integer, Object> channelInfo){

Expand All @@ -122,7 +122,7 @@ record ImageJMetaData(long[] dimensions ,int[] blockSize, HashMap<String, String

public static ImageJMetaData generateDefaultRecord(long[] dimensions ,int[] blockSize, HashMap<String, String> compression, String dataSetName, int numChannels,
int numSlices, int numFrames, HashMap<Integer, String> maskMapping, double pixelHeight, double pixelWidth,
double pixelDepth, String unit, HashMap<Integer, Object> channelInfo){
double pixelDepth, String unit, String timeUnit , HashMap<Integer, Object> channelInfo){
return new ImageJMetaData(dimensions, blockSize, compression, DataType.FLOAT64.name().toLowerCase() ,dataSetName, 0.0, 0.0,
pixelWidth, pixelHeight, pixelDepth, 0.0, 0.0, 0.0, numChannels, numSlices, numFrames, 2, unit, maskMapping, channelInfo);
}
Expand Down

0 comments on commit 8c33b44

Please sign in to comment.