Skip to content

Commit

Permalink
Merge pull request #1468 from AllenInstitute/feature/1468-sweepformul…
Browse files Browse the repository at this point in the history
…a-epsp
  • Loading branch information
t-b authored Aug 4, 2023
2 parents 3ff5cf0 + f2344e3 commit 8419c3f
Show file tree
Hide file tree
Showing 22 changed files with 9,281 additions and 60 deletions.
46 changes: 46 additions & 0 deletions Packages/MIES/MIES_Cache.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,52 @@ Function/S CA_HardwareDataTPKey(s)
return num2istr(crc) + "HW Datawave Testpulse Version 2"
End

Function/S CA_PSXKernelOperationKey(variable riseTau, variable decayTau, variable amp, variable numPoints, variable dt, WAVE range)
variable crc

crc = StringCRC(crc, num2strHighPrec(riseTau, precision = MAX_DOUBLE_PRECISION))
crc = StringCRC(crc, num2strHighPrec(decayTau, precision = MAX_DOUBLE_PRECISION))
crc = StringCRC(crc, num2strHighPrec(amp, precision = MAX_DOUBLE_PRECISION))
crc = StringCRC(crc, num2strHighPrec(numPoints, precision = MAX_DOUBLE_PRECISION))
crc = StringCRC(crc, num2strHighPrec(dt, precision = MAX_DOUBLE_PRECISION))
crc = WaveCRC(crc, range)

return num2istr(crc) + "PSX Kernel Version 1"
End

static Function/S CA_PSXBaseKey(string comboKey, string psxParameters)

ASSERT(!IsEmpty(comboKey), "Invalid comboKey")
ASSERT(!IsEmpty(psxParameters), "Invalid psxParameters")

return comboKey + Hash(psxParameters, HASH_SHA2_256)
End

/// @brief Generate the key for the cache and the results wave for psxEvent
/// data of the `psx` SweepFormula operation
///
/// @param comboKey combination key, see PSX_GenerateComboKey()
/// @param psxParameters JSON dump of the psx/psxKernel operation parameters
Function/S CA_PSXEventsKey(string comboKey, string psxParameters)

return CA_PSXBaseKey(comboKey, psxParameters) + " Events " + ":Version 1"
End

Function/S CA_PSXOperationKey(string comboKey, string psxParameters)

return CA_PSXBaseKey(comboKey, psxParameters) + " Operation " + ":Version 1"
End

Function/S CA_PSXRiseTimeKey(string comboKey, string psxParameters)

return CA_PSXBaseKey(comboKey, psxParameters) + " PSX Rise time " + ":Version 1"
End

Function/S CA_PSXAnalyzePeaks(string comboKey, string psxParameters)

return CA_PSXBaseKey(comboKey, psxParameters) + " Analyze Peaks " + ":Version 1"
End

/// @}

/// @brief Make space for one new entry in the cache waves
Expand Down
94 changes: 91 additions & 3 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ Constant EVENT_WINDOW_HOOK_TABLEENTRYCANCELLED = 25
Constant EVENT_WINDOW_HOOK_EARLYKEYBOARD = 26
/// @}

/// @name Trace Display Types
/// @anchor TraceDisplayTypes
/// @{
Constant TRACE_DISPLAY_MODE_LINES = 0
Constant TRACE_DISPLAY_MODE_STICKS = 1
Constant TRACE_DISPLAY_MODE_DOTS = 2
Constant TRACE_DISPLAY_MODE_MARKERS = 3
Constant TRACE_DISPLAY_MODE_LINES_MARKERS = 4
Constant TRACE_DISPLAY_MODE_BARS = 5
Constant TRACE_DISPLAY_MODE_CITY = 6
Constant TRACE_DISPLAY_MODE_FILL = 7
Constant TRACE_DISPLAY_MODE_STICKS_MARKERS = 8
Constant TRACE_DISPLAY_MODE_LAST_VALID = 8
/// @}

/// Used by CheckName and UniqueName
Constant CONTROL_PANEL_TYPE = 9

Expand Down Expand Up @@ -363,6 +378,7 @@ Constant UNKNOWN_MODE = NaN
Constant DATA_ACQUISITION_MODE = 0
Constant TEST_PULSE_MODE = 1
Constant SWEEP_FORMULA_RESULT = 2
Constant SWEEP_FORMULA_PSX = 3
/// @}

Constant NUMBER_OF_LBN_DAQ_MODES = 4
Expand Down Expand Up @@ -714,6 +730,20 @@ Constant COMMON_CONTROL_GROUP_COUNT_TXT = 10
/// Equals 2^5 from `GetKeyState`
Constant ESCAPE_KEY = 32

