Skip to content

Commit 2031129

Browse files
authored
Merge pull request #157 from TGSAI/DocumentationFix
Documentation fixes
2 parents d40539d + 5b6237c commit 2031129

4 files changed

Lines changed: 107 additions & 45 deletions

File tree

mdio/dataset.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ class Dataset {
450450
return variables.get<T, R, M>(variable_name);
451451
}
452452

453+
/**
454+
* @brief Gets the intervals of the the dataset.
455+
* @param 0 or more dimension labels for the intervals to retrieve.
456+
* No labels will return all intervals in the dataset.
457+
* @return A vector of intervals or NotFoundError if no intervals could be
458+
* found.
459+
*/
453460
template <typename... DimensionIdentifier>
454461
mdio::Result<std::vector<Variable<>::Interval>> get_intervals(
455462
const DimensionIdentifier&... labels) const {
@@ -604,7 +611,9 @@ class Dataset {
604611

605612
// Wrapper function that generates the index sequence
606613
/**
607-
* @brief Internal use only.
614+
* @brief This version of isel is only expected to be used interally.
615+
* Documentation is provided for clarity and usage in the case where
616+
* the number of descriptors cannot be known at compile time.
608617
* Calls the `isel` method with a vector of `RangeDescriptor` objects.
609618
* Limited to `internal::kMaxNumSlices` slices which may not be equal to the
610619
* number of descriptors.
@@ -1305,6 +1314,11 @@ class Dataset {
13051314
return pair.future;
13061315
}
13071316

1317+
/**
1318+
* @brief Commits changes made to the Variables metadata to durable media.
1319+
* @return A future representing the completion of the commit or an error if
1320+
* no changes were made but the commit was requested.
1321+
*/
13081322
tensorstore::Future<void> CommitMetadata() {
13091323
auto keys = variables.get_iterable_accessor();
13101324

@@ -1423,19 +1437,23 @@ class Dataset {
14231437
return pair.future;
14241438
}
14251439

1440+
/**
1441+
* @brief Gets the Dataset level metadata.
1442+
* @return A const reference to the Dataset's metadata.
1443+
*/
14261444
const nlohmann::json& getMetadata() const { return metadata; }
14271445

1428-
// variables contained in the dataset
1446+
/// variables contained in the dataset
14291447
VariableCollection variables;
14301448

1431-
// link a variable name to its coordinates via its name(s)
1449+
/// link a variable name to its coordinates via its name(s)
14321450
coordinate_map coordinates;
14331451

1434-
// enumerate the dimensions
1452+
/// enumerate the dimensions
14351453
tensorstore::IndexDomain<> domain;
14361454

14371455
private:
1438-
// the metadata associated with the dataset (root .zattrs)
1456+
/// the metadata associated with the dataset (root .zattrs)
14391457
::nlohmann::json metadata;
14401458
};
14411459
} // namespace mdio

mdio/impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ constexpr auto kCreateClean =
114114
/// Create a new file or error if it already exists.
115115
constexpr auto kCreate = tensorstore::OpenMode::create;
116116

117-
// Tensorstore appears to be imposing a max size of 0x3fffffffffffffff
117+
/// Tensorstore appears to be imposing a max size of 0x3fffffffffffffff
118118
constexpr uint64_t kMaxSize = 4611686018427387903;
119119

120120
// Supported dtypes

mdio/stats.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@
5151
*
5252
* @code
5353
* // NOTE: We do not verify the status of `dataset.variables.at("variable")` in
54-
* this example code. This is for brevity. mdio::UserAttributes userAttrs =
55-
* dataset.variables.at("variable").value().userAttrs; nlohmann::json
56-
* updatedAttrs = userAttrs.ToJson();
54+
* this example code. This is for brevity.
55+
* mdio::UserAttributes userAttrs =
56+
* dataset.variables.at("variable").value().userAttrs;
57+
* nlohmann::json updatedAttrs = userAttrs.ToJson();
5758
* // Modify updatedAttrs as any normal JSON object
5859
* // NOTE: FromJson can take an optional template of `int32_t` default to
59-
* `float` to specify the type of the histogram. auto updatedUserAttrsResult =
60-
* mdio::UserAttributes::FromJson(updatedAttrs); if
61-
* (!updatedUserAttrsResult.ok()) {
60+
* `float` to specify the type of the histogram.
61+
* auto updatedUserAttrsResult = mdio::UserAttributes::FromJson(updatedAttrs);
62+
* if (!updatedUserAttrsResult.ok()) {
6263
* // Handle error
6364
* }
6465
* mdio::UserAttributes updatedUserAttrs = updatedUserAttrsResult.value();
@@ -343,8 +344,9 @@ class UserAttributes {
343344
* @note This constructor is intended for internal use only. Please use the
344345
* static member function `FromJson(nlohmann::json)`
345346
* @code
346-
* auto attrs = UserAttributes::FromJson(j).value(); // j is some valid
347-
* nlohmann::json object nlohmann::json newAttrs = attrs.ToJson();
347+
* // j is some valid nlohmann::json object
348+
* auto attrs = UserAttributes::FromJson(j).value();
349+
* nlohmann::json newAttrs = attrs.ToJson();
348350
* newAttrs["attributes"]["newKey"] = "newValue";
349351
* auto newAttrsRes = UserAttributes::FromJson(newAttrs).value();
350352
* @endcode

mdio/variable.h

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ struct outer_type;
7575
template <typename T = Index>
7676
struct 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 {
122126
template <typename T>
123127
struct 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 {
136142
template <typename T>
137143
struct 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
*/
743752
template <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

Comments
 (0)