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

MTG: get projection and extent information from file #845

Merged
merged 35 commits into from Apr 3, 2020

Conversation

gerritholl
Copy link
Collaborator

@gerritholl gerritholl commented Jul 4, 2019

In the MTG FCI FDHSI L1C reader, get the projection coordinates and
extent information from file. For the projection coordinates, get those
from /data/mtg_geos_projection rather than from /state/processor, as
is consistent with the documentation. The extent information was
previously hardcoded but now obtained from data/channel/measured/x and
data/channel/measured/y, which contain this information in radians.
This commit fixes #840 although there are still some issues with the
resulting image that need to be resolved.

@gerritholl gerritholl requested a review from mraspaud as a code owner July 4, 2019 09:34
@gerritholl
Copy link
Collaborator Author

I'm not sure how to write a test for "coastlines look correct in image". It could be done with some fancy image processing but it may be more effort than it's worth?

@gerritholl
Copy link
Collaborator Author

The image still has some problems, it looks like this now:

fci_test_natural_color_germ

The coastlines are correct, but there are two kinds of artefacts:

  • concentric projection artefacts
  • zonal artefacts between the different chunks in the satellite image

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

try setting the radius_of_influence parameter to 10000 when you resample

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

As for the test, you could create some fake data with special pixel values at some landmarks, and then make sure the landmarks (with special pixel values) are in the right place in the resampled image.

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

Regarding the zonal artefacts, are you sure the area extent is correct, ie that is extends to the corner of the corner point ?

@gerritholl
Copy link
Collaborator Author

Thanks for the advice. I will look into those and then I need to look into the zonal artefacts, I seem to recall something about defining locations as pixel centres vs. pixel corners.

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

yes, I see in your code that you use pixel centers...

@gerritholl
Copy link
Collaborator Author

As for the test, you could create some fake data with special pixel values at some landmarks, and then make sure the landmarks (with special pixel values) are in the right place in the resampled image.

Are there examples for that in other reading routine testers?

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

No, it's never been done :) but maybe you don't need to got to these length to test the navigation of this reader. I would suggest that you just check the area extent computed from the parameters given in the file against what you have determined is correct experimentally.

@gerritholl
Copy link
Collaborator Author

After 0a7d0e2:

fci_test_natural_color_germ

it now appears to be correct as far as I can see.

I find actually unit testing this difficult as I'm not sure how to verify that a pixel in my mock data ends up where I expect it to end up, since I don't have an independent easy way of calculating the test reference.

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

Isn't the data shifted a bit to the right ? looks like the coastlines don't really match on the tip of Sweden.
As for tests, just record the correct values for area extent you find with the test data and use them as a reference in the unit tests

@gerritholl
Copy link
Collaborator Author

Hmm, looking at Bornholm it looks shifted indeed, I thought that the Dutch coast looked fine. That's puzzling.

@gerritholl gerritholl requested a review from djhoese as a code owner July 4, 2019 14:25
@coveralls
Copy link

coveralls commented Jul 4, 2019

Coverage Status

Coverage increased (+0.009%) to 89.545% when pulling c11926b on gerritholl:fix-fci-projection into d12bb7a on pytroll:master.

@codecov
Copy link

codecov bot commented Jul 4, 2019

Codecov Report

Merging #845 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #845   +/-   ##
=======================================
  Coverage   89.54%   89.54%           
=======================================
  Files         200      200           
  Lines       29392    29392           
=======================================
  Hits        26319    26319           
  Misses       3073     3073           

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 c11926b...c11926b. Read the comment docs.

@gerritholl
Copy link
Collaborator Author

It looks like it's farther off the farther east.

@gerritholl
Copy link
Collaborator Author

The coverage decreased because I shortened some methods that were covered, but did not shorten any methods that weren't. I produced a negative number of LOC, so to say...

@gerritholl
Copy link
Collaborator Author

The offset is location-dependent.

Socotra (12°N, 54°E), too far south:

image

La Gomera and Tenerife (28°N, 17°W), too far west:

image

