Skip to content

Commit

Permalink
Merge branch 'master' into fix_318
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-falco authored Aug 1, 2019
2 parents cd7fdf3 + eafbfc1 commit 9175ec7
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 31 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

Master:
ph5
* made pep8 compliant
* update all modules to use a standardized logger (issue #213)
* cleanup comments and remove commented out code (issue #216)
* cleanup comments and remove commented out code (issue #216)
* replace deprecated optparse with argparse module.
* update ph5 to better install c requirements
ph5.utilities.ph5
* add helpfile to utilities folder. Have not added pointer in setup.py as yet.
* add helpfile to utilities folder. Have not added pointer in setup.py as yet.
* Typing ph5 shows user the choices for help information.
* Usage: ph5 pforma (lists info about pforma)https://github.com/PIC-IRIS/PH5/pull/new/helpfile
ph5.clients.ph5toms
Expand Down Expand Up @@ -36,6 +37,8 @@ ph5.clients.ph5tostationxml
* Limit number of asynchronous processes
* Remove storage format from the sxml channel level to be compatible with sxml version 1.1
* ph5tostationxml now correctly handles stations with multiple deployments (issue #318)
* Add a new custom iris namespace attribute called iris:PH5ReportNum to the network StationXML element
* Remove the report number from the alternateCode value in the network StationXML element
ph5.utilities.ph5validate
* add data time checking
ph5.utilities.sort_kef_gen.py
Expand Down Expand Up @@ -79,6 +82,9 @@ ph5.entry_points
(2) entry points for use by setup.
ph5.help
* calls entry_points to print the short descriptions in alpha-order.
ph5.utilities.set_deploy_times
* An optional additional argument, --auto-correct, has been added. This argument permits the function to automatically change a .kef file's deploy times and pickup times.
* Times are changed to the floor and ceiling seconds that are defined by the start and end time of trace data to which the kef file refers.

v4.1.2:
ph5.utilities.ph5validate
Expand Down Expand Up @@ -230,7 +236,7 @@ v4.0.2

v4.0.1
- ph5.clients.ph5tostationxml
* updated to work with latest obspy response code
* updated to work with latest obspy response code

v4.0.0
- Initial Release
1 change: 1 addition & 0 deletions ph5/CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Jacobs, Katie
Pacheco, Celia
Thomas, David
Accardo, Natalie
Ronan, Tim
3 changes: 2 additions & 1 deletion ph5/clients/ph5toms.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,14 @@ def create_trace(self, station_to_cut, mp=False):
elif self.format.upper() == "SEGY1" or \
self.format.upper() == "SEGY2":
# These values are used to create the SEG-Y headers
obspy_trace.stats.receiver_id = stc.receiver_n_i
obspy_trace.stats.receiver_id = stc.station
obspy_trace.stats.ttype = trace.ttype
obspy_trace.stats.byteorder = trace.byteorder
obspy_trace.stats.elevation = float(stc.elev)
obspy_trace.stats.component = stc.component
obspy_trace.stats.response = self.get_response_obj(stc)
obspy_trace.stats.array = stc.array_code
obspy_trace.stats.das = stc.das
obspy_trace.stats.shot_id = stc.shot_id
obspy_trace.stats.shot_lat = stc.shot_lat
obspy_trace.stats.shot_lng = stc.shot_lng
Expand Down
10 changes: 8 additions & 2 deletions ph5/clients/ph5tostationxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,19 @@ def create_obs_network(self):
if obs_stations:
obs_network = inventory.Network(
self.experiment_t[0]['net_code_s'])
obs_network.alternate_code = \
self.experiment_t[0]['experiment_id_s']
obs_network.description = self.experiment_t[0]['longname_s']
start_time, end_time = self.get_network_date()
obs_network.start_date = UTCDateTime(start_time)
obs_network.end_date = UTCDateTime(end_time)
obs_network.total_number_of_stations = self.total_number_stations
extra = AttribDict({
'PH5ReportNum': {
'value': self.experiment_t[0]['experiment_id_s'],
'namespace': self.manager.iris_custom_ns,
'type': 'attribute'
}
})
obs_network.extra = extra
obs_network.stations = obs_stations
return obs_network
else:
Expand Down
112 changes: 87 additions & 25 deletions ph5/utilities/set_deploy_pickup_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import logging
import time
import re
from ph5.core import timedoy
import datetime
from ph5.core import timedoy, kefx, ph5api
from kef2ph5 import add_references
from math import floor, ceil

PROG_VERSION = '2018.268'

PROG_VERSION = '2019.197'
LOGGER = logging.getLogger(__name__)

os.environ['TZ'] = 'UTC'
Expand Down Expand Up @@ -65,14 +69,8 @@ def _epoch(self, epoch_l):
self.type_s = 'BOTH'


#
# Read Command line arguments
#


def get_args():
global ARRAY_FILE, DEPLOY, PICKUP

global ARRAY_FILE, DEPLOY, PICKUP, AUTO_CORRECT, NICKNAME, PATH
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.usage = (" set_deploy_pickup_times -a Array_t_xxx.kef "
Expand All @@ -85,19 +83,36 @@ def get_args():
help="The Array_t_xxx.kef file to modify.",
metavar="array_kef", required=True)

parser.add_argument("-d", "--deploy-time", dest="deploy_time",
parser.add_argument("-n", "--nickname", default="master.ph5",
type=str, metavar="nickname", required=False,
help="Name of the PH5 file.", dest="nickname")

parser.add_argument("-p", "--ph5path", action="store", default=".",
help=("Comma separated list of paths to ph5 "
"experiments."),
type=str, metavar="ph5path", required=False,
dest="path")

parser.add_argument("-dt", "--deploy-time", dest="deploy_time",
help="Array deployment time: YYYY:JJJ:HH:MM:SS",
metavar="deploy_time", required=True)
metavar="deploy_time", required=False)

parser.add_argument("-p", "--pickup-time", dest="pickup_time",
parser.add_argument("-pt", "--pickup-time", dest="pickup_time",
help="Array pickup time: YYYY:JJJ:HH:MM:SS",
metavar="pickup_time", required=True)
metavar="pickup_time", required=False)

args = parser.parse_args()
parser.add_argument("-ac", "--auto-correct", dest="auto_correct",
help="Assigns the metadata deploy and pickup times"
"to time stamps calculated by the PH5 traces.",
metavar="auto_correct", required=False, default=False)

args = parser.parse_args()
NICKNAME = args.nickname
PATH = args.path
ARRAY_FILE = args.array_kef
DEPLOY = args.deploy_time
PICKUP = args.pickup_time
AUTO_CORRECT = args.auto_correct


def barf(fh, of, dep_time, pu_time):
Expand Down Expand Up @@ -148,28 +163,75 @@ def barf(fh, of, dep_time, pu_time):
of.write("\t%s\n" % line)


def kefTables(kef_file, NICKNAME, PATH):

k = kefx.Kef(ARRAY_FILE)
k.open()
while True:
n = k.read(10000)
if n == 0:
LOGGER.error("Kef file is empty")
break
# Get Das_g references
ret = k.strip_receiver_g()
if ret:
add_references(ret)

# Make sure Array_t_xxx, Event_t_xxx, and Offset_t_aaa_sss exist
arrays, events, offsets = k.strip_a_e_o()


def main():
global ARRAY_FILE, DEPLOY, PICKUP
global ARRAY_FILE, DEPLOY, PICKUP, AUTO_CORRECT, NICKNAME, PATH

get_args()

if not os.path.exists(ARRAY_FILE):
LOGGER.error("Can't open {0}!".format(ARRAY_FILE))
sys.exit()
else:
fh = open(ARRAY_FILE)
mdir = os.path.dirname(ARRAY_FILE)
base = os.path.basename(ARRAY_FILE)
base = '_' + base
base = 'autocortime_{0}'.format(base)
of = open(os.path.join(mdir, base), 'w+')
LOGGER.info("Opened: {0}".join(os.path.join(mdir, base)))

dep_time = PH5_Time(passcal_s=DEPLOY)

pu_time = PH5_Time(passcal_s=PICKUP)

barf(fh, of, dep_time, pu_time)

# LOGGER.info("Opened: {0}".join(os.path.join(mdir, base)))
if AUTO_CORRECT:
ph5_api_object = ph5api.PH5(path=PATH, nickname=NICKNAME)
ph5_api_object.read_array_t_names()
if not ph5_api_object.Array_t_names:
LOGGER.error("No arrays or no events defined in ph5 file."
"Can not continue!")
ph5_api_object.close()
sys.exit()
LOGGER.info("Writing updated kef file: {0}".format(of.name))
for array_name in ph5_api_object.Array_t_names:
ph5_api_object.read_array_t(array_name)
arraybyid = ph5_api_object.Array_t[array_name]['byid']
arrayorder = ph5_api_object.Array_t[array_name]['order']
for ph5_station in arrayorder:
station_list = arraybyid.get(ph5_station)
for deployment in station_list:
station_len = len(station_list[deployment])
for st_num in range(0, station_len):
station = station_list[deployment][st_num]
true_deploy, true_pickup = \
ph5_api_object.get_extent(
das=station['das/serial_number_s'],
component=station['channel_number_i'],
sample_rate=station['sample_rate_i'])
julian_tdeploy = (
datetime.datetime.fromtimestamp(floor(true_deploy))
.strftime('%Y:%j:%H:%M:%S'))
julian_tpickup = (
datetime.datetime.fromtimestamp(ceil(true_pickup))
.strftime('%Y:%j:%H:%M:%S'))
dep_time = PH5_Time(passcal_s=julian_tdeploy)
pu_time = PH5_Time(passcal_s=julian_tpickup)
barf(fh, of, dep_time, pu_time)
else:
dep_time = PH5_Time(passcal_s=DEPLOY)
pu_time = PH5_Time(passcal_s=PICKUP)
barf(fh, of, dep_time, pu_time)
of.close()
fh.close()

Expand Down

0 comments on commit 9175ec7

Please sign in to comment.