Package loci.formats.services
Class NetCDFServiceImpl
java.lang.Object
loci.common.services.AbstractService
loci.formats.services.NetCDFServiceImpl
- All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable,loci.common.services.Service,NetCDFService
public class NetCDFServiceImpl
extends loci.common.services.AbstractService
implements NetCDFService, com.esotericsoftware.kryo.KryoSerializable
Utility class for working with NetCDF/HDF files. Uses reflection to
call the NetCDF Java library.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringarrayToString(ucar.ma2.Array values) voidclose()Closes and resets the service.Retrieves an HDF path's values.Retrieves an exhaustive list of the HDF paths for all attributes in the HDF document.getAttributeValue(String path) Retrieves an attribute's value.intgetDimension(String name) Retrieves the length of a dimension.private StringgetDirectory(String path) getFile()Retrieves the current initialized file path.private ucar.nc2.GroupRetrieves a group based on its fully qualified path.private StringgetVariableAttributes(String name) Retrieves all of a variable's attributes.Retrieves an exhaustive list of the HDF paths for all variables in the HDF document.getVariableValue(String name) Retrieves a variable's value.private voidinit()private voidparseAttributesAndVariables(List<ucar.nc2.Group> groups) Recursively parses attribute and variable paths, fillingattributeListandvariableList.voidread(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input in) voidInitializes the service on a given file path.voidwrite(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output out) Methods inherited from class loci.common.services.AbstractService
checkClassDependency
-
Field Details
-
NO_NETCDF_MSG
-
currentFile
-
attributeList
-
variableList
-
netCDFFile
private ucar.nc2.NetcdfFile netCDFFileNetCDF file instance. -
root
private ucar.nc2.Group rootRoot of the NetCDF file.
-
-
Constructor Details
-
NetCDFServiceImpl
public NetCDFServiceImpl()Default constructor.
-
-
Method Details
-
setFile
Description copied from interface:NetCDFServiceInitializes the service on a given file path.- Specified by:
setFilein interfaceNetCDFService- Parameters:
file- Path to initialize the service with.- Throws:
IOException- If there is an error initializing the service withfile.
-
getFile
Description copied from interface:NetCDFServiceRetrieves the current initialized file path.- Specified by:
getFilein interfaceNetCDFService- Returns:
- Current initialized file path or
nullif the service has yet to be initialized or is closed.
-
getAttributeList
Description copied from interface:NetCDFServiceRetrieves an exhaustive list of the HDF paths for all attributes in the HDF document.- Specified by:
getAttributeListin interfaceNetCDFService- Returns:
- Collection of attribute paths.
-
getVariableList
Description copied from interface:NetCDFServiceRetrieves an exhaustive list of the HDF paths for all variables in the HDF document.- Specified by:
getVariableListin interfaceNetCDFService- Returns:
- Collection of variable paths.
-
getAttributeValue
Description copied from interface:NetCDFServiceRetrieves an attribute's value.- Specified by:
getAttributeValuein interfaceNetCDFService- Parameters:
path- HDF path to the attribute.- Returns:
- String value or
nullif the attribute is not a string.
-
getVariableValue
Description copied from interface:NetCDFServiceRetrieves a variable's value.- Specified by:
getVariableValuein interfaceNetCDFService- Parameters:
name- HDF path to the variable.- Returns:
- The Java one-dimensional array representation of the variable's values.
- Throws:
loci.common.services.ServiceException- If there is an error with the range of values or reading from the file.- See Also:
-
getArray
public Object getArray(String path, int[] origin, int[] shape) throws loci.common.services.ServiceException Description copied from interface:NetCDFServiceRetrieves an HDF path's values.- Specified by:
getArrayin interfaceNetCDFService- Parameters:
path- HDF path to the values.origin- Array specifying the starting index. If null, assume all zeroes.shape- Array specifying the extents in each dimension. This becomes the shape of the returned Array.- Returns:
- The Java n-dimensional array representation of the path's values.
- Throws:
loci.common.services.ServiceException- If there is an error with the range of values or reading from the file.- See Also:
-
getVariableAttributes
Description copied from interface:NetCDFServiceRetrieves all of a variable's attributes.- Specified by:
getVariableAttributesin interfaceNetCDFService- Parameters:
name- HDF path to the variable.- Returns:
- Hash table of attributes to Java one-dimensional array representations of the attribute's values.
- See Also:
-
getDimension
Description copied from interface:NetCDFServiceRetrieves the length of a dimension.- Specified by:
getDimensionin interfaceNetCDFService- Parameters:
name- HDF path to the dimension.- Returns:
- Length of the dimension.
-
close
Description copied from interface:NetCDFServiceCloses and resets the service.- Specified by:
closein interfaceNetCDFService- Throws:
IOException- If there is an error closing the file.
-
parseAttributesAndVariables
Recursively parses attribute and variable paths, fillingattributeListandvariableList.- Parameters:
groups- List of groups to recursively parse.
-
getGroup
Retrieves a group based on its fully qualified path.- Parameters:
path- Fully qualified path to the group.- Returns:
- Group or
rootif the group cannot be found.
-
getDirectory
-
getName
-
arrayToString
-
init
- Throws:
IOException
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input in) - Specified by:
readin interfacecom.esotericsoftware.kryo.KryoSerializable
-
write
public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output out) - Specified by:
writein interfacecom.esotericsoftware.kryo.KryoSerializable
-