Skip to content
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

[Mid term] - Submission of Mid-term project #31

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b1f42be
Create KD_GPS_circular.md
dhamalakamal Oct 21, 2024
cb44b05
Data exported from phyphox app
dhamalakamal Oct 21, 2024
55de5fa
Create KD_GPS_triangular.md
dhamalakamal Oct 21, 2024
176f9f0
Create KD_acceleration.md
dhamalakamal Oct 21, 2024
5659d02
Create Documentation.md
dhamalakamal Oct 22, 2024
2e83017
Data files
dhamalakamal Oct 22, 2024
f08d1f8
Organize files
dhamalakamal Oct 22, 2024
3c0ba46
Created using Colab
dhamalakamal Oct 22, 2024
9602c6d
Create feet_to_meter.py
dhamalakamal Oct 22, 2024
88d9d2d
organize
dhamalakamal Oct 22, 2024
926f353
Created using Colab
dhamalakamal Oct 22, 2024
1298ccc
Code to convert feet , yard to meter using google colab
dhamalakamal Oct 22, 2024
44261de
Removing file and adding new ipynb file
dhamalakamal Oct 22, 2024
c2ac2c2
Create libraries_module.py
dhamalakamal Oct 23, 2024
8e47a80
Added gps distance measure module
dhamalakamal Oct 24, 2024
6ba520c
Added distance calculator module
dhamalakamal Oct 24, 2024
25d9de9
Added importable function to test distance calculator module
dhamalakamal Oct 24, 2024
874524f
Made corrections according to pylint
dhamalakamal Oct 24, 2024
0aec884
Removed unnecessary files
dhamalakamal Oct 24, 2024
5ab146e
Added docstrings
dhamalakamal Oct 24, 2024
564f4ce
Mvoed karkdown file from Documentation folder to Code folder
dhamalakamal Oct 24, 2024
f537920
Plot of GPS and acceleration coordinates
dhamalakamal Oct 24, 2024
69d8c12
Python file for acceleration calculation and importable functions
dhamalakamal Oct 25, 2024
28ddb1e
python module for Unix time calculation for and its importable functions
dhamalakamal Oct 25, 2024
953eaca
Merge branch 'mid_term' of https://github.com/dhamalakamal/CP1-24-mid…
dhamalakamal Oct 25, 2024
01e67e3
Fixed code and added docstring in the python module to calculate the …
dhamalakamal Oct 25, 2024
0dc923d
Added docstring at the front part of python module that converts feet…
dhamalakamal Oct 25, 2024
b621ed4
docstring format updated
dhamalakamal Oct 26, 2024
5577ef7
fixed format and docstring
dhamalakamal Oct 26, 2024
453a955
Added unit test for all modules and their methods
dhamalakamal Oct 26, 2024
f29c43c
cleaned imports
dhamalakamal Oct 26, 2024
03c6369
updated how to run md file
dhamalakamal Oct 26, 2024
b2d57ce
removed math from requirement file
dhamalakamal Oct 26, 2024
dd20d3c
fixed unix time expected value
dhamalakamal Oct 26, 2024
fa1a3ea
fix pylint
dhamalakamal Oct 26, 2024
c750696
line too long pylint issue fixed
dhamalakamal Oct 26, 2024
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
61 changes: 61 additions & 0 deletions Untitled2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyP30ixJ8Yfj1SlkejbeijC7",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/dhamalakamal/CP1-24-midterm/blob/mid_term/Untitled2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"id": "pBq2ejVqNAE1"
},
"outputs": [],
"source": [
"# Conversion factors\n",
"FEET_TO_METERS = 0.3048\n",
"YARDS_TO_METERS = 0.9144\n",
"def feet_to_meters(feet):\n",
" \"\"\"\n",
" Convert feet to meters.\n",
" Parameters:\n",
" feet (float): The distance in feet.\n",
" Returns:\n",
" float: The distance in meters.\n",
" \"\"\"\n",
" return feet * FEET_TO_METERS\n",
"def yards_to_meters(yards):\n",
" \"\"\"\n",
" Convert yards to meters.\n",
" Parameters:\n",
" yards (float): The distance in yards.\n",
" Returns:\n",
" float: The distance in meters.\n",
" \"\"\"\n",
" return yards * YARDS_TO_METERS"
]
}
]
}
21 changes: 21 additions & 0 deletions dhamalakamal/Code/acceleration_bottom_top.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
This module demonstrates the use of the `calculate_directions_from_csv`
function from the `acceleration_calculate` module to calculate azimuth
and elevation directions between GPS points provided in a CSV file.

