https://github.com/danielvartan/nlogo-utils
🧰 Utility Functions for NetLogo
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
â—‹CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
â—‹DOI references
-
â—‹Academic publication links
-
â—‹Academic email domains
-
â—‹Institutional organization owner
-
â—‹JOSS paper metadata
-
â—‹Scientific vocabulary similarity
Low similarity (12.0%) to scientific vocabulary
Keywords
Repository
🧰 Utility Functions for NetLogo
Basic Info
Statistics
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
nlogo-utils
Overview
nlogo-utils is a repository that I (Daniel Vartanian) use to store and organize my NetLogo utility functions (i.e., to and to-report procedures).
This is primarily intended for personal use, but you are welcome to use it if you find it helpful. Please note that not all functions are documented.
If you find this project useful, please consider giving it a star!
How to Use
All functions are located in the nlogo directory. Each function resides in its own file named after the function, except for test, check, and assertion functions, which are grouped by category (for example, check-integer.nls contains is-integer?, test-integer, check-integer, and assert-integer).
Some functions may require dependencies, such as NetLogo extensions or other functions. Any dependencies are listed in the file header.
Here are some examples:
Control Flow and Logic
any-member?(to-report): Tests if any element in a list is a member of another listany-true?(to-report): Tests if any element in a list istruelist-any?(to-report): Tests if any element in a list is equal to a specified value or to values in another listall-member?(to-report): Tests if all elements in a list are members of another listall-true?(to-report): Tests if all elements in a list aretruelist-all?(to-report): Tests if all elements in a list are equal to a specified value or to values in another list
Defensive Programming
These functions follow NetLogo naming conventions for testing, as well as the conventions used in the checkmate R package.
test functions return true or false. check functions return true if the test passes, or a string with an error message if it fails. assert functions are procedures (not reporters) that throw an error if the test fails.
is-atomic?test-atomic(to-report): Tests whether a value is not a listis-logical?test-logicaltest-boolean(to-report): Tests whether a value istrueorfalseis-integer?test-integer(to-report): Tests whether a value is an integer numberis-numeric?test-numbertest-numeric(to-report): Tests whether a value is a number (integer or float)is-string?test-string(to-report): Tests whether a value is a stringis-list?test-list(to-report): Tests whether a value is a listis-true?test-true(to-report): Tests whether a value istrueis-false?test-false(to-report): Tests whether a value isfalsedir-exists?test-dir-exists(to-report): Tests whether a directory existstest-file-exists(to-report): Tests whether a file existsis-gis?test-gis(to-report): Tests whether a value is a GIS datasetis-nan?test-nan(to-report): Tests whether a value isNaN(not a number). This is useful when using thegisextension, as GIS datasets may containNaNvalues.is-between?test-between(to-report): Tests whether a value is between two numberstest-choice(to-report): Tests whether a value is one of a set of choicesis-windows?test-windows(to-report): Tests whether the user is running NetLogo on a Windows operating system
assert-atomic(to): Asserts that a value is not a listassert-logicalassert-boolean(to): Asserts that a value istrueorfalseassert-integer(to): Asserts that a value is an integerassert-numberassert-numeric(to): Asserts that a value is a number (integer or float)assert-string(to): Asserts that a value is a stringassert-list(to): Asserts that a value is a listassert-true(to): Asserts that a value istrueassert-false(to): Asserts that a value isfalseassert-dir-exists(to): Asserts that a directory existsassert-file-exists(to): Asserts that a file existsassert-gis(to): Asserts that a value is a GIS datasetassert-between(to): Asserts that a value is between two numbersassert-choice(to): Asserts that a value is one of a set of choicesassert-windows(to): Asserts that the user is running NetLogo on a Windows operating system
Several other assertion functions are also available. Check the nlogo directory for more details.
File System
basename(to-report): Returns the base name of a file or directory (i.e., the last part of the path)file-path(to-report): Creates a file path from a directory and a file namelist-files-by-pattern(to-report): Lists files in a directory that match a specified patternnormalize-path(to-report): Normalizes a file path making it compatible with the user operating system
Lists
as-list(to-report): Converts an atomic value to a listcollapse(to-report): Collapses a list into a string using a separator (e.g.,[1 2 3 4]→"1, 2, 3, 4")combine(to-report): Combines two lists into a single listlist-to-c(to-report): Converts a NetLogo list into a string formatted as an Rc()expression, with elements separated by commas (e.g.,[1 2 3]→"c(1, 2, 3)")match(to-report): Returns the first element in a list that matches a specified valueunique-outliers(to-report): Returns a sorted list of unique outlier values from a given list. Outliers are defined as values greater than the third quartile plus a specified multiple of the interquartile range (IQR), or less than the first quartile minus the same multiple of the IQR. Duplicate values are removed before identifying outliers.
Mathematical
distance-between(to-report): Returns the distance between two numbersquartile(to-report): Returns the quartiles (Q1,Q2, Q3, Q4), the quartile length, and the interquartile range (IQR) of a list of numbersrandom-beta(to-report): Returns a random number from a beta distribution with parametersalphaandbetarescale(to-report): Rescales a number from one range to another
Strings
as-string(to-report): Converts any value to a stringnum-to-str-month(to-report): Converts a numeric month value (1for January,2for February, etc.) to its corresponding string representation (e.g.,1→"January")rep-collapse(to-report): Repeats and collapses a value into a string.single-quote(to-report): Returns values with single quotes. It also works with lists.str-detect(to-report): Detecs the presence/absense of a match in a string using a regular expression. Returnstrueif the match is found,falseotherwise.str-extract(to-report): Extracts a match from a string using a regular expression. Returns the first match found, or"NA"if no match is found.str-extract-all(to-report): Extracts all matches from a string using a regular expression. Returns a list of all matches found, with"NA"for any non-matching elements.str-remove(to-report): Removes a match from a string using a regular expression. Returns the string with the first match removed, or the original string if no match is found.str-remove-all(to-report): Removes all matches from a string using a regular expression. Returns the string with all matches removed, or the original string if no matches are found.str-replace(to-report): Replaces a match in a string using a regular expression. Returns the string with the first match replaced, or the original string if no match is found.str-replace-all(to-report): Replaces all matches in a string using a regular expression. Returns the string with all matches replaced, or the original string if no matches are found.str-to-num-month(to-report): Converts a string representing a month (e.g.,"January") to its corresponding numeric value (1for January,2for February, etc.).test-string-in-r(to-report): Tests whether a string is a valid R string.
World
check-world-bleed(to-report): Checks a range ofpxcorandpycorvalues to identify any lines of patches with a value of0,NA, orNaN. Returns a list containing two ordered lists: one with thepxcorvalues and one with thepycorvalues of patches that meet this condition. If no such patches are found, both lists are empty.remove-world-bleed(to): Checks for and removes world bleed patches—lines of patches at the edges of the world with values of0,"NA", orNaN.show-values(to): A procedure for use with aforeverbutton that displays patch values under the mouse cursor in the NetLogo view. Useful for interactively inspecting patch data during model runs.
License
The content is licensed under CC0 1.0 Universal, placing these materials in the public domain. You may freely copy, modify, distribute, and use this work, even for commercial purposes, without permission or attribution.
Owner
- Name: Daniel Vartanian
- Login: danielvartan
- Kind: user
- Location: São Paulo, Brazil
- Company: @sustentarea
- Website: danielvartan.com
- Repositories: 84
- Profile: https://github.com/danielvartan
Academic. Passionate about #opendata and #openscience.
GitHub Events
Total
- Watch event: 1
- Push event: 23
- Create event: 1
Last Year
- Watch event: 1
- Push event: 23
- Create event: 1