Skip to content

Commit 6763ec1

Browse files
committed
Improved the help strings across files in NDH_Tools (ended at read_gpx)
1 parent 400b2a2 commit 6763ec1

32 files changed

+295
-112
lines changed

add_arrow.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@
33

44
def add_arrow(lines, position=None, direction='forward', size=15, color='black'):
55
"""
6-
add an arrow to a line.
6+
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
7+
%
8+
% This function adds an arrow to a line. Adapted from:
9+
% https://stackoverflow.com/questions/34017866/arrow-on-a-line-plot
10+
%
11+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12+
% The inputs are:
13+
% line: Line2D object or list of lines
14+
% position: x-position of the arrow. If None, mean of xdata is taken
15+
% direction: 'left' or 'right'
16+
% size: size of the arrow in fontsize points
17+
% color: if None, line color is taken.
18+
%
19+
%%%%%%%%%%%%%%%
20+
% The outputs are:
21+
%
22+
% N/A
23+
%
24+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25+
"""
726

8-
line: Line2D object or list of lines
9-
position: x-position of the arrow. If None, mean of xdata is taken
10-
direction: 'left' or 'right'
11-
size: size of the arrow in fontsize points
12-
color: if None, line color is taken.
13-
"""
1427
if isinstance(lines,type([])) == 0:
1528
lines = [lines]
1629

add_datavariable_xr.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ def add_datavariable_xr(xarray_dataset,new_datavariable,varname,coordinate_names
55
"""
66
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
77
%
8-
% This function uses xarray to construct a netcdf
8+
% This function takes an existing xarray dataset and adds a new datavariable
9+
% to the existing coordinate axes (assumed to be y and x)
910
%
1011
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1112
% The inputs are:
12-
%
13+
% xarray_dataset -- the existing xarray dataset to be added to
14+
% new_datavariable -- the array containing the new data to be added
15+
% varname -- the name for the new datavariable
16+
% coordinate_names -- default: ['y','x'], the names and order of
17+
% coordinate variables to assign to the dimensions
1318
%
1419
%%%%%%%%%%%%%%%
1520
% The outputs are:
1621
%
17-
%
22+
% The updated xarray dataset
1823
%
1924
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2025
"""

box_from_corners.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import numpy as np
22

3-
43
def box_from_corners(xs,ys):
54
"""
65
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
76
%
8-
% This function prints out the minimum and maximum values of an array
7+
% This function takes x and y edge values for a rectangle, and produces a
8+
% 5x2 array of corner points that trace out the rectangle (for use in plotting)
99
%
1010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111
% The inputs are:
1212
%
13-
% input_array -- array of data to analyze
13+
% xs - 2 value array contaiining the x edges of the rectangle
14+
% ys - 2 value array contaiining the y edges of the rectangle
1415
%
1516
%%%%%%%%%%%%%%%
1617
% The outputs are:
1718
%
18-
% output -- the min and max in a 1x2 array
19+
% box -- the 5x2 array containing the corner points for the rectangle
1920
%
2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2122
"""

calculate_flowlines.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,36 @@ def calculate_flowlines(input_xr,seed_points,uv_varnames=['u','v'],xy_varnames=[
2020
"""
2121
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
2222
%
23-
% This function prints out the minimum and maximum values of an array
23+
% This function takes a vector field described in an xarray dataset, an
24+
% array of points, and calculates flowlines that pass through the array
25+
% points following the vector field.
2426
%
2527
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2628
% The inputs are:
2729
%
28-
% input_xr -- xarray dataarray that has the gradient objects in it
30+
% input_xr -- this must be an xarray dataset with two dataarrays, represting
31+
% the x components and the y components of a vector field. The data
32+
% variables and the coordinate variables that describe them can have
33+
% any name, but the defaults are 'u','v','x','y'.
34+
% seed_points -- this should be an nx2 array containing x/y pairs for seed points
35+
% used to constrain the calculated flowlines
36+
% uv_varnames -- default=['u','v'], these are the datavariable names for the
37+
% vector field components.
38+
% xy_varnames -- default=['x','y'], these are the coordinate variable names
39+
% describing the columns and rows of the vector field arrays
40+
% steps -- default=20000, this is the number of steps to take away from the seed
41+
% in either the forward or backward direction
42+
% ds -- default=2, this is the step-size to take when propagating the flowline away
43+
% from the seedpoint (in the same units as the coordinate variables
44+
% forward0_both1_backward2 -- default=1, this sets whether or not you want
45+
% the flowlines to extend down-vector, up-vector, or
46+
% both from the seed point.
2947
%
3048
%%%%%%%%%%%%%%%
3149
% The outputs are:
3250
%
33-
% output -- the min and max in a 1x2 array
51+
% output -- a list of nx2 arrays containing the flowlines associated with
52+
% each seed point
3453
%
3554
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3655
"""

clipped_colorbar.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ def clipped_colorbar(CS, **kwargs):
55
"""
66
% (C) Nick Holschuh - Amherst College - 2022 ([email protected])
77
% This function restricts the colorbar to the vmin/vmax values, so that
8-
% there aren't large chunks of the colorbar that are a single value. The
9-
% default behavior is make a colorbar that spans the min value to max value,
10-
% not the vmin/vmax.
8+
% there aren't large chunks of the colorbar that are a single value. This
9+
% oposes Matplotlib's default behavior, which is to make a colorbar that
10+
% spans the min value to max value, not the vmin/vmax.
1111
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1212
% The inputs are as follows:
1313
%

cmap_data.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import matplotlib
22

3-
43
def cmap_data(colormapname):
54
"""
65
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
76
%
8-
% This function gets the colormap object for value extraction
7+
% This function gets the colormap object from matplotlib for value extraction
98
%
109
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1110
% The inputs are:

compare_list.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ def compare_list(list1,list2):
44
"""
55
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
66
%
7-
% This function tests the equality of every item in a list
7+
% This function compares entire lists, and spits out two comparative statistics:
8+
% 1 -- Are all items across both lists both the same shape and same value
9+
% 2 -- Are all items across both lists the same value
10+
% 3 -- Are all items across both lists the same shape
811
%
912
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013
% The inputs are:
@@ -13,9 +16,11 @@ def compare_list(list1,list2):
1316
% list2 -- second list to compare
1417
%
1518
%%%%%%%%%%%%%%%
16-
% The outputs are:
19+
% The outputs, following the structure in the headline description:
1720
%
18-
% true/false
21+
% 1: true/false
22+
% 2: true/false
23+
% 3: true/false
1924
%
2025
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2126
"""

cresis_season.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def cresis_season(y,m=0,d=0,ant1_gre2=1):
1313
"""
1414
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
1515
%
16-
% This function finds the season name associated with a flight day
17-
% There are a small number of flight days in which both campaigns
16+
% This function finds the season name associated with a flight day.
17+
% There are a small number of flight days in which two campaigns
1818
% were running apparently. By default, this code will assume you want
19-
% the Antarctic Season. If you would prefer it prompt you to ask for
20-
% a selection, chanage the value to zero.
19+
% the Antarctic Season. You can force it to take the greenland season using
20+
% the given flag.
2121
%
2222
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2323
% The inputs are:

crop_image.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
def crop_image(inimage,outimage,margin=0):
55
"""
66
% (C) Nick Holschuh - Penn State University - 2015 ([email protected])
7-
% This function takes an image file and removes the solid white margins.
7+
% This function takes an image file and removes solid white margins.
88
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
% The inputs are as follows:
1010
%
11-
% inimage -- the filename for the video to crop
12-
% outimage -- the filename to write the cropped video to
13-
% margin=0 -- the number of additional rows/columns to add as buffer
11+
% inimage -- the filename for the image to crop
12+
% outimage -- the filename to write the cropped image to
13+
% margin=0 -- the number of additional rows/columns to add as buffer.
14+
% higher numbers here increases the addition of white margin
1415
%
1516
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1617
% The outputs are as follows:
@@ -23,7 +24,9 @@ def crop_image(inimage,outimage,margin=0):
2324

2425
frame_aggregate = imageio.imread(inimage)
2526

27+
######### Find the rows that are solid white
2628
row_margin = np.where(np.mean(frame_aggregate,0) == 255)[0]
29+
######### Find where the indeces of those rows jumps (as in, where the image is)
2730
middle = np.where(np.diff(row_margin) > 1)[0]
2831
x = row_margin[middle[0]]-margin
2932
w = row_margin[middle[-1]+1]-row_margin[middle[0]]+2*margin

crop_video.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def crop_video(invideo,outvideo,margin=0):
1111
%
1212
% invideo -- the filename for the video to crop
1313
% outvideo -- the filename to write the cropped video to
14-
% margin=0 -- the number of additional rows/columns to add as buffer
14+
% margin=0 -- the number of additional rows/columns to add as buffer.
15+
% higher numbers here increases the addition of white margin
1516
%
1617
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1718
% The outputs are as follows:

crossovers.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22

33

44
def crossovers(line1,line2):
5-
5+
"""
6+
% (C) Nick Holschuh - Amherst College -- 2024 ([email protected])
7+
% This function takes two lines and calculates any crossover points they may have
8+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9+
% The inputs are as follows:
10+
%
11+
% line1 -- this takes an nx2 array with x and y coordinates for the first line
12+
% line2 -- this takes an nx2 array with x and y coordinates for the second line
13+
%
14+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15+
% The outputs are as follows:
16+
%
17+
% crossover_dictionary -- the outpuut is a dictionary containing two things:
18+
% 1: The indecies in line1 and line 2 that are nearest to the crossover
19+
% 2: The position of the true crossover coordinates
20+
%
21+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22+
%%
23+
"""
624
import numpy.core.umath_tests as ut
725

826
x_down = line1[:,0]

depth_shift.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def depth_shift(data,time,surface,elevation,bed=[],disp_flag=0):
3434
%%
3535
"""
3636

37-
if np.nanmin(np.mod(surface,1)) == 0:
37+
if np.nanmax(np.mod(surface,1)) == 0:
3838
ind_flag = 1;
3939
else:
4040
ind_flag = 0;

edgetrim_mask.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ def edgetrim_mask(edge_trim_array, debug_flag=0, start_trim=0, end_trim=0, addit
99
%
1010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1111
% The inputs are:
12-
%
12+
% edge_trim_array -- this is typically a 64xn array, with values only
13+
% where edge trim values have been identified.
14+
% These typically are the 8th entry in the 'y' object
15+
% of a CSARP_surf file
16+
% debug_flag=0 -- this will produce a plot at the end showing the edge mask
17+
% start_trim=0 -- this removes additional columns at the front of the mask
18+
% end_trim=0 -- this removes additional columns from the end of the mask
19+
% additional_narrowing=0 -- this takes from both sides relative to the edge trim
1320
%
1421
%%%%%%%%%%%%%%%
1522
% The outputs are:
1623
%
17-
%
24+
% mask -- a 64xn array of zeros and ones defined by the trim values
1825
%
1926
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2027
% the edge trim array is typically surf_data['surf']['y'][7]
@@ -59,7 +66,7 @@ def edgetrim_mask(edge_trim_array, debug_flag=0, start_trim=0, end_trim=0, addit
5966

6067

6168
if debug_flag:
62-
import matplotlib.pyplot as pltdd
69+
import matplotlib.pyplot as plt
6370
plt.imshow(mask)
6471
plt.plot(et_col,et_row,'o',c='red')
6572
plt.plot(col_opts,left_row,'-',c='black')

elevation_shift.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def elevation_shift(data,time,surface,elevation,bed,disp_flag=0):
3434
%%
3535
"""
3636

37-
if np.nanmin(np.mod(surface,1)) == 0:
37+
if np.nanmax(np.mod(surface,1)) == 0:
3838
ind_flag = 1;
3939
else:
4040
ind_flag = 0;

find_COPdem_fn.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@
77

88
def find_COPdem_fn(lat,lon):
99
"""
10-
This is a function that outputs the filename associated wtih the desired latitude & longitude
11-
"""
12-
10+
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
11+
%
12+
% This is a function that outputs the filename associated wtih the
13+
% desired latitude & longitude of the COPdem
14+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15+
% The inputs are:
16+
%
17+
% lat -- individual latitude value to use for search
18+
% lon -- individual longitude value to use for search
19+
%
20+
%%%%%%%%%%%%%%%
21+
% The outputs are:
22+
%
23+
% file_info -- the filename for the COPDem tile that you want
24+
%
25+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26+
"""
27+
1328
from NDH_Tools import find_nearest_xy
1429
from NDH_Tools import loadmat
1530

find_cresisfiles.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
################################################################################################
1010

1111

12-
def find_cresisfiles(y,m=0,d=0,seg=0,frame=0):
12+
def find_cresisfiles(y,m=0,d=0,seg=0,frm=0):
1313
"""
1414
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
1515
%
@@ -21,7 +21,8 @@ def find_cresisfiles(y,m=0,d=0,seg=0,frame=0):
2121
% y - either the year, or a string for the filename you want the season for
2222
% m - the month
2323
% d - the day
24-
% ant1_gre2 - force a particular continent for days where there are surveys in both places
24+
% seg - the segment number
25+
% frm - the frame number
2526
%
2627
%%%%%%%%%%%%%%%
2728
% The outputs are:

find_nearest.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import numpy as np
22

3-
def find_nearest(vector_2_search,value,how_many=1):
3+
def find_nearest(vector_2_search,value):
44
"""
55
% (C) Nick Holschuh - Penn State University - 2013 ([email protected])
66
% In the way that the find commands finds values in a matrix identical to
77
% the search vector, this command finds the nearest entry.
88
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
% The inputs are:
1010
%
11-
% vector_2_search = The set of data that you want to search. Each entry
12-
% should be a row. This also works with a n x m x 2
13-
% matrix to search, with x y pairs in the 3rd dimension.
14-
% value = The value you want to find within "vector_2_search" (row vector)
15-
% how_many = The function will find the x nearest values to "value", where
16-
% x is an integer defined by "how_many"
17-
%
11+
% vector_2_search = The set of data that you want to search. Should be a
12+
% 0 or 1 dimensional array (I don't get zero dimensional arrays)
13+
% value = The value you want to find within "vector_2_search". Can be
14+
% a single value or an array of values.
1815
%
1916
%%%%%%%%%%%%%%%
20-
% The outputs are:
17+
% The output is a dictionary containing:
18+
%
19+
% index = the index values for the location within "vector_2_search" where
20+
% the nearest possible values are stored.
2121
%
22-
% index = the index values for the location within "vector_2_search" where
23-
% the nearest possible values are stored.
22+
% distance = the distance between the values and their nearest point within
23+
% the vector_2_search
2424
%
25-
% results = the values themselves within the vector.
25+
% results = the values themselves within the vector.
2626
%
2727
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2828
"""

0 commit comments

Comments
 (0)