Bornholm (55°N, 15°E) too far east:

image

Île Europa (22°S, 40°E) too far north:

image

São Tomé (0°N, 7°E), almost correct:

image

There's still something wrong with either:

  • The projection information
  • The area extent information
  • The simulation of FCI from SEVIRI
  • The calculation of the rectified image from the swath
  • Something else

@mraspaud
Copy link
Member

mraspaud commented Jul 4, 2019

Maybe time to ask the data provider ?

@gerritholl
Copy link
Collaborator Author

Can this be due to different datums / projections / ellipsoids?

@gerritholl
Copy link
Collaborator Author

After discussion with EUMETSAT, we think the remaining projection issues are probably in the data and that the reader is fine.

Therefore, I propose this PR is ready to merge. Is anyone available to review it?

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

@mraspaud
Copy link
Member

Sorry for reviewing this so late, it passed under my radar.
I can merge this as it is, I was just wondering if you had tested with the latest test dataset ?

@mraspaud mraspaud added component:readers enhancement code enhancements, features, improvements labels Oct 21, 2019
@gerritholl
Copy link
Collaborator Author

NB: EUMETSAT reports that with the same test data, they consider the geolocation to be accurate. So there is still something either with the reader, or with the coastline database.

@mraspaud
Copy link
Member

mraspaud commented Nov 6, 2019

Ok, interesting. Maybe something to look at during the next PCW ?

@gerritholl gerritholl added this to In progress in PCW Copenhagen 2019 Nov 6, 2019
The scale factors and add offsets for the MTG FCI test data as published
in 2019-09 are factually incorrect.  This probably causes the
differences between the pytroll and FCI geolocations.  Until this is
fixed from EUMETSATs side, hardcode corrected add_offset and
scale_factor values.

Also correct for an off-by-one error in the scale factors.
The scale factors and add offsets for the MTG FCI test data as published
in 2019-09 are factually incorrect.  This probably causes the
differences between the pytroll and FCI geolocations.  Until this is
fixed from EUMETSATs side, hardcode corrected add_offset and
scale_factor values.

Similarly, there was a small error in the semi minor axis.

Also correct for an off-by-one error in the scale factors.
@gerritholl
Copy link
Collaborator Author

Mean distance is now approximately 18 metre, after re-hardcoding several figures that were wrong in the file.

test

Which unfortunately defeats the title of this PR.

The FCI semi-minor axis correction does not improve anything, remove
this hardcoding correction.
@gerritholl
Copy link
Collaborator Author

Those parameters will be corrected in the next version of the testdata, so the hardcoding won't be necessary. The median difference is down to 8.56 metre. That doesn't explain the coastline problem but I'm probably doing something wrong there independently of the reader.

@gerritholl
Copy link
Collaborator Author

Latest coastline comparison at Tenerife and La Gomera.

coastline-latest

For comparison, for SEVIRI

coastline-seviri

@gerritholl
Copy link
Collaborator Author

Image with enhanced brightness (convert -brightness-contrast 50x50 in.tiff out.jpg)

FCI with latest geolocation corrections:

today-tenerife-gomera

SEVIRI:

seviri-tenerife-gomera

Swapping between the two, the island moves.

@gerritholl
Copy link
Collaborator Author

Are those differences consistent with what one would expect due to this being test data?

@gerritholl
Copy link
Collaborator Author

Related? SEVIRI georeferencing offset correction.

@gerritholl
Copy link
Collaborator Author

This is very likely caused by the SEVIRI georeferencing offset correction. Since SEVIRI data from before 2017-12 needs a correction, so does FCI test data based on SEVIRI data from before 2017-12. Thanks to @ameraner for finding this.

It looks like each of the SEVIRI readers repeat this correction:

seviri_l1b_hrit:

xadj = 1500
yadj = -1500
aex = (aex[0] + xadj, aex[1] + yadj,
aex[2] + xadj, aex[3] + yadj)

seviri_l1b_icare: not found

seviri_l1b_native:

if earth_model == 2:
ns_offset = 0
we_offset = 0
elif earth_model == 1:
ns_offset = -0.5
we_offset = 0.5
if dataset_id.name == 'HRV':
ns_offset = -1.5
we_offset = 1.5

seviri_l1b_nc:

if earth_model == 2:
ns_offset = 0 # north +ve
we_offset = 0 # west +ve
elif earth_model == 1:
ns_offset = -0.5 # north +ve
we_offset = 0.5 # west +ve

Expand the mocking of variable attributes for the routine testing the
FCI reader.  One attribute was missing, and none were created in the
"/attr/..." caching in which they are accessed by the reader.
@ameraner
Copy link
Member

We can (finally) confirm that the root of the "big" shift is the geolocation offset present in SEVIRI images recorded prior to 2017, that went uncorrected into the creation of the FCI test data. When feeding the EUM processor with a SEVIRI image from 2019 as a proxy for the FCI data, and reading that FCI image with the FCI reader, the shift is gone:

natural_color_tenerifegomera_sev2019
natural_color_tenerifegomera_fci2019

@mraspaud
Copy link
Member

@gerritholl @ameraner thanks for sorting this out and making the FCI reader perfectly geolocated.
@ameraner are there plans from EUM to provide an updated dataset that will take care of the aforementioned problems ?

Remove the hardcoded scale factor, add offset, and sweep.  Those had
been added to correct for errors in the 2019-09 release of FCI testdata,
but should be fixed in the upcoming release, so should be no longer
needed.
From the FCI reader, remove an unused hardcoded dictionary containing
extent information.  This information was only used for debugging, but
is redundant relative to what is available in the file, assuming a full
disk image is square.
In the FCI reader, make minor fixes to comments and docstring, and
replace a RuntimeError by a more specific ValueError if an invalid
calibration key is passed.
@gerritholl
Copy link
Collaborator Author

Using the 2020-04 pre-release testdata and satpy-0.20.1.dev211+ga8ddb7d3, which removes any hardcoded corrections for sweep, offset, or scale factor:

grafik

@gerritholl gerritholl requested a review from mraspaud April 2, 2020 17:12
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.

This looks good to me. I just have a couple minor comments. Thanks for the comprehensive work on the FCI reader!

satpy/readers/fci_l1c_fdhsi.py Outdated Show resolved Hide resolved
# Channel dependent swath resoultion
area_extent = self.calc_area_extent(key)

# assumption: channels with same resolution should have same area
Copy link
Member

Choose a reason for hiding this comment

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

@ameraner can you confirm this ?

Copy link
Member

Choose a reason for hiding this comment

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

@mraspaud Yes it's correct, for this L1c FDHSI product we define two rectification grids (with 1 km and 2 km nadir resolution), and channels with the same resolution share the same grid (and therefore also same area definition).

Copy link
Member

Choose a reason for hiding this comment

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

perfect, thanks for then confirmation.

gerritholl and others added 2 commits April 3, 2020 10:13
Apparently, PEP 257 insists that the closing quotes for a single-line docstring must be on the same line as the rest of the docstring.  I will abide by what is apparently the community standard, although I will hereby note my (minority?) preference for the "closing quotes on next line" alternative.

Co-Authored-By: Martin Raspaud <martin.raspaud@smhi.se>
Remove an empty line immediately after a method docstring, in order to
satisfy the flake8-docstrings plugin.
@ghost
Copy link

ghost commented Apr 3, 2020

Congratulations 🎉. DeepCode analyzed your code in 1.109 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard

☺️ If you want to provide feedback on our bot, here is how to contact us.

@mraspaud mraspaud added this to the v0.21.0 milestone Apr 3, 2020
@mraspaud mraspaud merged commit 0b54987 into pytroll:master Apr 3, 2020
PCW Copenhagen 2019 automation moved this from In progress to Done Apr 3, 2020
@gerritholl gerritholl deleted the fix-fci-projection branch April 3, 2020 15:44
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
Development

Successfully merging this pull request may close these issues.

MTG-FCI-FDHSI reader has wrong projection
4 participants