@@ -75,9 +75,13 @@ struct outer_type;
7575template <typename T = Index>
7676struct RangeDescriptor {
7777 using type = T;
78+ // / The label of the dimension to slice. Either a string or an index.
7879 DimensionIdentifier label;
80+ // / The start index or value of the slice.
7981 T start;
82+ // / The stop index or value of the slice.
8083 T stop;
84+ // / The step index or value of the slice. Only 1 is supported currently.
8185 Index step = 1 ;
8286};
8387
@@ -122,7 +126,9 @@ struct SliceDescriptor {
122126template <typename T>
123127struct ValueDescriptor {
124128 using type = T;
129+ // / The label of the dimension to slice.
125130 DimensionIdentifier label;
131+ // / The value to slice.
126132 T value;
127133};
128134
@@ -136,7 +142,9 @@ struct ValueDescriptor {
136142template <typename T>
137143struct ListDescriptor {
138144 using type = T;
145+ // / The label of the dimension to slice.
139146 DimensionIdentifier label;
147+ // / The vector of values to slice.
140148 std::vector<T> values;
141149};
142150
@@ -287,8 +295,7 @@ Result<std::tuple<nlohmann::json, nlohmann::json>> ValidateAndProcessJson(
287295 * @tparam R The rank of the Variable.
288296 * @tparam M The read-write mode of the Variable.
289297 * @param spec The JSON specification to parse. `spec` is expected to contain
290- * ["attributes"]["variable_name"] and
291- * ["attributes"]["dimension_names"].
298+ * ["attributes"]["variable_name"] and ["attributes"]["dimension_names"].
292299 * @param store The TensorStore to use for the Variable.
293300 * @return A Result object containing the created Variable.
294301 */
@@ -323,8 +330,9 @@ Result<Variable<T, R, M>> from_json(
323330 return attrsRes.status ();
324331 }
325332
326- std::string long_name =
327- " " ; // Default case. TODO: Look into making this optional.
333+ // Default case.
334+ // TODO(BrianMichell): Look into making this optional.
335+ std::string long_name = " " ;
328336 if (scrubbed_spec.contains (" long_name" )) {
329337 if (scrubbed_spec[" long_name" ].is_string () &&
330338 scrubbed_spec[" long_name" ].get <std::string>().size () > 0 ) {
@@ -379,7 +387,7 @@ Result<Variable<T, R, M>> from_json(
379387 * to create.
380388 * @param options The transactional open options to use when opening the
381389 * TensorStore.
382- * @throws absl::StatusCode::kInvalidArgument if the attributes are empty.
390+ * @return absl::StatusCode::kInvalidArgument if the attributes are empty.
383391 * @return mdio::Future<Variable<T, R, M>> A future that will be fulfilled with
384392 * the created variable.
385393 */
@@ -561,7 +569,7 @@ Future<Variable<T, R, M>> OpenVariable(const nlohmann::json& json_store,
561569 }
562570 // attributes is not a valid key for the tensorstore open ...
563571 // FIXME - resolve opening struct array with field and no metadata
564- // udpates to Tensorstore required ...
572+ // updates to Tensorstore required ...
565573 if (!store_spec.contains (" field" ) && store_spec.contains (" metadata" )) {
566574 store_spec.erase (" metadata" );
567575 }
@@ -730,15 +738,16 @@ Future<Variable<T, R, M>> Open(const nlohmann::json& json_spec,
730738/* *
731739 * @brief A templated struct representing an MDIO Variable with a tensorstore.
732740 * This is an MDIO specified zarr V2 tensorstore variable.
733- * It represents the non-volitile (on-disc , in-cloud, etc.) data.
741+ * It represents the non-volitile (on-disk , in-cloud, etc.) data.
734742 *
735743 * @tparam T The type of the data stored in the tensorstore.
736744 * @tparam R The rank of the tensorstore.
737745 * @tparam M The read-write mode of the tensorstore.
738- * @param variableName
739- * @param longName
740- * @param metadata
741- * @param store
746+ * @param variableName The name of the variable.
747+ * @param longName The optional long name of the variable.
748+ * @param metadata Any metadata associated with the variable.
749+ * @param store The underlying Tensorstore.
750+ * @param attributes The user attributes associated with the variable.
742751 */
743752template <typename T = void , DimensionIndex R = dynamic_rank,
744753 ReadWriteMode M = ReadWriteMode::dynamic>
@@ -851,8 +860,9 @@ class Variable {
851860 * to the target variable.
852861 * @code
853862 * MDIO_ASSIGN_OR_RETURN(auto velocity, mdio::Variable<>::Open(velocity_path,
854- * mdio::constants::kOpen)); MDIO_ASSIGN_OR_RETURN(auto velocityData,
855- * mdio::from_variable(velocity));
863+ * mdio::constants::kOpen));
864+ * // Get an empty version of the Variable.
865+ * MDIO_ASSIGN_OR_RETURN(auto velocityData, mdio::from_variable(velocity));
856866 * // Do some manipulation of velocity here before writing it out.
857867 * auto velocityWriteFuture = velocity.Write(velocityData);
858868 * // This is a future. It will be ready when the write is complete.
@@ -1014,8 +1024,8 @@ class Variable {
10141024 * @brief Slices the Variable along the specified dimensions and returns the
10151025 * resulting sub-Variable. This slice is performed as a half open interval.
10161026 * Dimensions that are not described will remain fully intact.
1017- * @pre The step of the slice descriptor must be 1.
1018- * @pre The start of the slice descriptor must be less than the stop.
1027+ * @pre The step of the descriptor object must be 1.
1028+ * @pre The start of the descriptor object must be less than the stop.
10191029 * @post The resulting Variable will be sliced along the specified dimensions
10201030 * within it's domain. If the slice lay outside of the domain of the Variable,
10211031 * the slice will be clamped to the domain.
@@ -1174,6 +1184,10 @@ class Variable {
11741184 return *this ;
11751185 }
11761186
1187+ /* *
1188+ * @brief Retrieves the spec of the Variable as a JSON object.
1189+ * @return A JSON object representing the spec of the Variable.
1190+ */
11771191 Result<nlohmann::json> get_spec () const {
11781192 auto spec_res = spec ();
11791193 if (!spec_res.ok ()) {
@@ -1202,8 +1216,6 @@ class Variable {
12021216 * otherwise a vector of the chunk shape.
12031217 */
12041218 Result<std::vector<DimensionIndex>> get_chunk_shape () const {
1205- // TODO(BrianMichell): Depricate this method name
1206- // Reasoning: To reduce confusion between it and get_store_shape
12071219 auto spec_res = get_spec ();
12081220 if (!spec_res.status ().ok ()) {
12091221 return spec_res;
@@ -1254,7 +1266,8 @@ class Variable {
12541266 * @brief Publishes new ".zattrs" metadata to the Variable's durable storage.
12551267 * This method should not be called independantly as it will result in a
12561268 * mismatch between the Variable metadata and Dataset metadata
1257- * @return
1269+ * @return A future representing the timestamped storage generation of the
1270+ * updated Variable.
12581271 */
12591272 Future<tensorstore::TimestampedStorageGeneration> PublishMetadata () {
12601273 auto publish = [](const ::nlohmann::json& json_var, bool isCloudStore,
@@ -1331,18 +1344,21 @@ class Variable {
13311344 * an error and the attributes remain unchanged.
13321345 * @details \b Intended_Usage
13331346 * @code
1334- * auto var = my_dataset.variables.at("my_variable_key").value(); // Status
1335- * check ignored for berevity nlohmann::json to_update = var.GetAttributes();
1347+ * // Status check ignored for brevity
1348+ * auto var = my_dataset.variables.at("my_variable_key").value();
1349+ * nlohmann::json to_update = var.GetAttributes();
13361350 * to_update["attributes"]["new_attr"] = "new_value";
1337- * std::vector<int32_t> binCenters; // Populate with your data as needed
1351+ * std::vector<int32_t> binCenters;
1352+ * // Populate with your data as needed
13381353 * to_update["statsV1"]["histogram"]["binCenters"] = binCenters;
1339- * // NOTE: The vector is of type int32_t. We should pass the type as a
1340- * template argument. auto update_result =
1341- * var.UpdateAttributes<int32_t>(to_update); if (!update_result.status().ok())
1342- * {
1354+ * // NOTE: The vector is of type int32_t. We must pass the type as a
1355+ * template argument.
1356+ * auto update_result = var.UpdateAttributes<int32_t>(to_update);
1357+ * if (!update_result.status().ok()) {
13431358 * // In this case nothing will happen. We output an error and move on
1344- * with what previously existed. std::cerr << "Failed to update attributes: "
1345- * << update_result.status() << std::endl;
1359+ * // with what previously existed.
1360+ * std::cerr << "Failed to update attributes: " <<
1361+ * update_result.status() << std::endl;
13461362 * }
13471363 * @endcode
13481364 * NOTE: This does not commit changes to durable media.
@@ -1358,13 +1374,22 @@ class Variable {
13581374 return res;
13591375 }
13601376
1377+ /* *
1378+ * @brief Gets the User Attributes of the Variable as a JSON object.
1379+ * Returned object is expected to have a parent key of "attributes".
1380+ * This is expected to be the exact copy of the attributes field.
1381+ * @see
1382+ * https://mdio-python.readthedocs.io/en/v1/data_models/version_1.html#mdio.schema.v1.variable.VariableMetadata.attributes
1383+ * @return The User Attributes in JSON form.
1384+ */
13611385 nlohmann::json GetAttributes () const {
13621386 // Dereference the outer std::shared_ptr to get the inner std::shared_ptr
13631387 return (*attributes)->ToJson ();
13641388 }
13651389
13661390 /* *
13671391 * @brief Gets the entire metadata of the Variable.
1392+ * Returned object is expected to have a parent key of "metadata".
13681393 * @return The metadata in JSON form
13691394 */
13701395 nlohmann::json getMetadata () const {
@@ -1384,7 +1409,7 @@ class Variable {
13841409 * @brief A reduced version of the metadata
13851410 * NOTE: This may only be useful for internal uses. See `getMetadata()` for
13861411 * the full metadata. This version should lack the mutable UserAttributes
1387- * portions, if they exist
1412+ * portions, if they exist.
13881413 * @return The reduced metadata in JSON form
13891414 */
13901415 const nlohmann::json getReducedMetadata () const {
@@ -1422,15 +1447,21 @@ class Variable {
14221447 }
14231448 }
14241449
1450+ /* *
1451+ * @brief A struct representing the half open interval of a dimension.
1452+ */
14251453 struct Interval {
14261454 friend std::ostream& operator <<(std::ostream& os, const Interval& obj) {
14271455 os << obj.label .label () << " : [" << obj.inclusive_min << " , "
14281456 << obj.exclusive_max << " )" ;
14291457 return os;
14301458 }
14311459
1460+ // / The string or index label of the dimension.
14321461 mdio::DimensionIdentifier label;
1462+ // / The inclusive minimum of the interval.
14331463 mdio::Index inclusive_min;
1464+ // / The exclusive maximum of the interval.
14341465 mdio::Index exclusive_max;
14351466 };
14361467
@@ -1489,10 +1520,22 @@ class Variable {
14891520 }
14901521
14911522 // ===========================Member data getters===========================
1523+ /* *
1524+ * @brief Gets the name of the variable.
1525+ * @return The name of the variable.
1526+ */
14921527 const std::string& get_variable_name () const { return variableName; }
14931528
1529+ /* *
1530+ * @brief Gets the long name of the variable.
1531+ * @return The long name of the variable.
1532+ */
14941533 const std::string& get_long_name () const { return longName; }
14951534
1535+ /* *
1536+ * @brief Gets the underlying tensorstore of the variable.
1537+ * @return The tensorstore of the variable.
1538+ */
14961539 const tensorstore::TensorStore<T, R, M>& get_store () const { return store; }
14971540
14981541 // The data that should remain static, but MAY need to be updated.
@@ -1757,14 +1800,13 @@ struct VariableData {
17571800 * mdio::RangeDescriptor<Index> dim_zero_slice = {"Dimension_0", 4, 10, 1};
17581801 * MDIO_ASSIGN_OR_RETURN(auto sliced_dataset, dataset.isel(dim_zero_slice));
17591802 * MDIO_ASSIGN_OR_RETURN(auto sliced_variable,
1760- * sliced_dataset.variables.get<mdio::dtypes::float32>("my_variable"));
1803+ * sliced_dataset.variables.get<mdio::dtypes::float32>("my_variable"));
17611804 * MDIO_ASSIGN_OR_RETURN(auto sliced_data, sliced_variable.Read().result());
17621805 * auto flattened_data =
17631806 * reinterpret_cast<mdio::float32_t*>(sliced_data.get_data_accessor().data());
17641807 * auto offset = sliced_data.get_flattened_offset();
17651808 * // We can use the method `sliced_data.get_data_accessor().num_elements()`
1766- * in conjunction with
1767- * // `offset` instead of hardcoding 6 for n-dimensional data.
1809+ * // in conjunction with `offset` instead of hardcoding 6.
17681810 * for (size_t i=0; i<6; ++i) {
17691811 * std::cout << flattened_data[i + offset] << std::endl;
17701812 * }
0 commit comments