Skip to content
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

Implementing a more flexibel data ingest for a_b() #141

Merged
merged 8 commits into from Nov 10, 2023

Conversation

maxmargraf
Copy link
Contributor

@maxmargraf maxmargraf commented Nov 9, 2023

This PR is solving #140.

a_b() previously was not flexible in regard of data type of input. Now xr.DataArray, np.array, float(for frequency) and str (for polarization) are allowed. Tests are updated to also checkxr.DataArray as input (also with str vor polarization) and one new raise.

This also will help to slacken nearby_rain_retrival().

ToDo:

  • Check if example notebooks still run
  • Check tests

@maxmargraf
Copy link
Contributor Author

maxmargraf commented Nov 9, 2023

Thanks to the tests i found a strange behavior of np.full_like which can be fixed by determining the dtype of np.nan:
image
This resolves almost all of the failing test.

@cchwala
Copy link
Contributor

cchwala commented Nov 9, 2023

Good to know!

But it is actually not a "strange behavior" because the docs of np.full_like state

Return a full array with the same shape and type as a given array

So you have to specify dtype to override the one from the provided array.

Copy link

codecov bot commented Nov 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (86c64a9) 74.53% compared to head (6c02aa4) 75.17%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #141      +/-   ##
==========================================
+ Coverage   74.53%   75.17%   +0.64%     
==========================================
  Files          29       29              
  Lines        1084     1112      +28     
==========================================
+ Hits          808      836      +28     
  Misses        276      276              
Flag Coverage Δ
unittests 75.17% <100.00%> (+0.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pycomlink/processing/k_R_relation.py 86.25% <100.00%> (+7.40%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maxmargraf
Copy link
Contributor Author

maxmargraf commented Nov 9, 2023

Further update of the function: when f_GHz and pol are xr.DataArray but only consit of one value and the @xarray_apply_along_time_dim()decorator is used to calc_R_from_A(), then returning a and b as xr.DataArray with one empty dim (caused by f_GHz and pol being xr.DataArray) will lead to an error.
Therefore, now a and b are only returned as xr.DataArray when f_GHz has at least one dim.

Copy link
Contributor

@cchwala cchwala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @maxmargraf. Looks good. I have some small comments regarding required adjustments.

b[pol_mask_v] = b_v[pol_mask_v]

if return_xarray:
if tmp_dims_f_GHz != ():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment with an explanation here, why this is needed.

else:
return_xarray = False

f_GHz = xr.DataArray(f_GHz)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We allow certain combinations of np.ndarray, xr.DataArray and float or str. But other combinations are not allowed. I suggest to add that info to the docstring at f_GHz and pol.

I know that we do not mention xr.DataArray as input data type in many docstrings, even though they are handled via the xarray-wrapper decorator. I actually always wanted to add the featuer that this wrappers add a note about that behavior to the docstring of the wrapped function. Yet another todo... But here, since we actually handled xr.DataArrays expliclity in the function body, I would adjust the docstring accordingly.


f_GHz = np.asarray(f_GHz)
if tmp_dims_f_GHz != tmp_dims_pol:
raise ValueError("Frequency and polarization must have identical "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not yet covered by a test. Please add one simple test for that.

Copy link
Contributor Author

@maxmargraf maxmargraf Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed already by commit 7440056. This code coverage report is three hours old right now.

@cchwala
Copy link
Contributor

cchwala commented Nov 10, 2023

thanks for this enhancement 👍

@cchwala cchwala merged commit 975242b into pycomlink:master Nov 10, 2023
5 checks passed
cchwala pushed a commit that referenced this pull request Nov 10, 2023
)

* remove test of removed function
* update nearby wet dry test and remove test for dims for input as only one variable is passed anyway now
* require pmax in power correction
* update test to proper pmax behavior
* update nearby example notebook
* update rainfall retrival test with more realistic pmax values
* adjust code to use new a_b() function from #141 
* add xarray wrapper decorator to handle sublink dimension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants