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

Can't resample mscn to GridDefinition #1536

Closed
zxdawn opened this issue Feb 6, 2021 · 3 comments
Closed

Can't resample mscn to GridDefinition #1536

zxdawn opened this issue Feb 6, 2021 · 3 comments

Comments

@zxdawn
Copy link
Member

zxdawn commented Feb 6, 2021

Describe the bug
Resample works when the mscn is resampled to AreaDefinition.
But, it doesn't work for GridDefinition.

To Reproduce

import satpy
import numpy as np
from glob import glob
from satpy import MultiScene
from satpy.multiscene import timeseries
from pyresample.geometry import GridDefinition

disk_filenames = glob('../data/AGRI_L1/2019/*20190816003*.HDF', recursive=True)

mscn = MultiScene.from_files(disk_filenames, reader="agri_l1")
mscn.load(['C12'])

# create the grid as same as H8 gridded data
lat = plot.arange(55, 15, -0.05)
lon = plot.arange(80, 135, 0.05)
lons, lats = np.meshgrid(lon ,lat)
area = GridDefinition(lons=lons, lats=lats)

new_mscn = mscn.resample(area, resampler='bucket_count')
imgs = new_mscn.blend(blend_function=timeseries)
Error
[DEBUG: 2021-02-06 21:50:27 : satpy.readers.yaml_reader] Reading ('/student/zhangxin/github/satpy_tobac/satpy/etc/readers/agri_l1.yaml',)
[DEBUG: 2021-02-06 21:50:27 : satpy.multiscene] Forcing iteration of generator-like object of Scenes
[DEBUG: 2021-02-06 21:50:27 : satpy.readers.yaml_reader] Reading ('/student/zhangxin/github/satpy_tobac/satpy/etc/readers/agri_l1.yaml',)
[DEBUG: 2021-02-06 21:50:27 : satpy.readers.yaml_reader] Assigning to agri_l1: ['../data/AGRI_L1/2019/FY4A-_AGRI--_N_REGC_1047E_L1-_FDI-_MULT_NOM_20190816003000_20190816003416_4000M_V0001.HDF']
[DEBUG: 2021-02-06 21:50:27 : satpy.composites.config_loader] Looking for composites config file agri.yaml
[DEBUG: 2021-02-06 21:50:27 : satpy.composites.config_loader] Looking for composites config file visir.yaml
[DEBUG: 2021-02-06 21:50:27 : satpy.readers.agri_l1] Reading in get_dataset C12.
[DEBUG: 2021-02-06 21:50:27 : satpy.readers.agri_l1] Calibrating to brightness_temperature
[DEBUG: 2021-02-06 21:50:27 : satpy.scene] Resampling DataID(name='C12', wavelength=WavelengthRange(min=10.3, central=10.8, max=11.1, unit='µm'), resolution=4000, calibration=<calibration.brightness_temperature>, modifiers=())
[INFO: 2021-02-06 21:50:27 : satpy.scene] Not reducing data before resampling.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-e5cfbeb31e58> in <module>
     11 
     12 new_mscn = mscn.resample(area, resampler='bucket_count')
---> 13 imgs = new_mscn.blend(blend_function=timeseries)