The CSV file is expected to contain data that allows for the calculation
of directional angles (azimuth and elevation) for each point in relation to others.

Functions used:
- calculate_directions_from_csv(file_path):
Calculates the azimuth and elevation directions from the data provided in the CSV file.
"""

from acceleration_calculate import calculate_directions_from_csv

CSV_FILE = r'dhamalakamal/Data/Accl_bottom_top.csv'
calculated_directions = calculate_directions_from_csv(CSV_FILE)

print("Direction for points:")
for index, (azimuth, elevation) in enumerate(calculated_directions):
print(f"{index + 1}: Azimuth = {azimuth:.2f}°, Elevation = {elevation:.2f}°")
74 changes: 74 additions & 0 deletions dhamalakamal/Code/acceleration_calculate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
This module provides functions to calculate the direction of motion from recorded acceleration data,
based on azimuth and elevation angles derived from accelerometer readings in the X, Y, and Z axes.

Functions:
- calculate_direction(accel_x, accel_y, accel_z): Computes the azimuth (XY plane angle) and
elevation (vertical angle) from the provided acceleration data.
- calculate_directions_from_csv(file_path): Reads acceleration data from a CSV
file and calculates the direction of motion for each data point using the
calculate_direction function.

The calculated direction is represented by two angles:
- Azimuth: The angle between the positive X-axis and the projection of the
vector onto the XY plane (in degrees).
- Elevation: The angle between the vector and the XY plane,
i.e., how "upward" or "downward" the motion is (in degrees).

CSV File Structure:
The CSV file should contain the following columns:
- 'Acceleration_X': Acceleration data along the X-axis.
- 'Acceleration_Y': Acceleration data along the Y-axis.
- 'Acceleration_Z': Acceleration data along the Z-axis.
Additional columns like 'Timestamp' may be present, but are not used by the function.
"""

import pandas as pd
import numpy as np

COLS = [
"Linear Acceleration x (m/s^2)",
"Linear Acceleration y (m/s^2)",
"Linear Acceleration z (m/s^2)"
]

def calculate_direction(acc_x, acc_y, acc_z):
"""
Calculate the direction of motion based on acceleration data.
Args:
accel_x (float): Acceleration in the X direction.
accel_y (float): Acceleration in the Y direction.
accel_z (float): Acceleration in the Z direction.
Returns:
tuple: A tuple containing the angles (in degrees) representing the direction
of motion in the XY plane (azimuth) and elevation.
"""

# Calculate azimuth angle in the XY plane
direction_azimuth = np.arctan2(acc_y, acc_x) * (180 / np.pi)
# Calculate elevation angle
hypotenuse = np.sqrt(acc_x**2 + acc_y**2)
direction_elevation = np.arctan2(acc_z, hypotenuse) * (180 / np.pi)
return direction_azimuth, direction_elevation

def calculate_directions_from_csv(file_path):
"""
Read acceleration data from a CSV file and calculate the direction of motion
for each recorded data point.
Args:
file_path (str): Path to the CSV file containing acceleration data.
Returns:
list: A list of tuples containing the azimuth and elevation angles
for each recorded acceleration data point.
"""

