Python API
This section serves as reference for contributors who are looking to understand NcCut’s underlying structure. This is not a user facing API.
Builds app and sets initial window.
Creates the widget tree and sets the initial window size. To load app, run NcCut().run()
- class nccut.nccut.NcCut(file=None, config=None, **kwargs)
Bases:
AppBuilds app and widget tree.
Creates the initial window and ensures font sizes in the app update uniformly when the window resizes.
- build()
Override App class build method and return widget tree.
- Returns
Root of widget tree
- on_resize(*args)
Triggers font adjustments when the window size is adjusted.
- Parameters:
*args – Accepts args App class supplies though they aren’t needed.
- on_start()
Sets initial window size according to operating system.
nccut.nccut module
Builds app and sets initial window.
Creates the widget tree and sets the initial window size. To load app, run NcCut().run()
- class nccut.nccut.NcCut(file=None, config=None, **kwargs)
Bases:
AppBuilds app and widget tree.
Creates the initial window and ensures font sizes in the app update uniformly when the window resizes.
- build()
Override App class build method and return widget tree.
- Returns
Root of widget tree
- on_resize(*args)
Triggers font adjustments when the window size is adjusted.
- Parameters:
*args – Accepts args App class supplies though they aren’t needed.
- on_start()
Sets initial window size according to operating system.
nccut.dropdowns module
Functionality for the setting dropdown menus.
Creates the dropdown lists for the various setting dropdown menus. Manages the execution of setting changes when they occur. This module only defines the dynamic aspect of the menus. Static aspects are in the nccut.kv file.
- class nccut.dropdowns.CircleSizeDropDown(**kwargs)
Bases:
DropDownDynamic elements of the circle size drop down menu.
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- pass_setting(cir_size)
Pass new circle size to display.
- Parameters:
cir_size – New circle size value
- class nccut.dropdowns.LineColorDropDown(**kwargs)
Bases:
DropDownDynamic elements of the line color drop down menu.
- app
Reference to current running app
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- pass_setting(line_color)
Passes new line color to display
- Parameters:
line_color (str) – New line color. Either Blue, Orange, or Green.
- class nccut.dropdowns.NetCDFDropDown(**kwargs)
Bases:
DropDownDynamic elements of the NetCDF setting menu
Creates all dropdown lists and executes all setting changes. Other settings are defined statically in nccut.kv file.
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- font
Font size for app
- cmap_dropdown
Color map selection kivy.uix.dropdown.Dropdown object
- var_dropdown
Variable selection kivy.uix.dropdown.Dropdown object
- depth_dropdown
Z dimension value selection kivy.uix.dropdown.Dropdown object
- pass_setting(setting, value)
Pass setting changes to display.
- Parameters:
setting (str) – Name of setting being changed.
value – New setting value of appropriate data type for setting
nccut.filedisplay module
Functionality for viewing window and interactive display.
This module manages the scrolling, rotation, and flipping of the image. It also executes the creation of and updates made to the image/dataset being displayed. The dragability of the image is managed by the parent ScatterLayout class. Manages the creation and deletion of tools.
- class nccut.filedisplay.FileDisplay(home, f_config, g_config, t_config, **kwargs)
Bases:
ScatterLayoutCreation and management of the interactive display.
If file is a NetCDF file it turns dataset into an image according to settings. Loads image and updates it when settings are changed. Also manages the scrolling, flipping, and rotating of the image.
- config
A dictionary holding info about the file necessary for loading, updating, and accessing data from the file. Highest level should have one key that is the name of the file type (“image” or “netcdf”) whose value is the necessary configuration settings. For images, the config dictionary has form {“image”: str(file_path)}. For a netcdf file the value is a dictionary of configuration values (see
nccut.netcdfconfig.NetCDFConfig.check_inputs()for structure of dictionary)- Type:
dict
- default_orthogonal_width
Default width for the orthogonal transect tool
- f_type
File type being loaded (“image” or “netcdf”)
- Type:
str
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- pos
Position of viewer. Used to properly place transect widgets on screen.
- Type:
tuple
- sidebar
Reference to list of sidebar buttons
- Type:
list
- og_sidebar
Original state of sidebar before any tools added widgets
- Type:
list
- im
kivy.core.CoreImage made from data array
- byte
io.BytesIO object containing image made from NetCDF dataset loaded in memory
- img
kivy.uix.image.Image UI element which displays the image over the scatter object
- tool
Reference to currently loaded tool
- nc_data
If file is a NetCDF file, actively loaded data array
- dragging
Whether in dragging mode or not
- Type:
bool
- editing
Whether in editing mode or not
- Type:
bool
- t_mode
Whether a tool is currently loaded
- Type:
bool
- axis_font
Font to use for the plot axes. Not adjustable.
- Type:
float
- x_pix
- Type:
float
- y_pix
Y coordinate units represented by one pixel
- Type:
float
- x_labels
List of x axis tick labels
- Type:
list
- y_labels
List of y axis tick labels
- Type:
list
- h_flip
Has the data been flipped horizontally
- Type:
bool
- v_flip
Has the data been flipped vertically
- Type:
bool
- contrast
Int from -127 to 127, contrast value to use when making image from NetCDF file
- Type:
int
- l_col
Line color for transect tools: ‘Blue’, ‘Green’ or ‘Orange’
- Type:
str
- cir_size
Circle size for transect tools
- Type:
float
- cmaps
Dictionary of colormap names mapping to colormap values from cv2
- Type:
dict
- colormap
current colormap data
- btn_height
Height for buttons in sidebar which adapts to font size
- tools_lbl
“Tools” sidebar label
- inline_chain_btn
Inline chain button which opens inline chain tool
- orthogonal_chain_btn
Orthogonal chain button which opens orthogonal chain tool
- initial_side_bar
List of sidebar buttons in ‘Transect Tools’ sidebar menu
- Type:
list
- tool_actions_lbl
“Tool Actions” sidebar label
- new_chain_btn
New Chain button to be loaded when in transect mode
- drag_btn
Drag button to be loaded when in transect mode
- edit_btn
Edit button to be loaded when in transect mode
- close_tool_btn
Button to close currently loaded tool
- chain_data_lbl
“Chain Data” sidebar label
- open_data_btn
Button to open previously exported chain data
- tool_sb_widgets_constant
Initial list of widgets in main tool meny menu, not including any widgets added by the tool
- tool_sb_widgets
List of widgets in main tool menu at any given moment
- drag_mode_lbl
“Drag Mode” sidebar label
- tran_mode_btn
Button to close Drag Mode
- edit_mode_lbl
“Edit Mode” sidebar label
- back_btn
Back button for editing mode
- delete_chain_btn
Delete chain button
- delete_point_btn
Delete point button
- edit_widgets
List of widgets that must be added to screen when entering editing mode
- Type:
list
- add_to_sidebar(element, index=-1)
Adds elements to the dynamic sidebar.
- Parameters:
element – List of kivy.uix.Widget to add to sidebar
index (int) – Index in which to insert elements. Default is -1 which adds it to bottom of sidebar.
- close_tool(*args)
Closes tool and resets sidebar elements to non tool state.
- Parameters:
args – Unused arguments passed to the method
- drag_mode(*args)
Calls for transecting tool to turn dragging mode on if off and off if on
- Parameters:
*args – Unused arguments passed to method when called.
- edit_mode(*args)
Turns editing mode on if off and off if on.
When editing mode is being turned on, all sidebar buttons below ‘Actions’ label are added to a temporary holding list and then replaced with editing buttons. When editing mode is turned off, the editing buttons are removed and the original buttons are returned to the sidebar.
- Parameters:
*args – Unused arguments passed to method when called.
- flip_horizontally()
Flips display horizontally
- flip_vertically()
Flips display vertically
- font_adapt(font)
Update editing mode button and color bar font sizes.
- Parameters:
font (float) – New font size
- load_image()
Creates UI Image element, loads it in viewer, and scales it to window size.
- manual_check_file(text)
When native file browser is not working, checks manually entered text is a valid file path.
- Parameters:
text – User entered file path
- netcdf_to_image()
Creates image from NetCDF dataset defined in
nccut.filedisplay.FileDisplay.f_configNormalizes data and then applies colormap and contrast settings and then calls for the creation of colorbar. Loads image into memory as io.BytesIO object so kivy can make image out of an array.
- on_key(*args)
If escape key is pressed, tool is loaded, and plot menu is not open then delete chain
- Parameters:
args – Index 1 is key ascii code
- on_touch_down(touch)
If touch is of a scrolling type zoom in or out of the image.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- on_touch_move(touch)
Calls for axes to update when plot is moved.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- open_data_pop()
Opens native operating system file browser to allow user to select previously exported file
- remove_from_tool_sb_widgets(element)
Removes element from widgets in main tool sidebar menu.
- Parameters:
element – kivy.uix.Widget to remove
- resize_to_fit(*args)
Resizes image to be just large enough to fill viewer screen. Method is bound to size property.
- Parameters:
args – Two element list of object and it’s size
- tool_btn(t_type)
Manages the creation and deletion of each tool.
If a tool is currently loaded, remove it, switch cursor to an arrow and clean up. If not, load indicated tool and switches cursor to a cross.
- Parameters:
t_type (str) – Tool type: ‘inline_chain’ or ‘orthogonal_chain’
- update_netcdf()
Reload netcdf image when netcdf data is changed.
- update_settings(setting, value)
Updates app settings depending on context of setting
- Parameters:
setting (str) – Name of setting being changed
value – New setting value of appropriate data type
- x_axis()
Chooses x-axis tick distributions, calculates their locations, and draws them.
- y_axis()
Chooses y-axis tick distributions, calculates their locations, and draws them.
nccut.functions module
Miscellaneous helper functions to support other widgets.
Provides reference to custom UI elements defined in nccut.kv file so they can be used in python scripts. Contains error banner functionality, file management function, and transect taking function.
- class nccut.functions.AlertPopup(**kwargs)
Bases:
PopupDisplays a popup with the given message as well as a back button. Adapts to the height of the text.
UI Code for this is in nccut.kv. This code outlines the functionality for the popup.
- quit()
Closes popup
- set_message(message)
Sets popup message
- Parameters:
message (str) – Text to display
- update_height(height)
Updates popup height to match text height
- Parameters:
height – Text height
- class nccut.functions.BackgroundLabel(background_color=[0, 0, 0, 1], **kwargs)
Bases:
LabelCode for this is in nccut.kv. Referenced here so it can be used in scripts.
- class nccut.functions.Click(x, y)
Bases:
objectObject that mimics a user click.
- x
X coordinate of click point
- Type:
float
- y
Y coordinate of click point
- Type:
float
- pos
2 element tuple: (X coord, Y coord)
- Type:
tuple
- class nccut.functions.RoundedButton(**kwargs)
Bases:
ButtonCode for this is in nccut.kv. Referenced here so it can be used in scripts.
- class nccut.functions.SidebarHeaderLabel(text='', **kwargs)
Bases:
BackgroundLabel- update_line(*args)
Update the line position when the label moves or resizes.
- update_text_size(*args)
Ensure text_size always matches the label’s size.
- nccut.functions.alert(text, home)
Creates alert banner.
Creates alert banner with given text and adds it to top left corner of the home screen. Schedules it to be removed after 2 seconds.
- Parameters:
text (str) – Alert banner message
home – Active
nccut.homescreen.HomeScreenreference
- nccut.functions.alert_popup(text)
Creates popup with an alert with given text.
- Parameters:
text (str) – Alert message
- nccut.functions.chain_find(data, res, need, c_type)
Recursively examines dictionary and determines if dictionary is valid project file containing the needed fields.
- Parameters:
data (dict) – Dictionary to examine
res (list) – Empty list to fill with chain click coordinates and orthogonal transect widths
need (list) – List of required fields to qualify as an orthogonal chain: [“Click <cord>”, “Click <cord>”, “Width”]
c_type – Type of chain to look for
- Returns:
click X coords, click y coords, and the orthogonal transect width for each click point in the chain. If no qualifying data was found returns empty list. If duplicate data is found (ex: multiple variables in a file) only returns one instance of orthogonal chain data.
- Return type:
Nested List. A list containing a list for each orthogonal chain which each contains three lists
- nccut.functions.contrast_function(value)
Function to transform a setting value to the actual contrast value to apply with PIL.
Transforms domain [-20, 20] to [0, 2]
- Parameters:
value (int) – The user selected contrast setting value
- Returns:
Float, contrast value to actually apply to the image.
- nccut.functions.convert_found_coords(found, config)
If coordinates from loaded project file came from the currently loaded NetCDF file convert the coordinates to pixel coordinates for plotting the chains on the viewer.
- Parameters:
config
found – The found chains from the project file that have already been verified to have come from the current NetCDF file. A list containing a list for each chain which contains three lists: [X Coord List, Y Coord List, Width List]
- Returns:
The original found list except the Click points have been converted to pixel coordinates
- nccut.functions.correct_test(data, need)
Check if dictionary has necessary fields to be an orthogonal chain
- Parameters:
data (dict) – Dictionary to be tested.
need (list) – List of required fields to qualify as an orthogonal chain: [“Click <cord>”, “Click <cord>”, “Width”]
- Returns:
Boolean, whether dictionary has necessary keys with a list has the value
- nccut.functions.coverage(d_min, d_max, l_min, l_max)
Calculates coverage score
- Parameters:
d_min – Start of data range
d_max – End of data range
l_min – Start of proposed label sequence
l_max – End of proposed label sequence
- Returns:
Coverage score that encourages balanced labels with roughly equal amounts of whitespace on both ends, with rarely more than 20% whitespace
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.coverage_max(d_min, d_max, span)
Calculates maximum possible coverage score
- Parameters:
d_min – Start of data range
d_max – End of data range
span – Length of label range
- Returns:
Maximum possible coverage score for the data range and current label range
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.density(k, m, d_min, d_max, l_min, l_max)
Calculates density score
- Parameters:
k – Number of labels in label sequence
m – User provided target label density
d_min – Start of data range
d_max – End of data range
l_min – Start of proposed label sequence
l_max – End of proposed label sequence
- Returns:
Density score based on how close the label density is to the user provided target density
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.density_max(k, m)
Calculates maximum possible density score.
- Parameters:
k – Number of labels in label sequence
m – User provided target label density
- Returns:
Maximum possible density score given the current number of labels in the sequence and the provided target density
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.find_config(config_file)
Looks for nccut_config.toml file. If found, validates and applied configuration changes.
Looks for an environment variable ‘NCCUT_CONFIG’ holding the config file. If not found, looks in the current working directory and then in either ‘%APPDATA%
ccut ccut_config.toml’ on Windows or
‘~/.config/your_app/config.toml’ on Linux and macOS
- Args:
- config_file (str): Path to configuration file given by user on command line start. Empty string if none was
given.
- Returns:
If valid configuration file, returns dictionary of config values. If none was found or invalid, returns empty dictionary.
- nccut.functions.get_color_bar(colormap, data, face_color, text_color, font)
Create color bar image according to colormap and dataset
- Parameters:
colormap – cv2 colormap
data – 2D indexable array of numerical data to apply the to
face_color – Color (R, G, B) to use as the background color for the image
text_color (str) – Color to use as text color
font (float) – Font to use for tick labels
- Returns:
kivy.uix.image.Image object containing image of colorbar
- nccut.functions.ip_get_points(line, curr, config)
Creates a data frame containing x, y, and value of points on transect line
From end points finds points of line connecting them. Interpolates higher resolution version of given data set, and then grabs data values at each line point. If the file is a NetCDF file with valid coordinates the x, y coordinates are translated to the selected NetCDF coordinates
- Parameters:
line – 4 element 1D array with coordinates of the two transect end points: [X1, Y1, X2, Y2]
curr – 2D indexable array of data in which the transect was taken.
config (dict) – Information necessary for accessing the file. For images this is the file path and for NetCDF files this is a dictionary of configuration values (see
nccut.netcdfconfig.NetCDFConfig.check_inputs()for structure of dictionary)
- Returns:
- ‘x’: 1D array of x-coordinates of transect points. If valid NetCDF is loaded these are interpolated from the
selected x dimension
- ’y’: 1D array of y-coordinates of transect points. If valid NetCDF is loaded these are interpolated from the
selected y dimension
- ’Cut’: 1D array of data values at each point along line connecting end points. If from an image the data
value is the mean of the pixel RGB values. If from a NetCDF file the data comes from the loaded Dataset.
- Return type:
Dictionary with three keys
- nccut.functions.label_placer(d_min, d_max, m, q_arr=array([1, 5, 2, 4, 3]), w=array([0.2, 0.25, 0.5, 0.05]))
Algorithm for determining ideal axis labels in a way that optimizes a simplicity, legibility, coverage, and density score.
- Parameters:
d_min – Start of data range
d_max – End of data range
m – User provided target label density
q_arr – Preference-ordered list of ‘nice numbers’ to choose from
w – Four element array of weights for the four axis qualities used to calculate final score
- Returns:
Array of selected axis labels. This implementation of Talbot (et al.)’s algorithm omits the legibility score.
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.remove_alert(alert, home, *largs)
Remove alert banner.
- Parameters:
alert – Alert kivy.uix.label.Label reference.
home – Active
nccut.homescreen.HomeScreeninstance.*largs – Unused args from kivy Clock class.
- nccut.functions.simplicity(q, q_arr, j, l_min, l_max, l_step)
Calculates simplicity score
- Parameters:
q – Current step size
q_arr – Preference-ordered list of ‘nice numbers’ to choose from
j – Amount of elements to skip in current step size sequence
l_min – Start of labeling sequence
l_max – End of labeling sequence
l_step – Labeling sequence step size
- Returns:
Simplicity score that prefers step sizes that appear earlier in Q, penalizes large j’s, and rewards label sequences that include 0.
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.simplicity_max(q, q_arr, j)
Calculates maximum possible simplicity score
- Parameters:
q – Current step size
q_arr – Preference-ordered list of ‘nice numbers’ to choose from
j – Amount of elements to skip in current step size sequence
- Returns:
Maximum possible simplicity score for current step size and skip amount
References
- Talbot, Lin and Hanrahan, ‘An Extension of Wilkinson’s Algorithm for Positioning Tick Labels on Axes’,
IEEE Transactions on Visualization and Computer Graphics (2010)
- nccut.functions.subset_around_transect(config, points)
Determines and loads a subset of the data that surrounds the transect.
- Parameters:
config – config (dict): Information necessary for accessing the loaded data. For images this is the file path and for NetCDF files this is a dictionary of configuration values (see
nccut.netcdfconfig.NetCDFConfig.check_inputs()for structure of dictionary)points – 4 element 1D array with coordinates of the two transect end points: [X1, Y1, X2, Y2]
- Returns:
Subset of data, rescaled points [X1, Y1, X2, Y2], list of [X, Y] rescale factors>. If passed data is an image doesn’t do sub-secting since efficiency is less of an issue.
- nccut.functions.text_wrap(*args)
Updates a widgets text box so that it is always within the bounds of the widget.
- Parameters:
args – List where first item is a Button or Label and the second item is a tuple of that widgets current size.
- nccut.functions.validate_config(config)
Given a dictionary parsed from a configuration file, ensures that no invalid elements or values are present.
- Parameters:
config – Dictionary parsed from a configuration file of configuration sections, keys, and values
- Returns:
True if configuration is valid, False if any invalid elements or values we’re found
nccut.homescreen module
Functionality for the main screen as well as root of widget tree.
This module manages the functionality of the home screen elements. It also serves as the root node for the app and passes necessary commands to their appropriate recipient further down the tree.
- class nccut.homescreen.HomeScreen(btn_img_path, file=None, conf=None, **kwargs)
Bases:
ScreenManages the dynamic functionality of the main screen UI elements. Creates and calls upon other modules to execute GUI operations.
- general_config
Dictionary of default configuration values
- btn_img_path
Path to location of settings bar button icons
- file_on
Whether there is a file currently loaded in viewer
- Type:
bool
- loaded
Whether the window has fully loaded
- Type:
bool
- rel_path
pathlib.Path object to use as output directory
- font
Current font size for all buttons
- Type:
float
- display
FileDisplay object (draggable image) created when a file is loaded
- nc_popup
Reference to NetCDF configuration popup
- plot_popup
Plotting popup, held here so can be loaded in testing framework
- file
File if one was given on start up from command line, otherwise None
- color_bar_box
BoxLayout containing colorbar and related graphics
- cb_bg
Background for colorbar box
- netcdf_info
Label object containing information about NetCDF file if it has necessary attributes
- sidebar_spacer
Spacer to fill any remaining area in dynamic sidebar not filled by widgets
- settings_bar
SettingsBar object holding view manipulation buttons and NetCDF menu
- browse()
Opens native operating system file browser to allow user to select their file
- canvas_remove(item, *largs)
Allows external sources to clear canvas.
- Parameters:
item – Canvas item to be removed
*largs – Any other args that are passed
- clean_file()
Resets file related attributes.
- font_adapt()
Updates font size throughout widget tree to the size automatically determined for static UI elements.
When the window is resized Kivy automatically updates the font size of UI elements defined in nccut.kv but not those defined in scripts. Thus, this method updates font size for such elements to be the same as the static elements.
- initial_load()
If a file was given on start up, wait until app is fully loaded and then load given file.
- load_btn()
If file name is valid and exists, load image or NetCDF File.
If a file and any transect tools are already loaded, first clears viewer.
- load_colorbar_and_info(colorbar, config)
Adds colorbar image and NetCDF file information bar to viewer.
- Parameters:
colorbar – kivy.uix.image.Image, colorbar graphic
config (dict) – A dictionary holding info about the file necessary for loading, updating, and accessing data from the file. Highest level should have one key that is the name of the file type (“image” or “netcdf”) whose value is the necessary configuration settings. For images, the config dictionary has form {“image”: str(file_path)}. For a netcdf file the value is a dictionary of configuration values (see
nccut.netcdfconfig.NetCDFConfig.check_inputs()for structure of dictionary)
- load_netcdf(config)
Load NetCDF file
- Parameters:
config (dict) – Dictionary of verified NetCDF file configuration settings. Check FileDisplay for more details
- populate_dynamic_sidebar(elements)
Removes current sidebar elements and replaces them with the widgets provided.
- Parameters:
elements (list) – List of widgets to add. Assumes all have the same height.
- update_cb_bg(*args)
Update size and position of color bar box when app window is resized
- Parameters:
args – 2 element list of object and the new size/position
- update_colorbar(colorbar)
Changes colorbar to new colorbar
- Parameters:
colorbar – kivy.uix.image.Image, colorbar graphic
nccut.orthogonalchain module
Singular orthogonal chain widget.
Graphics and functionality of a singular orthogonal chain created by the orthogonal chain tool.
- class nccut.orthogonalchain.OrthogonalChain(home, width, **kwargs)
Bases:
WidgetSingular orthogonal chain widget.
Graphics and functionality of an orthogonal chain created by the orthogonal chain tool. Determines endpoints of where transects should be made orthogonally to the user marked out line, and then stores the transects.
- clicks
Number of clicks user has made. Decreases when points are deleted.
- Type:
int
- points
List of Tuples, For each click user makes: (X-coord, Y-coord, t_width).
- Type:
list
- t_width
Current width in pixels of orthogonal transects
- Type:
int
- loaded
Whether chain was loaded from file data or clicked out manually
- Type:
bool
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- transects
List of transects made
- Type:
list
- number
kivy.uix.label.Label, Reference to the number label
- size
2 element array of ints, Size of widget
- pos
2 element array of ints, Position of widget
- l_color
kivy.graphics.Color, Color to use for graphics
- c_size
2 element tuple of floats that defines size of circles
- line_width
Width of lines
- Type:
float
- del_point()
Remove most recent point, line, and transect points.
Graphics are grouped by the number of clicks made when they were created for easier deletion.
- draw_dashed_line(group, start, end)
Draws a dashed line on the canvas between two points.
- Parameters:
group – Canvas group to group line segments in
start – Tuple of (x, y) coordinates for the start point.
end – Tuple of (x, y) coordinates for the end point.
- draw_line(instance, pos)
Draw line from most recent click point to user cursor.
Updates anytime cursor moves. Does not draw if not current chain being drawn or if tool in dragging mode. Also won’t draw if chain was loaded and it was final chain.
- Parameters:
instance – WindowSDL instance, current window loaded (not used by method)
pos (tuple) – 2 element tuple of floats, x and y coord of cursor position
- get_orthogonal(line_start, line_end)
Get a line orthogonal to line drawn by user to use as transect.
- Parameters:
line_start – x, y of start point
line_end – x, y of end point
- Returns:
Coordinates of the two endpoints of the centered orthogonal line with length t_width.
- Return type:
4 element array of floats
- in_bounds(points)
Determine if points are within bounds of image.
- Parameters:
points (list) – List of 4 floats, X,Y coords of the two endpoints: [X1, Y1, X2, Y2]
- Returns:
Boolean whether both endpoints are within image bounds
- load_mode(val)
Update whether in load mode or not
- Parameters:
val (bool) – Whether in load mode or not
- on_touch_down(touch)
On user click draws line, endpoints and orthogonal points.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- stop_drawing()
Remove line from most recent point to cursor.
- update_c_size(value)
Updates graphic sizes according to the new circle size value.
- Parameters:
value (float) – New graphics size
- update_l_col(color)
Update the line color and redraw all items on canvas.
- Parameters:
color (str) – New line color to use
- update_width(width)
Update t_width to change width for next transect made.
- Parameters:
width (int) – New width to use
nccut.orthogonalchainwidth module
Orthogonal chain width adjustment tool.
Popup that allows the control of width of orthogonal transects made via the orthogonal chain tool. Ensures given width is within bounds of data.
- class nccut.orthogonalchainwidth.OrthogonalChainWidth(orthogonal_chain, **kwargs)
Bases:
PopupOrthogonal Chain width adjustment tool.
Popup that allows the control of width of orthogonal transects made via the orthogonal chain tool. Ensures given width is within bounds of data.
- spacing
The spacing between widgets in the layout
- txt
kivy.uix.textinput.TextInput widget where user enters their desired width
- btn
‘Set’ Button
- orthogonal_chain
Current
nccut.multiorthogonalchain.MultiOrthogonalChaininstance
- min
Minimum width allowed
- Type:
int
- max
Maximum width allowed
- Type:
int
- update()
Update width of current orthogonal chain if given a valid width.
nccut.multiorthogonalchain module
Orthogonal chain tool widget.
Manages having multiple orthogonal chains on screen at once and the loading of previous chain data.
- class nccut.multiorthogonalchain.MultiOrthogonalChain(home, t_width, b_height, **kwargs)
Bases:
WidgetOrthogonal chain tool widget.
Created when ‘Orthogonal Chain’ button is selected. From there on this object manages the creation, modification, and data packaging of orthogonal chains. Manages the loading of previous chain data into the viewer.
- c_on
Whether there are any chains active
- Type:
bool
- load_fail
If anything has gone wrong in the chain data loading process
- Type:
bool
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- d_btn
RoundedButton, Plot button to activate
nccut.plotpopup.PlotPopup
- dragging
Whether viewer is in dragging mode
- Type:
bool
- width_btn
Button to open transect width adjustment popup
- clicks
Number of clicks made by user. Decreases when points are deleted
- Type:
int
- curr_width
Current orthogonal transect width being used. Used to initialize width of new chains.
- Type:
int
- change_dragging(val)
Change whether in dragging mode or not.
- Parameters:
val (bool) – Whether in dragging mode or not.
- check_file(file)
Checks is given file name is a properly formatted chain data file. If it is it loads file. If not, shows error message.
- Parameters:
file (str) – File path
- del_chain()
Delete most recent chain with some safeguards.
If only one chain on screen, delete but add new chain and remove sidebar elements. Otherwise delete current chain and go to previous. If no chain are on screen nothing happens.
- del_point()
Delete most recently clicked point with some safeguards.
If no chains are on screen does nothing. If only one chain exists and no points have been clicked, does nothing. If more than one chain exists and no points have been clicked on most recent chain, Deletes most recent chain and then deletes last point of previous chain. Any other conditions simply deletes last clicked point.
- font_adapt(font)
Updates font of sidebar elements.
- Parameters:
font (float) – New font size
- gather_popup()
Gather data from chains and call for
nccut.plotpopup.PlotPopup
- load_data(points)
Loads chains from chain data file.
Adds chains by ‘clicking’ the points in the file with the orthogonal transect width denoted by the file
- Parameters:
points – Properly formatted nested list from
nccut.functions.chain_find()function.
- load_fail_alert()
Indicate load has failed
- new_chain()
Creates a new chain if not in dragging or editing mode and current chain has at least two clicks.
- on_touch_down(touch)
Manages when sidebar elements are added to sidebar and clears them as needed. If click is a right click and not the first click creates new chain.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- undo_load(chains)
Remove any previous chains that had been loaded if load fails
- Parameters:
chains (int) – Number of chains added so far
- update_c_size(value)
Asks each chain to update their circle size
- Parameters:
value (float) – New circle size
- update_l_col(color)
Asks each chain to update their line color
- Parameters:
color (str) – New color value: ‘Blue’, ‘Green’ or ‘Orange’
- update_width(num)
Update orthogonal transect width of active chain.
- Parameters:
num (int) – New width value
- width_pop()
Opens transect width adjustment popup
nccut.inlinechain module
Singular inline chain widget.
Graphics and functionality of a singular chain created by the transect chain tool.
- class nccut.inlinechain.InlineChain(home, **kwargs)
Bases:
WidgetSingular inline chain widget.
Graphics and functionality of a singular inline chain created by the inline chain tool. Draws point on each user click and connects points with a line creating a chain of transects.
- clicks
Number of clicks user has made. Decreases when points are deleted.
- Type:
int
- points
List of Tuples, For each click user makes: (X-coord, Y-coord, t_width).
- Type:
list
- loaded
Whether chain was loaded from file data or clicked out manually
- Type:
bool
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- transects
List of transects made
- Type:
list
- curr_line
kivy.graphics.Line, Line between cursor and last clicked
- number
kivy.uix.label.Label, Reference to the number label
- size
2 element array of ints, Size of widget
- pos
2 element array of ints, Position of widget
- l_color
kivy.graphics.Color, Color to use for graphics
- c_size
2 element tuple of floats that defines size of circles
- line_width
Width of lines
- Type:
float
- del_point()
Remove most recent point, line, and transect points.
Graphics are grouped by the number of clicks made when they were created for easier deletion.
- draw_line(instance, pos)
Draw line from most recent click point to user cursor.
Updates anytime cursor moves. Does not draw if not current chain being drawn or if tool in dragging mode.
- Parameters:
instance – WindowSDL instance, current window loaded (not used by method)
pos (tuple) – 2 element tuple of floats, x and y coord of cursor position
- load_mode(val)
Update whether in load mode or not
- Parameters:
val (bool) – Whether in load mode or not
- on_touch_down(touch)
On user click draws line and endpoints.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- stop_drawing()
Remove line from most recent point to cursor.
- update_c_size(value)
Updates graphic sizes according to the new circle size value.
- Parameters:
value (float) – New graphics size
- update_l_col(color)
Update the line color and redraw all items on canvas.
- Parameters:
color (str) – New line color to use
nccut.multiinlinechain module
Transect chain tool widget.
Manages having multiple chains on screen at once.
- class nccut.multiinlinechain.MultiInlineChain(home, b_height, **kwargs)
Bases:
WidgetInline chain tool widget.
Created when ‘Inline Chain’ button is selected. From there on this object manages the creation, modification, and data packaging of inline chains.
- c_on
Whether there are any chains active
- Type:
bool
- load_fail
If anything has gone wrong in the chain data loading process
- Type:
bool
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- d_btn
RoundedButton, Plot button to activate PlotPopup
- dragging
Whether viewer is in dragging mode
- Type:
bool
- clicks
Number of clicks made by user. Does not decrease when points are deleted unless all points are deleted in which case it goes back to zero.
- Type:
int
- change_dragging(val)
Change whether in dragging mode or not.
- Parameters:
val (bool) – Whether in dragging mode or not.
- check_file(file)
Checks is given file name is a properly formatted chain data file. If it is it loads file. If not, shows error message.
- Parameters:
file (str) – File path
- del_chain()
Delete most recent inline chain with some safeguards.
If only one chain on screen, delete but add new inline chain and remove sidebar elements. Otherwise, delete current chain and go to previous. If no chains are on screen nothing happens.
- del_point()
Delete most recently clicked point with some safeguards.
If no chains are on screen does nothing. If only one chain exists and no points have been clicked, does nothing. If more than one chain exists and no points have been clicked on most recent chain, Deletes most recent chain and then deletes last point of previous chain. Any other conditions simply deletes last clicked point.
- font_adapt(font)
Updates font of sidebar elements. :param font: New font size :type font: float
- gather_popup()
Gather data from chains and call for
nccut.plotpopup.PlotPopup
- load_data(points)
Loads chains from chain data file.
Adds chains by ‘clicking’ the points in the file
- Parameters:
points – Properly formatted nested list from
nccut.functions.chain_find()function.
- load_fail_alert()
Indicate load has failed
- new_chain()
Creates a new chain if not in dragging or editing mode and current chain has at least two clicks.
- on_touch_down(touch)
Manages when sidebar elements are added to sidebar and clears them as needed. If click is a right click and not the first click creates new chain.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- undo_load(chains)
Remove any previous chains that had been loaded if load fails
- Parameters:
chains (int) – Number of chains added so far
- update_c_size(value)
Asks each chain to update their circle size
- Parameters:
value (float) – New circle size
- update_l_col(color)
Asks each chain to update their line color
- Parameters:
color (str) – New color value: ‘Blue’, ‘Green’ or ‘Orange’
nccut.netcdfconfig module
UI and functionality for NetCDF configuration popup
Creates the NetCDF configuration popup that opens when a user loads a NetCDF file. Ensures that the file is in a viable configuration for the viewer.
- class nccut.netcdfconfig.ListDropDown(items, button, font, **kwargs)
Bases:
DropDownStandard dropdown for all selections in the menu.
- Inherits attributes from kivy.uix.dropdown.Dropdown
- Type:
see kivy docs
- class nccut.netcdfconfig.NetCDFConfig(file, home, dim_order, **kwargs)
Bases:
PopupUI and functionality for NetCDF configuration popup
Creates the NetCDF configuration popup that opens when a user loads a NetCDF file. Ensures that the file is in a viable configuration for the viewer.
- home
Reference to root
nccut.homescreen.HomeScreeninstance
- file
File path to the NetCDF file
- Type:
str
- data
xarray.Dataset, Opened NetCDF file
- running
Whether the ‘Go’ button has been pressed. Used to prevent user from spamming the button.
- Type:
bool
- var_select
RoundedButton, Variable select button
- var_drop
Dropdown(), Dropdown of variable options
- x_select
Rounded Button, X dimension select button
- y_select
Rounded Button, Y dimension select button
- z_select
Rounded Button, Z dimension select button
- depth_select
Rounded Button, Z dimension value select button
- error
Label for displaying error alerts
- title
Popup title
- content
BoxLayout containing all widgets of the popup
- size_hint
Tuple (width, height) of relative size of popup to window
- Type:
tuple
- check_inputs(*args)
Check selected configurations are valid before loading dataset
When values are selected the button text changes to the selection. This method accesses values from the text of the buttons. If all checks are passed sends dictionary of configurations to HomeScreen instance and closes popup. Otherwise an error message is displayed and popup stays open.
- clean()
Resets file related attributes of the root
nccut.homescreen.HomeScreeninstance
- depth_options(*args)
Creates dropdown for the value of Z dimension if third dimension is selected.
- Parameters:
*args – Unused arguments passed to method
- dim_options(dim, *args)
Creates dropdown for X, Y, or Z dimension selection button. If variable is already selected options listed are all dimensions for selected variable. If variable is not selected sets button to ‘Select …’
- Parameters:
dim – x_select, y_select, or z_select Button
*args – Unused arguments passed to method
- update_depth_btn(*args)
Updates selected depth option to be the first z value from the currently selected z dimension if variable has three dimensions.
- Parameters:
*args – Unused args passed by event handler
- var_update(var, *args)
When a variable is selected updates var_select button text to the variable name. Then finds first two or three dimensions of the variable and sets them as the X, Y, and Z (if three) dimension selections.
- Parameters:
var (str) – Variable selected
*args – Unused arguments passed to method
nccut.plotpopup module
UI and functionality for plotting and saving popup.
Creates UI elements of the popup and manages the creation of plots based on user input. Manages the saving of the plots and user selected data.
- class nccut.plotpopup.BackgroundDropDown(**kwargs)
Bases:
DropDownGeneral class for a dropdown menu with a background color
- rect
Rectangle object that serves as background to the dropdown.
- open(widget)
Overwrites DropDown open method to also draw a background rectangle.
- Parameters:
widget – RoundedButton to which dropdown is bound
- open_obj(obj, widget)
Calls for open even when passed object by Kivy
- Parameters:
obj – Instance of object that called it… redundant in this case
widget – RoundedButton to which dropdown is bound
- update_canvas(*args)
Update graphics if window size is changed
- class nccut.plotpopup.PlotPopup(**kwargs)
Bases:
PopupPopup with plotting and saving selections.
Creates UI elements of the popup, creates plots according to user selections, and saves plots and/or selected data.
- is_open
Whether popup is currently open
- Type:
bool
- home
Reference to root
nccut.homescreen.HomeScreeninstance.
- all_transects
Dictionary of data from all transects marked out by the user.
- Type:
dict
- t_type
‘Orthogonal’ if transects came from orthogonal chain tool or ‘Inline’ if transects came from inline chain tool
- Type:
str
- active_transects
Dictionary of currently selected transects. ‘Click <X Cord>’, ‘Click <Y Cord>’, and ‘Width’ fields should be removed (if orthogonal chain tool) to simplify plotting. Contains average of transects if orthogonal chain tool was used with a constant transect width.
- Type:
dict
- f_type
If file is NetCDF file: ‘netcdf’. If file is a JPG or PNG: ‘image’.
- Type:
str
- config
Information necessary for accessing the file. For images this is the file path and for NetCDF files this is a dictionary of configuration values (see
nccut.netcdfconfig.NetCDFConfig.check_inputs()for structure of dictionary)- Type:
dict
- active_z
List of selected Z values. Empty list if 2D NetCDF or Image file.
- Type:
list
- active_vars
List of selected variables. Empty list if image file.
- Type:
list
- active_data
Currently plotted data
- b_height
Button height, adapts to font size
- Type:
int
- plot
Image containing plot.
- plotting
BoxLayout that holds plot and selection sidebar.
- title
Popup title
- Type:
str
- content
BoxLayout containing all UI elements in popup
- size_hint
(width, height) of relative size of popup to window
- Type:
tuple
- buttons
BoxLayout containing the save buttons and the close button
- f_m
Multiplier for the font size for the save buttons since they need to be slightly smaller
- t_select
RoundedButton which opens transect selection dropdown menu
- widgets_with_text
List of widgets with text whose font size must be updated when the window is resized
- v_select
RoundedButton which opens variable selection dropdown menu (Only if NetCDF file)
- z_select
RoundedButton which opens z value selection dropdown menu (Only if 3D NetCDF file)
- t_drop
Transect dropdown
- v_drop
Variable dropdown
- z_drop
Z Value dropdown
- add_group_info(dicti)
Adds back fields removed for plotting purposes
- Parameters:
dicti (dict) – Dictionary of transect data from a single group
- Returns:
Dictionary of transect data with non-plotted data fields added back in.
- add_metadata(dicti)
Adds global and variable specific data to an output dictionary.
- Parameters:
dicti – Dictionary of data about to be exported
- Returns:
Dictionary of data with metadata fields added
- Return type:
dicti
- clean()
Cleans plot and optional widgets from plotting popup
- close(*args)
Cleans up popup and marks it as closed :param args: :return:
- download_all_data(f_path)
Downloads selected data for all transects/groups into a JSON file if valid file name given.
- Parameters:
f_path (str) – Output file path
- download_all_z_data(f_path)
Get and download data for all selected variables for all z dimension values.
- Parameters:
f_path (str) – Output file path
- download_pdf_plot(f_path)
Download the current plot as a PDF file if valid file name given
- Parameters:
f_path (str) – Output file path
- download_png_plot(f_path)
Download the current plot as a PNG file if valid file name given
- Parameters:
f_path (str) – Output file path
- download_selected_data(f_path)
Downloads selected transect data into a JSON file if valid file name given.
- Parameters:
f_path (str) – Output file path
- file_input(s_type)
Popup window for user to give name for plot/json file to be saved.
- Parameters:
s_type (str) – String corresponding to what is being saved: ‘s_data’: Transect data for selections ‘a_data’: Transect data for all transects taken ‘all_z’: Transect data for selections for all z dimension values ‘png’: Current plot as a PNG file ‘pdf’: Current plot as a PDF file
- font_adapt(font)
Updates font of elements in plotting menu with text and size of dropdown menus.
- Parameters:
font (float) – New font size
- get_all_z_inline_chain()
Gather data over all z values for current variable when inline chain tool was used. Assumes only one variable and only one chain are selected.
- Returns:
3D Array of concatenated transect data over all z values in the NetCDF file.
- get_all_z_orthogonal_chain()
Gather transect data over all z values for current variable. Assumes only one variable and only one transect are selected.
- Returns:
3D Array of transect data over all z values in the NetCDF file
- get_all_z_plot()
Determines if settings are okay to do an all z value plot. If so calls for plot, if not creates an error popup.
- get_average(key, config)
Finds average of all transects in an orthogonal chain. Orthogonal transect width must be the same for the entire chain.
- Parameters:
key (str) – ‘Orthogonal Chain #’
config – 2D array, currently loaded dataset
- Returns:
1D array of length of transect width containing average transect values for the orthogonal chain.
- get_data()
Gathers transect data for currently selected variables, z values, and transects.
- Returns:
Variables -> Z values -> Groups -> Transects -> X,Y, Cut If only 2D NetCDF file there is no Z values level. If an image there is no Variables or Z Values level.
- Return type:
Nested dictionary of transect data with hierarchy
- get_inline_chain_dropdown()
Build dropdown menu for selecting entire inline chains.
- Returns:
nccut.plotpopup.BackgroundDropDownfor transect options
- get_orthogonal_chain_dropdown()
Build dropdown menu for orthogonal chains with sub-menus for the individual transects.
- Returns:
nccut.plotpopup.BackgroundDropDownfor orthogonal chain options
- get_transect_data(config)
Iterates through the active transect points and returns the transect data.
- Parameters:
config – Either a Dataset (NetCDF) or a 2D array (Image) to take transect data from
- Returns:
Returns dictionary of nested tool group dictionaries of transect data
- get_transect_dropdown(key)
Build dropdown menu for selecting orthogonal transects from an orthogonal chain.
- Parameters:
key (str) – Name of orthogonal chain selecting from. Ex: ‘Orthogonal Chain #’
- Returns:
nccut.plotpopup.BackgroundDropDownfor transect options
- get_var_dropdown()
Get dropdown for NetCDF variable options. Variable only available if dimensions match current variable
- Returns:
nccut.plotpopup.BackgroundDropdownmenu of variable options
- get_z_dropdown()
Get dropdown for NetCDF z value selections
- Returns:
nccut.plotpopup.BackgroundDropDownmenu of z value options
- manual_file_input(fname, s_type)
Checks if a filename is valid and prevents overwriting. Checks a file name doesn’t have any problematic characters. If file name is a file path ensures that the directories exists. If a file name is the same as one that already exists it adds a (#) to avoid overwriting existing file. Calls for data/plot to be saved to corrected file name.
- Parameters:
fname – File name/path given by user
s_type (str) – String corresponding to what is being saved: ‘data’: Transect data for selections ‘all_z_data’: Transect data for selections for all z dimension values ‘png’: Current plot as a PNG file ‘pdf’: Current plot as a PDF file
- on_check_button(check, *args)
Turns checkbox on if off and vice versa
- Parameters:
check – kivy.uix.checkbox.CheckBox
args – Unused arguments passed by button callback
- on_inline_chain_checkbox(check, chain, *args)
Updates plot when a chain checkbox is clicked. Safeguards so at least one chain is always selected.
- Parameters:
check – Reference to kivy.uix.checkbox.CheckBox in transect list
chain (str) – Name of chain ‘Inline Chain #’
- on_transect_checkbox(check, chain, transect, *args)
Updates plot when a transect checkbox is clicked. Safeguards so at least one transect is always selected.
- Parameters:
check – Reference to kivy.uix.checkbox.CheckBox in transect list
chain (str) – Name of orthogonal chain selecting from. Ex: ‘Orthogonal Chain #’
transect (str) – Name of transect ‘Cut #’
- on_var_checkbox(check, var, *args)
Updates plot when a variable checkbox is clicked. Safeguards so at least one variable is always selected.
- Parameters:
check – Reference to kivy.uix.checkbox.CheckBox in variable list
var (str) – String, name of variable
- on_z_checkbox(check, z, *args)
Updates plot when a z value checkbox is clicked. Safeguards so at least one z value is always selected.
- Parameters:
check – Reference to kivy.uix.checkbox.CheckBox in variable list
z (str) – Name of z value
*args – Unused args passed to method
- plot_active()
Creates figure of plots of currently selected data
- Returns:
Final completed figure
- plot_gather_data(dat, name_start, plot_dat)
Iterates group transect data and gathers it into a dictionary for plotting. If tool used is inline chain, ensures that transect data is in direction user clicked the points (left to right or right to left).
- Parameters:
dat (dict) – Dictionary of all chains or all transect data that are selected for plotting
name_start (str) – Start of string to use as key name for plotting dictionary. Key names are ultimately used for labels in plot legend. ‘Z: <z_value>’ if 3D NetCDF data, otherwise just ‘’.
plot_dat – Plotting dictionary to add data to
- Returns:
Plotting dictionary with chain/transect data added in the correct plotting format
- plot_single(data, ax, label)
Creates a single plot of selected chain/transect data for a single variable (if NetCDF)
- Parameters:
data – Currently selected chain/transect data. Either self.active_data itself or a sub-dictionary
ax – Plot axis on which to make plot
label – Label for the y axis of plot. If NetCDF use variable if Image use ‘Mean RGB Value’
- Returns:
List of string labels for the plot’s legend
- run(transects, home, config)
Defines popup UI elements and opens popup.
- Parameters:
transects (dict) – Dictionary of transect data from tool which opened popup
home – Reference to root
nccut.homescreen.HomeScreeninstance.config – Dictionary of configuration data for currently loaded file
- select_all(boxes)
If all checkboxes are checked, uncheck all boxes. Otherwise, check all boxes. If a box is the only box checked across all groups it will remain checked no matter what.
- Parameters:
boxes – List of BoxLayouts containing checkbox widgets
- transect_drop(chain, button)
Attaches transect dropdowns to orthogonal chain buttons in orthogonal chain dropdown menu
- Parameters:
chain (str) – Orthogonal chain label. Ex: ‘Orthogonal Chain #’
button – RoundedButton, Orthogonal chain’s button in orthogonal chain dropdown menu
- update_plot()
Remakes and replaces plot based on current selections.
nccut.interactiveplot module
This is the draggable and scalable plot image that is created when a user plots a transect over all z values for a 3D NetCDF file.
- class nccut.interactiveplot.InteractivePlot(array, z_coords, bounds, window, **kwargs)
Bases:
ScatterLayoutDraggable and scalable plot image created from given transect data and constrained within the bounds of a viewing window.
- Parameters:
data (arr) – The 2D array of data to be plotted
bounds (arr) – Factors that define the maximum percentage of the layout space that the plot is allowed to take up in both width and height ([w_factor, h_factor])
window – Reference to the PlotWindow object that is managing this plot
byte – io.BytesIO object containing image made from data loaded in memory
min_scale – The minimum scale the plot is able to have such that the plot always fills as much of the plotting widget as possible.
- load_image()
Creates the kivy.uix.image.Image object to be placed on to this Scatter object and then rescales scatter to it’s maximum possible size.
- on_touch_down(touch)
If touch is of a scrolling type, zoom in or out of the image. Chooses scaling anchor to be as close to the user touch as possible without allowing the image to move beyond the bounds of the viewing window.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- on_touch_move(touch)
Calls for axes to update when plot is moved.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- see_future_pos_size(anchor, scale_mat)
Determine the resulting size and position of this scatter if the provided scale matrix is applied to this scatter at the provided anchor. The scale matrix is not actually applied.
- Parameters:
anchor (tuple) – (x, y) coordinates of the proposed anchor
scale_mat – Proposed scale matrix
- Returns:
Tuples of the resulting position (x, y) and the resulting size (w, h)
- transform_with_touch(touch)
Translates the scatter object when user clicks and drags the plot ensuring that it does not get dragged out of the bounds of the viewing window. Adapted from original ScatterLayout.transform_with_touch method, with multitouch functionality taken out.
- Parameters:
touch – MouseMotionEvent, see kivy docs for details
- Returns:
Whether a transformation has successfully taken place (even if transformation does not alter position of plot)
- z_data_to_img()
Creates an image with a colormap applied from the supplied transect data over all z values. Stores result in memory as an io.BytesIO object.
nccut.plotwindow module
Functionality for the interactive plot and the adjustable axes in the plotting popup menu when all z levels are plotted as an image.
- class nccut.plotwindow.PlotWindow(config, z_data, colormap, **kwargs)
Bases:
RelativeLayout- Manages the functionality of the interactive plot and the dynamic axes as well as creating the colorbar. Static UI
elements are defined in plotwindow.kv
- Parameters:
config (dict) – Dictionary of configuration information about the laoded NetCDF file (see
nccut.netcdfconfig.NetCDFConfig.check_inputs()for structure of dictionary).z_data (arr) – 2D Numpy Array of transect data for all z values to be plotted.
resized (int) – How many times the window has been resized. Used to ensure children widget sizes are determined only after the plotting widget has reached it’s full size.
plot – Reference to current :class: nccut.interactiveplot.InteractivePlot object
x_axis – Reference to current :class: nccut.plotwindow.XAxis object
y_axis – Reference to current :class: nccut.plotwindow.YAxis object
font (float) – Font size to use for all text elements in the plotting window
colormap (str) – Matplotlib colormap to use for plot
- load(*args)
Loads all plotting widgets once this widget has reached it’s final size so children are sized correctly.
Creates InteractivePlot which determines it’s own maximum size and centered position, and then fits the StencilView window to the plot along with a black border. Then the axes, title widgets, and color bar are positioned and sized according to the StencilView window.
- update_axes()
Signals axes to adjust to new plot. Triggered any time the interactive plot changes size or position.
- class nccut.plotwindow.XAxis(window_box, main, font, transect_points, **kwargs)
Bases:
FloatLayoutManages the tick labels and locations for the x axis of the interactive plot.
- font
Font size for the x axis label and tick labels.
- Type:
float
- window
RelativeLayout object which holds the plotting menu and has been reshaped to the plot at it’s maximum possible size.
- size_hint
Relative size of the object, set to none so the size can be set directly.
- size
Size of the object.
- pos
Position of the object.
- x_label
Label object for the x axis label (Along Transect Point).
- transect_points
Number of pixels in transect
- Type:
int
- x_axis_labels
List of x tick labels
- Type:
list
- on_plot_change(n_pos, n_size)
Determines the optimal positioning and distribution of x ticks and labels for the current plot size and position. X tick label values are between zero and the length of the transect.
- Parameters:
n_pos (tuple) – The current position of the plot (x, y) relative to the viewing window.
n_size (tuple) – The current size of the plot (w, h).
- class nccut.plotwindow.YAxis(config, window_box, main, font, **kwargs)
Bases:
FloatLayoutManages the tick labels and locations for the y axis of the interactive plot.
- font
Font size for the y axis label and tick labels.
- Type:
float
- z_var
Name of the z coordinate to use as y axis label.
- Type:
str
- z_coords
Z coordinate array. If the datasets selected z dimension is numeric then those coordinate values are used, otherwise the index positions of the coordinates are used.
- window
RelativeLayout object which holds the plotting menu and has been reshaped to the plot at it’s maximum possible size.
- size_hint
Relative size of the object, set to none so the size can be set directly.
- size
Size of the object.
- pos
Position of the object.
- y_label
Label object for the y axis label (z coordinate name).
- y_tick_labels
List of y tick labels
- Type:
list
- on_plot_change(n_pos, n_size)
Determines the optimal positioning and distribution of y ticks and labels for the current plot size and position. Y tick label values come from the selected z dimension.
- Parameters:
n_pos (tuple) – The current position of the plot (x, y) relative to the viewing window.
n_size (tuple) – The current size of the plot (w, h).
nccut.settingsbar module
Defines functionality for adding, removing, and adjusting the settings bar menu at the top of the screen. The UI code is in nccut.kv and code for the individual dropdowns is in nccut.dropdowns.
- class nccut.settingsbar.SettingsBar(font, home, **kwargs)
Bases:
BoxLayoutDefines functionality for adding, removing, and adjusting the settings bar menu at the top of the screen. The UI code is in nccut.kv and code for the individual dropdowns is in nccut.dropdowns.
- Parameters:
home – Reference to root HomeScreen instance
font (float) – Current font_size for all text containing elements
f_m (float) – Multiplier to use across all elements for font_size adjustment
netcdf_btn – Reference to the button that opens the NetCDF settings menu.
- add_netcdf_button()
Adds button to access NetCDF settings menu
- font_adapt(font)
Sets font of widgets with text to new font.
- Parameters:
font – New font
- h_flip()
Call for a horizontal flip of view of current display
- open_netcdf(*args)
Opens NetCDF settings menu
- remove_netcdf_button()
Removes button to access NetCDF settings menu
- rotate()
Call for a 45 degree rotation of current display by 45 degrees
- set_line_color_btn(btn_img_path)
Sets line color setting button image to image at specified path
- Parameters:
btn_img_path (String) – Path to button image
- v_flip()
Call for a vertical flip of view of current display