Skip to content

Commit

Permalink
WIP jupyterlab#4: Frontend compatibility for n-dimensional backend ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
JonjonHays committed Oct 15, 2019
1 parent 759fa3d commit 013e9f4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 195 deletions.
3 changes: 1 addition & 2 deletions jupyterlab_hdf/baseHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ def get(self, path):
selected hyperslab of a dataset and return it as serialized JSON.
"""
uri = '/' + self.get_query_argument('uri').lstrip('/')
select = self.get_query_argument('select', default='ALL')
select = self.get_query_argument('select', default=None)
try:
self.finish(json.dumps(self.manager.get(path, uri, select)))

except HTTPError as err:
self.set_status(err.code)
response = err.response.body if err.response else str(err.code)
Expand Down
1 change: 0 additions & 1 deletion jupyterlab_hdf/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class HdfDataManager(HdfBaseManager):
"""Implements HDF5 data handling
"""
def _get(self, f, uri, select):
print("SELECT: " + str(select))
return dsetChunk(f[uri], select)


Expand Down
161 changes: 0 additions & 161 deletions jupyterlab_hdf/temp_utils.py

This file was deleted.

11 changes: 5 additions & 6 deletions jupyterlab_hdf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,9 @@ def _getHyperslabSlices(dsetshape, select):
:returns: tuple of Python slices based on the SELECT query param
"""

# rank = len(dsetshape)
if select == 'ALL':
if select is None:
# Default: return entire dataset
return tuple(slice(0, extent) for extent in dsetshape)
# if rank == 1:
# TODO: make brackets optional for 1d? Or not...
# trimmed = select.
# return slice()

if not select.startswith('['):
msg = "Bad Request: selection query missing start bracket"
Expand All @@ -98,6 +93,10 @@ def _getHyperslabSlices(dsetshape, select):
select = select[1:-1]

select_array = select.split(',')
if len(select_array) > len(dsetshape):
msg = "Bad Request: number of selected dimensions exceeds the rank of the dataset"
raise HTTPError(400, reason=msg)

slices = []
for dim, dim_slice in enumerate(select_array):
extent = dsetshape[dim]
Expand Down
3 changes: 1 addition & 2 deletions src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ export class HdfDatasetModelBase extends DataModel {
const params = {
fpath: this._fpath,
uri: this._uri,
col: [colStart, colStop],
row: [rowStart, rowStop]
select: `[${rowStart}:${rowStop}, ${colStart}:${colStop}]`
};
hdfDataRequest(params, this._serverSettings).then(data => {
this._blocks[rowBlock][colBlock] = data;
Expand Down
24 changes: 7 additions & 17 deletions src/hdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,12 @@ export function hdfDataRequest(
parameters: IContentsParameters,
settings: ServerConnection.ISettings
): Promise<number[][]> {
// require the uri, row, and col query parameters
const { fpath, uri, row, col } = parameters;

// Remove
console.log("TEST QUERY: " + URLExt.objectToQueryString({ "test-slice": "[0:1, 3:4, 5:6, 0:-1]"}));
console.log("TEST QUERY: " + URLExt.objectToQueryString({ "test-lists": [[0, 1], [1, 2], [3, 4], [5, 6]]}));
// Remove
// require the uri query parameter, select is optional
const { fpath, uri, ...select } = parameters;

const fullUrl =
URLExt.join(settings.baseUrl, "hdf", "data", fpath).split("?")[0] +
URLExt.objectToQueryString({ uri, row, col });

console.log("fullUrl: " + fullUrl);
URLExt.objectToQueryString({ uri, ...select });

return ServerConnection.makeRequest(fullUrl, {}, settings).then(response => {
if (response.status !== 200) {
Expand All @@ -112,14 +105,11 @@ export interface IContentsParameters {
uri: string;

/**
* Row slice. Up to 3 integers, same syntax as for Python `slice` built-in.
*/
row?: number[];

/**
* Column slice. Up to 3 integers, same syntax as for Python `slice` built-in.
* String representing an array of slices that determine a
* hyperslab selection of an HDF5 dataset. Syntax and semantics
* matches that of h5py's Dataset indexing.
*/
col?: number[];
select?: string;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,9 @@ function addBrowserCommands(
fpath: args["fpath"] as string,
uri: args["uri"] as string
};
if (args["col"]) {
params.col = args["col"] as number[];
if (args["select"]) {
params.select = args["select"] as string;
}
if (args["row"]) {
params.row = args["row"] as number[];
}

return hdfContentsRequest(params, serverSettings);
},
label: "For an HDF5 file at `fpath`, fetch the contents at `uri`"
Expand Down

0 comments on commit 013e9f4

Please sign in to comment.