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

Fix bug absolute path on linux and macos #164

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions borea/datastruct/dtm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
A module for manipulating a digital elevation model.
"""
from pathlib import Path, PureWindowsPath
import numpy as np
from osgeo import gdal
from scipy import ndimage
from borea.transform_world_image.transform_dtm.world_image_dtm import WorldImageDtm
from borea.utils.check.check_path import check_path
from borea.utils.singleton.singleton import Singleton
gdal.UseExceptions()

Expand Down Expand Up @@ -49,7 +49,7 @@ def set_dtm(self, path_dtm: str, type_dtm: str) -> None:
if path_dtm:
gdal.AllRegister()
self.type_dtm = type_dtm
self.path_dtm = Path(PureWindowsPath(path_dtm))
self.path_dtm = check_path(path_dtm)
self.img = gdal.Open(self.path_dtm.as_posix())
self.rb = self.img.GetRasterBand(1)
self.nodata = self.rb.GetNoDataValue()
Expand Down
4 changes: 2 additions & 2 deletions borea/reader/orientation/manage_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Photogrammetry site file reader module.
"""
import importlib
from pathlib import Path, PureWindowsPath
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite


Expand All @@ -19,7 +19,7 @@ def reader_orientation(file: str, args: dict) -> Worksite:
"""
# Attention multiple file management orientation
# Attention management of files with the same extension but different formats
file = Path(PureWindowsPath(file))
file = check_path(file)
name_work = file.stem
ext = file.suffix[1:]

Expand Down
5 changes: 3 additions & 2 deletions borea/reader/reader_camera.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Script to read camera file txt or xml.
"""
from pathlib import Path, PureWindowsPath
from pathlib import Path
from borea.datastruct.camera import Camera
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite


Expand All @@ -15,7 +16,7 @@ def read_camera(files: list, work: Worksite) -> None:
work (Worksite): Worksite which needs camera data.
"""
for file in files:
camera_txt(Path(PureWindowsPath(file)), work)
camera_txt(check_path(file), work)


def camera_txt(file: Path, work: Worksite) -> None:
Expand Down
6 changes: 3 additions & 3 deletions borea/reader/reader_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Script to read point (connecting point, gcp2d gcp3d) format
.txt/.mes/.app with data arranged in columns.
"""
from pathlib import Path, PureWindowsPath
import pandas as pd
import numpy as np
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite
from borea.utils.check.check_args_reader_pt import check_header_file

Expand All @@ -26,7 +26,7 @@ def read_file_pt(path: str, header: list, type_point: str, work: Worksite) -> No
work.type_z_data = type_z

try:
with open(Path(PureWindowsPath(path)), 'r', encoding="utf-8") as file_pts:
with open(check_path(path), 'r', encoding="utf-8") as file_pts:
for pt in file_pts.readlines():
if pt != '\n' and pt[0] != '#':
info = pt.split()
Expand Down Expand Up @@ -74,7 +74,7 @@ def read_file_pt_dataframe(path: str, header: list, type_point: str) -> tuple:
ttype = []
coor = []
try:
with open(Path(PureWindowsPath(path)), 'r', encoding="utf-8") as file_pts:
with open(check_path(path), 'r', encoding="utf-8") as file_pts:
for pt in file_pts.readlines():
if pt != '\n' and pt[0] != '#':
info = pt.split()
Expand Down
4 changes: 2 additions & 2 deletions borea/stat/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""
import os
import io
from pathlib import Path, PureWindowsPath
import numpy as np
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite


Expand All @@ -22,7 +22,7 @@ def __init__(self, work: Worksite, pathoutput: str, type_point: list = None) ->
type_point (list): List of type point on which we make the stats.
"""
self.work = work
self.pathoutput = Path(PureWindowsPath(pathoutput))
self.pathoutput = check_path(pathoutput)

if type_point is None:
self.type_point = []
Expand Down
26 changes: 26 additions & 0 deletions borea/utils/check/check_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Script to check path of data.
"""
from pathlib import Path, PureWindowsPath, PurePosixPath


def check_path(file: str) -> Path:
"""
Check path of data if Posix of Windows path.

Args:
file (str): The path of data.

Returns:
Path: The good path.
"""
file = Path(file)
name = file.stem

if "/" in name:
return Path(PurePosixPath(file))

if "\\" in name:
return Path(PureWindowsPath(file))

return file
4 changes: 2 additions & 2 deletions borea/writer/writer_con.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Photogrammetry worksite to writing in rpc.
"""
import os
from pathlib import Path, PureWindowsPath
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite
from borea.geodesy.proj_engine import ProjEngine
from borea.format.conl import Conl
Expand Down Expand Up @@ -31,6 +31,6 @@ def write(name: str, folder_con: str, param_con: dict, work: Worksite) -> None:

for name_shot, shot in work.shots.items():
cam = work.cameras[shot.name_cam]
path_conical = os.path.join(Path(PureWindowsPath(folder_con)), f"{name_shot}.CON")
path_conical = os.path.join(check_path(folder_con), f"{name_shot}.CON")

Conl(shot, cam, geoview_proj).save_conl(path_conical)
4 changes: 2 additions & 2 deletions borea/writer/writer_df_to_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Photogrammetry worksite to writing dataframe to txt.
"""
import os
from pathlib import Path, PureWindowsPath
import pandas as pd
from borea.utils.check.check_path import check_path