/// Window hook key constants
/// @{
Constant LEFT_KEY = 28
Constant RIGHT_KEY = 29
Constant UP_KEY = 30
Constant DOWN_KEY = 31
Constant SPACE_KEY = 32
Constant C_KEY = 99
Constant E_KEY = 101
Constant F_KEY = 102
Constant R_KEY = 114
Constant Z_KEY = 122
/// @}

Constant MAX_COMMANDLINE_LENGTH = 2500

StrConstant WAVEBUILDER_COMBINE_FORMULA_VER = "1"
Expand Down Expand Up @@ -1909,6 +1939,7 @@ Constant DFREF_FREE = 0x2
/// @{
StrConstant CO_EMPTY_DAC_LIST = "emptyDACList"
StrConstant CO_SF_TOO_MANY_TRACES = "SF_tooManyTraces"
StrConstant CO_PSX_CLIPPED_STATS = "psx_clippedStats"
/// @}

/// @name Constants for SweepFormula Meta data in JSON format
Expand All @@ -1922,16 +1953,23 @@ StrConstant SF_META_CHANNELNUMBER = "/ChannelNumber" // number
StrConstant SF_META_ISAVERAGED = "/IsAveraged" // number
StrConstant SF_META_AVERAGED_FIRST_SWEEP = "/AveragedFirstSweep" // number
StrConstant SF_META_XVALUES = "/XValues" // numeric wave
StrConstant SF_META_XTICKLABELS = "/XTickLabels" // text wave
StrConstant SF_META_XTICKPOSITIONS = "/XTickPositions" // numeric wave
StrConstant SF_META_XAXISLABEL = "/XAxisLabel" // string
StrConstant SF_META_YAXISLABEL = "/YAxisLabel" // string
StrConstant SF_META_OPSTACK = "/OperationStack" // string
StrConstant SF_META_MOD_MARKER = "/Marker" // numeric wave
StrConstant SF_META_SHOW_LEGEND = "/ShowLegend" // numeric, boolean, defaults to true (1)
StrConstant SF_META_CUSTOM_LEGEND = "/CustomLegend" // string with custom legend text, honours /ShowLegend
StrConstant SF_META_ARGSETUPSTACK = "/ArgSetupStack" // string
StrConstant SF_META_TRACECOLOR = "/TraceColor" // numeric wave
StrConstant SF_META_TRACECOLOR = "/TraceColor" // numeric wave, applies to markers and lines
StrConstant SF_META_LINESTYLE = "/LineStyle" // number
StrConstant SF_META_TRACE_MODE = "/TraceMode" // number
StrConstant SF_META_TRACETOFRONT = "/TraceToFront" // number, boolean, defaults to false (0)

StrConstant SF_META_USER_GROUP = "/User/" // custom metadata for individual operations,
// top-level group with individual entries

StrConstant SF_DATATYPE_SWEEP = "SweepData"
StrConstant SF_DATATYPE_FINDLEVEL = "FindLevel"
StrConstant SF_DATATYPE_APFREQUENCY = "ApFrequency"
Expand All @@ -1954,6 +1992,7 @@ StrConstant SF_DATATYPE_TPINST = "TestPulseMode_Instantaneous"
StrConstant SF_DATATYPE_TPBASE = "TestPulseMode_Baseline"
StrConstant SF_DATATYPE_TPFIT = "TestPulseMode_Fit"
StrConstant SF_DATATYPE_POWERSPECTRUM = "Powerspectrum"
StrConstant SF_DATATYPE_PSX = "PSX"

StrConstant SF_WREF_MARKER = "\"WREF@\":"
StrConstant SF_VARIABLE_MARKER = "/SF_IsVariable" // numeric
Expand Down Expand Up @@ -1998,8 +2037,9 @@ StrConstant SFH_USER_DATA_BROWSER = "browser"
/// @name Available result types for SFH_CreateResultsWaveWithCode()
/// @anchor ResultTypes
/// @{
Constant SFH_RESULT_TYPE_STORE = 0x01
Constant SFH_RESULT_TYPE_EPSP = 0x02
Constant SFH_RESULT_TYPE_STORE = 0x01
Constant SFH_RESULT_TYPE_PSX_EVENTS = 0x02
Constant SFH_RESULT_TYPE_PSX_MISC = 0x04
/// @}

/// @name Constants used in the wave note JSON support
Expand Down Expand Up @@ -2103,3 +2143,51 @@ Constant SECONDS_PER_DAY = 86400
/// @{
Strconstant DB_AXIS_PART_EPOCHS = "_EP"
/// @}

StrConstant SF_OP_PSX = "psx"
StrConstant SF_OP_PSX_KERNEL = "psxKernel"
StrConstant SF_OP_PSX_STATS = "psxStats"
StrConstant SF_OP_PSX_RISETIME = "psxRiseTime"
StrConstant SF_OP_PSX_PREP = "psxPrep"

