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

Add GK-2A AMI L1B Reader #911

Merged
merged 21 commits into from
Oct 22, 2019
Merged

Add GK-2A AMI L1B Reader #911

merged 21 commits into from
Oct 22, 2019

Conversation

djhoese
Copy link
Member

@djhoese djhoese commented Sep 22, 2019

Add GEO-KOMPSAT-2A AMI Level 1B reader.

  • Verify geolocation (possibly need floating point handling like ABI)
  • Add calibration to something other than counts
  • Closes Add reader for GEO-KOMPSAT AMI #737
  • Tests added and test suite added to parent suite
  • Tests passed
  • Passes flake8 satpy
  • Fully documented

@djhoese djhoese added enhancement code enhancements, features, improvements component:readers labels Sep 22, 2019
@djhoese djhoese self-assigned this Sep 22, 2019
@coveralls
Copy link

coveralls commented Oct 3, 2019

Coverage Status

Coverage increased (+0.6%) to 85.929% when pulling 4cfec82 on djhoese:feature-ami-reader into 35739e4 on pytroll:master.

@djhoese djhoese changed the title [WIP] Add initial GK-2A AMI L1B Reader Add initial GK-2A AMI L1B Reader Oct 6, 2019
@djhoese djhoese marked this pull request as ready for review October 6, 2019 19:10
@djhoese djhoese requested a review from mraspaud as a code owner October 6, 2019 19:10
@codecov
Copy link

codecov bot commented Oct 6, 2019

Codecov Report

Merging #911 into master will increase coverage by 0.64%.
The diff coverage is 96.2%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #911      +/-   ##
==========================================
+ Coverage   85.28%   85.92%   +0.64%     
==========================================
  Files         174      174              
  Lines       25822    26452     +630     
==========================================
+ Hits        22022    22730     +708     
+ Misses       3800     3722      -78
Impacted Files Coverage Δ
satpy/composites/__init__.py 75.09% <100%> (-0.01%) ⬇️
satpy/composites/ahi.py 100% <100%> (ø) ⬆️
satpy/tests/reader_tests/__init__.py 98.21% <100%> (+0.03%) ⬆️
satpy/tests/reader_tests/test_ami_l1b.py 94.73% <94.73%> (ø)
satpy/readers/ami_l1b.py 97.32% <97.32%> (ø)
satpy/readers/abi_l2_nc.py 19.14% <0%> (-8.13%) ⬇️
satpy/readers/abi_base.py 88.42% <0%> (-2.4%) ⬇️
satpy/tests/test_demo.py 94.73% <0%> (-1.35%) ⬇️
satpy/readers/nucaps.py 93.71% <0%> (-0.53%) ⬇️
... and 25 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 35739e4...4cfec82. Read the comment docs.

@songhan89
Copy link

songhan89 commented Oct 11, 2019

This is neat. Just checked out this branch and testing. Let me know if there are specific tasks i can help.

@djhoese
Copy link
Member Author

djhoese commented Oct 11, 2019

@songhan89 Thanks. I just made some updates and got some changes from @simonrp84. If you have time to make sure things look ok that'd be great. I think the only thing remaining for this PR is making sure that AMI has the same (or similar) RGB composites configured like AHI. I think I only added true color iirc.

@songhan89
Copy link

songhan89 commented Oct 13, 2019

Hi @djhoese . The 9 Oct commit worked fine for me but the latest merge into the feature branch on 12 Oct somehow broke it. Running python 3.6 on Mac here.

from satpy import available_readers
from satpy import Scene
import glob
filenames = glob.glob('./data/gk2a_ami_le1b*_201905100300.nc')
scn = Scene(reader="ami_l1b", filenames=filenames)
scn.available_dataset_names()
['IR087',
 'IR096',
 'IR105',
 'IR112',
 'IR123',
 'IR133',
 'NR013',
 'NR016',
 'SW038',
 'VI004',
 'VI005',
 'VI006',
 'VI008',
 'WV063',
 'WV069',
 'WV073']

scn.load(['IR105'])

