honeybee-radiance-postprocess 0.4.425__py2.py3-none-any.whl → 0.4.427__py2.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.
@@ -8,6 +8,7 @@ from .postprocess import post_process
8
8
  from .schedule import schedule
9
9
  from .translate import translate
10
10
  from .viewfactor import view_factor
11
+ from .merge import merge
11
12
 
12
13
 
13
14
  # command group for all postprocess extension commands.
@@ -24,6 +25,7 @@ postprocess.add_command(post_process, name='post-process')
24
25
  postprocess.add_command(schedule)
25
26
  postprocess.add_command(translate)
26
27
  postprocess.add_command(view_factor)
28
+ postprocess.add_command(merge)
27
29
 
28
30
  # add postprocess sub-commands to honeybee CLI
29
31
  main.add_command(postprocess)
@@ -0,0 +1,156 @@
1
+ """honeybee radiance postprocess merge commands."""
2
+ import click
3
+ import sys
4
+ import logging
5
+ import json
6
+ import numpy as np
7
+ from pathlib import Path
8
+
9
+ from honeybee_radiance_postprocess.reader import binary_to_array
10
+
11
+ _logger = logging.getLogger(__name__)
12
+
13
+
14
+ @click.group(help='Commands for generating and modifying sensor grids.')
15
+ def merge():
16
+ pass
17
+
18
+
19
+ @merge.command('merge-files')
20
+ @click.argument(
21
+ 'input-folder',
22
+ type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True))
23
+ @click.argument('extension', type=str)
24
+ @click.option(
25
+ '--output-file', '-of',
26
+ help='Name of the merged file.', default='results',
27
+ type=click.STRING
28
+ )
29
+ @click.option(
30
+ '--dist-info', '-di',
31
+ help='An optional input for distribution information to put the grids back together '
32
+ '. Alternatively, the command will look for a _redist_info.json file inside the '
33
+ 'folder.', type=click.Path(file_okay=True, dir_okay=False, resolve_path=True)
34
+ )
35
+ @click.option(
36
+ '--merge-axis', '-ma',
37
+ help='Merge files along axis.', default='0', show_default=True,
38
+ type=click.Choice(['0', '1', '2']), show_choices=True
39
+ )
40
+ @click.option(
41
+ '--output-extension', '-oe',
42
+ help='Output file extension. This is only used if as_text is set to True. '
43
+ 'Otherwise the output extension will be npy.', default='ill', type=click.STRING
44
+ )
45
+ @click.option(
46
+ '--as-text', '-at',
47
+ help='Set to True if the output files should be saved as text instead of '
48
+ 'NumPy files.', default=False, type=click.BOOL
49
+ )
50
+ @click.option(
51
+ '--fmt',
52
+ help='Format for the output files when saved as text.', default='%.2f',
53
+ type=click.STRING
54
+ )
55
+ @click.option(
56
+ '--delimiter',
57
+ help='Delimiter for the output files when saved as text.',
58
+ type=click.Choice(['space', 'tab']), default='tab'
59
+ )
60
+ def merge_files(
61
+ input_folder, output_file, extension, dist_info, merge_axis,
62
+ output_extension, as_text, fmt, delimiter):
63
+ """Merge files in a distributed folder.
64
+
65
+ \b
66
+ Args:
67
+ input_folder: Path to input folder.
68
+ output_folder: Path to the new restructured folder
69
+ extension: Extension of the files to collect data from. It will be ``pts`` for
70
+ sensor files. Another common extension is ``ill`` for the results of daylight
71
+ studies.
72
+ """
73
+ try:
74
+ # handle optional case for Functions input
75
+ if dist_info and not Path(dist_info).is_file():
76
+ dist_info = None
77
+ _merge_files(input_folder, output_file, int(merge_axis), extension, dist_info,
78
+ output_extension, as_text, fmt, delimiter)
79
+ except Exception:
80
+ _logger.exception('Failed to merge files from folder.')
81
+ sys.exit(1)
82
+ else:
83
+ sys.exit(0)
84
+
85
+
86
+ def _merge_files(
87
+ input_folder, output_file, merge_axis=0, extension='npy', dist_info=None,
88
+ output_extension='ill', as_text=False, fmt='%.2f', delimiter='tab'):
89
+ """Restructure files to the original distribution based on the distribution info.
90
+
91
+ It will assume that the files in the input folder are NumPy files. However,
92
+ if it fails to load the files as arrays it will try to load from binary
93
+ Radiance files to array.
94
+
95
+ Args:
96
+ input_folder: Path to input folder.
97
+ output_folder: Path to the new restructured folder.
98
+ merge_axis: Merge along axis.
99
+ extension: Extension of the files to collect data from. Default is ``npy`` for
100
+ NumPy files. Another common extension is ``ill`` for the results of daylight
101
+ studies.
102
+ dist_info: Path to dist_info.json file. If None, the function will try to load
103
+ ``_redist_info.json`` file from inside the input_folder. (Default: None).
104
+ output_extension: Output file extension. This is only used if as_text
105
+ is set to True. Otherwise the output extension will be ```npy``.
106
+ as_text: Set to True if the output files should be saved as text instead
107
+ of NumPy files.
108
+ fmt: Format for the output files when saved as text.
109
+ delimiter: Delimiter for the output files when saved as text.
110
+ """
111
+ if not dist_info:
112
+ _redist_info_file = Path(input_folder, '_redist_info.json')
113
+ else:
114
+ _redist_info_file = Path(dist_info)
115
+
116
+ assert _redist_info_file.is_file(), 'Failed to find %s' % _redist_info_file
117
+
118
+ with open(_redist_info_file) as inf:
119
+ data = json.load(inf)
120
+
121
+ out_arrays = []
122
+ src_file = Path()
123
+ for f in data:
124
+ output_file = Path(output_file)
125
+ # ensure the new folder is created. in case the identifier has a subfolder
126
+ parent_folder = output_file.parent
127
+ if not parent_folder.is_dir():
128
+ parent_folder.mkdir()
129
+
130
+ for src_info in f['dist_info']:
131
+ new_file = Path(input_folder, '%s.%s' %
132
+ (src_info['identifier'], extension))
133
+
134
+ if not new_file.samefile(src_file):
135
+ src_file = new_file
136
+ try:
137
+ array = np.load(src_file)
138
+ except Exception:
139
+ array = binary_to_array(src_file)
140
+
141
+ out_arrays.append(array)
142
+
143
+ out_array = np.concatenate(out_arrays, axis=merge_axis)
144
+
145
+ # save numpy array, .npy extension is added automatically
146
+ if not as_text:
147
+ np.save(output_file, out_array)
148
+ else:
149
+ if output_extension.startswith('.'):
150
+ output_extension = output_extension[1:]
151
+ if delimiter == 'tab':
152
+ delimiter = '\t'
153
+ elif delimiter == 'space':
154
+ delimiter = ' '
155
+ np.savetxt(output_file.with_suffix(f'.{output_extension}'),
156
+ out_array, fmt=fmt, delimiter=delimiter)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: honeybee-radiance-postprocess
3
- Version: 0.4.425
3
+ Version: 0.4.427
4
4
  Summary: Postprocessing of Radiance results and matrices
