-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor telemetry to use xarray #134
Open
mraspaud
wants to merge
3
commits into
pytroll:main
Choose a base branch
from
mraspaud:refactor-to-xarray-from-the-start
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
IntFlag = object | ||
|
||
import numpy as np | ||
import xarray as xr | ||
from pyorbital.geoloc import compute_pixels, get_lonlatalt | ||
from pyorbital.geoloc_instrument_definitions import avhrr_gac | ||
|
||
|
@@ -278,9 +279,9 @@ def read(self, filename, fileobj=None): | |
LOG.info("Reading %s", self.filename) | ||
# choose the right header depending on the date | ||
with file_opener(fileobj or filename) as fd_: | ||
self.tbm_head, self.head = self.read_header( | ||
self.archive_header, self.head = self.read_header( | ||
filename, fileobj=fd_, header_date=self.header_date) | ||
if self.tbm_head: | ||
if self.archive_header: | ||
tbm_offset = tbm_header.itemsize | ||
else: | ||
tbm_offset = 0 | ||
|
@@ -347,8 +348,10 @@ def _validate_tbm_header(cls, potential_tbm_header): | |
return potential_tbm_header.copy() | ||
|
||
# This will raise a DecodingError if the data_set_name is not valid. | ||
cls._decode_data_set_name(data_set_name) | ||
return potential_tbm_header.copy() | ||
data_set_name = cls._decode_data_set_name(data_set_name) | ||
tbm_header = potential_tbm_header.copy() | ||
tbm_header["data_set_name"] = data_set_name.decode().strip("\x80").encode() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the |
||
return tbm_header | ||
|
||
|
||
@classmethod | ||
|
@@ -558,29 +561,49 @@ def get_telemetry(self): | |
space_counts: np.array | ||
|
||
""" | ||
number_of_scans = self.scans["telemetry"].shape[0] | ||
decode_tele = np.zeros((int(number_of_scans), 105)) | ||
decode_tele[:, ::3] = (self.scans["telemetry"] >> 20) & 1023 | ||
decode_tele[:, 1::3] = (self.scans["telemetry"] >> 10) & 1023 | ||
decode_tele[:, 2::3] = self.scans["telemetry"] & 1023 | ||
|
||
prt_counts = np.mean(decode_tele[:, 17:20], axis=1) | ||
telemetry = self.scans["telemetry"] | ||
decode_tele = self.unpack_telemetry(telemetry) | ||
|
||
hmf_dtype = np.dtype([("frame_sync", "u2", (6, )), | ||
("id", [("id", "u2"), | ||
("spare", "u2")]), | ||
("timecode", "u2", (4, )), | ||
("telemetry", [("ramp_calibration", "u2", (5, )), | ||
("PRT", "u2", (3, )), | ||
("ch3_patch_temp", "u2"), | ||
("spare", "u2"), ]), | ||
("back_scan", "u2", (10, 3)), | ||
("space_data", "u2", (10, 5)), | ||
("sync", "u2")]) | ||
|
||
hmf_array = decode_tele[:, :103].view(dtype=hmf_dtype).squeeze() | ||
prt_counts = xr.DataArray(hmf_array["telemetry"]["PRT"], | ||
dims=["scan_line_index", "PRT_measurement"]) | ||
|
||
# getting ICT counts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could also remove the comments |
||
|
||
ict_counts = np.zeros((int(number_of_scans), 3)) | ||
ict_counts[:, 0] = np.mean(decode_tele[:, 22:50:3], axis=1) | ||
ict_counts[:, 1] = np.mean(decode_tele[:, 23:51:3], axis=1) | ||
ict_counts[:, 2] = np.mean(decode_tele[:, 24:52:3], axis=1) | ||
ict_counts = xr.DataArray(hmf_array["back_scan"], | ||
dims=["scan_line_index", "back_scan", "channel_name"], | ||
coords=dict(channel_name=["3", "4", "5"])) | ||
|
||
# getting space counts | ||
|
||
space_counts = np.zeros((int(number_of_scans), 3)) | ||
space_counts[:, 0] = np.mean(decode_tele[:, 54:100:5], axis=1) | ||
space_counts[:, 1] = np.mean(decode_tele[:, 55:101:5], axis=1) | ||
space_counts[:, 2] = np.mean(decode_tele[:, 56:102:5], axis=1) | ||
|
||
return prt_counts, ict_counts, space_counts | ||
space_counts = xr.DataArray(hmf_array["space_data"], | ||
dims=["scan_line_index", "back_scan", "channel_name"], | ||
coords=dict(channel_name=["1", "2", "3", "4", "5"])) | ||
|
||
return xr.Dataset(dict(PRT=prt_counts, ICT=ict_counts, space_counts=space_counts)) | ||
|
||
def unpack_telemetry(self, telemetry): | ||
"""Unpack the telemetry from 10 to 16 bits.""" | ||
# Documentation (POD guide, section 3) says: | ||
# "The telemetry data are stored in 140 bytes. The first 103 (10 bit) words are packed three (10 bit) words in | ||
# four bytes, right justified. The last four byte group contains one (10 bit) word with 20 trailing bits. All | ||
# unused bits are set to zero." | ||
number_of_scans = telemetry.shape[0] | ||
decode_tele = np.zeros((int(number_of_scans), 105), dtype=np.uint16) | ||
decode_tele[:, ::3] = (telemetry >> 20) & 1023 | ||
decode_tele[:, 1::3] = (telemetry >> 10) & 1023 | ||
decode_tele[:, 2::3] = telemetry & 1023 | ||
return decode_tele | ||
|
||
@staticmethod | ||
def _get_ir_channels_to_calibrate(): | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could
be replaced with
?