Failed to load DatasetID(name='IR105', wavelength=(10.115, 10.35, 10.585), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=()) from <AMIL1bNetCDF: './data/gk2a_ami_le1b_ir105_fd020ge_201905100300.nc'>
Traceback (most recent call last):
  File "/Users/songhanwong/anaconda3/envs/gk2a_test/lib/python3.6/site-packages/satpy/readers/yaml_reader.py", line 578, in _load_dataset
    projectable = fh.get_dataset(dsid, ds_info)
  File "/Users/songhanwong/anaconda3/envs/gk2a_test/lib/python3.6/site-packages/satpy/readers/ami_l1b.py", line 167, in get_dataset
    gain = self.nc.attrs['DN_to_Radiance_Gain']
KeyError: 'DN_to_Radiance_Gain'
Could not load dataset 'DatasetID(name='IR105', wavelength=(10.115, 10.35, 10.585), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())': "Could not load DatasetID(name='IR105', wavelength=(10.115, 10.35, 10.585), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=()) from any provided files"
Traceback (most recent call last):
  File "/Users/songhanwong/anaconda3/envs/gk2a_test/lib/python3.6/site-packages/satpy/readers/yaml_reader.py", line 722, in _load_dataset_with_area
    ds = self._load_dataset_data(file_handlers, dsid)
  File "/Users/songhanwong/anaconda3/envs/gk2a_test/lib/python3.6/site-packages/satpy/readers/yaml_reader.py", line 602, in _load_dataset_data
    proj = self._load_dataset(dsid, ds_info, file_handlers)
  File "/Users/songhanwong/anaconda3/envs/gk2a_test/lib/python3.6/site-packages/satpy/readers/yaml_reader.py", line 588, in _load_dataset
    "Could not load {} from any provided files".format(dsid))
KeyError: "Could not load DatasetID(name='IR105', wavelength=(10.115, 10.35, 10.585), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=()) from any provided files"
The following datasets were not created and may require resampling to be generated: DatasetID(name='IR105', wavelength=(10.115, 10.35, 10.585), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())

@simonrp84
Copy link
Member

Hi,
This is because of a change I made. The calibration information is missing from your data file. I can fix with a patch on Monday.
Out of interest, what is the source of your data? I've not yet discovered any files without the calibration info so would be interested to know where this comes from.

@songhan89
Copy link

songhan89 commented Oct 13, 2019

@simonrp84 , thanks. I'm using the sample data from KMA website.

The download link is here
.
I do have access to the latest .nc files from KMA, will test with those too.

@djhoese
Copy link
Member Author

djhoese commented Oct 13, 2019

@simonrp84 I would not update the reader to work with the sample data. The latest sample data .zip file is corrupt and the sample data before that does not represent what the files look like now (ex. all bands used 14 bits of the 16-bit unsigned integer space even though it is supposed to vary by channel).

@simonrp84
Copy link
Member

Thanks @songhan89. I agree with @djhoese, if it's only the sample data that is causing problems then I don't think that the reader should be corrected. But please let us know if any other data has a problem!

@songhan89
Copy link

songhan89 commented Oct 14, 2019 via email

@songhan89
Copy link

Tested and works fine with the data. Thanks.

@songhan89
Copy link

songhan89 commented Oct 14, 2019

Seemed to have run into issues with natural_color and true_color composites. Managed to get it to work fine with airmass and convection rgb. Thought i had done resampling.

I turned on the debug mode here. Scroll down to the end to see the error.

from satpy import available_readers
from satpy import Scene
import glob
from satpy.utils import debug_on
debug_on()
filenames = glob.glob('/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_*_201909180900.nc')
scn = Scene(reader="ami_l1b", filenames=filenames)
scn.available_dataset_names()
[DEBUG: 2019-10-15 00:29:26 : satpy.scene] Setting 'PPP_CONFIG_DIR' to '/Users/songhanwong/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/etc'
[DEBUG: 2019-10-15 00:29:26 : satpy.readers] Reading ['/Users/songhanwong/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/etc/readers/ami_l1b.yaml']
[DEBUG: 2019-10-15 00:29:26 : satpy.readers.yaml_reader] Assigning to ami_l1b: ['/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_ir087_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_ir096_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_ir105_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_ir112_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_ir123_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_ir133_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_nr013_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_nr016_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_sw038_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_vi004_fd010ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_vi005_fd010ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_vi006_fd005ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_vi008_fd010ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_wv063_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_wv069_fd020ge_201909180900.nc', '/Users/songhanwong/Google Drive/NEA/GK2A/gk2a_ami_le1b_wv073_fd020ge_201909180900.nc']
[DEBUG: 2019-10-15 00:29:26 : satpy.composites] Looking for composites config file ami.yaml
[DEBUG: 2019-10-15 00:29:26 : satpy.composites] Looking for composites config file visir.yaml





