Hi Marc,
Would you perhaps have a code that cuts and exports SAC signal per hour?
Thank you!
split signal per hour
Re: split signal per hour
Hi Leandro,
From the command line you can run a "waveform" script in which an export command will do the job.
For instance,
'HIS0000_Z.sac' is a 6-hour long signal. The file 'cut1h.js' is a javascript:
All available functions are listed here. Writing this small example, I noticed that justifying numbers is not a straight forward task with Javascript. Here I added a condition to insert the 0 if the number is lower than 10. I'm not a expert in Javascript but I found no simple solution from all I searched. I will probably add a function like 'justify' to provide this basic functionality.
The starting and ending time of the considered signal can be queried with header. A string representing the absolute time is returned. There is currently no function to manipulate this time easily. For example to add a given amount of seconds or hours. I will fix this in future releases.
Time operations can be also achieved outside the javascript in Bash or Python. Several calls to geopsy are then necessary which is slightly less efficient than running all inside a single instance. If scripting with Bash, you might be interested by 'gptime' (included in geopsypack, 'gptime -h all' for detials) to manipulate absolute times.
Best regards,
Marc
From the command line you can run a "waveform" script in which an export command will do the job.
For instance,
Code: Select all
geopsy -waveform cut1h.js HIS0000_Z.sac
Code: Select all
for(i=0;i<6;i++) {
if(i<10) {
istr="0"+i;
} else {
istr=i;
}
cut("[abs 20000101"+istr+"0000.000000; delta 1h]");
exportFile("cut_"+istr+".sac", false, "SacBigEndian");
restoreStep("original");
}
The starting and ending time of the considered signal can be queried with header. A string representing the absolute time is returned. There is currently no function to manipulate this time easily. For example to add a given amount of seconds or hours. I will fix this in future releases.
Time operations can be also achieved outside the javascript in Bash or Python. Several calls to geopsy are then necessary which is slightly less efficient than running all inside a single instance. If scripting with Bash, you might be interested by 'gptime' (included in geopsypack, 'gptime -h all' for detials) to manipulate absolute times.
Best regards,
Marc
Re: split signal per hour
The documentation was not up-to-date. In fact, there are some functions available for justifying numbers.
results with '0002'
I modified the documentation to list all function provided by geopsy on top of usual Javascript functions.
In particular, several functions to manipulate absolute time are available. A script to split a signal into blocks of one hour could be written this way:
The functions startTime() and endTime() will be available in the next release 3.6.0. They are currently only available if the code is compiled from the git repository. Meanwhile a workaround can be built with header(0, "StartTime") which returns the same information as startTime() with a distinct format not suitable for addSeconds() and elapsedSeconds().
Code: Select all
print(rightJustified(2. 4, "0"))
I modified the documentation to list all function provided by geopsy on top of usual Javascript functions.
In particular, several functions to manipulate absolute time are available. A script to split a signal into blocks of one hour could be written this way:
Code: Select all
for(t=startTime(0);elapsedSeconds(t, endTime(0))>=3600;t=addSeconds(t, 3600)) {
print(t);
cut("[abs "+t+"; delta 1h]");
exportFile("cut_"+t+".sac", false, "SacBigEndian");
restoreStep("original");
}
Code: Select all
function convertTime(t)
{
t=t.replace("-", "");
t=t.replace("-", "");
t=t.replace(":", "");
t=t.replace(":", "");
t=t.replace(" ", "");
return t;
}
for(t=convertTime(header(0, "StartTime"));
elapsedSeconds(t, convertTime(header(0, "EndTime")))>=3600;
t=addSeconds(t, 3600)) {
print(t);
cut("[abs "+t+"; delta 1h]");
exportFile("cut_"+t+".sac", false, "SacBigEndian");
restoreStep("original");
}