Difference between revisions of "Geopsy: Waveform Scripting Language"

From GeopsyWiki
Jump to navigation Jump to search
Line 164: Line 164:
  
 
=== Description ===
 
=== Description ===
Creates a new group with signals from '''start''' to '''end'''.
+
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 ===
 
=== Examples ===
 
Divides the current viewer in three groups
 
Divides the current viewer in three groups

Revision as of 16:04, 8 January 2024

The scripting language is Javascript (a comprehensive tutorial)

Geopsy provides several additional functions for processing signals details here below

Categories

Alphabetical list

cut() restoreStep() shift()
exportFile() saveStep() signalCount()
header() setHeader() system()

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();

restoreStep

Syntax

 restoreStep(string tag);

Description

Restore signals previously saved onto the stack under tag.

Examples

 see saveStep()

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");

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);
 }

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");

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()

fastFourierTransfrom

subtractValue

subtractSignal

subtractSignals

multiply

filter

agc

whiten

stddevClip

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);

overSample

taper

 taper( Geopsy: Time range specification, number width);

cut

cut( Geopsy: Time range specification );

merge

mergeStations

decimateAmplitude

decimateTime

waveletTransform

stalta

discreteFourierTransform

rotateComponents

correlations

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.");
 }

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);

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");