Skip to content

Instantly share code, notes, and snippets.

@pyRobShrk
pyRobShrk / removeDupeVertices.py
Last active October 12, 2018 20:13
Quick function (arcpy) to remove redundant vertices from polyline layer
# Remove duplicate vertices from lines
# A point is considered duplicate if it has the same XY coordinates within a tolerance (precision)
# The precision is an integer number of decimal places
# for X,Y in lat, long, 5 decimals is 1.1 meters and 6 is 11 cm
def removeDupeVertices(feature, precision):
fields = ['SHAPE@'] + [f.name for f in arcpy.ListFields(feature)]
sr = arcpy.Describe(feature).SpatialReference
upd = arcpy.da.UpdateCursor(feature,fields)
orphanList = []
for row in upd:
@pyRobShrk
pyRobShrk / interpolate.bas
Created October 21, 2021 15:38
Linear Interpolation function for Excel VBA
Function interp(X As Double, xRange As Range, yRange As Range) As Double
ascending = xRange.Cells(1) < xRange.Cells(2)
With WorksheetFunction
If ascending Then i = .Match(X, xRange) Else i = .Match(X, xRange, -1)
Set x1x2 = Range(xRange.Cells(i), xRange.Cells(i + 1))
Set y1y2 = Range(yRange.Cells(i), yRange.Cells(i + 1))
interp = X * .Slope(y1y2, x1x2) + .Intercept(y1y2, x1x2)
End With
@pyRobShrk
pyRobShrk / MuskyRouting.bas
Last active February 5, 2025 17:37
Muskingum hydrologic routing in Microsoft Excel (UDF)
Function Muskingum(timeSeries As Range, _
K As Double, X As Double, _
Optional Reaches As Integer = 1) As Variant
'Muskingum routing in Excel
'Returns a column array the same length as timeSeries (use array formula or spill)
'K (travel time) is in same units as the time step of the input timeSeries
'X must be between 0 and 0.5
'Reaches will be automatically adjusted to avoid negative coefficients if K is < 1 / (2*(1-X)) or K > 1/2X
Dim Coeffs(1 To 5) As Double
@pyRobShrk
pyRobShrk / wordleList.txt
Created February 3, 2022 18:16
This is a list of five letter words appearing in the wordle game (https://www.powerlanguage.co.uk/wordle/). The list has been alphabetized.
aalii
aargh
aarti
abaca
abaci
aback
abacs
abaft
abaka
abamp
@pyRobShrk
pyRobShrk / Excel_LAMBDAs.txt
Last active November 13, 2024 21:59
A random assortment of LAMBDA functions for Excel
/*
Name: Show Moon Phase Emoji (MOONPHASE)
Description: Returns a lunar phase character closest matching to any Excel Date/Time value.
If you calculate for daily values at midnight, the lunar cycle will be the same for every 3 or 4 days (3.691 days).
🌑🌒🌓🌔🌕🌖🌗🌘
*/
MOONPHASE = LAMBDA(datetime,LET(
phase,MOD(ROUND(MOD(datetime-1.5,29.53059)/3.69125,0),8)+1,
UNICHAR(127760+phase)));
@pyRobShrk
pyRobShrk / Text
Created November 29, 2022 22:45 — forked from jack-williams/Text
Excel text functions
_search = LAMBDA(txt, searchtext, [case_sensitive],
// Test the inputs for errors so that we can distinguish
// the error that comes from FIND/SEARCH as meaning "not-found".
IFS(
ISERROR(txt),
txt,
ISERROR(searchtext),
searchtext,
ISERROR(case_sensitive),
case_sensitive,
@pyRobShrk
pyRobShrk / Godin.py
Last active November 13, 2024 19:50
Godin Filter jython script for HEC-DSSVue
# name=Godin
# description=This jython script reads your DSSVue selection, and performs Godin tidal smoothing.
# description=The original 1972 Godin algorithm was to apply successive 25-hour averages to hourly data.
# description=This filter is slightly modified for 15-minute data, and specific to the periods of tidal constituents.
# description=The 51-period (12.5-hr) filters M4, MS4 and MN4, 97-period (24-hr) filters S2 and K2, and 101-period (25-hr) filters M2, N2, and L2.
# displayinmenu=false
# displaytouser=true
# displayinselector=false
from hec.hecmath import HecMath
from hec.heclib.dss import HecDss, DSSPathname