Skip to content

Commit

Permalink
simplify method names
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 9, 2024
1 parent 8f43fce commit 2769177
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/main/java/io/bioimage/modelrunner/numpy/DecodeNumpy.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public static < T extends RealType< T > & NativeType< T > > void main(String[] a
//RandomAccessibleInterval<?> aa = retrieveImgLib2FromNpy(npy);
String npy = "C:\\Users\\angel\\OneDrive\\Documentos\\pasteur\\test_input.npy";
RandomAccessibleInterval<T> rai = Cast.unchecked(ArrayImgs.doubles(new long[] {1, 512, 512}));
writeRaiToNpyFile(npy, rai);
RandomAccessibleInterval<?> bb = retrieveImgLib2FromNpy(npy);
saveNpy(npy, rai);
RandomAccessibleInterval<?> bb = loadNpy(npy);
}

/**
Expand All @@ -173,7 +173,7 @@ public static < T extends RealType< T > & NativeType< T > > void main(String[] a
* @throws IOException if there is any error opening the numpy file
*/
public static < T extends RealType< T > & NativeType< T > >
RandomAccessibleInterval<T> retrieveImgLib2FromNpy(String path) throws FileNotFoundException, IOException{
RandomAccessibleInterval<T> loadNpy(String path) throws FileNotFoundException, IOException{
File npyFile = new File(path);
if (!npyFile.isFile() || !path.endsWith(NUMPY_EXTENSION)) {
throw new IllegalArgumentException("Path provided does not correspond to a Numpy file: " + path);
Expand All @@ -191,7 +191,7 @@ RandomAccessibleInterval<T> retrieveImgLib2FromNpy(String path) throws FileNotFo
* @return an ImgLib2 image with the same datatype, shape and data that the numpy array
* @throws IOException if there is any error reading the {@link InputStream}
*/
public static HashMap<String, Object> decodeNumpyFromByteArrayStreamToRawMap(InputStream is) throws IOException {
private static HashMap<String, Object> decodeNumpyFromByteArrayStreamToRawMap(InputStream is) throws IOException {
DataInputStream dis;
if (is instanceof DataInputStream) {
dis = (DataInputStream) is;
Expand Down Expand Up @@ -281,7 +281,7 @@ public static HashMap<String, Object> decodeNumpyFromByteArrayStreamToRawMap(Inp
* @return an ImgLib2 image with the same datatype, shape and data that the numpy array
* @throws IOException if there is any error reading the {@link InputStream}
*/
public static < T extends RealType< T > & NativeType< T > >
private static < T extends RealType< T > & NativeType< T > >
RandomAccessibleInterval<T> decodeNumpyFromByteArrayStream(InputStream is) throws IOException {
DataInputStream dis;
if (is instanceof DataInputStream) {
Expand Down Expand Up @@ -475,7 +475,7 @@ private static void readData(DataInputStream dis, ByteBuffer data, int len) thro
* If the tensor type is not supported.
*/
@SuppressWarnings("unchecked")
public static <T extends NativeType<T>> RandomAccessibleInterval<T> build(ByteBuffer buf, ByteOrder byteOrder, String dtype, long[] shape, boolean fortranOrder) throws IllegalArgumentException
private static <T extends NativeType<T>> RandomAccessibleInterval<T> build(ByteBuffer buf, ByteOrder byteOrder, String dtype, long[] shape, boolean fortranOrder) throws IllegalArgumentException
{
long[] transposedShape = new long[shape.length];
for (int i = 0; i < shape.length; i ++)
Expand Down Expand Up @@ -764,7 +764,7 @@ long calculateNpyStyleByteArrayLength(long[] shape, T datatype) {
* @throws IOException if there is any error saving the file
*/
public static < T extends RealType< T > & NativeType< T > >
void writeRaiToNpyFile(String filePath, RandomAccessibleInterval<T> rai) throws FileNotFoundException, IOException {
void saveNpy(String filePath, RandomAccessibleInterval<T> rai) throws FileNotFoundException, IOException {
byte[] total = createNumpyStyleByteArray(rai);
try (FileOutputStream fos = new FileOutputStream(filePath)) {
fos.write(total);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class SharedMemoryFile
*/
public static <T extends RealType<T> & NativeType<T>>
void buildFileFromRai(String fileDir, RandomAccessibleInterval<T> rai) throws FileNotFoundException, IOException {
DecodeNumpy.writeRaiToNpyFile(fileDir, rai);
DecodeNumpy.saveNpy(fileDir, rai);
}

/**
Expand All @@ -65,6 +65,6 @@ void buildFileFromRai(String fileDir, RandomAccessibleInterval<T> rai) throws Fi
*/
public static <T extends RealType<T> & NativeType<T>>
RandomAccessibleInterval<T> buildRaiFromFile(String fileName) throws FileNotFoundException, IOException {
return DecodeNumpy.retrieveImgLib2FromNpy(fileName);
return DecodeNumpy.loadNpy(fileName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static void main(String[] args) throws FileNotFoundException, IOException
PythonTransformation pt = new PythonTransformation();
//RandomAccessibleInterval<FloatType> img = ArrayImgs.floats(new long[] {1, 1024, 1024, 33});
String fname = "C:\\Users\\angel\\OneDrive\\Documentos\\pasteur\\git\\deep-icy\\models\\stardist\\test_output.npy";
RandomAccessibleInterval<FloatType> img = DecodeNumpy.retrieveImgLib2FromNpy(fname);
RandomAccessibleInterval<FloatType> img = DecodeNumpy.loadNpy(fname);
Tensor<FloatType> tt = Tensor.build("output", "bcyx", img);
Tensor<FloatType> out = pt.apply(tt);
System.out.println();
Expand Down

0 comments on commit 2769177

Please sign in to comment.