-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Used Irregular tags which are parsed from the file
- Loading branch information
1 parent
48564f6
commit dd676b7
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import logging | ||
import re | ||
from .base import Reader | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
UNIT_EXTENSION = "_unit" | ||
|
||
|
||
class TifReader(Reader): | ||
identifier = 'tif_reader' | ||
priority = 96 | ||
_parsed_values = None | ||
|
||
|
||
def check(self): | ||
result = False | ||
if self.file.suffix.lower() == '.tif' and self.file.mime_type == 'image/tiff': | ||
self._parsed_values = self._read_img() | ||
result = self._parsed_values is not None and len(self._parsed_values) > 0 | ||
logger.debug('result=%s', result) | ||
return result | ||
def _read_img(self): | ||
txt = re.sub(r'\\x[0-9a-f]{2}', '', self.file.content.__str__()) | ||
|
||
txt = re.sub(r'^.+@@@@@@0\\r\\n', '', txt) | ||
lines = re.split(r'\\r\\n', txt) | ||
del lines[-1] | ||
return [x.split('=') for x in lines] | ||
|
||
|
||
def get_value(self, value): | ||
if self.float_de_pattern.match(value): | ||
# remove any digit group seperators and replace the comma with a period | ||
return value.replace('.', '').replace(',', '.') | ||
if self.float_us_pattern.match(value): | ||
# just remove the digit group seperators | ||
return value.replace(',', '') | ||
else: | ||
return None | ||
|
||
def get_tables(self): | ||
tables = [] | ||
table = self.append_table(tables) | ||
for val in self._parsed_values: | ||
if len(val) == 1: | ||
num_val = self.get_value(val[0]) | ||
if num_val is not None: | ||
table['rows'].append([len(table['rows']), len(table['rows']), float(num_val)]) | ||
else: | ||
table['metadata'][val[0]] = '='.join(val[1:]) | ||
table['header'].append(f"{'='.join(val)}") | ||
|
||
table['columns'].append({ | ||
'key': '1', | ||
'name': 'Idx' | ||
}) | ||
table['columns'].append({ | ||
'key': '2', | ||
'name': 'Number' | ||
}) | ||
|
||
table['metadata']['rows'] = str(len(table['rows'])) | ||
table['metadata']['columns'] = str(len(table['columns'])) | ||
|
||
return tables |