/// @name Available PSX states
/// @anchor PSXStates
/// @{
Constant PSX_ACCEPT = 0x01
Constant PSX_REJECT = 0x02
Constant PSX_UNDET = 0x04
Constant PSX_LAST = 0x04 // neeeds to be the same as the last valid state
Constant PSX_ALL = 0x07
/// @}

/// @name Available PSX state types
/// @anchor PSXStateTypes
/// @{
Constant PSX_STATE_EVENT = 0x1
Constant PSX_STATE_FIT = 0x2
Constant PSX_STATE_BOTH = 0x3
/// @}

StrConstant PSX_EVENTS_COMBO_KEY_WAVE_NOTE = "comboKey"

Constant PSX_MARKER_ACCEPT = 19
Constant PSX_MARKER_REJECT = 23
Constant PSX_MARKER_UNDET = 18

/// @name Custom error codes for PSX_FitEventDecay()
/// @anchor FitEventDecayCustomErrors
/// @{
Constant PSX_DECAY_FIT_ERROR = -10000
/// @}

StrConstant PSX_STATS_LABELS = "Average;Median;Average Deviation;Standard deviation;Skewness;Kurtosis"

/// @name Horizontal offset modes in all event graph
///
/// Corresponds to zero-based indizes of popup_event_offset
///
/// @anchor HorizOffsetModesAllEvent
/// @{
Constant PSX_HORIZ_OFFSET_ONSET = 0
Constant PSX_HORIZ_OFFSET_PEAK = 1
/// @}
29 changes: 23 additions & 6 deletions Packages/MIES/MIES_JSONWaveNotes.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma ModuleName=MIES_JSONWAVENOTE
#endif

static Constant JWN_DEFAULT_RELEASE = 1

/// @brief Gets the JSON wave note part as string
threadsafe Function/S JWN_GetWaveNoteAsString(WAVE wv)

Expand All @@ -32,12 +34,18 @@ threadsafe Function JWN_GetWaveNoteAsJSON(WAVE wv)
return JSON_Parse(JWN_GetWaveNoteAsString(wv))
End

/// @brief Set the JSON json document as JSON wave note. Releases json.
threadsafe Function JWN_SetWaveNoteFromJSON(WAVE wv, variable jsonID)
/// @brief Set the JSON json document as JSON wave note. Releases json if `release` is true (default).
threadsafe Function JWN_SetWaveNoteFromJSON(WAVE wv, variable jsonID, [variable release])

ASSERT_TS(WaveExists(wv), "Missing wave")

JWN_WriteWaveNote(wv, JWN_GetWaveNoteHeader(wv), jsonID)
if(ParamIsDefault(release))
release = JWN_DEFAULT_RELEASE
else
release = !!release
endif

JWN_WriteWaveNote(wv, JWN_GetWaveNoteHeader(wv), jsonID, release = release)
End

/// @brief Return the numerical value at jsonPath found in the wave note
Expand Down Expand Up @@ -126,12 +134,21 @@ threadsafe Function/S JWN_GetWaveNoteHeader(WAVE/Z wv)
return StringFromList(0, note(wv), WAVE_NOTE_JSON_SEPARATOR)
End

/// @brief Writes a wave note from header string and json back. Releases json.
threadsafe static Function JWN_WriteWaveNote(WAVE wv, string header, variable jsonID)
/// @brief Writes a wave note from header string and json back. Releases json if `release` is true (default).
threadsafe static Function JWN_WriteWaveNote(WAVE wv, string header, variable jsonID, [variable release])

if(ParamIsDefault(release))
release = JWN_DEFAULT_RELEASE
else
release = !!release
endif

ASSERT_TS(WaveExists(wv), "Missing wave")
Note/K wv, header + WAVE_NOTE_JSON_SEPARATOR + JSON_Dump(jsonID)
JSON_Release(jsonID)

if(release)
JSON_Release(jsonID)
endif
End

/// @brief Updates the numeric value of `key` found in the wave note as jsonPath
Expand Down
9 changes: 9 additions & 0 deletions Packages/MIES/MIES_MiesUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -4327,6 +4327,15 @@ Function/WAVE ConvertFreeWaveToPermanent(WAVE freeWave, DFREF dfr, string wName)
return permWave
End

Function/WAVE MoveFreeWaveToPermanent(WAVE freeWave, DFREF dfr, string wvName)

wvName = UniqueWaveName(dfr, wvName)
MoveWave freeWave, dfr:$wvName
WAVE/SDFR=dfr permWave = $wvName

return permWave
End

/// @brief Zero all given traces
static Function ZeroTracesIfReq(graph, traces, zeroTraces)
string graph
Expand Down
Loading

0 comments on commit 8419c3f

Please sign in to comment.