ign-borea 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. borea/__init__.py +0 -0
  2. borea/datastruct/__init__.py +0 -0
  3. borea/datastruct/camera.py +25 -0
  4. borea/datastruct/dtm.py +119 -0
  5. borea/datastruct/gcp.py +22 -0
  6. borea/datastruct/shot.py +222 -0
  7. borea/datastruct/workdata.py +220 -0
  8. borea/format/__init__.py +0 -0
  9. borea/format/conl.py +143 -0
  10. borea/format/rpc.py +244 -0
  11. borea/geodesy/__init__.py +0 -0
  12. borea/geodesy/approx_euclidean_proj.py +91 -0
  13. borea/geodesy/euclidean_proj.py +25 -0
  14. borea/geodesy/local_euclidean_proj.py +127 -0
  15. borea/geodesy/proj_engine.py +70 -0
  16. borea/geodesy/projectionlist/__init__.py +0 -0
  17. borea/geodesy/projectionlist/search_proj.py +60 -0
  18. borea/geodesy/transform_geodesy.py +114 -0
  19. borea/process/__init__.py +0 -0
  20. borea/process/p_add_data/__init__.py +0 -0
  21. borea/process/p_add_data/p_add_shot.py +63 -0
  22. borea/process/p_add_data/p_file_gcp2d.py +55 -0
  23. borea/process/p_add_data/p_file_gcp3d.py +53 -0
  24. borea/process/p_add_data/p_gen_param.py +76 -0
  25. borea/process/p_add_data/p_pt2d.py +48 -0
  26. borea/process/p_add_data/p_pt3d.py +48 -0
  27. borea/process/p_add_data/p_unit_shot.py +48 -0
  28. borea/process/p_add_data/p_write.py +23 -0
  29. borea/process/p_format/__init__.py +0 -0
  30. borea/process/p_format/p_read_opk.py +78 -0
  31. borea/process/p_format/p_write_con.py +36 -0
  32. borea/process/p_format/p_write_opk.py +64 -0
  33. borea/process/p_format/p_write_rpc.py +48 -0
  34. borea/process/p_func/__init__.py +0 -0
  35. borea/process/p_func/p_control.py +67 -0
  36. borea/process/p_func/p_image_world.py +48 -0
  37. borea/process/p_func/p_spaceresection.py +51 -0
  38. borea/process/p_func/p_world_image.py +49 -0
  39. borea/reader/__init__.py +0 -0
  40. borea/reader/orientation/__init__.py +0 -0
  41. borea/reader/orientation/manage_reader.py +33 -0
  42. borea/reader/orientation/reader_opk.py +58 -0
  43. borea/reader/reader_camera.py +52 -0
  44. borea/reader/reader_point.py +113 -0
  45. borea/stat/__init__.py +0 -0
  46. borea/stat/statistics.py +215 -0
  47. borea/transform_world_image/__init__.py +0 -0
  48. borea/transform_world_image/transform_dtm/__init__.py +0 -0
  49. borea/transform_world_image/transform_dtm/world_image_dtm.py +47 -0
  50. borea/transform_world_image/transform_shot/__init__.py +0 -0
  51. borea/transform_world_image/transform_shot/conversion_coor_shot.py +58 -0
  52. borea/transform_world_image/transform_shot/image_world_shot.py +153 -0
  53. borea/transform_world_image/transform_shot/world_image_shot.py +117 -0
  54. borea/transform_world_image/transform_worksite/__init__.py +0 -0
  55. borea/transform_world_image/transform_worksite/image_world_intersection.py +154 -0
  56. borea/transform_world_image/transform_worksite/image_world_least_square.py +184 -0
  57. borea/transform_world_image/transform_worksite/image_world_work.py +49 -0
  58. borea/transform_world_image/transform_worksite/space_resection.py +343 -0
  59. borea/transform_world_image/transform_worksite/world_image_work.py +43 -0
  60. borea/utils/__init__.py +0 -0
  61. borea/utils/check/__init__.py +0 -0
  62. borea/utils/check/check_args_opk.py +59 -0
  63. borea/utils/check/check_args_reader_pt.py +44 -0
  64. borea/utils/check/check_array.py +56 -0
  65. borea/utils/check/check_header.py +90 -0
  66. borea/utils/check/check_order_axe.py +50 -0
  67. borea/utils/miscellaneous/__init__.py +0 -0
  68. borea/utils/miscellaneous/miscellaneous.py +83 -0
  69. borea/utils/miscellaneous/param_bundle.py +36 -0
  70. borea/utils/miscellaneous/sparse.py +31 -0
  71. borea/utils/singleton/__init__.py +0 -0
  72. borea/utils/singleton/singleton.py +23 -0
  73. borea/utils/xml/__init__.py +0 -0
  74. borea/utils/xml/xml.py +63 -0
  75. borea/worksite/__init__.py +0 -0
  76. borea/worksite/worksite.py +240 -0
  77. borea/writer/__init__.py +0 -0
  78. borea/writer/manage_writer.py +23 -0
  79. borea/writer/writer_con.py +29 -0
  80. borea/writer/writer_df_to_txt.py +32 -0
  81. borea/writer/writer_opk.py +70 -0
  82. borea/writer/writer_rpc.py +55 -0
  83. borea_tools/__init__.py +0 -0
  84. borea_tools/opk_control.py +33 -0
  85. borea_tools/opk_to_conl.py +33 -0
  86. borea_tools/opk_to_opk.py +33 -0
  87. borea_tools/opk_to_rpc.py +33 -0
  88. borea_tools/pt_image_to_world.py +32 -0
  89. borea_tools/pt_world_to_image.py +32 -0
  90. borea_tools/ptfile_image_to_world.py +32 -0
  91. borea_tools/ptfile_world_to_image.py +32 -0
  92. borea_tools/spaceresection_opk.py +34 -0
  93. ign_borea-0.1.5.dist-info/LICENSE +21 -0
  94. ign_borea-0.1.5.dist-info/METADATA +274 -0
  95. ign_borea-0.1.5.dist-info/RECORD +98 -0
  96. ign_borea-0.1.5.dist-info/WHEEL +5 -0
  97. ign_borea-0.1.5.dist-info/entry_points.txt +10 -0
  98. ign_borea-0.1.5.dist-info/top_level.txt +2 -0
