-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into antenna-calibration-202310
- Loading branch information
Showing
62 changed files
with
3,460 additions
and
734 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# chart-config | ||
|
||
Build a chart plotting stream config file from delta meta & response information. | ||
|
||
## Overview | ||
|
||
The chart plotting software currently uses miniseed data as its input for plotting. To convert this to meaningful data, and to allow | ||
annotations some form of meta data is required. | ||
|
||
Two forms of metadata are compiles: the station and network descriptions; and the stream's scaling response to convert signal values. | ||
|
||
Extra streams can be provided, so long as the station details have been loaded into delta, this requires the stream srcname (NN_SSSS_LL_CCC) | ||
and the sampling frequency (e.g. `IU_RAR_10_BHZ:40`). | ||
|
||
## Usage: | ||
|
||
./chart-config [options] | ||
|
||
## Options: | ||
|
||
-base string | ||
delta base files | ||
-channels value | ||
channel selection regexp (default .*) | ||
-exclude value | ||
station exclusion regexp | ||
-extra string | ||
extra streams to include | ||
-include value | ||
station inclusion regexp | ||
-locations value | ||
location selection regexp (default .*) | ||
-networks value | ||
network selection regexp (default .*) | ||
-output string | ||
output chart configuration file | ||
-primary string | ||
add phase constituent for tsunami streams (default "M2") | ||
-resp string | ||
base directory for response xml files on disk | ||
-single | ||
only add one stream per station | ||
-skip string | ||
extra streams to exclude | ||
-stations value | ||
station selection regexp (default .*) | ||
|
||
## Example | ||
|
||
This is the output for the station `CAW` and the channel `EHZ`: | ||
|
||
``` | ||
[ | ||
{ | ||
"srcname": "NZ_CAW_10_EHZ", | ||
"network-code": "NZ", | ||
"station-code": "CAW", | ||
"location-code": "10", | ||
"channel-code": "EHZ", | ||
"station-name": "Cannon Point", | ||
"internal-network": "WL", | ||
"network-description": "Wellington regional seismic network", | ||
"latitude": -41.107194232, | ||
"longitude": 175.066438523, | ||
"sampling-period": 10000000, | ||
"sensitivity": 167772160, | ||
"gain": 1, | ||
"input_units": "m/s", | ||
"output_units": "count" | ||
} | ||
] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"os" | ||
"time" | ||
) | ||
|
||
// Stream is used to identify and describe streams that may be used for chart drawing. | ||
type Stream struct { | ||
// Srcname is the Stream identification encoded as per NN_SSSS_LL_CCC. | ||
Srcname string `json:"srcname"` | ||
// NetworkCode is the short code of Stream network (NN). | ||
NetworkCode string `json:"network-code"` | ||
// StationCode is the short code of the Stream station (SSSS). | ||
StationCode string `json:"station-code"` | ||
// LocationCode is the short code of the Stream site location (LL). | ||
LocationCode string `json:"location-code"` | ||
// ChannelCode is the short code of the Stream channel (CCC). | ||
ChannelCode string `json:"channel-code"` | ||
// StationName is the long name of the Stream station. | ||
StationName string `json:"station-name"` | ||
// InternalNetwok is the shore code of the Stream network lookup. | ||
InternalNetwork string `json:"internal-network"` | ||
// NetworkDescription is the long name of the Stream internal network. | ||
NetworkDescription string `json:"network-description,omitempty"` | ||
// Latitude is the Stream site latitude in decimal degrees. | ||
Latitude float64 `json:"latitude"` | ||
// Longitude is the Stream site longitude in decimal degrees. | ||
Longitude float64 `json:"longitude"` | ||
// Elevation is the Stream site height in meters above sea level. | ||
Elevation float64 `json:"elevation,omitempty"` | ||
// Depth is the Stream site depth in meters below water level. | ||
Depth float64 `json:"depth,omitempty"` | ||
// SamplingPeriod is the time interval between samples, in nanoseconds. | ||
SamplingPeriod time.Duration `json:"sampling-period,omitempty"` | ||
// TidalLag is lag of the primary tide for the site if appropriate. | ||
TidalLag float64 `json:"tidal-lag,omitempty"` | ||
// Sensitivity is the initial conversion factor to convert from counts to the desired units, or volts. | ||
Sensitivity float64 `json:"sensitivity,omitempty"` | ||
// Gain is an optional factor to convert from, usually, volts to the desired units. | ||
Gain float64 `json:"gain,omitempty"` | ||
// Bias is an optional factor to add to the output after scaling to offset the signal. | ||
Bias float64 `json:"bias,omitempty"` | ||
// InputUnits describes the expected input signal units. | ||
InputUnits string `json:"input_units,omitempty"` | ||
// OutputUnits describes the expected output signal units, which is usually counts. | ||
OutputUnits string `json:"output_units,omitempty"` | ||
} | ||
|
||
// Config is a slice of Stream vales. | ||
type Config []Stream | ||
|
||
// Write sends a JSON encoded byte array to a Writer interface. | ||
func (c Config) Write(wr io.Writer) error { | ||
enc := json.NewEncoder(wr) | ||
|
||
return enc.Encode(c) | ||
} | ||
|
||
// Marshal converts a Config into a JSON encoded byte array. | ||
func (c Config) Marshal() ([]byte, error) { | ||
var buf bytes.Buffer | ||
if err := c.Write(&buf); err != nil { | ||
return nil, err | ||
} | ||
return buf.Bytes(), nil | ||
} | ||
|
||
// Write sends a JSON encoded byte array to a file. | ||
func (c Config) WriteFile(path string) error { | ||
file, err := os.Create(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
return c.Write(file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
|
||
config := Config([]Stream{ | ||
{ | ||
Srcname: "NZ_CAW_10_EHZ", | ||
NetworkCode: "NZ", | ||
StationCode: "CAW", | ||
LocationCode: "10", | ||
ChannelCode: "EHZ", | ||
StationName: "Cannon Point", | ||
InternalNetwork: "WL", | ||
NetworkDescription: "Wellington regional seismic network", | ||
Latitude: -41.107194232, | ||
Longitude: 175.066438523, | ||
SamplingPeriod: 10000000, | ||
Sensitivity: 167772160, | ||
Gain: 1, | ||
InputUnits: "m/s", | ||
OutputUnits: "count", | ||
}, | ||
}) | ||
|
||
raw, err := os.ReadFile("./testdata/config.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
data, err := config.Marshal() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !cmp.Equal(raw, data) { | ||
t.Errorf("unexpected content -got/+exp\n%s", cmp.Diff(raw, data)) | ||
} | ||
} |
Oops, something went wrong.