### ASDF Node Exploration in Java Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Shows how to fetch and explore nodes within an ASDF file using AsdfFile and AsdfNode. It covers getting the tree, accessing specific nodes like 'roman', checking node types, and iterating over keys. ```Java import org.asdfformat.asdf.AsdfFile; import org.asdfformat.asdf.node.AsdfNode; import org.asdfformat.asdf.node.AsdfNodeType; // Assuming asdfFile is an opened AsdfFile object AsdfNode roman = asdfFile.getTree().get("roman"); // Check node type assert roman.getNodeType() == AsdfNodeType.MAPPING; // Iterate over keys of the 'roman' node System.out.println("Keys in 'roman' node:"); for (AsdfNode key : roman) { System.out.println(key.asString()); } // Access and iterate over 'meta' child node System.out.println("\nKeys in 'meta' node:"); for (AsdfNode metaKey : roman.get("meta")) { System.out.println(metaKey.asString()); } ``` -------------------------------- ### Retrieving Array Shape Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Shows how to get the shape of an n-dimensional array using the Shape interface and iterate through its dimensions. ```java Shape shape = roman.getNdArray("context").getShape(); for (int dimension = 0; dimension < shape.getRank(); dimension++) { System.out.println(String.format("[%d]: %d", dimension, shape.get(dimension))); } ``` -------------------------------- ### Open ASDF File in Java Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Demonstrates how to open an ASDF file using the Asdf class. This is the entry point for the Java ASDF reader. It requires a Path object pointing to the ASDF file. ```Java import java.nio.file.Path; import java.nio.file.Paths; import org.asdfformat.asdf.Asdf; import org.asdfformat.asdf.AsdfFile; // Eventually this will include configuration options Asdf asdf = new Asdf(); Path path = Paths.get("/path/to/r00001_p_v01001001001_r274dp63x31y80_f158_coadd_i2d.asdf"); try (AsdfFile asdfFile = asdf.open(path)) { // Interact with the ASDF file } ``` -------------------------------- ### Converting Sequences to Lists Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Demonstrates converting a sequence of elements with a consistent type into a Java List. ```java List filenames = roman.get("meta").get("resample").getList("members", String.class); ``` -------------------------------- ### ASDF Java Reader API Source: https://github.com/asdf-format/asdf-java/blob/main/README.md This section outlines the proposed API for the ASDF Java reader. It details the core classes like Asdf and AsdfFile, and the AsdfNode interface for interacting with the ASDF data structure. ```APIDOC Asdf: __init__() Initializes the ASDF reader. open(Path path) Opens an ASDF file for reading. Parameters: path: The path to the ASDF file. Returns: An AsdfFile object representing the opened file. AsdfFile: getTree() Retrieves the root node of the ASDF file's data tree. Returns: An AsdfNode representing the root of the tree. close() Closes the ASDF file. AsdfNode: getNodeType() Returns the type of the ASDF node (e.g., MAPPING, SEQUENCE, SCALAR). Returns: An AsdfNodeType enum value. get(String key) Retrieves a child node by its key (for MAPPING nodes). Parameters: key: The key of the child node to retrieve. Returns: An AsdfNode representing the child node. asString() Converts the node's value to a String. Returns: The String representation of the node's value. (iterable) Allows iteration over child nodes (for MAPPING and SEQUENCE nodes). ``` -------------------------------- ### Accessing Sequence Elements Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Shows how to access individual elements within a sequence in an ASDF file by index. ```java String filename = roman.get("meta").get("resample").get("members").getString(2); ``` -------------------------------- ### Iterating Over Sequence Elements Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Illustrates how to iterate through the elements of a sequence node, yielding each element as an AsdfNode. ```java for (AsdfNode element : roman.get("meta").get("resample").get("members")) { System.out.println(element.asString()); } ``` -------------------------------- ### Slicing N-dimensional Arrays by Index Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Demonstrates using the NdArray.index method to select specific indices, resulting in an array view with reduced rank. ```java FloatNdArray data = roman.getNdArray("data").asFloatNdArray(); assert data.getShape().getRank() == 2; FloatNdArray dataAtIndexZero = data.index(0); assert dataAtIndexZero.getShape().getRank() == 1; float[] arrayAtIndexZero = dataAtIndexZero.toArray(new float[0]); ``` -------------------------------- ### Handling ASDF UINT32 in Java Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Demonstrates reading ASDF UINT32 data into Java's signed int type. Note that large unsigned values will be interpreted as negative numbers. ```Java assert roman.getNdArray("context").getDataType() == DataType.UINT32; IntNdArray context = roman.getNdArray("context").asIntNdArray(); int[][][] contextArray = context.toArray(new int[0][0][0]); ``` -------------------------------- ### Numeric Value Handling and Type Errors Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Demonstrates fetching numeric values from ASDF files. It highlights that attempting to fetch as int, long, or float can cause ArithmeticException, while double or BigDecimal are suitable. ```java assert roman.get("meta").get("basic").get("time_last_mjd").getNodeType() == AsdfNodeType.NUMBER; // Throws ArithmeticException // roman.get("meta").get("basic").getInt("time_last_mjd"); // roman.get("meta").get("basic").getLong("time_last_mjd"); // roman.get("meta").get("basic").getFloat("time_last_mjd"); // Succeeds roman.get("meta").get("basic").getDouble("time_last_mjd"); // Succeeds roman.get("meta").get("basic").getBigDecimal("time_last_mjd"); ``` -------------------------------- ### Fetch String Value Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Retrieves a value known to be a string from an ASDF node. It demonstrates direct retrieval using getString. ```java String telescope = roman.get("meta").getString("telescope"); ``` -------------------------------- ### Handling ASDF UINT32 with Wider Java Type Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Shows how to read ASDF UINT32 data into Java's wider signed long type to preserve the full range of unsigned values. ```Java LongNdArray context = roman.getNdArray("context").asLongNdArray(); long[][][] contextArray = context.toArray(new long[0][0][0]); ``` -------------------------------- ### Slicing N-dimensional Arrays by Range Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Illustrates using the NdArray.slice method with ranges to select portions of an array across specified dimensions. ```java FloatNdArray data = roman.getNdArray("data").asFloatNdArray(); FloatNdArray slicedData = data.slice(Slices.range(0, 100), Slices.range(200, 400)); assert slicedData.getShape().getRank() == 2; assert slicedData.getShape().get(0) == 100; assert slicedData.getShape().get(1) == 200; // Showing the relationship with the original array: assert slicedData.get(0, 0) == data.get(0, 200); float[][] slicedArray = slicedData.toArray(new float[0][0]); ``` -------------------------------- ### Converting NdArray to Primitive Array Views Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Demonstrates converting an NdArray to a type-specific view (e.g., FloatNdArray) for element access or conversion to a primitive array. ```java FloatNdArray floatData = data.asFloatNdArray(); // Get a single element float value = floatData.get(100, 100); // Get the entire array as a Java primitive array: float[][] array = floatData.toArray(new float[0][0]); ``` -------------------------------- ### Accessing N-dimensional Arrays Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Explains how to access n-dimensional arrays using the NdArray interface and retrieve their data type. ```java assert roman.get("data").getNodeType() == AsdfNodeType.NDARRAY; NdArray data = roman.getNdArray("data"); assert data.getDataType() == DataType.FLOAT32; ``` -------------------------------- ### Fetch Value with Type Check Source: https://github.com/asdf-format/asdf-java/blob/main/README.md Fetches a value as an AsdfNode and checks its type before converting it to a string. This is useful when the node type is uncertain. ```java AsdfNode telescopeNode = roman.get("meta").get("telescope"); if (telescopeNode.getNodeType() == AsdfNodeType.STRING) { String telescope = telescopeNode.asString(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.