Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/test_adria_array_embargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# ///

import requests
from obspy.core.inventory import Network, Station, Channel
from obspy.clients.fdsn import Client
from datetime import datetime

Expand All @@ -21,6 +22,35 @@ def list_stations(dc: dict, net: str):
return stations


def get_restricted_status(net: Network, sta: Station, cha: Channel):
"""
Determine "restricted status" of a channel, embedded in station and network
objects. It is assumed that a) the restricted status set on inner nodes
(e.g. Channel) overrules any potentially set restricted status set on outer
nodes (e.g. Network) and b) that the default restricted status is "open".
"""
# sanity check, make sure the provided items are actually nested
if sta not in net or cha not in sta:
raise ValueError('expected nested Network/Station/Channel')

# if Channel has restricted status set, use that
if cha.restricted_status is not None:
level = 'channel'
value = cha.restricted_status
# fall back to Station and check restricted status there
elif sta.restricted_status is not None:
level = 'station'
value = sta.restricted_status
# fall back to Network and check restricted status there
elif net.restricted_status is not None:
level = 'network'
value = net.restricted_status
else:
level = 'default'
value = 'open'
return level, value


# First fetch ADRIA ARRAY stations from the routing
resp = requests.get(
"https://www.orfeus-eu.org/eidaws/routing/1/query?service=station&network=_ADARRAY&format=json"
Expand All @@ -30,6 +60,7 @@ def list_stations(dc: dict, net: str):
# Embargo should start 2 years before now
embargo_start = datetime(datetime.now().year - 2, 1, 1)


for svc in inventory:
url = svc["url"]
# Make a unique list of networks
Expand All @@ -46,10 +77,11 @@ def list_stations(dc: dict, net: str):
for net in inventory.networks:
for sta in net.stations:
for cha in sta:
if cha.restricted_status == "closed":
r_level, r_status = get_restricted_status(net, sta, cha)
if r_status != 'open':
if cha.start_date < embargo_start:
restricted_channels.append(
f"{net.code}_{sta.code}_{cha.location_code}_{cha.code} [{cha.restricted_status}] {cha.start_date} -> {cha.end_date}"
f"{net.code}_{sta.code}_{cha.location_code}_{cha.code} [{r_level}:{r_status}] {cha.start_date} -> {cha.end_date}"
)

if len(restricted_channels) > 0:
Expand Down