hdfmap 0.4__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.
hdfmap/logging.py ADDED
@@ -0,0 +1,40 @@
1
+ """
2
+ Create logging objects and functions
3
+
4
+ See https://docs.python.org/3/howto/logging.html
5
+ """
6
+
7
+ import logging
8
+
9
+ # Setup config - doesn't work properly without this
10
+ logging.basicConfig() # setup logging
11
+
12
+
13
+ def create_logger(name: str) -> logging.Logger:
14
+ """Create new logger instance"""
15
+ return logging.getLogger(name)
16
+
17
+
18
+ def set_all_logging_level(level: str | int):
19
+ """
20
+ Set logging level of all loggers
21
+ Logging Levels (see builtin module logging)
22
+ 'notset' | 0
23
+ 'debug' | 10
24
+ 'info' | 20
25
+ 'warning' | 30
26
+ 'error' | 40
27
+ 'critical' | 50
28
+ :param level: str level name or int level
29
+ :return: None
30
+ """
31
+ try:
32
+ level = level.upper()
33
+ level = logging.getLevelNamesMapping()[level]
34
+ except AttributeError:
35
+ level = int(level)
36
+
37
+ logging_logger = logging.getLogger(__name__)
38
+ for logger in [logging.getLogger(name) for name in logging.root.manager.loggerDict]:
39
+ logger.setLevel(level)
40
+ logging_logger.info(f"Logging level set to {level}")
hdfmap/nexus.py ADDED
@@ -0,0 +1,240 @@
1
+ """
2
+ Nexus Related functions and nexus class
3
+ """
4
+
5
+ import h5py
6
+
7
+ from .logging import create_logger
8
+ from .hdfmap_class import HdfMap, build_hdf_path, generate_identifier, disp_dict
9
+
10
+ NX_CLASS = 'NX_class'
11
+ NX_ENTRY = 'NXentry'
12
+ NX_DATA = 'NXdata'
13
+ NX_LOCALNAME = 'local_name'
14
+ NX_DEFAULT = 'default'
15
+ NX_MEASUREMENT = 'measurement'
16
+ NX_SCANFIELDS = 'scan_fields'
17
+ NX_SIGNAL = 'signal'
18
+ NX_AXES = 'axes'
19
+ NX_DETECTOR = 'NXdetector'
20
+ NX_DETECTOR_DATA = 'data'
21
+ logger = create_logger(__name__)
22
+
23
+
24
+ def check_nexus_class(hdf_group: h5py.Group, nxclass: str) -> bool:
25
+ """
26
+ Check if hdf_group is a certain NX_class
27
+ :param hdf_group: hdf or nexus group object
28
+ :param nxclass: str name in NX_class attribute
29
+ :return: True/False
30
+ """
31
+ return (hdf_group and
32
+ (group_class := hdf_group.attrs.get(NX_CLASS)) is not None and
33
+ (group_class.decode() if isinstance(group_class, bytes) else group_class) == nxclass)
34
+
35
+
36
+ def default_nxentry(hdf_file: h5py.File) -> str | bytes:
37
+ """Return the default NXentry path, or the first NXentry if there is no default, errors if no NXentry"""
38
+ return entry if (
39
+ NX_DEFAULT in hdf_file.attrs and
40
+ isinstance(hdf_file.get(entry := hdf_file.attrs[NX_DEFAULT]), h5py.Group)
41
+ ) else next(path for path in hdf_file if check_nexus_class(hdf_file.get(path), NX_ENTRY))
42
+
43
+
44
+ def default_nxdata(entry_group: h5py.Group) -> str | bytes:
45
+ """Return the default NXdata path within an NXentry group"""
46
+ nx_data_name = entry_group.attrs[NX_DEFAULT] if NX_DEFAULT in entry_group.attrs else NX_MEASUREMENT
47
+ if nx_data_name not in entry_group:
48
+ nx_data_name = next(name for name in entry_group if check_nexus_class(entry_group.get(name), NX_DATA))
49
+ return nx_data_name
50
+
51
+
52
+ def find_nexus_data(hdf_file: h5py.File) -> tuple[list[str], str]:
53
+ """
54
+ Nexus compliant method of finding default plotting axes in hdf files
55
+ - find "default" entry group in top File group
56
+ - find "default" data group in entry (or 'measurement', or first 'NXdata')
57
+ - find "axes" attr in default data
58
+ - find "signal" attr in default data
59
+ - generate paths of signal and axes
60
+ if not nexus compliant, raises KeyError
61
+ This method is very fast but only works on nexus compliant files
62
+ :param hdf_file: open HDF file object, i.e. h5py.File(...)
63
+ :return axes_paths: list of str hdf paths for axes datasets
64
+ :return signal_path: str hdf path for signal dataset
65
+ """
66
+ # From: https://manual.nexusformat.org/examples/python/plotting/index.html
67
+ # find the default NXentry group
68
+ nx_entry_name = default_nxentry(hdf_file)
69
+ nx_entry = hdf_file[nx_entry_name]
70
+ # find the default NXdata group
71
+ nx_data_name = default_nxdata(nx_entry)
72
+ nx_data = nx_entry[nx_data_name]
73
+ # find the axes field(s)
74
+ if isinstance(axes := nx_data.attrs[NX_AXES], (str, bytes)):
75
+ axes_paths = [build_hdf_path(nx_entry_name, nx_data_name, axes)]
76
+ else:
77
+ axes_paths = [build_hdf_path(nx_entry_name, nx_data_name, _axes) for _axes in axes]
78
+ # get the signal field
79
+ if NX_SIGNAL in nx_data.attrs:
80
+ signal_path = build_hdf_path(nx_entry_name, nx_data_name, nx_data.attrs[NX_SIGNAL])
81
+ else:
82
+ signal_path = build_hdf_path(nx_entry_name, nx_data_name, NX_DETECTOR_DATA)
83
+ return axes_paths, signal_path
84
+
85
+
86
+ def find_nexus_data_strict(hdf_file: h5py.File) -> tuple[list[h5py.Dataset], h5py.Dataset]:
87
+ """
88
+ Nexus compliant method of finding default plotting axes in hdf files
89
+ - find "default" entry group in top File group
90
+ - find "default" data group in entry
91
+ - find "axes" attr in default data
92
+ - find "signal" attr in default data
93
+ - generate paths of signal and axes
94
+ if not nexus compliant, raises KeyError
95
+ This method is very fast but only works on nexus compliant files
96
+ :param hdf_file: open HDF file object, i.e. h5py.File(...)
97
+ :return axes_datasets: list of dataset objects for axes
98
+ :return signal_dataset: dataset object for plot axis
99
+ """
100
+ # From: https://manual.nexusformat.org/examples/python/plotting/index.html
101
+ # find the default NXentry group
102
+ nx_entry = hdf_file[hdf_file.attrs[NX_DEFAULT]]
103
+ # find the default NXdata group
104
+ nx_data = nx_entry[nx_entry.attrs[NX_DEFAULT]]
105
+ # find the axes field(s)
106
+ if isinstance(nx_data.attrs[NX_AXES], (str, bytes)):
107
+ axes_datasets = [nx_data[nx_data.attrs[NX_AXES]]]
108
+ else:
109
+ axes_datasets = [nx_data[_axes] for _axes in nx_data.attrs[NX_AXES]]
110
+ # find the signal field
111
+ signal_dataset = nx_data[nx_data.attrs[NX_SIGNAL]]
112
+ return axes_datasets, signal_dataset
113
+
114
+
115
+ class NexusMap(HdfMap):
116
+ """
117
+ HdfMap for Nexus (.nxs) files
118
+
119
+ Extends the HdfMap class with additional behaviours for NeXus files.
120
+ http://www.nexusformat.org/
121
+
122
+ E.G.
123
+ nxmap = NexusMap()
124
+ with h5py.File('file.nxs', 'r') as nxs:
125
+ nxmap.populate(nxs, default_entry_only=True) # populates only from the default entry
126
+
127
+ # Special behaviour
128
+ nxmap['axes'] -> return path of default axes dataset
129
+ nxmap['signal'] -> return path of default signal dataset
130
+ """
131
+
132
+ def __repr__(self):
133
+ return f"NexusMap based on '{self.filename}'"
134
+
135
+ def all_nxclasses(self) -> list[str]:
136
+ """Return list of unique NX_class attributes used in NXgroups"""
137
+ return list({
138
+ nxclass.decode() if isinstance(nxclass, bytes) else nxclass
139
+ for path, grp in self.groups.items() if (nxclass := grp.attrs.get(NX_CLASS))
140
+ })
141
+
142
+ def info_nexus(self) -> str:
143
+ """Return str info on nexus format"""
144
+ out = f"{repr(self)}\n"
145
+ out += f"{NX_CLASS}:\n"
146
+ nx_classes = self.all_nxclasses()
147
+ out += disp_dict({k: v for k, v in self.classes.items() if k in nx_classes}, 20)
148
+ out += '\nDefaults:\n'
149
+ out += f" @{NX_DEFAULT}: {self.find_attr(NX_DEFAULT)}\n"
150
+ out += f" @{NX_AXES}: {self.find_attr(NX_AXES)}\n"
151
+ out += f" @{NX_SIGNAL}: {self.find_attr(NX_SIGNAL)}\n"
152
+ return out
153
+
154
+ def _default_nexus_paths(self, hdf_file):
155
+ """Load Nexus default axes and signal"""
156
+ try:
157
+ axes_paths, signal_path = find_nexus_data(hdf_file)
158
+ # TODO: add method of including multiple axes, e.g. axes1, axes2, ..., or self.get_axes
159
+ if axes_paths and axes_paths[0] in hdf_file:
160
+ self.arrays[NX_AXES] = axes_paths[0]
161
+ logger.info(f"DEFAULT axes: {axes_paths}")
162
+ if signal_path in hdf_file:
163
+ self.arrays[NX_SIGNAL] = signal_path
164
+ logger.info(f"DEFAULT signal: {signal_path}")
165
+ except KeyError:
166
+ pass
167
+
168
+ def _scannables_from_scan_fields_or_nxdata(self, hdf_file: h5py.File):
169
+ """Generate scannables from scan_field names or default NXdata"""
170
+ # find 'scan_fields' to generate scannables list
171
+ if NX_SCANFIELDS in self.arrays:
172
+ scan_fields_path = self.arrays[NX_SCANFIELDS]
173
+ scan_fields = hdf_file[scan_fields_path][()]
174
+ logger.info(f"NX ScanFields: {scan_fields_path}: {scan_fields}")
175
+ self.generate_scannables_from_names(scan_fields)
176
+ else:
177
+ # find the default NXdata group and generate the scannables list
178
+ nx_entry = hdf_file.get(default_nxentry(hdf_file))
179
+ nx_data = nx_entry.get(default_nxdata(nx_entry))
180
+ logger.info(f"{nx_entry}, {nx_data}")
181
+ if nx_data:
182
+ logger.info(f"NX Data: {nx_data.name}")
183
+ self.generate_scannables_from_group(nx_data)
184
+
185
+ if not self.scannables:
186
+ logger.warning("No NXdata found, scannables not populated!")
187
+
188
+ def _image_data_from_nxdetector(self):
189
+ """find the NXdetector group and assign the image data"""
190
+ self.image_data = {}
191
+ if NX_DETECTOR in self.classes:
192
+ for group_path in self.classes[NX_DETECTOR]:
193
+ detector_name = generate_identifier(group_path)
194
+ data_path = build_hdf_path(group_path, NX_DETECTOR_DATA)
195
+ if data_path in self.datasets and len(self.datasets[data_path].shape) > 1:
196
+ self.image_data[detector_name] = data_path
197
+
198
+ if not self.image_data:
199
+ logger.warning("!!!Warning: No NXdetector found, image_data not populated!")
200
+
201
+ def populate(self, hdf_file: h5py.File, groups=None, default_entry_only=False):
202
+ """
203
+ Populate only datasets from default or first entry, with scannables from given groups.
204
+ Automatically load defaults (axes, signal) and generate scannables from default group
205
+ :param hdf_file: HDF File object
206
+ :param groups: list of group names or NXClass names to search for datasets, within default entry
207
+ :param default_entry_only: if True, only the first or default entry will be loaded
208
+ """
209
+ self.filename = hdf_file.filename
210
+
211
+ # Add defaults to arrays
212
+ self._default_nexus_paths(hdf_file)
213
+
214
+ if default_entry_only:
215
+ entries = [default_nxentry(hdf_file)]
216
+ else:
217
+ entries = [entry for entry in hdf_file if check_nexus_class(hdf_file.get(entry), NX_ENTRY)]
218
+
219
+ for entry in entries:
220
+ # find default or first entry
221
+ nx_entry = hdf_file.get(entry)
222
+ if nx_entry is None:
223
+ logger.warning(
224
+ f"NX Entry {entry} doesn't exist - may be a missing link.\n" +
225
+ f"Missing link: {hdf_file.get(entry, getlink=True)}"
226
+ )
227
+ continue # group may be missing due to a broken link
228
+ hdf_path = build_hdf_path(entry)
229
+ logger.debug(f"NX Entry: {hdf_path}")
230
+ self.all_paths.append(hdf_path)
231
+ self._store_group(nx_entry, hdf_path, entry)
232
+ self._populate(nx_entry, root=hdf_path, groups=groups) # nx_entry.name can be wrong!
233
+
234
+ if not self.datasets:
235
+ logger.warning("!!!Warning: No datasets found!")
236
+
237
+ self._scannables_from_scan_fields_or_nxdata(hdf_file)
238
+
239
+ # find the NXdetector group and assign the image data
240
+ self._image_data_from_nxdetector()
@@ -0,0 +1,140 @@
1
+ """
2
+ Reloader class
3
+ """
4
+
5
+ import h5py
6
+ import numpy as np
7
+
8
+ from .hdfmap_class import HdfMap
9
+ from .nexus import NexusMap
10
+ from .file_functions import load_hdf, create_hdf_map, create_nexus_map
11
+
12
+
13
+ class HdfLoader:
14
+ """
15
+ HDF Loader
16
+ contains the filename and hdfmap for a HDF file, the hdfmap contains all the dataset paths and a
17
+ namespace, allowing data to be called from the file using variable names, loading only the required datasets
18
+ for each operation.
19
+ E.G.
20
+ hdf = HdfLoader('file.hdf')
21
+ [data1, data2] = hdf.get_data(['dataset_name_1', 'dataset_name_2'])
22
+ data = hdf.eval('dataset_name_1 * 100 + 2')
23
+ string = hdf.format('my data is {dataset_name_1:.2f}')
24
+ """
25
+
26
+ def __init__(self, hdf_filename: str, hdf_map: HdfMap | None = None):
27
+ self.filename = hdf_filename
28
+ if hdf_map is None:
29
+ self.map = create_hdf_map(hdf_filename)
30
+ else:
31
+ self.map = hdf_map
32
+
33
+ def __repr__(self):
34
+ return f"HdfReloader('{self.filename}')"
35
+
36
+ def __str__(self):
37
+ with self._load() as hdf:
38
+ out = self.map.info_data(hdf)
39
+ return out
40
+
41
+ def __getitem__(self, item):
42
+ return self.get_data(item)
43
+
44
+ def __call__(self, expression):
45
+ return self.eval(expression)
46
+
47
+ def _load(self) -> h5py.File:
48
+ return load_hdf(self.filename)
49
+
50
+ def get_hdf_path(self, name_or_path: str) -> str or None:
51
+ """Return hdf path of object in HdfMap"""
52
+ return self.map.get_path(name_or_path)
53
+
54
+ def find_hdf_paths(self, string: str, name_only: bool = True) -> list[str]:
55
+ """
56
+ Find any dataset paths that contain the given string argument
57
+ :param string: str to find in list of datasets
58
+ :param name_only: if True, search only the name of the dataset, not the full path
59
+ :return: list of hdf paths
60
+ """
61
+ return self.map.find_paths(string, name_only)
62
+
63
+ def find_names(self, string: str) -> list[str]:
64
+ """
65
+ Find any dataset names that contain the given string argument, searching names in self.combined
66
+ :param string: str to find in list of datasets
67
+ :return: list of names
68
+ """
69
+ return self.map.find_names(string)
70
+
71
+ def get_data(self, *name_or_path, index: slice = (), default=None, direct_load=False):
72
+ """
73
+ Return data from dataset in file, converted into either datetime, str or squeezed numpy.array objects
74
+ See hdfmap.eval_functions.dataset2data for more information.
75
+ :param name_or_path: str name or path pointing to dataset in hdf file
76
+ :param index: index or slice of data in hdf file
77
+ :param default: value to return if name not found in hdf file
78
+ :param direct_load: return str, datetime or squeezed array if False, otherwise load data directly
79
+ :return: dataset2data(dataset) -> datetime, str or squeezed array as required.
80
+ """
81
+ with self._load() as hdf:
82
+ out = [self.map.get_data(hdf, name, index, default, direct_load) for name in name_or_path]
83
+ if len(name_or_path) == 1:
84
+ return out[0]
85
+ return out
86
+
87
+ def get_image(self, index: slice = None) -> np.ndarray:
88
+ """
89
+ Get image data from file, using default image path
90
+ :param index: (slice,) or None to take the middle image
91
+ :return: numpy array of image
92
+ """
93
+ with self._load() as hdf:
94
+ return self.map.get_image(hdf, index)
95
+
96
+ def get_metadata(self, defaults=None):
97
+ with self._load() as hdf:
98
+ return self.map.get_metadata(hdf, default=defaults)
99
+
100
+ def get_scannables(self):
101
+ """Return scannables from file (values associated with hdfmap.scannables)"""
102
+ with self._load() as hdf:
103
+ return self.map.get_scannables(hdf)
104
+
105
+ def eval(self, expression: str):
106
+ """
107
+ Evaluate an expression using the namespace of the hdf file
108
+ :param expression: str expression to be evaluated
109
+ :return: eval(expression)
110
+ """
111
+ with self._load() as hdf:
112
+ return self.map.eval(hdf, expression)
113
+
114
+ def format(self, expression: str):
115
+ """
116
+ Evaluate a formatted string expression using the namespace of the hdf file
117
+ :param expression: str expression using {name} format specifiers
118
+ :return: eval_hdf(f"expression")
119
+ """
120
+ with self._load() as hdf:
121
+ return self.map.format_hdf(hdf, expression)
122
+
123
+
124
+ class NexusLoader(HdfLoader):
125
+ """
126
+ Nexus Loader
127
+ contains the filename and hdfmap for a NeXus file, the hdfmap contains all the dataset paths and a
128
+ namespace, allowing data to be called from the file using variable names, loading only the required datasets
129
+ for each operation.
130
+ E.G.
131
+ hdf = NexusLoader('file.hdf')
132
+ [data1, data2] = hdf.get_data(['dataset_name_1', 'dataset_name_2'])
133
+ data = hdf.eval('dataset_name_1 * 100 + 2')
134
+ string = hdf.format('my data is {dataset_name_1:.2f}')
135
+ """
136
+
137
+ def __init__(self, nxs_filename: str, hdf_map: NexusMap | None = None):
138
+ if not hdf_map:
139
+ hdf_map = create_nexus_map(nxs_filename)
140
+ super().__init__(nxs_filename, hdf_map)
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.