/student/zhangxin/github/satpy_tobac/satpy/multiscene.py in blend(self, blend_function)
    301         """
    302         new_scn = Scene()
--> 303         common_datasets = self.shared_dataset_ids
    304         for ds_id in common_datasets:
    305             datasets = [scn[ds_id] for scn in self.scenes if ds_id in scn]

/student/zhangxin/github/satpy_tobac/satpy/multiscene.py in shared_dataset_ids(self)
    235     def shared_dataset_ids(self):
    236         """Dataset IDs shared by all children."""
--> 237         shared_ids = set(self.scenes[0].keys())
    238         for scene in self.scenes[1:]:
    239             shared_ids &= set(scene.keys())

/student/zhangxin/github/satpy_tobac/satpy/multiscene.py in scenes(self)
    219         if self.is_generator:
    220             log.debug("Forcing iteration of generator-like object of Scenes")
--> 221             self._scenes = list(self._scenes)
    222         return self._scenes
    223 

/student/zhangxin/github/satpy_tobac/satpy/multiscene.py in __iter__(self)
    121             if idx >= len(self._scene_cache):
    122                 try:
--> 123                     scn = next(self._self_iter)
    124                 except StopIteration:
    125                     return

/student/zhangxin/github/satpy_tobac/satpy/multiscene.py in _create_cached_iter(self)
    111     def _create_cached_iter(self):
    112         """Iterate over the provided scenes, caching them for later."""
--> 113         for scn in self._scene_gen:
    114             self._scene_cache.append(scn)
    115             yield scn

/student/zhangxin/github/satpy_tobac/satpy/multiscene.py in _call_scene_func(gen, func_name, create_new_scene, *args, **kwargs)
    261         """Abstract method for running a Scene method on each Scene."""
    262         for scn in gen:
--> 263             new_scn = getattr(scn, func_name)(*args, **kwargs)
    264             if create_new_scene:
    265                 yield new_scn

/student/zhangxin/github/satpy_tobac/satpy/scene.py in resample(self, destination, datasets, generate, unload, resampler, reduce_data, **resample_kwargs)
    785         # we may have some datasets we asked for but don't exist yet
    786         new_scn._wishlist = self._wishlist.copy()
--> 787         self._resampled_scene(new_scn, destination, resampler=resampler,
    788                               reduce_data=reduce_data, **resample_kwargs)
    789 

/student/zhangxin/github/satpy_tobac/satpy/scene.py in _resampled_scene(self, new_scn, destination_area, reduce_data, **resample_kwargs)
    735                 LOG.info("Not reducing data before resampling.")
    736             if source_area not in resamplers:
--> 737                 key, resampler = prepare_resampler(
    738                     source_area, destination_area, **resample_kwargs)
    739                 resamplers[source_area] = resampler

/student/zhangxin/github/satpy_tobac/satpy/resample.py in prepare_resampler(source_area, destination_area, resampler, **resample_kwargs)
   1260            hash_dict(resample_kwargs).hexdigest())
   1261     try:
-> 1262         resampler_instance = resamplers_cache[key]
   1263     except KeyError:
   1264         resampler_instance = resampler_class(source_area, destination_area)

/yin_raid/xin/miniconda3/envs/tobac2.0_dev/lib/python3.8/weakref.py in __getitem__(self, key)
    129         if self._pending_removals:
    130             self._commit_removals()
--> 131         o = self.data[key]()
    132         if o is None:
    133             raise KeyError(key)

/yin_raid/xin/miniconda3/envs/tobac2.0_dev/lib/python3.8/site-packages/pyresample/geometry.py in __hash__(self)
    110         """Compute the hash of this object."""
    111         if self.hash is None:
--> 112             self.hash = int(self.update_hash().hexdigest(), 16)
    113         return self.hash
    114 

AttributeError: 'GridDefinition' object has no attribute 'update_hash'

Environment Info:

  • OS: Linux
  • Satpy Version: 0.25.2.dev55+g5c827cb5
  • PyResample Version: 0.17.0
@djhoese
Copy link
Member

djhoese commented Feb 6, 2021

I'm not sure GridDefinition is an approved/supported type for resample. You should be able to make an AreaDefinition that defines the same geographic region on a WGS84 latlong grid.

@djhoese
Copy link
Member

djhoese commented Feb 6, 2021

A better, simpler case may be to try a regular Scene with a GridDefinition.

@zxdawn
Copy link
Member Author

zxdawn commented Feb 7, 2021

Thanks. The WSG84 works well for single Scene and Multiple Scenes:

# wsg84
area_def = create_area_def('my_area',
                            {'proj': 'longlat', 'datum': 'WGS84'},
                            area_extent=[80, 15, 135, 55],
                            resolution=0.05,
                            units='degrees',
                            description='Test 0.05x0.05 degree lat-lon grid')

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