use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readHdf5SolutionMetaData.
private void readHdf5SolutionMetaData(InputStream is) throws Exception {
File tempFile = null;
FileFormat solFile = null;
try {
tempFile = createTempHdf5File(is);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solGroup = (Group) rootGroup.getMemberList().get(0);
List<HObject> memberList = solGroup.getMemberList();
for (HObject member : memberList) {
if (!(member instanceof Dataset)) {
continue;
}
Dataset dataset = (Dataset) member;
String dsname = dataset.getName();
int vt = -1;
String domain = null;
List<Attribute> solAttrList = dataset.getMetadata();
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
if (attrName.equals("variable type")) {
Object obj = attr.getValue();
vt = ((int[]) obj)[0];
} else if (attrName.equals("domain")) {
Object obj = attr.getValue();
domain = ((String[]) obj)[0];
}
}
long[] dims = dataset.getDims();
String varName = domain == null ? dsname : domain + Variable.COMBINED_IDENTIFIER_SEPARATOR + dsname;
dataBlockList.addElement(DataBlock.createDataBlock(varName, vt, (int) dims[0], 0));
}
} finally {
try {
if (solFile != null) {
solFile.close();
}
if (tempFile != null) {
if (!tempFile.delete()) {
System.err.println("couldn't delete temp file " + tempFile);
}
}
} catch (Exception e) {
// ignore
}
}
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class ChomboFileReader method readMembraneVarData.
//
// Membrane data are stored as a UCHC (or vcell) extension to the normal Chombo Data.
// ChomboMembraneVarData was formally called VCellSolution by Fei.
//
private static void readMembraneVarData(ChomboMeshData chomboMeshData, Group rootGroup) {
// I added solution and extrapolated_volumes group to hold all the solutions from vcell
String[] groups = new String[] { "solution" /*, "extrapolated_volumes"*/
};
for (String group : groups) {
try {
Group vcellGroup = Hdf5Reader.getChildGroup(rootGroup, group);
if (vcellGroup != null) {
List<HObject> children = vcellGroup.getMemberList();
for (HObject c : children) {
if (c instanceof Dataset) {
Dataset dataset = (Dataset) c;
String name = dataset.getName();
List<Attribute> solAttrList = dataset.getMetadata();
String domain = null;
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
if (attrName.equals("domain")) {
Object obj = attr.getValue();
domain = ((String[]) obj)[0];
break;
}
}
ChomboMembraneVarData vcellSolution = new ChomboMembraneVarData(name, domain, (double[]) dataset.read());
chomboMeshData.addMembraneVarData(vcellSolution);
}
}
}
} catch (Exception ex) {
// it is ok if there is no vcell group
}
}
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readHdf5VariableSolution.
static double[] readHdf5VariableSolution(File zipfile, String fileName, String varName) throws Exception {
File tempFile = null;
FileFormat solFile = null;
try {
tempFile = createTempHdf5File(zipfile, fileName);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
solFile.open();
if (varName != null) {
String varPath = Hdf5Utils.getVarSolutionPath(varName);
HObject solObj = FileFormat.findObject(solFile, varPath);
if (solObj instanceof Dataset) {
Dataset dataset = (Dataset) solObj;
return (double[]) dataset.read();
}
}
} finally {
try {
if (solFile != null) {
solFile.close();
}
if (tempFile != null) {
if (!tempFile.delete()) {
System.err.println("couldn't delete temp file " + tempFile.getAbsolutePath());
}
}
} catch (Exception e) {
// ignore
}
}
return null;
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readMBSData.
private double[] readMBSData(String varName, Double time) throws Exception {
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
FileFormat solFile = null;
double[] data = null;
try {
solFile = fileFormat.createInstance(fileName, FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solutionGroup = null;
for (Object member : rootGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group) {
MBSDataGroup group = MBSDataGroup.valueOf(memberName);
if (group == MBSDataGroup.Solution) {
solutionGroup = (Group) member;
break;
}
}
}
if (solutionGroup == null) {
throw new Exception("Group " + MBSDataGroup.Solution + " not found");
}
int varIndex = -1;
int size = 0;
for (int i = 0; i < dataBlockList.size(); ++i) {
DataBlock dataBlock = dataBlockList.get(i);
if (dataBlock.getVarName().equals(varName)) {
varIndex = i;
size = dataBlock.getSize();
break;
}
}
if (varIndex == -1) {
throw new Exception("Variable " + varName + " not found");
}
// find time group for that time
Group timeGroup = null;
for (Object member : solutionGroup.getMemberList()) {
if (member instanceof Group) {
Group group = (Group) member;
List<Attribute> dsAttrList = group.getMetadata();
Attribute timeAttribute = null;
for (Attribute attr : dsAttrList) {
if (attr.getName().equals(MSBDataAttribute.time.name())) {
timeAttribute = attr;
break;
}
}
if (timeAttribute != null) {
double t = ((double[]) timeAttribute.getValue())[0];
if (Math.abs(t - time) < 1e-8) {
timeGroup = group;
break;
}
}
}
}
if (timeGroup == null) {
throw new Exception("No time group found for time=" + time);
}
// find variable dataset
Dataset varDataset = null;
for (Object member : timeGroup.getMemberList()) {
if (member instanceof Dataset) {
List<Attribute> dsAttrList = ((Dataset) member).getMetadata();
String var = null;
for (Attribute attr : dsAttrList) {
if (attr.getName().equals(MSBDataAttribute.name.name())) {
var = ((String[]) attr.getValue())[0];
break;
}
}
if (var != null && var.equals(varName)) {
varDataset = (Dataset) member;
break;
}
}
}
if (varDataset == null) {
throw new Exception("Data for Variable " + varName + " at time " + time + " not found");
}
data = new double[size];
System.arraycopy((double[]) varDataset.getData(), 0, data, 0, size);
return data;
} finally {
if (solFile != null) {
try {
solFile.close();
} catch (Exception e) {
// ignore
}
}
}
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readChomboExtrapolatedValues.
static double[] readChomboExtrapolatedValues(String varName, FileFormat solFile) throws Exception {
double[] data = null;
if (varName != null) {
String varPath = Hdf5Utils.getVolVarExtrapolatedValuesPath(varName);
HObject solObj = FileFormat.findObject(solFile, varPath);
if (solObj == null) {
throw new IOException("Extrapolated values for variable '" + varName + "' does not exist in the results.");
}
if (solObj instanceof Dataset) {
Dataset dataset = (Dataset) solObj;
return (double[]) dataset.read();
}
}
return data;
}
Aggregations