['IR087',
 'IR096',
 'IR105',
 'IR112',
 'IR123',
 'IR133',
 'NR013',
 'NR016',
 'SW038',
 'VI004',
 'VI005',
 'VI006',
 'VI008',
 'WV063',
 'WV069',
 'WV073']
scn.available_composite_names()
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional satellite_azimuth_angle: Unknown dataset satellite_azimuth_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional satellite_zenith_angle: Unknown dataset satellite_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_azimuth_angle: Unknown dataset solar_azimuth_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional satellite_azimuth_angle: Unknown dataset satellite_azimuth_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional satellite_zenith_angle: Unknown dataset satellite_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_azimuth_angle: Unknown dataset solar_azimuth_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional satellite_azimuth_angle: Unknown dataset satellite_azimuth_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional satellite_zenith_angle: Unknown dataset satellite_zenith_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_azimuth_angle: Unknown dataset solar_azimuth_angle
[DEBUG: 2019-10-15 00:29:30 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle





['airmass',
 'ash',
 'cloud_phase_distinction',
 'convection',
 'day_microphysics_eum',
 'green',
 'green_raw',
 'ir_cloud_day',
 'mid_vapor',
 'natural_color',
 'natural_color_sun',
 'night_background',
 'night_background_hires',
 'overview',
 'true_color',
 'true_color_raw',
 'water_vapors1',
 'water_vapors2']
scn.load(['convection'])
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Delaying generation of DatasetID(name='_convection_dep_2', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None) because of incompatible areas
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Delaying generation of DatasetID(name='convection', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None) because of dependency's delayed generation: DatasetID(name='_convection_dep_2', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None)
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Delayed prerequisite for 'DatasetID(name='convection', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None)': 'DatasetID(name='_convection_dep_2', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None)'
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Delaying generation of DatasetID(name='_convection_dep_2', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None) because of incompatible areas
[WARNING: 2019-10-15 00:29:32 : satpy.scene] The following datasets were not created and may require resampling to be generated: DatasetID(name='convection', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None)
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Unloading dataset: DatasetID(name='WV073', wavelength=(7.24, 7.33, 7.42), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Unloading dataset: DatasetID(name='WV069', wavelength=(6.74, 6.94, 7.14), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Unloading dataset: DatasetID(name='SW038', wavelength=(3.74, 3.83, 3.92), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:32 : satpy.scene] Unloading dataset: DatasetID(name='IR105', wavelength=(10.115, 10.35, 10.585), resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
from pyresample import create_area_def
custom_area = create_area_def('my_area', {'proj': 'merc', 'lon_0': 0.0},
                              width=1000, height=1000,
                              area_extent=[90, 15, 130, 40], units='degrees')
new_scn = scn.resample(custom_area)
[DEBUG: 2019-10-15 00:29:34 : satpy.scene] Setting 'PPP_CONFIG_DIR' to '/Users/songhanwong/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/etc'
[DEBUG: 2019-10-15 00:29:34 : satpy.scene] Resampling DatasetID(name='VI006', wavelength=(0.599, 0.639, 0.679), resolution=500, polarization=None, calibration='reflectance', level=None, modifiers=())
[INFO: 2019-10-15 00:29:35 : satpy.resample] Using default KDTree resampler
[DEBUG: 2019-10-15 00:29:35 : satpy.resample] Check if ./resample_lut-872f9cc8139a5bb6122b7fcba12f03ed7bdd1843.npz exists
[DEBUG: 2019-10-15 00:29:35 : satpy.resample] Computing kd-tree parameters
[DEBUG: 2019-10-15 00:29:35 : satpy.resample] Resampling image_pixel_values
[DEBUG: 2019-10-15 00:29:35 : satpy.scene] Resampling DatasetID(name='NR016', wavelength=(1.59, 1.61, 1.63), resolution=2000, polarization=None, calibration='reflectance', level=None, modifiers=())
[INFO: 2019-10-15 00:29:36 : satpy.resample] Using default KDTree resampler
[DEBUG: 2019-10-15 00:29:36 : satpy.resample] Check if ./resample_lut-b7e4e4427138c55906a9140b9f2aa4793207d6fa.npz exists
[DEBUG: 2019-10-15 00:29:36 : satpy.resample] Computing kd-tree parameters
[DEBUG: 2019-10-15 00:29:36 : satpy.resample] Resampling image_pixel_values
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Resampling DatasetID(name='_convection_dep_1', wavelength=None, resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:37 : satpy.resample] Check if ./resample_lut-b7e4e4427138c55906a9140b9f2aa4793207d6fa.npz exists
[DEBUG: 2019-10-15 00:29:37 : satpy.resample] Computing kd-tree parameters
[DEBUG: 2019-10-15 00:29:37 : satpy.resample] Resampling image_pixel_values
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Resampling DatasetID(name='_convection_dep_0', wavelength=None, resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:37 : satpy.resample] Check if ./resample_lut-b7e4e4427138c55906a9140b9f2aa4793207d6fa.npz exists
[DEBUG: 2019-10-15 00:29:37 : satpy.resample] Computing kd-tree parameters
[DEBUG: 2019-10-15 00:29:37 : satpy.resample] Resampling image_pixel_values
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Unloading dataset: DatasetID(name='VI006', wavelength=(0.599, 0.639, 0.679), resolution=500, polarization=None, calibration='reflectance', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Unloading dataset: DatasetID(name='NR016', wavelength=(1.59, 1.61, 1.63), resolution=2000, polarization=None, calibration='reflectance', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Unloading dataset: DatasetID(name='_convection_dep_1', wavelength=None, resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Unloading dataset: DatasetID(name='_convection_dep_0', wavelength=None, resolution=2000, polarization=None, calibration='brightness_temperature', level=None, modifiers=())
[DEBUG: 2019-10-15 00:29:37 : satpy.scene] Unloading dataset: DatasetID(name='_convection_dep_2', wavelength=None, resolution=None, polarization=None, calibration='reflectance', level=None, modifiers=())
%matplotlib notebook
import matplotlib.pyplot as plt
from satpy.writers import get_enhanced_image

plt.figure()
img = get_enhanced_image(new_scn['convection'])
# get DataArray out of `XRImage` object
img_data = img.data
img_data.plot.imshow(rgb='bands', vmin=0, vmax=1)
[DEBUG: 2019-10-15 00:29:37 : matplotlib.pyplot] Loaded backend nbAgg version unknown.



<IPython.core.display.Javascript object>






[DEBUG: 2019-10-15 00:29:37 : satpy.writers] Enhancement configuration options: [{'name': 'stretch', 'method': <function stretch at 0x119939488>, 'kwargs': {'stretch': 'crude', 'min_stretch': [-30, 0, -70], 'max_stretch': [0, 55, 20]}}]
[DEBUG: 2019-10-15 00:29:37 : trollimage.xrimage] Applying stretch crude with parameters {'min_stretch': [-30, 0, -70], 'max_stretch': [0, 55, 20]}
/Users/songhanwong/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/dask/core.py:119: RuntimeWarning: invalid value encountered in log
  return func(*args2)





<matplotlib.image.AxesImage at 0x1308f8f60>
new_scn.load(['natural_color'])
scaled_scn = new_scn.resample(resampler='native')
---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

<ipython-input-327-999b42931746> in <module>
----> 1 new_scn.load(['natural_color'])
      2 scaled_scn = new_scn.resample(resampler='native')


~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/scene.py in load(self, wishlist, calibration, resolution, polarization, level, generate, unload, **kwargs)
    963         if unknown:
    964             unknown_str = ", ".join(map(str, unknown))
--> 965             raise KeyError("Unknown datasets: {}".format(unknown_str))
    966 
    967         self.read(**kwargs)


KeyError: "Unknown datasets: DatasetID(name='VI006', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=()), DatasetID(name='VI008', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=()), DatasetID(name='NR016', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=())"
scaled_scn.load(['natural_color'])
---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

<ipython-input-350-2e63ccc2c3ff> in <module>
----> 1 scaled_scn.load(['natural_color'])


~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/scene.py in load(self, wishlist, calibration, resolution, polarization, level, generate, unload, **kwargs)
    963         if unknown:
    964             unknown_str = ", ".join(map(str, unknown))
--> 965             raise KeyError("Unknown datasets: {}".format(unknown_str))
    966 
    967         self.read(**kwargs)


KeyError: "Unknown datasets: DatasetID(name='VI006', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=()), DatasetID(name='VI008', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=()), DatasetID(name='NR016', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=())"

@djhoese
Copy link
Member Author

djhoese commented Oct 14, 2019

You can't call .load on a resampled Scene object (your new_scn). A resampled Scene no longer has access to the original readers and can't load any datasets from the files that it may need to make the RGB. You should try loading all the RGBs in the original .load call.

@songhan89
Copy link

Sorry for the spam. Seems that the problem lies with computing sunz correction. Tested and it only affects those composites with [sunz_corrected] in ami.yaml.

scn.load(['true_color'])

[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional satellite_azimuth_angle: Unknown dataset satellite_azimuth_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional satellite_zenith_angle: Unknown dataset satellite_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_azimuth_angle: Unknown dataset solar_azimuth_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional satellite_azimuth_angle: Unknown dataset satellite_azimuth_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional satellite_zenith_angle: Unknown dataset satellite_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_azimuth_angle: Unknown dataset solar_azimuth_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional satellite_azimuth_angle: Unknown dataset satellite_azimuth_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional satellite_zenith_angle: Unknown dataset satellite_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_azimuth_angle: Unknown dataset solar_azimuth_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.node] Skipping optional solar_zenith_angle: Unknown dataset solar_zenith_angle
[DEBUG: 2019-10-15 00:48:42 : satpy.composites] Applying sun zen correction
[DEBUG: 2019-10-15 00:48:42 : satpy.composites] Computing sun zenith angles.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-405-871a5986e45a> in <module>
----> 1 scn.load(['true_color'])

~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/scene.py in load(self, wishlist, calibration, resolution, polarization, level, generate, unload, **kwargs)
    967         self.read(**kwargs)
    968         if generate:
--> 969             keepables = self.generate_composites()
    970         else:
    971             # don't lose datasets we loaded to try to generate composites

~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/scene.py in generate_composites(self, nodes)
    882             nodes = set(self.dep_tree.trunk(nodes=required_nodes)) - \
    883                 set(self.datasets.keys())
--> 884         return self._read_composites(nodes)
    885 
    886     def _remove_failed_datasets(self, keepables):

~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/scene.py in _read_composites(self, compositor_nodes)
    856         keepables = set()
    857         for item in compositor_nodes:
--> 858             self._generate_composite(item, keepables)
    859         return keepables
    860 

~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/scene.py in _generate_composite(self, comp_node, keepables)
    831             composite = compositor(prereq_datasets,
    832                                    optional_datasets=optional_datasets,
--> 833                                    **self.attrs)
    834 
    835             cid = DatasetID.from_dict(composite.attrs)

~/anaconda3/envs/gk2a_dev/lib/python3.6/site-packages/satpy/composites/__init__.py in __call__(self, projectables, **info)
    402             if self.max_sza is not None:
    403                 coszen = coszen.where(coszen >= self.max_sza_cos)
--> 404             self.coszen[key] = coszen
    405         elif coszen is None:
    406             # we were given the SZA, calculate the cos(SZA)

~/anaconda3/envs/gk2a_dev/lib/python3.6/weakref.py in __setitem__(self, key, value)
    166         if self._pending_removals:
    167             self._commit_removals()
--> 168         self.data[key] = KeyedRef(value, self._remove, key)
    169 
    170     def copy(self):

~/anaconda3/envs/gk2a_dev/lib/python3.6/weakref.py in __new__(type, ob, callback, key)
    333 
    334     def __new__(type, ob, callback, key):
--> 335         self = ref.__new__(type, ob, callback)
    336         self.key = key
    337         return self

TypeError: cannot create weak reference to 'DataArray' object

@djhoese
Copy link
Member Author

djhoese commented Oct 14, 2019

This is a bug in xarray 0.13.0. Either downgrade xarray or wait for the next release (hopefully this week they said).

@simonrp84
Copy link
Member

@songhan89 Just FYI, the bug that @djhoese mentioned has been fixed now - if you upgrade to xarray 0.14.0 then it should be OK.

@mraspaud
Copy link
Member

mraspaud commented Oct 21, 2019

@simonrp84 @djhoese did one of you check the geolocation in the end ?
Is there anything left otherwise for this PR to be ready ?

@simonrp84
Copy link
Member

@mraspaud I've checked against coastline overlays and it looks fine - but I can't find an alternative source of comparison.

@mraspaud
Copy link
Member

Good enough for me 👍

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.

Good work guys in putting everything together into this comprehensive reader. I have a couple of comments, but nothing serious to mention

Comment on lines +57 to +66
wv063:
file_reader: !!python/name:satpy.readers.ami_l1b.AMIL1bNetCDF
file_patterns: ['{platform_shortname:4s}_{sensor:3s}_le1b_wv063_{sector_info:s}_{start_time:%Y%m%d%H%M}.nc']
wv069:
file_reader: !!python/name:satpy.readers.ami_l1b.AMIL1bNetCDF
file_patterns: ['{platform_shortname:4s}_{sensor:3s}_le1b_wv069_{sector_info:s}_{start_time:%Y%m%d%H%M}.nc']
wv073:
file_reader: !!python/name:satpy.readers.ami_l1b.AMIL1bNetCDF
file_patterns: ['{platform_shortname:4s}_{sensor:3s}_le1b_wv073_{sector_info:s}_{start_time:%Y%m%d%H%M}.nc']

Copy link
Member

Choose a reason for hiding this comment

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

can't these be compacted in one generic filetype instead ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. Not unless we implement what I talked about on slack or in another PR where the file handler updates its own file type once it parses the file. Otherwise when you ask for "VI006" then Satpy (yaml reader) is going to ask each file handler for this data. In my opinion this is unnecessarily wasteful computation.

Copy link
Member

Choose a reason for hiding this comment

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

hmmm, ok. the viirs_sdr reader proceedes in this way, do you think it should be changed back ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think you can do it with the viirs_sdr reader since you have to look through all possible combinations of the various file types (and in any order).

Comment on lines +87 to +97
cfac = self.nc.attrs['cfac']
coff = self.nc.attrs['coff']
lfac = self.nc.attrs['lfac']
loff = self.nc.attrs['loff']
bit_shift = 2**16
area_extent = (
h * np.deg2rad((0 - coff - 0.5) * bit_shift / cfac),
-h * np.deg2rad((0 - loff - 0.5) * bit_shift / lfac),
h * np.deg2rad((cols - coff + 0.5) * bit_shift / cfac),
-h * np.deg2rad((rows - loff + 0.5) * bit_shift / lfac),
)
Copy link
Member

Choose a reason for hiding this comment

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

This looks really similar to the hrit code, any possibility to factorize these ?
https://github.com/pytroll/satpy/blob/master/satpy/readers/hrit_base.py#L262-L277

Copy link
Member Author

Choose a reason for hiding this comment

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

It does look pretty similar doesn't it. That's probably because these L1b files are based off of "uhrit" files which are probably similar in data structure to hrit files. I'm going to say that I don't want to make this refactor in this PR. We can make it an issue if you'd like, but there is a lot in that module that has nothing to do with these AMI files. We could move the method to another module, but it is also pretty specific to hrit, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's hrit specific, but I don't see any reason not to factorize. An issue would be the least :)

Copy link
Member

Choose a reason for hiding this comment

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

Just a note, it's not HRIT specific but Geostationary specific. The AGRI reader uses similar code. Perhaps this type of thing could be added to a geo_utils.py or similar file?

Copy link
Member Author

Choose a reason for hiding this comment

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

@simonrp84 But the 2**16 part isn't geostationary specific, right? We don't need these types of calculations for ABI because we have the X/Y radian coordinates already.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, @djhoese that's right. But ABI is a bit of an exception, we could do it the same way as the other geosats - but why bother with the extra computation :)
To my knowledge all the other geosats need this calculation.

Copy link
Member Author

Choose a reason for hiding this comment

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

ABI is CF compliant. Hopefully future satellite data files (at least for higher level processing output) can also be CF compliant.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed!

satpy/tests/reader_tests/test_ami_l1b.py Show resolved Hide resolved
@mraspaud
Copy link
Member

@djhoese do you still want to tick the first item in the check list or should with just merge this ?

@djhoese
Copy link
Member Author

djhoese commented Oct 22, 2019

I think it is the best we're going to get and follows the sample code provided by KMA. I'm sure when it comes down to it we may want to be more precise like my updates to the ABI reader allowed, but that was being nit-picky.

@djhoese djhoese changed the title Add initial GK-2A AMI L1B Reader Add GK-2A AMI L1B Reader Oct 22, 2019
@djhoese djhoese merged commit e40961e into pytroll:master Oct 22, 2019
@djhoese djhoese deleted the feature-ami-reader branch October 22, 2019 15:25
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.

Add reader for GEO-KOMPSAT AMI
5 participants