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

Dev - Testing run on python 3.11 with GitHub workflow. #6

Merged
merged 9 commits into from
Jan 21, 2024
6 changes: 5 additions & 1 deletion .github/workflows/preliminary_test_conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- os: ubuntu-latest
label: linux-64
prefix: /usr/share/miniconda3/envs/my-env
python-version: 3.9
python-version: '3.11'

- os: ubuntu-latest
label: linux-64b
Expand Down Expand Up @@ -58,3 +58,7 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run Unit test with pytest
shell: bash -l {0}
run: |
python -m pytest --import-mode=append test/
55 changes: 33 additions & 22 deletions PtsLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ class PtsLine:
"""
Class to compute the equation of a line passing through two points.
"""
def __init__(self, x1: float, y1: float,
x2: float, y2: float) -> None:
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.m = (y2 - y1) / (x2 - x1)
self.q = y1 - (self.m * x1)
def __init__(self, x_pt1: float, y_pt1: float,
x_pt2: float, y_pt2: float) -> None:
self.x_1 = x_pt1
self.y_1 = y_pt1
self.x_2 = x_pt2
self.y_2 = y_pt2
self.m_val = (y_pt2 - y_pt1) / (x_pt2 - x_pt1)
self.q_val = y_pt1 - (self.m_val * x_pt1)

def y(self, x: float | np.ndarray) -> float | np.ndarray:
return self.m * x + self.q
def y_val(self, x_pt: float | np.ndarray) -> float | np.ndarray:
"""Return the y coordinate of the line at the given x coordinate."""
return self.m_val * x_pt + self.q_val

def x(self, y: float | np.ndarray) -> float | np.ndarray:
return (y - self.q) / self.m
def x_val(self, y_pt: float | np.ndarray) -> float | np.ndarray:
"""Return the x coordinate of the line at the given y coordinate."""
return (y_pt - self.q_val) / self.m_val


class PtsLineIntersect:
Expand All @@ -35,13 +37,22 @@ class PtsLineIntersect:
two points.
"""
def __init__(self, line_1: PtsLine, line_2: PtsLine) -> None:
self.m1 = line_1.m
self.q1 = line_1.q
self.m2 = line_2.m
self.q2 = line_2.q

def intersect(self) -> tuple[float, float]:
x = (self.q2 - self.q1) / (self.m1 - self.m2)
y = self.m1 * x + self.q1
return x, y

self.m_1 = line_1.m_val
self.q_1 = line_1.q_val
self.m_2 = line_2.m_val
self.q_2 = line_2.q_val

@property
def intersection(self) -> tuple[float, float]:
"""
Compute the intersection point of two lines.
Returns: Coordinates of the intersection point tuple[float, float].
"""
x_c = None
y_c = None
try:
x_c = (self.q_2 - self.q_1) / (self.m_1 - self.m_2)
y_c = self.m_1 * x_c + self.q_1
except ZeroDivisionError:
print("# - Lines are parallel.")
return x_c, y_c
8 changes: 3 additions & 5 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dependencies:
- cartopy
- gdal
- matplotlib
- netCDF4
- numpy
- pip
- pyproj
Expand All @@ -15,9 +14,8 @@ dependencies:
- pandas
- geopandas
- shapely
- rasterio
- xarray
- flake8
- pytest
- pydantic
- pytest-cov
- pytest-cov
- codecov
- coverage
Loading
Loading