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

Resampling MODIS Level 1B data #1745

Closed
samueljackson92 opened this issue Jun 29, 2021 · 4 comments
Closed

Resampling MODIS Level 1B data #1745

samueljackson92 opened this issue Jun 29, 2021 · 4 comments

Comments

@samueljackson92
Copy link

Describe the bug
Hi, I am trying to plot some MODIS level 1B data and trying out different resampling strategies. The "nearest" strategy seems to work, but other resampling strategies seem to give the following exception:

 AttributeError: 'SwathDefinition' object has no attribute 'proj_dict'

Am I doing something obviously wrong? Is there an issue here?

To Reproduce

files = {"modis_l1b" : ['datasets/sept20200901/modis/level1/MOD021KM.A2020244.0930.061.2020244192029.hdf']}
modis_scn = Scene(filenames=files)
modis_scn.load(['20'], resolution=1000)

modis_scn = modis_scn.resample(modis_scn.coarsest_area(), resampler='bucket_avg')
modis_scn.show('20')

Expected behavior
The scene to be resampled correctly and the resampled data to be plotted.

Actual results
Text output of actual results or error messages including full tracebacks if applicable.

/home/lhs18285/miniconda3/envs/pangeo/lib/python3.9/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.yaml_reader] Reading ('/home/lhs18285/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/etc/readers/modis_l1b.yaml',)
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.yaml_reader] Assigning to modis_l1b: ['datasets/sept20200901/modis/level1/MOD021KM.A2020244.0930.061.2020244192029.hdf']
[DEBUG: 2021-06-29 17:00:31 : satpy.composites.config_loader] Looking for composites config file modis.yaml
[DEBUG: 2021-06-29 17:00:31 : satpy.composites.config_loader] Looking for composites config file visir.yaml
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.hdfeos_base] Loading latitude
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.hdfeos_base] Interpolating from 5000 to 1000
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.yaml_reader] No coordinates found for DataID(name='latitude', resolution=1000, modifiers=())
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.hdfeos_base] Loading longitude
[DEBUG: 2021-06-29 17:00:31 : satpy.readers.yaml_reader] No coordinates found for DataID(name='longitude', resolution=1000, modifiers=())
[DEBUG: 2021-06-29 17:00:31 : satpy.scene] Resampling DataID(name='20', wavelength=WavelengthRange(min=3.66, central=3.75, max=3.84, unit='µm'), resolution=1000, calibration=<calibration.brightness_temperature>, modifiers=())
[INFO: 2021-06-29 17:00:31 : satpy.scene] Not reducing data before resampling.
[DEBUG: 2021-06-29 17:00:31 : satpy.resample] Initializing bucket resampler.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-87-463c0a036c40> in <module>
      4 modis_scn.load(['20'], resolution=1000)
      5 
----> 6 modis_scn = modis_scn.resample(modis_scn.coarsest_area(), resampler='bucket_avg')
      7 modis_scn.show('20')

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/scene.py in resample(self, destination, datasets, generate, unload, resampler, reduce_data, **resample_kwargs)
    810             destination = self.finest_area(datasets)
    811         new_scn = self.copy(datasets=datasets)
--> 812         self._resampled_scene(new_scn, destination, resampler=resampler,
    813                               reduce_data=reduce_data, **resample_kwargs)
    814 

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/scene.py in _resampled_scene(self, new_scn, destination_area, reduce_data, **resample_kwargs)
    771             kwargs = resample_kwargs.copy()
    772             kwargs['resampler'] = resamplers[source_area]
--> 773             res = resample_dataset(dataset, destination_area, **kwargs)
    774             new_datasets[ds_id] = res
    775             if ds_id in new_scn._datasets:

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/resample.py in resample_dataset(dataset, destination_area, **kwargs)
   1380 
   1381     fill_value = kwargs.pop('fill_value', get_fill_value(dataset))
-> 1382     new_data = resample(source_area, dataset, destination_area, fill_value=fill_value, **kwargs)
   1383     new_attrs = new_data.attrs
   1384     new_data.attrs = dataset.attrs.copy()

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/resample.py in resample(source_area, data, destination_area, resampler, **kwargs)
   1343         res = [resampler_instance.resample(ds, **kwargs) for ds in data]
   1344     else:
-> 1345         res = resampler_instance.resample(data, **kwargs)
   1346 
   1347     return res

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/resample.py in resample(self, data, **kwargs)
   1108                              'Please update Pyresample to 1.18.0 or higher to be able to use this argument.')
   1109 
-> 1110         self.precompute(**kwargs)
   1111         attrs = data.attrs.copy()
   1112         data_arr = data.data

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/satpy/resample.py in precompute(self, **kwargs)
   1086         source_lons, source_lats = self.source_geo_def.get_lonlats(
   1087             chunks=CHUNK_SIZE)
-> 1088         self.resampler = bucket.BucketResampler(self.target_geo_def,
   1089                                                 source_lons,
   1090                                                 source_lats)

~/miniconda3/envs/pangeo/lib/python3.9/site-packages/pyresample/bucket/__init__.py in __init__(self, target_area, source_lons, source_lats)
     84         self.source_lons = source_lons
     85         self.source_lats = source_lats
---> 86         self.prj = Proj(self.target_area.proj_dict)
     87         self.x_idxs = None
     88         self.y_idxs = None

AttributeError: 'SwathDefinition' object has no attribute 'proj_dict'

Environment Info:

  • OS: Linux (Ubuntu 20.04)
  • Satpy Version: 0.29.0
  • PyResample Version: 1.20.0

Additional context
N/a

@djhoese
Copy link
Member

djhoese commented Jun 29, 2021

Some resamplers do not support SwathDefinitions as target/destination areas. It is not well documented and it is not actively checked for. It is something we want to improve in pyresample 2.0 which we are designing and working on. You will need to resample to an AreaDefinition with these other resamplers.

@samueljackson92
Copy link
Author

@djhoese thanks for the quick response! That makes sense. Is there an easy way to define a sensible AreaDefinition from the SwathDefinition? For example, the min area containing the swath extent? I could not see an example in the docs, but perhaps I missed something?

@djhoese
Copy link
Member

djhoese commented Jun 29, 2021

I'm not sure it is well documented. You would have to decide what projection your MODIS data would look best in and then create an AreaDefinition. There are utilities in pyresample to help with this: https://pyresample.readthedocs.io/en/latest/geometry_utils.html

But right now they still require you, the user, to know what projection you want to use. If you don't provide all the information (like the extents), these utilities will return a DynamicAreaDefinition which can be passed to Scene.resample and will automatically define a static AreaDefinition to match the extents of the data.

@samueljackson92
Copy link
Author

Thanks for clarifying and pointing me to some useful docs. I think you can mark this one as closed.

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

No branches or pull requests

2 participants