5
5
  Home-page: https://github.com/ladybug-tools/honeybee-radiance-postprocess
6
6
  Author: Ladybug Tools
@@ -13,7 +13,7 @@ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
13
13
  Classifier: Operating System :: OS Independent
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
- Requires-Dist: honeybee-radiance (==1.66.97)
16
+ Requires-Dist: honeybee-radiance (==1.66.99)
17
17
  Requires-Dist: numpy (>=1.21.6)
18
18
 
19
19
  [![Build Status](https://github.com/ladybug-tools/honeybee-radiance-postprocess/actions/workflows/ci.yaml/badge.svg)](https://github.com/ladybug-tools/honeybee-radiance-postprocess/actions)
@@ -13,10 +13,11 @@ honeybee_radiance_postprocess/reader.py,sha256=6myKzfGC1pO8zPixg1kKrKjPihHabTKUh
13
13
  honeybee_radiance_postprocess/type_hints.py,sha256=4R0kZgacQrqzoh8Tq7f8MVzUDzynV-C_jlh80UV6GPE,1122
14
14
  honeybee_radiance_postprocess/util.py,sha256=-J5k1dhvyYJkb42jvTS_xxtokfGbmcucVPXdMWU1jUk,5098
15
15
  honeybee_radiance_postprocess/vis_metadata.py,sha256=7ywIgdiuNKcctxifhpy7-Q2oaSX2ngQBeA0Kh7q1Gg0,1780
16
- honeybee_radiance_postprocess/cli/__init__.py,sha256=PVfwkuPFl4TnvQt8ovVm01JK0Alon81BaY-0tshAXyg,795
16
+ honeybee_radiance_postprocess/cli/__init__.py,sha256=uR3Q-VEhA6ZJPszRvOg_He8qm9HVFm_UxZTCfpLzLGw,851
17
17
  honeybee_radiance_postprocess/cli/abnt.py,sha256=GNLmVVrEQ-1oKr5ZmBllY-KODhgJPjLVidQ_dQMcpFk,15537
18
18
  honeybee_radiance_postprocess/cli/grid.py,sha256=6peLEAPVe-iw05_wdRpFruZLqO8myvC-_QT5W1q5sk8,10677
19
19
  honeybee_radiance_postprocess/cli/leed.py,sha256=bxGX2UBehYNcaPJWHL2yEasSP6dATD7B0aNNQOflqqM,3712
20
+ honeybee_radiance_postprocess/cli/merge.py,sha256=oOqqud3VSo-3f3coDoUILcp78OI4DKxXLWCS1bi3PC4,5752
20
21
  honeybee_radiance_postprocess/cli/mtxop.py,sha256=UZJnjNpPjDmShy1-Mxos4H2vTUqk_yP3ZyaC1_LLFeI,5015
21
22
  honeybee_radiance_postprocess/cli/postprocess.py,sha256=pzZ419eBt_LNNilW1y47c4lGTFxmV7cJyWnjV78GzY8,39202
22
23
  honeybee_radiance_postprocess/cli/schedule.py,sha256=6uIy98Co4zm-ZRcELo4Lfx_aN3lNiqPe-BSimXwt1F8,3877
@@ -31,9 +32,9 @@ honeybee_radiance_postprocess/results/__init__.py,sha256=1agBQbfT4Tf8KqSZzlfKYX8
31
32
  honeybee_radiance_postprocess/results/annual_daylight.py,sha256=11d4J1iIuITKuoWyWa-2_2WdrHYBULC0YP-mWBWi4JQ,34724
32
33
  honeybee_radiance_postprocess/results/annual_irradiance.py,sha256=5zwrr4MNeHUebbSRpSBbscPOZUs2AHmYCQfIIbdYImY,8298
33
34
  honeybee_radiance_postprocess/results/results.py,sha256=ABb_S8kDPruhGkDsfREXMg6K0p8FRhAZ3QIRUZCQPAI,54888
34
- honeybee_radiance_postprocess-0.4.425.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
35
- honeybee_radiance_postprocess-0.4.425.dist-info/METADATA,sha256=rAHEOlANogFdBn5e65jeedD6cgaV0TqaQWzj2yByUrY,2245
36
- honeybee_radiance_postprocess-0.4.425.dist-info/WHEEL,sha256=unfA4MOaH0icIyIA5oH6E2sn2Hq5zKtLlHsWapZGwes,110
37
- honeybee_radiance_postprocess-0.4.425.dist-info/entry_points.txt,sha256=gFtVPx6UItXt27GfEZZO00eOZChJJEL6JwGSAB_O3rs,96
38
- honeybee_radiance_postprocess-0.4.425.dist-info/top_level.txt,sha256=4-sFbzy7ewP2EDqJV3jeFlAFx7SuxtoBBELWaKAnLdA,30
39
- honeybee_radiance_postprocess-0.4.425.dist-info/RECORD,,
35
+ honeybee_radiance_postprocess-0.4.427.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
36
+ honeybee_radiance_postprocess-0.4.427.dist-info/METADATA,sha256=MzGC5ziOSmSVIde2gx7jfbA3VegykMHkX6oTCwqM6LE,2245
37
+ honeybee_radiance_postprocess-0.4.427.dist-info/WHEEL,sha256=unfA4MOaH0icIyIA5oH6E2sn2Hq5zKtLlHsWapZGwes,110
38
+ honeybee_radiance_postprocess-0.4.427.dist-info/entry_points.txt,sha256=gFtVPx6UItXt27GfEZZO00eOZChJJEL6JwGSAB_O3rs,96
39
+ honeybee_radiance_postprocess-0.4.427.dist-info/top_level.txt,sha256=4-sFbzy7ewP2EDqJV3jeFlAFx7SuxtoBBELWaKAnLdA,30
40
+ honeybee_radiance_postprocess-0.4.427.dist-info/RECORD,,