Difference between revisions of "Geopsy: Waveform Scripting Language"
(→taper) |
|||
(47 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
The scripting language is Javascript ([http://www.w3schools.com/js a comprehensive tutorial]) | The scripting language is Javascript ([http://www.w3schools.com/js a comprehensive tutorial]) | ||
− | Geopsy provides several additional functions for processing signals details here below | + | Geopsy provides several additional functions for processing signals details here below. If the description is incomplete hereinafter, run the function in the graphical user interface and check the generated code in the waveform console. |
== Categories == | == Categories == | ||
− | * Header data: [[#header|header | + | * Header data: [[#header|header]], [[#setHeader|setHeader]] |
− | * Signal transformations: [[#cut|cut | + | * Signal transformations: [[#cut|cut]], [[#shift|shift]] |
− | * Miscelaneous: [[#signalCount|signalCount | + | * Input/ouput: [[#exportFile|exportFile]] |
+ | * Time: [[#addSeconds|addSeconds]], [[#addDays|addDays]], [[#addMonths|addMonths]], [[#addYears|addYears]], [[#elapsedSeconds|elapsedSeconds]], [[#startTime|startTime]], [[#endTime|endTime]], [[#setStartTime|setStartTime]] | ||
+ | * Miscelaneous: [[#signalCount|signalCount]], [[#saveStep|saveStep]], [[#restoreStep|restoreStep]] | ||
− | == | + | == addDays == |
+ | === Syntax === | ||
+ | string addDays(string '''dateTime''', integer '''days'''); | ||
+ | |||
+ | === Description === | ||
+ | From a string containing an absolute time '''dateTime''' (format: yyyyMMddhhmmssz), adds '''days''' and returns a modified absolute time. '''days''' must by an integer. | ||
+ | === Examples === | ||
+ | print(addDays("20240829160235.540000", 1)); | ||
+ | |||
+ | == addMonths == | ||
+ | === Syntax === | ||
+ | string addMonths(string '''dateTime''', integer '''months'''); | ||
− | + | === Description === | |
− | + | From a string containing an absolute time '''dateTime''' (format: yyyyMMddhhmmssz), adds '''months''' and returns a modified absolute time. '''months''' must by an integer. | |
− | + | === Examples === | |
− | + | print(addMonths("20240829160235.540000", 1)); | |
− | |||
− | |||
− | |||
− | == | + | == addSeconds == |
=== Syntax === | === Syntax === | ||
− | + | string addSeconds(string '''dateTime''', number '''seconds'''); | |
=== Description === | === Description === | ||
− | + | From a string containing an absolute time '''dateTime''' (format: yyyyMMddhhmmssz), adds '''seconds''' and returns a modified absolute time. | |
− | + | === Examples === | |
+ | print(addSeconds("20240829160235.540000", 86401.06)); | ||
+ | |||
+ | == addYears == | ||
+ | === Syntax === | ||
+ | string addYears(string '''dateTime''', integer '''years''']]]); | ||
+ | === Description === | ||
+ | From a string containing an absolute time '''dateTime''' (format: yyyyMMddhhmmssz), adds '''years''' and returns a modified absolute time. '''years''' must by an integer. | ||
=== Examples === | === Examples === | ||
− | + | print(addYears("20240829160235.540000", 1)); | |
− | + | ||
− | + | == agc == | |
− | + | ||
− | + | == correlations == | |
− | + | ||
+ | == cut == | ||
+ | === Syntax === | ||
+ | cut( [[Geopsy: Time range specification]] ); | ||
+ | === Description === | ||
+ | Cut the signal between two time specifications | ||
− | == | + | == decimateAmplitude == |
+ | == decimateTime == | ||
+ | == elapsedSeconds == | ||
=== Syntax === | === Syntax === | ||
− | + | elapsedSeconds(string '''dateTime1''', string '''dateTime2'''); | |
=== Description === | === Description === | ||
− | + | Returns the number of seconds between '''dateTime1''' and '''dateTime2''' (format: yyyyMMddhhmmssz). | |
=== Examples === | === Examples === | ||
− | + | print(elapsedSeconds("20240829160235.540000", "20240830160236.6")); | |
+ | |||
+ | == discreteFourierTransform == | ||
+ | |||
+ | == endTime == | ||
+ | === Syntax === | ||
+ | string endTime(integer '''index'''); | ||
+ | === Description === | ||
+ | Returns the ending time of signal '''index''' with format yyyyMMddhhmmssz. See also [[#startTime|startTime]]. | ||
== exportFile == | == exportFile == | ||
Line 54: | Line 86: | ||
exportFile("myfolder/mysignal.sac", false, "SacBigEndian"); | exportFile("myfolder/mysignal.sac", false, "SacBigEndian"); | ||
− | == | + | == fastFourierTransfrom == |
− | === | + | == filter== |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== header == | == header == | ||
Line 82: | Line 105: | ||
} | } | ||
cut("Pick", "t1", "Pick", "t2"); | cut("Pick", "t1", "Pick", "t2"); | ||
+ | |||
+ | == leftJustified == | ||
+ | === Syntax === | ||
+ | leftJustified(string '''text''', integer '''nChars''', string '''fillChar'''); | ||
+ | === Description === | ||
+ | Add '''fillChar''' at the end of '''text''' so that its length is '''nChars'''. '''text''' is not modified. Returned value: the modified text. It does nothing if the length of '''text''' is greater or equal to '''nChars'''. | ||
+ | |||
+ | === Examples === | ||
+ | see [[#rightJustified|rightJustified]] | ||
+ | |||
+ | == merge == | ||
+ | |||
+ | == mergeStations == | ||
+ | == multiply== | ||
+ | |||
+ | == newGroup == | ||
+ | === Syntax === | ||
+ | newGroup(string '''path''', string '''name''', number '''start''', number '''end'''); | ||
+ | |||
+ | === Description === | ||
+ | Creates a new group with signals from '''start''' to '''end'''. If '''path''' is empty, it adds the group at the root level. If not, it adds it in the tree at '''path'''. | ||
+ | |||
+ | === Examples === | ||
+ | Divides the current viewer in three groups | ||
+ | |||
+ | path="ISTerre/SmartSolo/Z" | ||
+ | newGroup(path, "low gain", 0, 65); | ||
+ | newGroup(path, "mid gain", 66, 131); | ||
+ | newGroup(path, "high gain", 132, 219); | ||
+ | |||
+ | == overSample == | ||
+ | |||
+ | == print == | ||
+ | ===Syntax=== | ||
+ | print(string '''text''') | ||
+ | |||
+ | ===Description=== | ||
+ | Prints a message to the log console. It is mainly used for debug. | ||
+ | |||
+ | ===Examples=== | ||
+ | |||
+ | print("Hello "+2024+" world!"); | ||
+ | |||
+ | == restoreStep == | ||
+ | === Syntax === | ||
+ | restoreStep(string '''tag'''); | ||
+ | === Description === | ||
+ | Restore signals previously saved onto the stack under '''tag'''. | ||
+ | === Examples === | ||
+ | see [[#saveStep|saveStep()]] | ||
+ | |||
+ | == rightJustified == | ||
+ | === Syntax === | ||
+ | rightJustified(string '''text''', integer '''nChars''', string '''fillChar'''); | ||
+ | === Description === | ||
+ | Add '''fillChar''' at the beginning of '''text''' so that its length is '''nChars'''. '''text''' is not modified. The result is returned by the function. It does nothing if the length of '''text''' is greater or equal to '''nChars'''. | ||
+ | === Examples === | ||
+ | print(rightJustified(2, 4, "0")); | ||
+ | |||
+ | == rotateComponents == | ||
+ | |||
+ | == saveStep == | ||
+ | === Syntax === | ||
+ | saveStep(string '''tag'''); | ||
+ | |||
+ | === Description === | ||
+ | Saves the current signals onto the stack under '''tag'''. '''tag''' is an arbitrary string used to [[#restoreStep|restoreStep()]] previously saved signals. | ||
+ | This function is systematically produced when using the [[Geopsy: Waveform Menu|waveform menu]] items. | ||
+ | |||
+ | === Examples === | ||
+ | filter(); | ||
+ | saveStep("Low pass 10 Hz"); | ||
+ | whiten(); | ||
+ | saveStep("Whiten"); | ||
+ | restoreStep("Low pass 10 Hz"); | ||
+ | clipStddev(); | ||
+ | |||
+ | == selectSignals == | ||
+ | === Syntax === | ||
+ | selectSignals(number '''start''', number '''end'''); | ||
+ | |||
+ | === Description === | ||
+ | Restrict the current list of signals to indexes ranging from '''start''' to '''end'''. | ||
+ | === Examples === | ||
+ | Rotate horizontal components to get north components parallel to the tangent of a circular array. Rotated components are exported. | ||
+ | |||
+ | n=signalCount()/3; | ||
+ | cx=2000; | ||
+ | cy=2000; | ||
+ | for(i=0; i<n;i++) { | ||
+ | restoreStep("original"); | ||
+ | name=header(i*3, "Name"); | ||
+ | x=header(i*3, "ReceiverX"); | ||
+ | y=header(i*3, "ReceiverY"); | ||
+ | a=Math.atan2(y-cy,x-cx)*180/3.141592; | ||
+ | if(a<0) a+=360; | ||
+ | selectSignals(i*3, i*3+2); | ||
+ | rotateComponents(true, a, false, 0, false, 0); | ||
+ | exportFile("/my/path/"+name+"_0001.sac"); | ||
+ | print("Station "+name+" rotated by "+ a+" deg."); | ||
+ | } | ||
== setHeader == | == setHeader == | ||
Line 95: | Line 219: | ||
See [[#signalCount|signalCount()]] or [[#header|header()]] | See [[#signalCount|signalCount()]] or [[#header|header()]] | ||
− | == | + | == setStartTime == |
− | == | + | === Syntax === |
− | + | string setStartTime(integer '''index''', string '''dateTime'''); | |
− | + | === Description === | |
− | == | + | Sets the starting time of signal '''index''' with format yyyyMMddhhmmssz. See also [[#startTime|startTime]], [[#endTime|endTime]]. |
− | == | + | |
− | |||
− | |||
− | |||
== shift == | == shift == | ||
=== Syntax === | === Syntax === | ||
Line 117: | Line 238: | ||
setHeader(0, "T0", t0rounded); | setHeader(0, "T0", t0rounded); | ||
− | == | + | == signalCount == |
− | == | + | === Syntax === |
− | + | integer signalCount(); | |
+ | === Description === | ||
+ | Returns the number of signals to process. | ||
+ | === Examples === | ||
+ | Sets the sampling frequency to 100 Hz for all signals | ||
+ | n=signalCount(); | ||
+ | for(i=0;i<n;i++) { | ||
+ | setHeader(i, "DeltaT", 0.01); | ||
+ | } | ||
− | == | + | == subtractSignal == |
− | + | == subtractSignals == | |
− | + | == subtractValue == | |
− | |||
− | |||
− | |||
− | == | ||
− | == | ||
== stalta == | == stalta == | ||
− | |||
− | |||
− | |||
− | == | + | == startTime == |
=== Syntax === | === Syntax === | ||
− | + | string startTime(integer '''index'''); | |
=== Description === | === Description === | ||
− | + | Returns the starting time of signal '''index''' with format yyyyMMddhhmmssz. See also [[#endTime|endTime]]. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== system == | == system == | ||
=== Syntax === | === Syntax === | ||
− | system(string command); | + | system(string '''command'''); |
+ | |||
=== Description === | === Description === | ||
Executes any system command with its arguments. | Executes any system command with its arguments. | ||
Line 161: | Line 272: | ||
system("rm -f myfolder/mysignal.sac"); | system("rm -f myfolder/mysignal.sac"); | ||
exportFile("myfolder/mysignal.sac", false, "SacBigEndian"); | exportFile("myfolder/mysignal.sac", false, "SacBigEndian"); | ||
+ | |||
+ | == taper == | ||
+ | === Syntax === | ||
+ | taper( [[Geopsy: Time range specification]], number '''width'''); | ||
+ | === Description === | ||
+ | Multiply signal in time domain by a window function. | ||
+ | |||
+ | == waveletTransform == | ||
+ | == whiten == |
Latest revision as of 14:38, 29 August 2024
The scripting language is Javascript (a comprehensive tutorial)
Geopsy provides several additional functions for processing signals details here below. If the description is incomplete hereinafter, run the function in the graphical user interface and check the generated code in the waveform console.
Contents
- 1 Categories
- 2 addDays
- 3 addMonths
- 4 addSeconds
- 5 addYears
- 6 agc
- 7 correlations
- 8 cut
- 9 decimateAmplitude
- 10 decimateTime
- 11 elapsedSeconds
- 12 discreteFourierTransform
- 13 endTime
- 14 exportFile
- 15 fastFourierTransfrom
- 16 filter
- 17 header
- 18 leftJustified
- 19 merge
- 20 mergeStations
- 21 multiply
- 22 newGroup
- 23 overSample
- 24 print
- 25 restoreStep
- 26 rightJustified
- 27 rotateComponents
- 28 saveStep
- 29 selectSignals
- 30 setHeader
- 31 setStartTime
- 32 shift
- 33 signalCount
- 34 subtractSignal
- 35 subtractSignals
- 36 subtractValue
- 37 stalta
- 38 startTime
- 39 system
- 40 taper
- 41 waveletTransform
- 42 whiten
Categories
- Header data: header, setHeader
- Signal transformations: cut, shift
- Input/ouput: exportFile
- Time: addSeconds, addDays, addMonths, addYears, elapsedSeconds, startTime, endTime, setStartTime
- Miscelaneous: signalCount, saveStep, restoreStep
addDays
Syntax
string addDays(string dateTime, integer days);
Description
From a string containing an absolute time dateTime (format: yyyyMMddhhmmssz), adds days and returns a modified absolute time. days must by an integer.
Examples
print(addDays("20240829160235.540000", 1));
addMonths
Syntax
string addMonths(string dateTime, integer months);
Description
From a string containing an absolute time dateTime (format: yyyyMMddhhmmssz), adds months and returns a modified absolute time. months must by an integer.
Examples
print(addMonths("20240829160235.540000", 1));
addSeconds
Syntax
string addSeconds(string dateTime, number seconds);
Description
From a string containing an absolute time dateTime (format: yyyyMMddhhmmssz), adds seconds and returns a modified absolute time.
Examples
print(addSeconds("20240829160235.540000", 86401.06));
addYears
Syntax
string addYears(string dateTime, integer years]]]);
Description
From a string containing an absolute time dateTime (format: yyyyMMddhhmmssz), adds years and returns a modified absolute time. years must by an integer.
Examples
print(addYears("20240829160235.540000", 1));
agc
correlations
cut
Syntax
cut( Geopsy: Time range specification );
Description
Cut the signal between two time specifications
decimateAmplitude
decimateTime
elapsedSeconds
Syntax
elapsedSeconds(string dateTime1, string dateTime2);
Description
Returns the number of seconds between dateTime1 and dateTime2 (format: yyyyMMddhhmmssz).
Examples
print(elapsedSeconds("20240829160235.540000", "20240830160236.6"));
discreteFourierTransform
endTime
Syntax
string endTime(integer index);
Description
Returns the ending time of signal index with format yyyyMMddhhmmssz. See also startTime.
exportFile
Syntax
exportFile(string filePath[, bool useOriginalBaseName[, string format[, number pickNumber]]]);
Description
Export signal(s) to filePath. format is one of the string returned by:
geopsy -export-formats
Examples
Export the signal (assumed to have only one) to a SAC file (big endian).
exportFile("myfolder/mysignal.sac", false, "SacBigEndian");
fastFourierTransfrom
filter
header
Syntax
header(number signalIndex, string dataName, [string dataIndex]);
Description
Returns the value of dataName from signal having signalIndex. All header data related to signal file are not valid, because the process is always applied to a temporary copy of the original signal. Hence, a property like "ShortFileName" is useless in this environment.
Examples
Removes the first and the last sample of all signals
n=signalCount(); for(i=0;i<n;i++) { dt=header(i, "DeltaT"); setHeader(i, "TimePick", "t1", header(i, "T0")+dt); setHeader(i, "TimePick", "t2", header(i, "EndTime")-dt); } cut("Pick", "t1", "Pick", "t2");
leftJustified
Syntax
leftJustified(string text, integer nChars, string fillChar);
Description
Add fillChar at the end of text so that its length is nChars. text is not modified. Returned value: the modified text. It does nothing if the length of text is greater or equal to nChars.
Examples
see rightJustified
merge
mergeStations
multiply
newGroup
Syntax
newGroup(string path, string name, number start, number end);
Description
Creates a new group with signals from start to end. If path is empty, it adds the group at the root level. If not, it adds it in the tree at path.
Examples
Divides the current viewer in three groups
path="ISTerre/SmartSolo/Z" newGroup(path, "low gain", 0, 65); newGroup(path, "mid gain", 66, 131); newGroup(path, "high gain", 132, 219);
overSample
Syntax
print(string text)
Description
Prints a message to the log console. It is mainly used for debug.
Examples
print("Hello "+2024+" world!");
restoreStep
Syntax
restoreStep(string tag);
Description
Restore signals previously saved onto the stack under tag.
Examples
see saveStep()
rightJustified
Syntax
rightJustified(string text, integer nChars, string fillChar);
Description
Add fillChar at the beginning of text so that its length is nChars. text is not modified. The result is returned by the function. It does nothing if the length of text is greater or equal to nChars.
Examples
print(rightJustified(2, 4, "0"));
rotateComponents
saveStep
Syntax
saveStep(string tag);
Description
Saves the current signals onto the stack under tag. tag is an arbitrary string used to restoreStep() previously saved signals. This function is systematically produced when using the waveform menu items.
Examples
filter(); saveStep("Low pass 10 Hz"); whiten(); saveStep("Whiten"); restoreStep("Low pass 10 Hz"); clipStddev();
selectSignals
Syntax
selectSignals(number start, number end);
Description
Restrict the current list of signals to indexes ranging from start to end.
Examples
Rotate horizontal components to get north components parallel to the tangent of a circular array. Rotated components are exported.
n=signalCount()/3; cx=2000; cy=2000; for(i=0; i<n;i++) { restoreStep("original"); name=header(i*3, "Name"); x=header(i*3, "ReceiverX"); y=header(i*3, "ReceiverY"); a=Math.atan2(y-cy,x-cx)*180/3.141592; if(a<0) a+=360; selectSignals(i*3, i*3+2); rotateComponents(true, a, false, 0, false, 0); exportFile("/my/path/"+name+"_0001.sac"); print("Station "+name+" rotated by "+ a+" deg."); }
setHeader
Syntax
setHeader(number signalIndex, string dataName, [string dataIndex,] value);
Description
set dataName of signal having signalIndex to value. dataName may have an additional dataIndex for vectorial data (e.g. TimePick). For vectorial header data, dataIndex is mandatory.
Waveform processes described here are always applied to a temporary copy of the original signal. Hence, this function is not appropriate to modify signal header attributes of the original signal. The correct method is through Set header in menu Edit.
Examples
See signalCount() or header()
setStartTime
Syntax
string setStartTime(integer index, string dateTime);
Description
Sets the starting time of signal index with format yyyyMMddhhmmssz. See also startTime, endTime.
shift
Syntax
shift(number s);
Description
Shift signals by s seconds. s can a floating-point number and preferably a fraction a sampling period. The shift is made in frequency domain by altering only the phase of the signal.
Examples
Align samples to a round second for a signal sampled at 100 Hz. Current group of signal is supposed to contain only one signal (index=0).
t0=header(0, "T0"); t0rounded=Math.floor(t0*100)*0.01; shift(t0rounded-t0); setHeader(0, "T0", t0rounded);
signalCount
Syntax
integer signalCount();
Description
Returns the number of signals to process.
Examples
Sets the sampling frequency to 100 Hz for all signals
n=signalCount(); for(i=0;i<n;i++) { setHeader(i, "DeltaT", 0.01); }
subtractSignal
subtractSignals
subtractValue
stalta
startTime
Syntax
string startTime(integer index);
Description
Returns the starting time of signal index with format yyyyMMddhhmmssz. See also endTime.
system
Syntax
system(string command);
Description
Executes any system command with its arguments.
Examples
Removes file to exported right after to avoid confusion and warnings.
system("rm -f myfolder/mysignal.sac"); exportFile("myfolder/mysignal.sac", false, "SacBigEndian");
taper
Syntax
taper( Geopsy: Time range specification, number width);
Description
Multiply signal in time domain by a window function.