Skip to content

Fix fixed camera offsets feature #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
39 changes: 33 additions & 6 deletions wmpl/Trajectory/Trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2544,12 +2544,14 @@ def __init__(self, jdt_ref, output_dir='.', max_toffset=None, meastype=4, verbos

# Estimating the difference in timing between stations, and the initial velocity if this flag is True
self.fixed_time_offsets = {}
self.fixed_time_offsets_copy = {}
if isinstance(estimate_timing_vel, str):

# If a list of fixed timing offsets was given, parse it into a dictionary
for entry in estimate_timing_vel.split(','):
station, offset = entry.split(":")
self.fixed_time_offsets[station] = float(offset)
self.fixed_time_offsets_copy[station] = float(offset)

print("Fixed timing given:", self.fixed_time_offsets)

Expand All @@ -2568,10 +2570,12 @@ def __init__(self, jdt_ref, output_dir='.', max_toffset=None, meastype=4, verbos
if estimate_timing_vel:

self.fixed_time_offsets = {}
self.fixed_time_offsets_copy = {}

for entry in self.fixed_times.split(','):
station, offset = entry.split(":")
self.fixed_time_offsets[station] = float(offset)
self.fixed_time_offsets_copy[station] = float(offset)


# Running Monte Carlo simulations to estimate uncertainties
Expand Down Expand Up @@ -2823,6 +2827,12 @@ def infillTrajectory(self, meas1, meas2, time_data, lat, lon, ele, station_id=No
if str(station_id) in self.fixed_time_offsets:
time_data += self.fixed_time_offsets[str(station_id)]

# Make a copy of the fixed offset values for output display purposes.
self.fixed_time_offsets_copy[str(station_id)] = self.fixed_time_offsets[str(station_id)]

# set the original value to zero as it has already been applied.
self.fixed_time_offsets[str(station_id)] = 0

# Skip the observation if all points were ignored
if ignore_list is not None:
if np.all(ignore_list):
Expand Down Expand Up @@ -3360,31 +3370,38 @@ def estimateTimingAndVelocity(self, observations, weights, estimate_timing_vel=T
# - if the time is fixed, a number is given
# - if the time is to be estimated, True is set
self.stations_time_dict = collections.OrderedDict()
self.stations_time_dict_copy = collections.OrderedDict()
station_list = [str(obs.station_id) for obs in observations]
for obs in observations:
if str(obs.station_id) in self.fixed_time_offsets:
self.stations_time_dict[str(obs.station_id)] = self.fixed_time_offsets[str(obs.station_id)]
self.stations_time_dict_copy[str(obs.station_id)] = self.fixed_time_offsets_copy[str(obs.station_id)]
else:
self.stations_time_dict[str(obs.station_id)] = True
self.stations_time_dict_copy[str(obs.station_id)] = True

# If no fixed times are given, set the station with the longest track as the reference station
# (time difference = 0)
if len(self.fixed_time_offsets) == 0:
obs_points = [obs.kmeas for obs in observations]
ref_index = obs_points.index(max(obs_points))
self.stations_time_dict[station_list[ref_index]] = 0
self.stations_time_dict_copy[station_list[ref_index]] = 0


# Generate an initial guess for stations which have no fixed time
p0 = np.zeros(len([val for val in self.stations_time_dict.values() if val is True]))

# If all stations are supplied with a time offset value, set them all to zero
if len([val for val in self.stations_time_dict.values() if val is True]) == 0:
p0 = np.zeros(1)


if self.verbose:
print('Initial function evaluation:', timingResiduals(p0, observations,
self.stations_time_dict,
weights=weights))


# Set bounds for timing to +/- given maximum time offset
bounds = []
for i in range(len(p0)):
Expand Down Expand Up @@ -3462,18 +3479,31 @@ def estimateTimingAndVelocity(self, observations, weights, estimate_timing_vel=T
# Check the station timing dictionary to see if the station is fixed
stat_status = self.stations_time_dict[str(obs.station_id)]

# Make a copy of the time offset from the original values stored before they were zeroed.
stat_status_copy = self.stations_time_dict_copy[str(obs.station_id)]

# If the station has a fixed time offset, read it
if not isinstance(stat_status, bool):
t_diff = stat_status
t_diff_copy = stat_status_copy

# Add the final time difference of the site to the list
time_diffs[i] = t_diff_copy

if self.verbose:
print('STATION ' + str(obs.station_id) + ' TIME OFFSET = ' + str(t_diff_copy) + ' s (fixed offset applied)')

# Otherwise read the estimated offset
else:
t_diff = timing_mini.x[stat_count]
stat_count += 1

# Add the final time difference of the site to the list
time_diffs[i] = t_diff

if self.verbose:
print('STATION ' + str(obs.station_id) + ' TIME OFFSET = ' + str(t_diff) + ' s')

if self.verbose:
print('STATION ' + str(obs.station_id) + ' TIME OFFSET = ' + str(t_diff) + ' s')

# Skip NaN and inf time offsets
if np.isnan(t_diff) or np.isinf(t_diff):
Expand All @@ -3486,9 +3516,6 @@ def estimateTimingAndVelocity(self, observations, weights, estimate_timing_vel=T
if obs.excluded_time is not None:
obs.excluded_time = [ex_time + t_diff for ex_time in obs.excluded_time]

# Add the final time difference of the site to the list
time_diffs[i] = t_diff



# Add in time and distance points, excluding the ignored points
Expand Down