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

Ascat soilmoisture reader #1505

Merged
merged 15 commits into from
Jan 25, 2021
Merged

Conversation

eysteinn
Copy link
Contributor

@eysteinn eysteinn commented Jan 8, 2021

Reads Eumetsats soil moisture bufr message based on scatterometry data.
Tests are coming soon.

  • Tests added
  • Passes flake8 satpy
  • Fully documented
  • Add your name to AUTHORS.md if not there already

eysteinn and others added 3 commits December 18, 2020 23:20
Add composite / enhancements for scatterometry soil moisture data
@ghost
Copy link

ghost commented Jan 8, 2021

DeepCode's analysis on #dff630 found:

  • ℹ️ 1 minor issue. 👇

Top issues

Description Example fixes
assertTrue cannot provide an informative message about the values in the comparison _ if it fails Occurrences: 🔧 Example fixes

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@codecov
Copy link

codecov bot commented Jan 18, 2021

Codecov Report

Merging #1505 (2e385c3) into master (e25415b) will increase coverage by 3.57%.
The diff coverage is 92.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1505      +/-   ##
==========================================
+ Coverage   88.08%   91.65%   +3.57%     
==========================================
  Files         191      248      +57     
  Lines       29412    36171    +6759     
==========================================
+ Hits        25907    33152    +7245     
+ Misses       3505     3019     -486     
Flag Coverage Δ
behaviourtests 4.36% <36.02%> (?)
unittests 92.19% <92.57%> (?)

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

Impacted Files Coverage Δ
satpy/enhancements/mimic.py 0.00% <0.00%> (ø)
satpy/modifiers/__init__.py 100.00% <ø> (ø)
satpy/modifiers/atmosphere.py 50.00% <ø> (ø)
satpy/modifiers/base.py 80.00% <ø> (ø)
satpy/modifiers/geometry.py 83.87% <ø> (ø)
satpy/modifiers/spectral.py 92.39% <ø> (ø)
satpy/multiscene.py 90.76% <ø> (+1.44%) ⬆️
satpy/node.py 88.88% <ø> (-5.81%) ⬇️
satpy/plugin_base.py 88.00% <ø> (ø)
satpy/readers/__init__.py 97.40% <ø> (+2.84%) ⬆️
... and 394 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc911e2...dff630a. Read the comment docs.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Thanks for adding this reader, I have some comments...

logger = logging.getLogger('ASCATSOILMOISTUREBUFR')


class ASCATSOILMOISTUREBUFR(BaseFileHandler):
Copy link
Member

Choose a reason for hiding this comment

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

You should use CamelCase for class names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment on lines 75 to 80
while True:
# get handle for message
bufr = ec.codes_bufr_new_from_file(fh)
if bufr is None:
break
ec.codes_set(bufr, 'unpack', 1)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with bufr and eccodes, but will this read the file entirely? In which case, maybe the metadata and the data should be extracted in the same loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will read the whole file but the file is usually small. The only metadata is the start / end date. The bufr data (channels) are optional and I don't think it fits with the metadata so I would read this separately even if it means scanning the file twice.

Comment on lines 82 to 91
years = np.resize(ec.codes_get_array(bufr, 'year'), size)
months = np.resize(ec.codes_get_array(bufr, 'month'), size)
days = np.resize(ec.codes_get_array(bufr, 'day'), size)
hours = np.resize(ec.codes_get_array(bufr, 'hour'), size)
minutes = np.resize(ec.codes_get_array(bufr, 'minute'), size)
seconds = np.resize(ec.codes_get_array(bufr, 'second'), size)
for year, month, day, hour, minute, second in zip(years, months, days, hours, minutes, seconds):
time_stamp = datetime(year, month, day, hour, minute, second)
date_min = time_stamp if not date_min else min(date_min, time_stamp)
date_max = time_stamp if not date_max else max(date_max, time_stamp)
Copy link
Member

Choose a reason for hiding this comment

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

This could be factorized into a separate method for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I fixed this now, this has its own method.

return retmsg


msg = create_message()
Copy link
Member

Choose a reason for hiding this comment

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

This is a constant, so I would use upper case MSG

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment on lines +149 to +152
self.assertTrue('start_time' in scn.attrs)
self.assertTrue('end_time' in scn.attrs)
self.assertTrue('sensor' in scn.attrs)
self.assertTrue('scatterometer' in scn.attrs['sensor'])
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to check the actual values of the attributes to make sure they are interpreted correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added test for the values that are read from the file: start_time & end_time

from satpy import Scene
fname = os.path.join(self.base_dir, FILENAME)
scn = Scene(reader='ascat_l2_soilmoisture_bufr', filenames=[fname])
scn.load(scn.available_dataset_names())
Copy link
Member

Choose a reason for hiding this comment

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

What about checking the result of the loading?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I check if all available dataset names are actually loaded.

@@ -0,0 +1,180 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2019 Satpy developers
Copy link
Member

Choose a reason for hiding this comment

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

it's 2021 now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@@ -0,0 +1,122 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Satpy developers
Copy link
Member

Choose a reason for hiding this comment

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

2021!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

lat, lon = np.meshgrid(np.linspace(63, 65, nlat), np.linspace(-30, -20, nlon))
lat = np.round(np.ravel(lat), 4)
lon = np.round(np.ravel(lon), 4)
rstate=np.random.RandomState(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

E225 missing whitespace around operator

@eysteinn
Copy link
Contributor Author

I think all fixes are in

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding the reader!

@mraspaud mraspaud merged commit 0d4ef00 into pytroll:master Jan 25, 2021
@eysteinn eysteinn deleted the ascat_soilmoisture_reader branch January 25, 2021 14:52
@mraspaud mraspaud added component:readers enhancement code enhancements, features, improvements labels Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:readers enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants