Skip to content

Commit

Permalink
added extra help documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
samirchowdhury committed Dec 18, 2021
1 parent d5a15b4 commit cebc899
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 18 deletions.
18 changes: 18 additions & 0 deletions code/neumapper/find_cluster_cutoff.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
function [Z, cutoff] = find_cluster_cutoff(distMat, num_bins_clustering, linkage_method)
% Function find_cluster_cutoff
%
% Helper function used internally for get_cluster_bins.m
%
% Inputs:
% distMat : distance matrix restricted to the elements of a
% cover bin
% num_bins_clustering : Positive integer used to define the histogram.
% Default = 10 when used in neumapper
% linkage_method : Type of hierarchical clustering.
% Default = 'single'
%
% Outputs:
% Z : output of linkage function
% cutoff : threshold value used for subdividing cover bin into cluster
% bins
%

Z = linkage(distMat(tril(true(length(distMat)),-1))', linkage_method);

lkg_vals = unique(Z(:,3));
Expand Down
34 changes: 31 additions & 3 deletions code/tools/constructNPYheader.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@



function header = constructNPYheader(dataType, shape, varargin)
% Original repository: https://github.com/kwikteam/npy-matlab
% Please see below for details, and credit the original authors if you use
% this file.
%
% BSD 2-Clause License
%
% Copyright (c) 2015, npy-matlab developers
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%


if ~isempty(varargin)
fortranOrder = varargin{1}; % must be true/false
Expand Down
38 changes: 32 additions & 6 deletions code/tools/datToNPY.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@


function datToNPY(inFilename, outFilename, dataType, shape, varargin)
% Original repository: https://github.com/kwikteam/npy-matlab
% Please see below for details, and credit the original authors if you use
% this file.
%
%
% function datToNPY(inFilename, outFilename, shape, dataType, [fortranOrder, littleEndian])
%
% make a NPY file from a flat binary file, given that you know the shape,
Expand All @@ -10,7 +13,33 @@ function datToNPY(inFilename, outFilename, dataType, shape, varargin)
% existing binary file - instead you can just create the appropriate header
% and then concatenate it with the data.
%
% ** completely untested
% BSD 2-Clause License
%
% Copyright (c) 2015, npy-matlab developers
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%


if ~isempty(varargin)
fortranOrder = varargin{1}; % must be true/false
Expand All @@ -22,9 +51,6 @@ function datToNPY(inFilename, outFilename, dataType, shape, varargin)

header = constructNPYheader(dataType, shape, fortranOrder, littleEndian);

% ** TODO: need to put the header into a temp file instead, in case the
% outFilename is the same as the inFilename (and then delete the temp file
% later)
fid = fopen(tempFilename, 'w');
fwrite(fid, header, 'uint8');
fclose(fid)
Expand Down
6 changes: 5 additions & 1 deletion code/tools/px_maxmin.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function [L, DL, R] = px_maxmin(varargin)

% Function px_maxmin used for farthest point sampling
% Original authors: Vin de Silva, Patrick Perry, and collaborators from the
% Computational Topology working group at Stanford University. Please see
% below for details, and credit the original authors if you use this code.
%
%PX_MAXMIN -- select landmark points by greedy optimisation
%
% Given a set of N points, PX_MAXMIN selects a subset of n points called
Expand Down
33 changes: 31 additions & 2 deletions code/tools/readNPY.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@


function data = readNPY(filename)
% Function to read NPY files into matlab.
%
% Original repository: https://github.com/kwikteam/npy-matlab
% Please see below for details, and credit the original authors if you use
% this file.
%
% *** Only reads a subset of all possible NPY files, specifically N-D arrays of certain data types.
% See https://github.com/kwikteam/npy-matlab/blob/master/tests/npy.ipynb for
% more.
%
% BSD 2-Clause License
%
% Copyright (c) 2015, npy-matlab developers
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%

[shape, dataType, fortranOrder, littleEndian, totalHeaderLength, ~] = readNPYheader(filename);

Expand Down
35 changes: 32 additions & 3 deletions code/tools/readNPYheader.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@


function [arrayShape, dataType, fortranOrder, littleEndian, totalHeaderLength, npyVersion] = readNPYheader(filename)
% Original repository: https://github.com/kwikteam/npy-matlab
% Please see below for details, and credit the original authors if you use
% this file.
%
% function [arrayShape, dataType, fortranOrder, littleEndian, ...
% totalHeaderLength, npyVersion] = readNPYheader(filename)
%
% parse the header of a .npy file and return all the info contained
% therein.
%
%
% Based on spec at http://docs.scipy.org/doc/numpy-dev/neps/npy-format.html

%
% BSD 2-Clause License
%
% Copyright (c) 2015, npy-matlab developers
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
fid = fopen(filename);

% verify that the file exists
Expand Down
34 changes: 31 additions & 3 deletions code/tools/writeNPY.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@


function writeNPY(var, filename)
% function writeNPY(var, filename)
%
% Original repository: https://github.com/kwikteam/npy-matlab
% Please see below for details, and credit the original authors if you use
% this file.
%
% Only writes little endian, fortran (column-major) ordering; only writes
% with NPY version number 1.0.
%
% Always outputs a shape according to matlab's convention, e.g. (10, 1)
% rather than (10,).

%
% BSD 2-Clause License
%
% Copyright (c) 2015, npy-matlab developers
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%

shape = size(var);
dataType = class(var);
Expand Down

0 comments on commit cebc899

Please sign in to comment.