# Load the acceleration data into a DataFrame
data = pd.read_csv(file_path, header=0)
directions = []
for row in data.iterrows():
acc_x = row[1]['Linear Acceleration x (m/s^2)']
acc_y = row[1]['Linear Acceleration y (m/s^2)']
acc_z = row[1]['Linear Acceleration z (m/s^2)']
direction = calculate_direction(acc_x, acc_y, acc_z)
directions.append(direction)
return directions
16 changes: 16 additions & 0 deletions dhamalakamal/Code/circular_gps_distance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
This module is to check the distance calculator module by passing the gps data file path
"""

from distance_calculator import load_gps_data, calculate_distances


# Replace with your actual file path
GPS_DATA_FILE_PATH = "dhamalakamal/Data/Circular_path_GPS.csv"
gps_data = load_gps_data(GPS_DATA_FILE_PATH)

if gps_data is not None:
distances = calculate_distances(gps_data)
print("Distances between adjacent GPS positions (in meters):")
for idx, distance in enumerate(distances, start=1):
print(f"Distance {idx}: {distance:.2f} meters")
37 changes: 37 additions & 0 deletions dhamalakamal/Code/convert_to_meter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Unit Conversion Module

This module provides simple conversion functions to convert distances from
feet and yards to meters.

Constants:
- FEET_TO_METERS: Conversion factor from feet to meters (1 foot = 0.3048 meters).
- YARDS_TO_METERS: Conversion factor from yards to meters (1 yard = 0.9144 meters).

Functions:
- feet_to_meters(feet): Converts a given distance in feet to meters.
- yards_to_meters(yards): Converts a given distance in yards to meters.
"""
# Conversion factors
FEET_TO_METERS = 0.3048
YARDS_TO_METERS = 0.9144

def feet_to_meters(feet):
"""
Convert feet to meters.
Parameters:
feet (float): The distance in feet.
Returns:
float: The distance in meters.
"""
return feet * FEET_TO_METERS

def yards_to_meters(yards):
"""
Convert yards to meters.
Parameters:
yards (float): The distance in yards.
Returns:
float: The distance in meters.
"""
return yards * YARDS_TO_METERS
80 changes: 80 additions & 0 deletions dhamalakamal/Code/distance_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
This module provides functions for calculating distance between two adjacent gps data.

Functions:
load_gps_data(file_path): Loads GPS positions containin latitude and longitude

calculate_distance(gps_data): Calculates distance between 2 adjacent coordinates

haversine(lat1, lon1, lat2, lon2): Haversine function to convert and calculate distance in meters

"""

import math
import pandas as pd

# Initialize global variables
# Radius of the Earth in meters
R = 6371000
# Required columns list
COLUMNS_NEEDED = ["Latitude (°)","Longitude (°)"]


def load_gps_data(file_path):
"""
Load GPS positions from the CSV file containing GPS coordinates.

:param file_path: Path to the CSV file containing GPS positions.
:return: DataFrame containing latitude and longitude.
"""
try:
# Read csv file with first row as header
gps_data = pd.read_csv(file_path, header=0)

# Extract only the latitude and longitude columns
gps_lat_lon_data = gps_data[COLUMNS_NEEDED]
print("GPS data loaded successfully.")
return gps_lat_lon_data
except ImportError as e:
print(f"Error loading GPS data: {e}")
return None

def haversine(lat1, lon1, lat2, lon2):
"""
Calculate the great-circle distance between two points on the Earth's surface
using the Haversine formula.

:param lat1: Latitude of the first point.
:param lon1: Longitude of the first point.
:param lat2: Latitude of the second point.
:param lon2: Longitude of the second point.
:return: Distance in meters between the two points.
"""
# Convert latitude and longitude from degrees to radians
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])

# Haversine formula
dlat = lat2 - lat1
dlon = lon2 - lon1
a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
c = 2 * math.asin(math.sqrt(a))

# Distance in meters
distance = R * c
return distance

def calculate_distances(gps_data):
"""
Calculate distances between adjacent GPS positions.

:param gps_data: DataFrame containing GPS coordinates (latitude, longitude).
:return: List of distances between adjacent GPS positions.
"""
distances = []
# Looping through each row of gps data to calculate distance among two adjacent coordinates
for i in range(len(gps_data) - 1):
lat1, lon1 = gps_data.iloc[i]
lat2, lon2 = gps_data.iloc[i + 1]
distance = haversine(lat1, lon1, lat2, lon2)
distances.append(distance)
return distances
Loading