def write_df_to_txt(name: str, pathreturn: str, df: pd.DataFrame) -> None:
Expand All @@ -15,7 +15,7 @@ def write_df_to_txt(name: str, pathreturn: str, df: pd.DataFrame) -> None:
pathreturn (str): Path to save the file.
df (pd.DataFrame): DataFrame to save.
"""
path_txt = os.path.join(Path(PureWindowsPath(pathreturn)), f"{name}.txt")
path_txt = os.path.join(check_path(pathreturn), f"{name}.txt")

name_column = list(df.columns)

Expand Down
4 changes: 2 additions & 2 deletions borea/writer/writer_opk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Photogrammetry worksite to writing in opk.
"""
import os
from pathlib import Path, PureWindowsPath
import numpy as np
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite
from borea.utils.check.check_args_opk import check_header_file

Expand All @@ -24,7 +24,7 @@ def write(name_opk: str, path_opk: str, args: dict, work: Worksite) -> None:
linear alteration.
work (Worksite): The site to be recorded.
"""
path_opk = os.path.join(Path(PureWindowsPath(path_opk)), f"{name_opk}.opk")
path_opk = os.path.join(check_path(path_opk), f"{name_opk}.opk")

if args["header"]:
header, type_z = check_header_file(args["header"])
Expand Down
6 changes: 3 additions & 3 deletions borea/writer/writer_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Photogrammetry worksite to writing in rpc.
"""
import os
from pathlib import Path, PureWindowsPath
from borea.format.rpc import Rpc
from borea.utils.check.check_path import check_path
from borea.worksite.worksite import Worksite
from borea.datastruct.dtm import Dtm

Expand Down Expand Up @@ -53,6 +53,6 @@ def write(name: str, folder_rpc: str, param_rpc: dict, work: Worksite) -> None:
for idx, val in enumerate(rpc.param_rpc["SAMP_DEN_COEFF"]):
list_txt_rpc += [f"SAMP_DEN_COEFF_{idx + 1}: {val}"]

path_rpc = os.path.join(Path(PureWindowsPath(folder_rpc)),
path_rpc = os.path.join(check_path(folder_rpc),
f"{name_shot}_RPC.TXT")
Path(path_rpc).write_text("\n".join(list_txt_rpc), encoding="UTF-8")
check_path(path_rpc).write_text("\n".join(list_txt_rpc), encoding="UTF-8")
Binary file modified docs/sphinx/_build/doctrees/borea.utils.check.doctree
Binary file not shown.
Binary file modified docs/sphinx/_build/doctrees/borea.utils.solver.doctree
Binary file not shown.
Binary file modified docs/sphinx/_build/doctrees/environment.pickle
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
5 changes: 3 additions & 2 deletions docs/sphinx/_build/html/_modules/borea/datastruct/dtm.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down Expand Up @@ -275,11 +276,11 @@ <h1>Source code for borea.datastruct.dtm</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">A module for manipulating a digital elevation model.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span><span class="p">,</span> <span class="n">PureWindowsPath</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">osgeo</span> <span class="kn">import</span> <span class="n">gdal</span>
<span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="n">ndimage</span>
<span class="kn">from</span> <span class="nn">borea.transform_world_image.transform_dtm.world_image_dtm</span> <span class="kn">import</span> <span class="n">WorldImageDtm</span>
<span class="kn">from</span> <span class="nn">borea.utils.check.check_path</span> <span class="kn">import</span> <span class="n">check_path</span>
<span class="kn">from</span> <span class="nn">borea.utils.singleton.singleton</span> <span class="kn">import</span> <span class="n">Singleton</span>
<span class="n">gdal</span><span class="o">.</span><span class="n">UseExceptions</span><span class="p">()</span>

Expand Down Expand Up @@ -327,7 +328,7 @@ <h1>Source code for borea.datastruct.dtm</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="n">path_dtm</span><span class="p">:</span>
<span class="n">gdal</span><span class="o">.</span><span class="n">AllRegister</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type_dtm</span> <span class="o">=</span> <span class="n">type_dtm</span>
<span class="bp">self</span><span class="o">.</span><span class="n">path_dtm</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">PureWindowsPath</span><span class="p">(</span><span class="n">path_dtm</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">path_dtm</span> <span class="o">=</span> <span class="n">check_path</span><span class="p">(</span><span class="n">path_dtm</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">img</span> <span class="o">=</span> <span class="n">gdal</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path_dtm</span><span class="o">.</span><span class="n">as_posix</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">img</span><span class="o">.</span><span class="n">GetRasterBand</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">nodata</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rb</span><span class="o">.</span><span class="n">GetNoDataValue</span><span class="p">()</span>
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/_build/html/_modules/borea/datastruct/gcp.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/_build/html/_modules/borea/format/conl.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/_build/html/_modules/borea/format/rpc.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.check.html">borea.utils.check package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.miscellaneous.html">borea.utils.miscellaneous package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.singleton.html">borea.utils.singleton package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.solver.html">borea.utils.solver package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../../../borea.utils.xml.html">borea.utils.xml package</a></li>
</ul>
</li>
Expand Down
Loading
Loading