@@ -0,0 +1,78 @@
1
+ """
2
+ Args of parser for reading opk file
3
+ """
4
+ import argparse
5
+ from borea.process.p_add_data.p_gen_param import args_general_param, process_args_gen_param
6
+ from borea.process.p_add_data.p_unit_shot import args_input_shot
7
+ from borea.worksite.worksite import Worksite
8
+ from borea.reader.orientation.manage_reader import reader_orientation
9
+
10
+
11
+ def args_reading_opk(parser: argparse) -> argparse:
12
+ """
13
+ Args for reading opk file.
14
+
15
+ Args:
16
+ parser (argparse): Parser to add argument.
17
+
18
+ Returns:
19
+ argsparse: Parser with argument.
20
+ """
21
+ # pylint: disable=duplicate-code
22
+ parser.add_argument('-r', '--filepath',
23
+ type=str, help='File path of the workfile.')
24
+ parser.add_argument('-i', '--header',
25
+ type=str, default="NXYZOPKC",
26
+ help='Type of each column in the site file.'
27
+ 'e.g. NXYZOPKC'
28
+ 'S: to ignore the column'
29
+ 'N: name of shot'
30
+ 'X: coordinate x of the shot position'
31
+ 'Y: coordinate y of the shot position'
32
+ 'Z: coordinate z of the shot position in altitude'
33
+ 'H: coordinate z of the shot position in height'
34
+ 'O: omega rotation angle'
35
+ 'P: phi rotation angle'
36
+ 'K: kappa rotation angle'
37
+ 'C: name of the camera')
38
+ parser.add_argument('-f', '--first_line',
39
+ type=int, default=1,
40
+ help='Line number to start file playback. First line in the file is 1.'
41
+ ' Does not take file header into account.')
42
+ parser.add_argument('-z', '--last_line',
43
+ type=int, default=None,
44
+ help='Line number to end file playback.'
45
+ ' If not set, all lines below -f will be read.')
46
+ parser = args_input_shot(parser)
47
+ parser = args_general_param(parser)
48
+ return parser
49
+
50
+
51
+ def process_args_read_opk(args: argparse) -> Worksite:
52
+ """
53
+ Processing args with data.
54
+
55
+ Args:
56
+ args (argparse): Arg to apply on worksite (data)
57
+
58
+ Returns:
59
+ Worksite: data
60
+ """
61
+ # Readind data
62
+ if args.filepath is not None:
63
+ if args.header is not None:
64
+ work = reader_orientation(args.filepath, {"order_axe": args.order_axe_input.lower(),
65
+ "interval": [args.first_line, args.last_line],
66
+ "header": list(args.header.upper()),
67
+ "unit_angle": args.unit_angle,
68
+ "linear_alteration": args.linear_alteration})
69
+ print("Orientation file reading done.")
70
+ print(f"Number of image: {len(work.shots)}")
71
+ else:
72
+ raise ValueError("The header file is missing -i.")
73
+ else:
74
+ raise ValueError("The access road to the photogrammetric site is missing -r.")
75
+
76
+ work = process_args_gen_param(args, work)
77
+
78
+ return work
@@ -0,0 +1,36 @@
1
+ """
2
+ Args of parser for writing conical file
3
+ """
4
+ import argparse
5
+ from borea.worksite.worksite import Worksite
6
+ from borea.writer.manage_writer import manager_writer
7
+
8
+
9
+ def args_write_con(parser: argparse) -> argparse:
10
+ """
11
+ Args for writing conical file of GEOVIEW IGN.
12
+
13
+ Args:
14
+ parser (argparse): Parser to add argument.
15
+
16
+ Returns:
17
+ argsparse: Parser with argument.
18
+ """
19
+ parser.add_argument('-w', '--pathreturn',
20
+ type=str, default='./',
21
+ help='Conversion path e.g. test/tmp/.')
22
+ return parser
23
+
24
+
25
+ def process_args_write_con(args: argparse, work: Worksite) -> None:
26
+ """
27
+ Processing args with data.
28
+
29
+ Args:
30
+ args (argparse): Arg to apply on worksite (data).
31
+ work (Worksite): Data.
32
+ """
33
+ # Writing data
34
+ print("Writing Conical file.")
35
+ manager_writer("con", None, args.pathreturn, None, work)
36
+ print(f"File written in folder {args.pathreturn} in .CON format.")
@@ -0,0 +1,64 @@
1
+ """
2
+ Args of parser for writing opk file
3
+ """
4
+ import argparse
5
+ from borea.process.p_add_data.p_unit_shot import args_output_shot
6
+ from borea.process.p_add_data.p_write import args_writer
7
+ from borea.worksite.worksite import Worksite
8
+ from borea.writer.manage_writer import manager_writer
9
+
10
+
11
+ def args_writing_opk(parser: argparse) -> argparse:
12
+ """
13
+ Args for writing opk file.
14
+
15
+ Args:
16
+ parser (argparse): Parser to add argument.
17
+
18
+ Returns:
19
+ argsparse: Parser with argument.
20
+ """
21
+ # pylint: disable=duplicate-code
22
+ parser = args_writer(parser)
23
+ parser.add_argument('-o', '--output_header',
24
+ type=str, default=None,
25
+ help='Type of each column in the site file.'
26
+ 'e.g. NXYZOPKC'
27
+ 'N: name of shot'
28
+ 'X: coordinate x of the shot position'
29
+ 'Y: coordinate y of the shot position'
30
+ 'Z: coordinate z of the shot position in altitude'
31
+ 'H: coordinate z of the shot position in height'
32
+ 'O: omega rotation angle'
33
+ 'P: phi rotation angle'
34
+ 'K: kappa rotation angle'
35
+ 'C: name of the camera')
36
+ parser = args_output_shot(parser)
37
+ return parser
38
+
39
+
40
+ def process_args_write_opk(args: argparse, work: Worksite) -> None:
41
+ """
42
+ Processing args with data.
43
+
44
+ Args:
45
+ args (argparse): Arg to apply on worksite (data).
46
+ work (Worksite): Data.
47
+ """
48
+ if args.order_axe_output:
49
+ args.order_axe_output = args.order_axe_output.lower()
50
+
51
+ if args.output_header:
52
+ args.output_header = list(args.output_header.upper())
53
+
54
+ # Writing data
55
+ print("Writing OPK.")
56
+ if args.namereturn is not None:
57
+ args_writing = {"order_axe": args.order_axe_output,
58
+ "header": args.output_header,
59
+ "unit_angle": args.output_unit_angle,
60
+ "linear_alteration": args.output_linear_alteration}
61
+ manager_writer("opk", args.namereturn, args.pathreturn, args_writing, work)
62
+ print(f"File written in {args.pathreturn + args.namereturn}.opk.")
63
+ else:
64
+ raise ValueError("The name of the saving file is missing -n.")
@@ -0,0 +1,48 @@
1
+ """
2
+ Args of parser for writing Rpc file
3
+ """
4
+ import argparse
5
+ from borea.worksite.worksite import Worksite
6
+ from borea.writer.manage_writer import manager_writer
7
+
8
+
9
+ def args_writing_rpc(parser: argparse) -> argparse:
10
+ """
11
+ Args for writing rpc file.
12
+
13
+ Args:
14
+ parser (argparse): Parser to add argument.
15
+
16
+ Returns:
17
+ argsparse: Parser with argument.
18
+ """
19
+ parser.add_argument('-w', '--pathreturn',
20
+ type=str, default='./',
21
+ help='Conversion path e.g. test/tmp/.')
22
+ parser.add_argument('-o', '--order',
23
+ type=int, default=3, choices=[1, 2, 3],
24
+ help="Degree of the polynomial of the rpc (1, 2, 3)")
25
+ parser.add_argument('-d', '--size_grid',
26
+ type=int, default=100,
27
+ help="Size of the grid to calculate Rpc.")
28
+ parser.add_argument('-l', '--fact_rpc',
29
+ type=float, default=None,
30
+ help="Factor Rpc for pyproj convertion.")
31
+ return parser
32
+
33
+
34
+ def process_args_write_rpc(args: argparse, work: Worksite) -> None:
35
+ """
36
+ Processing args with data.
37
+
38
+ Args:
39
+ args (argparse): Arg to apply on worksite (data).
40
+ work (Worksite): Data.
41
+ """
42
+ # Writing data
43
+ print("Writing Rpc.")
44
+ args_writing = {"order": args.order,
45
+ "size_grid": args.size_grid,
46
+ "fact_rpc": args.fact_rpc}
47
+ manager_writer("rpc", None, args.pathreturn, args_writing, work)
48
+ print(f"File written in folder {args.pathreturn} .txt.")
File without changes
@@ -0,0 +1,67 @@
1
+ """
2
+ Args of parser to control file
3
+ """
4
+ import argparse
5
+ from borea.worksite.worksite import Worksite
6
+ from borea.process.p_add_data.p_file_gcp2d import args_gcp2d, process_gcp2d
7
+ from borea.process.p_add_data.p_file_gcp3d import args_gcp3d, process_gcp3d
8
+ from borea.stat.statistics import Stat
9
+ from borea.transform_world_image.transform_worksite.world_image_work import WorldImageWork
10
+ from borea.transform_world_image.transform_worksite.image_world_work import ImageWorldWork
11
+
12
+
13
+ def args_control(parser: argparse) -> argparse:
14
+ """
15
+ Args to control photogrametrique file.
16
+
17
+ Args:
18
+ parser (argparse): Parser to add argument.
19
+
20
+ Returns:
21
+ argsparse: Parser with argument.
22
+ """
23
+ parser = args_gcp2d(parser)
24
+ parser = args_gcp3d(parser)
25
+ parser.add_argument('-d', '--control_type',
26
+ type=str, default=[], nargs='*',
27
+ help='Type of gcp to control.')
28
+ parser.add_argument('-p', '--process',
29
+ type=str, default="inter", choices=["inter", "square"],
30
+ help="Type of process for the function image to world,"
31
+ "intersection or least_square")
32
+ parser.add_argument('-w', '--pathreturn',
33
+ type=str, default='./',
34
+ help='Conversion path e.g. test/tmp/.')
35
+ return parser
36
+
37
+
38
+ def process_args_control(args, work: Worksite) -> None:
39
+ """
40
+ Processing args with data.
41
+
42
+ Args:
43
+ args (argparse): Arg to apply on worksite (data).
44
+ work (Worksite): Data.
45
+ """
46
+ # Read GCP 2D
47
+ work = process_gcp2d(args, work)
48
+
49
+ # Read GCP 3D
50
+ work = process_gcp3d(args, work)
51
+
52
+ # Calculate ground coordinate of conneting point by intersection
53
+ print("Calculation of data image to world.")
54
+ ImageWorldWork(work).manage_image_world(type_point="gcp2d",
55
+ type_process=args.process,
56
+ control_type=args.control_type)
57
+
58
+ # Calculate image coordinate of GCP if they exist
59
+ print("Calculation of data world to image.")
60
+ WorldImageWork(work).calculate_world_to_image(args.control_type)
61
+
62
+ # Statistics
63
+ print("Make statistics.")
64
+ stat = Stat(work, args.pathreturn, args.control_type)
65
+ stat.main_stat_and_save()
66
+ print("Statistics on control point, if there are,")
67
+ print(f" in {args.pathreturn}Stat_module_{work.name}.txt .")
@@ -0,0 +1,48 @@
1
+ """
2
+ Args of parser to calcule world coordinate.
3
+ """
4
+ import argparse
5
+ from borea.process.p_add_data.p_write import args_writer
6
+ from borea.worksite.worksite import Worksite
7
+ from borea.process.p_add_data.p_file_gcp2d import args_gcp2d, process_gcp2d
8
+ from borea.transform_world_image.transform_worksite.image_world_work import ImageWorldWork
9
+ from borea.writer.writer_df_to_txt import write_df_to_txt
10
+
11
+
12
+ def args_image_world(parser: argparse) -> argparse:
13
+ """
14
+ Args to control photogrametrique file.
15
+
16
+ Args:
17
+ parser (argparse): Parser to add argument.
18
+
19
+ Returns:
20
+ argsparse: Parser with argument.
21
+ """
22
+ parser = args_gcp2d(parser)
23
+ parser.add_argument('-p', '--process',
24
+ type=str, default="inter", choices=["inter", "square"],
25
+ help="Type of process for the function image to world,"
26
+ "intersection or least_square")
27
+ parser = args_writer(parser)
28
+ return parser
29
+
30
+
31
+ def process_image_world(args, work: Worksite) -> None:
32
+ """
33
+ Processing args with data.
34
+
35
+ Args:
36
+ args (argparse): Arg to apply on worksite (data).
37
+ work (Worksite): Data.
38
+ """
39
+ # Read GCP 2D
40
+ work = process_gcp2d(args, work)
41
+
42
+ # Calculate ground coordinate of conneting point by intersection
43
+ print("Calculation of data image to world.")
44
+ ImageWorldWork(work).manage_image_world(type_point="gcp2d",
45
+ type_process=args.process,
46
+ control_type=None)
47
+ df3d = work.get_point_world_dataframe("gcp2d", [])
48
+ write_df_to_txt(args.namereturn, args.pathreturn, df3d)
@@ -0,0 +1,51 @@
1
+ """
2
+ Args of parser to calcule 6 externals parameters of shots.
3
+ """
4
+ import argparse
5
+
6
+ import numpy as np
7
+ from borea.process.p_add_data.p_file_gcp2d import args_gcp2d
8
+ from borea.process.p_add_data.p_gen_param import args_general_param, process_args_gen_param
9
+ from borea.process.p_add_data.p_pt3d import args_add_pt3d
10
+ from borea.reader.reader_point import read_file_pt_dataframe
11
+ from borea.transform_world_image.transform_worksite.space_resection import SpaceResection
12
+ from borea.utils.check.check_args_opk import check_header_file
13
+ from borea.worksite.worksite import Worksite
14
+ from borea.process.p_add_data.p_file_gcp3d import args_gcp3d
15
+
16
+
17
+ def args_space_resection(parser: argparse) -> argparse:
18
+ """
19
+ Args to calcule 6 externals parameters of shots.
20
+
21
+ Args:
22
+ parser (argparse): Parser to add argument.
23
+
24
+ Returns:
25
+ argsparse: Parser with argument.
26
+ """
27
+ parser = args_add_pt3d(parser)
28
+ parser = args_general_param(parser)
29
+ parser = args_gcp2d(parser)
30
+ parser = args_gcp3d(parser)
31
+ return parser
32
+
33
+
34
+ def process_space_resection(args: argparse) -> Worksite:
35
+ """
36
+ Processing args with data.
37
+
38
+ Args:
39
+ args (argparse): Arg to apply on worksite (data).
40
+
41
+ Returns:
42
+ Worksite: data
43
+ """
44
+ work = Worksite("Space_Resection")
45
+ work = process_args_gen_param(args, work)
46
+ work.set_type_z_shot(check_header_file(list(args.output_header.upper()))[1])
47
+ pt2d = read_file_pt_dataframe(args.gcp2d, list(args.head_gcp2d.upper()), "pt2d")
48
+ pt3d = read_file_pt_dataframe(args.gcp3d, list(args.head_gcp3d.upper()), "pt3d")
49
+ pinit = {"coor_init": np.array(args.point3d)}
50
+ SpaceResection(work).space_resection_to_worksite(pt2d, pt3d, pinit)
51
+ return work
@@ -0,0 +1,49 @@
1
+ """
2
+ Args of parser to calcule image coordinate.
3
+ """
4
+ import argparse
5
+ from borea.process.p_add_data.p_file_gcp2d import args_gcp2d, process_gcp2d
6
+ from borea.process.p_add_data.p_write import args_writer
7
+ from borea.worksite.worksite import Worksite
8
+ from borea.process.p_add_data.p_file_gcp3d import args_gcp3d, process_gcp3d
9
+ from borea.transform_world_image.transform_worksite.world_image_work import WorldImageWork
10
+ from borea.writer.writer_df_to_txt import write_df_to_txt
11
+
12
+
13
+ def args_world_image(parser: argparse) -> argparse:
14
+ """
15
+ Args to control photogrametrique file.
16
+
17
+ Args:
18
+ parser (argparse): Parser to add argument.
19
+
20
+ Returns:
21
+ argsparse: Parser with argument.
22
+ """
23
+ parser = args_gcp3d(parser)
24
+ parser = args_gcp2d(parser)
25
+ parser.add_argument('-d', '--control_type',
26
+ type=str, default=[], nargs='*',
27
+ help='Type of gcp to control.')
28
+ parser = args_writer(parser)
29
+ return parser
30
+
31
+
32
+ def process_world_image(args, work: Worksite) -> None:
33
+ """
34
+ Processing args with data.
35
+
36
+ Args:
37
+ args (argparse): Arg to apply on worksite (data).
38
+ work (Worksite): Data.
39
+ """
40
+ # Read GCP 3D and 2D
41
+ work = process_gcp3d(args, work)
42
+ work = process_gcp2d(args, work)
43
+
44
+ # Calculate image coordinate of GCP if they exist
45
+ print("Calculation of data world to image.")
46
+ WorldImageWork(work).calculate_world_to_image(args.control_type)
47
+
48
+ df2d = work.get_point_image_dataframe("gcp3d", [])
49
+ write_df_to_txt(args.namereturn, args.pathreturn, df2d)
File without changes
File without changes
@@ -0,0 +1,33 @@
1
+ """
2
+ Photogrammetry site file reader module.
3
+ """
4
+ import importlib
5
+ from pathlib import Path, PureWindowsPath
6
+ from borea.worksite.worksite import Worksite
7
+
8
+
9
+ def reader_orientation(file: str, args: dict) -> Worksite:
10
+ """
11
+ Photogrammetric site file reading function.
12
+
13
+ Args:
14
+ file (str): Path to the worksite.
15
+ args (dict): Other information for reading the file.
16
+
17
+ Returns:
18
+ Worksite: The worksite.
19
+ """
20
+ # Attention multiple file management orientation
21
+ # Attention management of files with the same extension but different formats
22
+ file = Path(PureWindowsPath(file))
23
+ name_work = file.stem
24
+ ext = file.suffix[1:]
25
+
26
+ work = Worksite(name_work)
27
+ try:
28
+ my_module = importlib.import_module("borea.reader.orientation.reader_" + ext.lower())
29
+ work = my_module.read(file, args, work)
30
+ except ModuleNotFoundError as e:
31
+ raise ModuleNotFoundError(f"{ext} file is not taken into account !!!") from e
32
+
33
+ return work
@@ -0,0 +1,58 @@
1
+ """
2
+ A script to read opk file.
3
+ """
4
+ import platform
5
+ from pathlib import Path
6
+ import numpy as np
7
+ from borea.worksite.worksite import Worksite
8
+ from borea.utils.check.check_args_opk import check_args_opk
9
+
10
+
11
+ def read(file: Path, args: dict, work: Worksite) -> Worksite:
12
+ """
13
+ Reads an opk file to transform it into a Workside object.
14
+
15
+ Args:
16
+ file (Path): Path to the worksite.
17
+ args (dict): Information for reading an opk file.
18
+ keys:
19
+ "order_axe" (str): Order of rotation matrix axes,
20
+ "interval" (list): Interval of lines taken into account,
21
+ [i, j] if i or j is None = :. e.g. [1, None] = [1:].
22
+ "header" (list): List of column type file.
23
+ "unit_angle" (str): Unit of angle 'degrees' or 'radian'.
24
+ "linear_alteration" (bool): True if data corrected by linear alteration.
25
+ work (Worksite): Worksite to add shot.
26
+
27
+ Returns:
28
+ Worksite: The worksite.
29
+ """
30
+ args, header, type_z = check_args_opk(args)
31
+
32
+ try:
33
+ with open(file, 'r', encoding="utf-8") as file_opk:
34
+ for item_opk in file_opk.readlines()[args["interval"][0]:args["interval"][1]]:
35
+ if item_opk != '\n' and item_opk[0] != '#':
36
+ item_shot = item_opk.split()
37
+ if len(item_shot) != len(header):
38
+ raise ValueError(f"The number of columns in your file {len(item_shot)}"
39
+ " is different from the number of columns in your input"
40
+ f" format {len(header)}.")
41
+ work.add_shot(item_shot[header.index("N")],
42
+ np.array([float(item_shot[header.index("X")]),
43
+ float(item_shot[header.index("Y")]),
44
+ float(item_shot[header.index("Z")])], dtype=float),
45
+ np.array([float(item_shot[header.index("O")]),
46
+ float(item_shot[header.index("P")]),
47
+ float(item_shot[header.index("K")])], dtype=float),
48
+ item_shot[header.index("C")],
49
+ args["unit_angle"], args["linear_alteration"], args["order_axe"])
50
+ file_opk.close()
51
+ except FileNotFoundError as e:
52
+ raise FileNotFoundError(f"The path {file} is incorrect !!! "
53
+ f"or your os is {platform.system()}."
54
+ "For Windows path is \\,"
55
+ " for Linux and MacOS (Darwin) is / .") from e
56
+
57
+ work.type_z_shot = type_z
58
+ return work
@@ -0,0 +1,52 @@
1
+ """
2
+ Script to read camera file txt or xml.
3
+ """
4
+ from pathlib import Path, PureWindowsPath
5
+ from borea.datastruct.camera import Camera
6
+ from borea.worksite.worksite import Worksite
7
+
8
+
9
+ def read_camera(files: list, work: Worksite) -> None:
10
+ """
11
+ Manage file in list files to read.
12
+
13
+ Args:
14
+ files (list): Path list of files cameras.
15
+ work (Worksite): Worksite which needs camera data.
16
+ """
17
+ for file in files:
18
+ camera_txt(Path(PureWindowsPath(file)), work)
19
+
20
+
21
+ def camera_txt(file: Path, work: Worksite) -> None:
22
+ """
23
+ Read txt file camera.
24
+
25
+ Args:
26
+ files (Path): Path list of files cameras.
27
+ work (Worksite): Worksite which needs camera data.
28
+ """
29
+ dict_info = {}
30
+ try:
31
+ with open(file, 'r', encoding="utf-8") as file_cam:
32
+ for info_cam in file_cam.readlines():
33
+ if info_cam != '\n' and info_cam[0] != '#':
34
+ # Camera info retrieval
35
+ info_name, info_data = info_cam.split(" = ")
36
+ dict_info[info_name.lower()] = info_data[:-1]
37
+
38
+ file_cam.close()
39
+ except FileNotFoundError as e:
40
+ raise FileNotFoundError(f"The path {file} is incorrect !!!") from e
41
+
42
+ # Create Camera
43
+ cam = Camera(dict_info["name"])
44
+
45
+ for name_attr, item in dict_info.items():
46
+ if name_attr != "name":
47
+ type_item = int if name_attr in ["width", "height"] else float
48
+ try:
49
+ setattr(cam, name_attr.lower(), type_item(item))
50
+ except ValueError:
51
+ continue
52
+ work.cameras[dict_info["name"]] = cam