Image parser¶
C
pynasonde.digisonde.parsers.image_parser — IonogramImageExtractor
Parses Ionogram (.png) format files, extract data from left table.
pynasonde.digisonde.parsers.image_parser
¶
Utilities to extract tabular metadata from ionogram image files.
This module contains:class:IonogramImageExtractor which uses OpenCV
and Tesseract OCR to extract textual parameter tables and header
metadata from ionogram images. The functionality is intentionally
focused and small so it can be used in documentation examples.
IonogramImageExtractor
¶
Bases: object
Extractor for ionogram images using OpenCV + Tesseract OCR.
The extractor offers helpers to read date/time information from the filename and to OCR specific regions of the image to parse parameter tables and header fields into pandas DataFrames.
Source code in pynasonde/digisonde/parsers/image_parser.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
__init__(filepath, extract_time_from_name=True, date=None, filestr_date_format='ion%y%m%d_%H%M%S.png')
¶
Create an IonogramImageExtractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath |
str
|
str Path to the ionogram image file. |
required |
extract_time_from_name |
bool
|
bool, optional
If True (default), attempt to parse the timestamp from the
filename using |
True
|
date |
dt.datetime
|
datetime.datetime, optional
Manually provided date; if None and
|
None
|
filestr_date_format |
str
|
str, optional Format string used when parsing the filename timestamp. |
'ion%y%m%d_%H%M%S.png'
|
Source code in pynasonde/digisonde/parsers/image_parser.py
extract_text(crop_axis=np.array([[50, 650], [0, 220]]), cv_props=dict(thresh=180, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU), OCR_custom_config='--oem 3 --psm 6')
¶
Extract text from a cropped region of the image using Tesseract OCR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crop_axis |
np.array
|
numpy.ndarray, optional 2x2 array specifying the crop region as [[y1, y2], [x1, x2]]. |
np.array([[50, 650], [0, 220]])
|
cv_props |
dict
|
dict, optional OpenCV thresholding parameters (keys: 'thresh', 'maxval', 'type'). |
dict(thresh=180, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
|
OCR_custom_config |
str
|
str, optional Tesseract configuration string (e.g. '--oem 3 --psm 6'). |
'--oem 3 --psm 6'
|
Returns:
| Type | Description |
|---|---|
str
|
Text extracted from the cropped region. |
Source code in pynasonde/digisonde/parsers/image_parser.py
parse_artist_params_table(crop_axis=np.array([[50, 650], [0, 220]]), cv_props=dict(thresh=180, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU), OCR_custom_config='--oem 3 --psm 6', lines_to_extracted=-8, word_filtes_for_table_values={'N/A': 'nan', ':': '.'})
¶
Parse a left-side artist-parameters table from the ionogram image.
The function OCRs a cropped region, extracts line-wise
key/value pairs, applies simple text replacements and converts
values to float where possible. The result is returned as a
single-row:class:pandas.DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crop_axis |
np.array
|
numpy.ndarray, optional Crop region as [[y1, y2], [x1, x2]]. |
np.array([[50, 650], [0, 220]])
|
cv_props |
dict
|
dict, optional OpenCV thresholding parameters. |
dict(thresh=180, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
|
OCR_custom_config |
str
|
str, optional Tesseract config string. |
'--oem 3 --psm 6'
|
lines_to_extracted |
int
|
int, optional Number of lines to keep from OCR output (negative values trim from the end). |
-8
|
word_filtes_for_table_values |
dict
|
dict, optional Mapping of substrings to replace in extracted values before conversion. |
{'N/A': 'nan', ':': '.'}
|
Returns:
| Type | Description |
|---|---|
pd.DataFrame
|
Single-row DataFrame with parsed parameter names and values. |
Source code in pynasonde/digisonde/parsers/image_parser.py
extract_header(crop_axis=np.array([[0, 50], [100, 800]]), cv_props=dict(thresh=180, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU), OCR_custom_config='--oem 3 --psm 6', word_filtes_for_table_values={',': '', ':': '.'})
¶
Extract and parse header fields from an ionogram image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crop_axis |
np.array
|
numpy.ndarray, optional Crop region for the header area. |
np.array([[0, 50], [100, 800]])
|
cv_props |
dict
|
dict, optional OpenCV thresholding parameters. |
dict(thresh=180, maxval=255, type=cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
|
OCR_custom_config |
str
|
str, optional Tesseract config string. |
'--oem 3 --psm 6'
|
word_filtes_for_table_values |
dict
|
dict, optional Mapping of substrings to replace in both header keys and values. |
{',': '', ':': '.'}
|
Returns:
| Type | Description |
|---|---|
pd.DataFrame
|
Single-row DataFrame with header keys and values when found. |