-
Notifications
You must be signed in to change notification settings - Fork 20
Correctly populate product fill values in geocoded datasets #167
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
Open
LiangJYu
wants to merge
17
commits into
opera-adt:main
Choose a base branch
from
LiangJYu:product_fill_values
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
17 commits
Select commit
Hold shift + click to select a range
133c801
rename init_ to create_ to reflect functionality
LiangJYu fba6197
Merge branch 'main' into product_fill_values
LiangJYu 98be089
correctly populate fill value in geocoded datasets
LiangJYu 73a6e79
Merge branch 'main' into product_fill_values
LiangJYu 3af5b7e
Merge branch 'main' into product_fill_values
LiangJYu 22778d3
Merge branch 'main' into product_fill_values
LiangJYu 3bd2de7
flesh out docstring
LiangJYu b2db866
move fill value related class and function to own file
LiangJYu fd52ea5
fix imports and update fill value logic
LiangJYu 9094ecb
syntax fix
LiangJYu 2bd57ed
fix None logic
LiangJYu c86fe32
address codacy issues
LiangJYu 94b6aa9
add comments for clarity
LiangJYu 6452587
Merge branch 'main' into product_fill_values
LiangJYu 40b32ab
Merge branch 'main' into product_fill_values
LiangJYu 7d842c0
use journal logging and fix docstring
LiangJYu 1c52097
add fill value to dataset attribs
LiangJYu 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,93 @@ | ||
''' | ||
Class and function for helping set and determine dataset fill values | ||
''' | ||
from dataclasses import dataclass | ||
|
||
import journal | ||
import numpy as np | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FillValues: | ||
''' | ||
Dataclass of fill values for float, complex, and int types with default | ||
values. | ||
''' | ||
# Catch all fill value for all float types (float32, float64, ...) | ||
float_fill: np.single = np.nan | ||
|
||
# Catch all fill value for all complex types (complex64, complex128, ...) | ||
complex_fill: np.csingle = np.nan * (0 + 1j) | ||
|
||
# Catch all fill value for all int types (int8, byte8, ...) | ||
# Currently hard coded for int8/layover_shadow | ||
int_fill: np.intc = 127 | ||
|
||
@classmethod | ||
def from_user_defined_value(cls, user_defined_value): | ||
''' | ||
Create and return a FillValues class object populated with all default | ||
values populated to a single user defined value. | ||
|
||
Parameters | ||
---------- | ||
user_defined_value: float | ||
User defined value to be assigned to default value of all types | ||
|
||
Returns | ||
------- | ||
FillValues | ||
FillValues object with all default values set to user defined value | ||
''' | ||
return cls(np.single(user_defined_value), | ||
np.csingle(user_defined_value), | ||
np.intc(user_defined_value)) | ||
|
||
|
||
def determine_fill_value(dtype, usr_fill_val=None): | ||
''' | ||
Helper function to determine COMPASS specific fill values based on h5py | ||
Dataset type (dtype) | ||
|
||
Parameters | ||
---------- | ||
dtype: type | ||
Given numeric type whose corresponding fill value of same type is to be | ||
determined | ||
usr_fill_val: float | ||
User specified non-default dataset fill value | ||
|
||
Returns | ||
------- | ||
Fill value of type dtype. An exception is raised if no appropriate | ||
value is found. | ||
''' | ||
if usr_fill_val is None: | ||
fill_values = FillValues() | ||
else: | ||
# Assign user provided non-default value to all fill values in | ||
# FillValues object with correct typing. Logic below will return on | ||
# accordingly. | ||
fill_values = FillValues.from_user_defined_value(usr_fill_val) | ||
|
||
# Check if float type and return float fill | ||
float_types = [np.double, np.single, np.float32, np.float64, 'float32', | ||
'float64'] | ||
if dtype in float_types: | ||
return fill_values.float_fill | ||
|
||
# Check if complex type and return complex fill | ||
complex_types = [np.complex128, 'complex64', np.complex64, 'complex32'] | ||
if dtype in complex_types: | ||
return fill_values.complex_fill | ||
|
||
# Check if int type and return int fill | ||
int_types = [np.byte, np.int8] | ||
if dtype in int_types: | ||
return fill_values.int_fill | ||
|
||
# No appropriate fill value found above. Raise exception. | ||
err_str = f'Unexpected COMPASS geocoded dataset type: {dtype}' | ||
error_channel = journal.error('fill_value.determine_fill_value') | ||
error_channel.log(err_str) | ||
raise ValueError(err_str) |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.