-
Notifications
You must be signed in to change notification settings - Fork 2
Feat(tracker): add rotation calculations #232
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
Merged
Merged
Changes from 52 commits
Commits
Show all changes
106 commits
Select commit
Hold shift + click to select a range
08e7204
fix(tracker): re-include masks in csv output
hollandjg 31cb081
feat: add csv joiner utility
hollandjg b75bfc0
Merge branch 'main' into feat(tracker)--add-rotation-calculations
hollandjg 7fa6d8b
remove psi column again
hollandjg 5540838
feat(cli): add get_rotation_single command to cli
hollandjg a5c51cc
feat(csvjoin): add support for joining on ISO8601 timestamps
hollandjg e869919
feat(cli): add stub of rotations function
hollandjg 9180765
test(cli): add test file for tracked floes with a satellite column
hollandjg d1bbb2e
feat(csvjoin): add support for different left and right columns
hollandjg 73cf648
feat(workflow): add support for rotation task
hollandjg 2a26614
add parsing of mask field
hollandjg aa31ca6
feat(rotation): add calculation of a single example rotation
hollandjg ed5be22
feat(rotation): output results for all rows in the input table
hollandjg eb53591
feat(rotation): add support for radians, degrees, and angular speeds …
hollandjg 20df957
chore(rotation): add dependencies
hollandjg b27bc8f
fix(workflow): update syntax for csvjoin and get_rotation_single scripts
hollandjg ae26884
chore: add missing whitespace
hollandjg 21f51a8
test(rotation): update path to tracked file
hollandjg 945790a
test(rotation): add synthetic rotation example
hollandjg 43e9501
test(rotation): add shorter test case
hollandjg f35b67f
test(rotation): add test-rotate file
hollandjg 68176b0
chore: export get_rotation_single
hollandjg 6f79737
test: fix function calls
hollandjg 99423f9
test(rotation): correct df index
hollandjg d74f833
test: rename test files
hollandjg 958bc98
rename rotation test set
hollandjg 4fdd6bc
refactor(rotation): change results calculation into a list comprehension
hollandjg 1900c2c
feat(rotation): convert time differences using Dates objects
hollandjg 7d23449
Revert "refactor(rotation): change results calculation into a list co…
hollandjg 7892667
refactor(rotation): update name of delta time column
hollandjg 559a45e
docs(rotation): add docstring
hollandjg f6f8ce2
refactor(rotations): rename variables
hollandjg 111610d
docs(rotation): update docstring
hollandjg 0bbe296
docs(rotation): add comment on append
hollandjg edd8290
downgrade required dates
hollandjg c817c49
refactor(rotation): split get_rotation_measurement into simpler funct…
hollandjg a1c374f
remove single-line function for calculating rotation mismatch
hollandjg 356dbea
refactor(rotation): split rotation function again for testing
hollandjg b638198
test(rotation): add testcases with less symmetric object
hollandjg 8701a5f
test(rotation): update testing function
hollandjg 00b0626
refactor(rotations): update the rotation function
hollandjg 1a9218e
teat(rotation): add some more testcases with larger images
hollandjg 6a36eea
chore: include LinearAlgebra dependency
hollandjg 07d9509
test(rotation): update testcases to allow some to fail
hollandjg b580de5
test(rotation): add note on target fraction
hollandjg 4418360
test: add LinearAlgebra dependency
hollandjg b44c7fd
test: update target correctness
hollandjg 1eed181
test(rotation): remove test weakening
hollandjg 220af60
feat(h5export): add support for zoned date times
hollandjg 539ce51
feat(tracker): add support for zoned date-times
hollandjg 2b77641
refactor(workflow): remove "Z" truncation on timestamps
hollandjg be035cc
fix(python): remove early instantiate call
hollandjg 30a22f6
add new rotation calculations
hollandjg 2d3e4d2
add extra dependencies
hollandjg fa53819
update rotation with new updates from Daniel
hollandjg cf9b66c
update tests to handle aliasing
hollandjg f9db046
add example vectors file
hollandjg 2941adb
delete vectors file
hollandjg 2c2f77e
add example floes tracked file
hollandjg 71efc9d
uncomment test cases for rotations
hollandjg 9805861
add debugging check to actions
hollandjg e1e9571
add additional check
hollandjg d961a13
add missing instantiate command
hollandjg eba42e3
Include Manifest for python setup
hollandjg f9b8b27
remove check registry steps
hollandjg 8b1cd97
fix timezone issue in tracker test
hollandjg cf4c224
delete quaddirect rotation algorithm
hollandjg cc04b83
add timezones to test package
hollandjg eab5dda
Merge branch 'cleanup-latlon-2' into feat(tracker)--add-rotation-calc…
hollandjg ec0f33f
import relevant functions at top of file
hollandjg d55ccf7
update type of props argument
hollandjg c1afbed
remove imageview dependency
hollandjg 4ad3e31
remove TestIMages dependency
hollandjg 05b0c1c
remove lots of dependencies
hollandjg 64bf6a5
remove CoordinateTransformations
hollandjg 9fe84f2
update overpass files with Z timezones
hollandjg 0af4a0c
rotations: cast string type to String
hollandjg 984fb04
update rotations to include additional columns as required
hollandjg 0c8189a
Add OrderedCollections dependency
hollandjg 76ca0e0
add rotation step in testcases
hollandjg 2999ae2
include satellite in output columns
hollandjg b75730d
add OrderedCollections compatibility
hollandjg 858baae
fix catenation
hollandjg ebe2c0c
revert changes to rose-suite.conf
hollandjg 121f9c9
remove cache directory
hollandjg 9f24c6c
undo other changes to flow.cylc
hollandjg 354a4d5
Merge branch 'main' into feat(tracker)--add-rotation-calculations
hollandjg cefdbe7
update rotations to use imported function from IceFloeTracker
hollandjg 7d74d7d
rename measure_rotation from get_rotations_single
hollandjg d7cccb9
remove LinearAlgebra dependency
hollandjg 976a00f
remove orderedColelctions dependency
hollandjg 9f294b6
remove unneeded imports
hollandjg 81e1b6f
remove interpolations dependency
hollandjg 9b0f4a0
remove unneeded dependencies
hollandjg 628e984
remove extra dependencies from test file
hollandjg 541adb2
rename rotations to rotation
hollandjg d7e4aba
update docstring
hollandjg ab9974e
update testcases
hollandjg 1422c30
fix testcase
hollandjg 2d19993
remove additional columns option in CLI
hollandjg 1dab817
remove outdated manifest file3
hollandjg 1d3c606
update IceFloeTracker version
hollandjg 814ba02
update pipeline CLI version
hollandjg 535eef6
remove broken instantiate call. No idea why this works sometimes and …
hollandjg b78aab3
remove setup python project file
hollandjg ce823e8
remove project and manifest file for python setup
hollandjg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,136 @@ | ||
using DataFrames | ||
using TimeZones | ||
using Dates | ||
using CSV | ||
|
||
# Base.tryparse(::Type{ZonedDateTime}, str) = ZonedDateTime | ||
# default_format(::Type{ZonedDateTime}) = Format("yyyy-mm-dd\\THH:MM:SS.sZ") | ||
|
||
""" | ||
Make a CSV of pairwise rotations between floes detected on adjacent days. | ||
|
||
Loads the floes from the `input` CSV file, and uses the columns: | ||
- `floe` ID | ||
- `satellite` name | ||
- `mask` – the binary mask (choose a column using argument `mask_column`) | ||
- `passtime` in ISO8601 format (with trailing Z or +00:00), e.g. 2022-09-11T09:21:00+00:00 (choose a column using argument `time_column`) | ||
- `date` of the overpass in YYYY-MM-DD format | ||
|
||
Returns a CSV with one row per floe comparison. | ||
In the following, `i=1` means the earlier observation, `i=2` the later. | ||
|
||
Columns returned: | ||
- `ID` of the floe | ||
- Angle measures `theta_<deg,rad>` – angle between floe image in degrees or radians | ||
- Time measurements: | ||
- `delta_time_sec` – number of seconds between overpass in the two measurements | ||
- `omega_<deg,rad>_per_<sec,hour,day>` – mean angular velocity of rotation in degrees or radians per second hour or day. | ||
- Metadata | ||
- `satellite<i>` – which satellite measurement `i` was from | ||
- `date<i>` – which date measurement `i` was taken | ||
- `datetime<i>` – which UTC time measurement `i`'s overpass occurred | ||
- Original data | ||
- `mask<i>` – the binary mask used for the measurement | ||
""" | ||
function get_rotation_single(; | ||
input::String, output::String, mask_column=:mask, time_column=:passtime | ||
) | ||
input_df = DataFrame(CSV.File(input)) | ||
|
||
input_df[!, mask_column] = eval.(Meta.parse.(input_df[:, mask_column])) | ||
input_df[!, time_column] = ZonedDateTime.(input_df[:, time_column]) | ||
|
||
results = [] | ||
for row in eachrow(input_df) | ||
append!( # adds the 0 – n measurements from `get_rotation_measurements` to the results array | ||
results, | ||
get_rotation_measurements( | ||
row, input_df; mask_column=mask_column, time_column=time_column | ||
), | ||
) | ||
end | ||
results_df = DataFrame(results) | ||
@info results_df | ||
|
||
FileIO.save(output, results_df) | ||
return results_df | ||
end | ||
|
||
function get_rotation_measurements( | ||
measurement::DataFrameRow, df::DataFrame; mask_column, time_column | ||
) | ||
filtered_df = subset( | ||
df, | ||
:ID => ByRow(==(measurement[:ID])), | ||
:date => ByRow(==(measurement[:date] - Dates.Day(1))), | ||
) | ||
|
||
results = [ | ||
get_rotation_measurements( | ||
earlier_measurement, measurement; mask_column, time_column | ||
) for earlier_measurement in eachrow(filtered_df) | ||
] | ||
|
||
return results | ||
end | ||
|
||
function get_rotation_measurements( | ||
row1::DataFrameRow, row2::DataFrameRow; mask_column, time_column | ||
) | ||
theta_rad = get_rotation(row1[mask_column], row2[mask_column]) | ||
theta_deg = rad2deg(theta_rad) | ||
|
||
dt = row2[time_column] - row1[time_column] | ||
dt_sec = dt / Dates.Second(1) | ||
dt_hour = dt / Dates.Hour(1) | ||
dt_day = dt / Dates.Day(1) | ||
|
||
omega_deg_per_sec = (theta_deg) / (dt_sec) | ||
omega_deg_per_hour = (theta_deg) / (dt_hour) | ||
omega_deg_per_day = (theta_deg) / (dt_day) | ||
|
||
omega_rad_per_sec = (theta_rad) / (dt_sec) | ||
omega_rad_per_hour = (theta_rad) / (dt_hour) | ||
omega_rad_per_day = (theta_rad) / (dt_day) | ||
|
||
return ( | ||
ID=row1.ID, | ||
theta_deg, | ||
theta_rad, | ||
delta_time_sec=dt_sec, | ||
omega_deg_per_sec, | ||
omega_deg_per_hour, | ||
omega_deg_per_day, | ||
omega_rad_per_sec, | ||
omega_rad_per_hour, | ||
omega_rad_per_day, | ||
satellite1=row1.satellite, | ||
satellite2=row2.satellite, | ||
date1=row1.date, | ||
date2=row2.date, | ||
datetime1=row1[time_column], | ||
datetime2=row2[time_column], | ||
mask1=row1[mask_column], | ||
mask2=row2[mask_column], | ||
) | ||
end | ||
|
||
""" | ||
Get the angle in radians to rotate mask1 to mask2. | ||
""" | ||
function get_rotation( | ||
mask1, mask2; mxshift::Tuple{Int64,Int64}=(100, 100), mxrot::Float64=Float64(pi) | ||
) | ||
affine_map, _ = IceFloeTracker.Register.RegisterQD.qd_rigid( | ||
IceFloeTracker.centered(mask1), | ||
IceFloeTracker.centered(mask2), | ||
mxshift, | ||
mxrot; | ||
print_interval=typemax(Int), | ||
) | ||
linear_map = affine_map.linear | ||
cosθ = linear_map[1, 1] | ||
sinθ = linear_map[2, 1] | ||
θ = atan(sinθ, cosθ) | ||
return θ | ||
end |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.