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

Saving resampled area fails with AttributeError: 'NoneType' object has no attribute 'split' #25

Open
gerritholl opened this issue Sep 27, 2021 · 1 comment

Comments

@gerritholl
Copy link
Member

Saving a scene resampled to an area with certain properties fails with AttributeError: 'NoneType' object has no attribute 'split':

from satpy import Scene
from satpy.utils import debug_on; debug_on()
sc = Scene(
        filenames=["/media/nas/x21308/scratch/hrpt_metop03_20210323_1809_12327.l1b"],
        reader=["avhrr_l1b_aapp"])
sc.load(["4"])
ls = sc.resample("nqceur250m")
ls.save_dataset("4",
        "/tmp/test.tif",
        writer="ninjotiff",
        physic_unit="C",
        sat_id=7900014,
        chan_id=900015,
        data_cat="PORN",
        nbits=8,
        data_source="HRPT",
        ch_min_measurement_unit=40,
        ch_max_measurement_unit=-87.5)

Area in question is defined as:

nqceur250m:
  description: nqceur250m
  projection:
    proj: longlat
    lon_0: 0.0
    lat_0: 50.0
    lat_ts: 0.0
    ellps: WGS84
  shape:
    height: 8000
    width: 16000
  area_extent:
    lower_left_xy: [-0.22689123196293604, 0.7155956398261123]
    upper_right_xy: [0.401424157162369, 1.0297336121682172]

Executing this code results in:

[DEBUG: 2021-09-27 18:14:26 : satpy.readers.yaml_reader] Reading ('/data/gholl/checkouts/satpy/satpy/etc/readers/avhrr_l1b_aapp.yaml',)
[DEBUG: 2021-09-27 18:14:26 : satpy.readers.yaml_reader] Assigning to avhrr_l1b_aapp: ['/media/nas/x21308/scratch/hrpt_metop03_20210323_1809_12327.l1b']
[DEBUG: 2021-09-27 18:14:26 : satpy.readers.aapp_l1b] Reading time 0:00:00.003269
[DEBUG: 2021-09-27 18:14:26 : satpy.composites.config_loader] Looking for composites config file avhrr-3.yaml
[DEBUG: 2021-09-27 18:14:26 : satpy.composites.config_loader] Looking for composites config file visir.yaml
[DEBUG: 2021-09-27 18:14:26 : satpy.readers.yaml_reader] No coordinates found for DataID(name='latitude', resolution=1050, modifiers=())
[DEBUG: 2021-09-27 18:14:26 : satpy.readers.yaml_reader] No coordinates found for DataID(name='longitude', resolution=1050, modifiers=())
[DEBUG: 2021-09-27 18:14:26 : satpy.scene] Resampling DataID(name='4', wavelength=WavelengthRange(min=10.3, central=10.8, max=11.3, unit='µm'), resolution=1050, calibration=<calibration.brightness_temperature>, modifiers=())
[INFO: 2021-09-27 18:14:26 : satpy.scene] Not reducing data before resampling.
[INFO: 2021-09-27 18:14:26 : satpy.resample] Using default KDTree resampler
[DEBUG: 2021-09-27 18:14:26 : satpy.resample] Check if ./resample_lut-31dcaed3f5e41d8b6d60b228206fe9fd414aa9f2.npz exists
[DEBUG: 2021-09-27 18:14:26 : satpy.resample] Computing kd-tree parameters
/data/gholl/miniconda3/envs/py39b/lib/python3.9/site-packages/pyresample/kd_tree.py:1025: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  input_coords = input_coords.astype(np.float)
/data/gholl/miniconda3/envs/py39b/lib/python3.9/site-packages/pyresample/kd_tree.py:1047: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  radius=self.radius_of_influence, dtype=np.int,
[DEBUG: 2021-09-27 18:14:26 : satpy.resample] Resampling where-9f3f1f4d3c037162a3d408d41ea4566f
[DEBUG: 2021-09-27 18:14:26 : satpy.writers] Reading ['/data/gholl/checkouts/satpy/satpy/etc/writers/ninjotiff.yaml']
/data/gholl/checkouts/pyninjotiff/pyninjotiff/tifffile.py:154: UserWarning: failed to import the optional _tifffile C extension module.
Loading of some compressed images will be slow.
Tifffile.c can be obtained at http://www.lfd.uci.edu/~gohlke/
  warnings.warn(
[DEBUG: 2021-09-27 18:14:26 : satpy.writers] Enhancement configuration options: [{'name': 'stretch', 'method': <function stretch at 0x7f035b1ab040>, 'kwargs': {'stretch': 'linear'}}]
[DEBUG: 2021-09-27 18:14:26 : trollimage.xrimage] Applying stretch linear with parameters {}
[DEBUG: 2021-09-27 18:14:26 : trollimage.xrimage] Perform a linear contrast stretch.
[DEBUG: 2021-09-27 18:14:26 : trollimage.xrimage] Calculate the histogram quantiles: 
[DEBUG: 2021-09-27 18:14:26 : trollimage.xrimage] Left and right quantiles: 0.005 0.005
[INFO: 2021-09-27 18:14:27 : pyninjotiff.ninjotiff] Will generate single band product
/data/gholl/miniconda3/envs/py39b/lib/python3.9/site-packages/pyproj/crs/crs.py:1216: UserWarning: You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
  return self._crs.to_proj4(version=version)
/data/gholl/miniconda3/envs/py39b/lib/python3.9/site-packages/pyproj/crs/crs.py:1216: UserWarning: You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
  return self._crs.to_proj4(version=version)
Traceback (most recent call last):
  File "/data/gholl/checkouts/protocode/mwe/ninjotiff-crash.py", line 8, in <module>
    ls.save_dataset("4",
  File "/data/gholl/checkouts/satpy/satpy/scene.py", line 1037, in save_dataset
    return writer.save_dataset(self[dataset_id],
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjotiff.py", line 206, in save_dataset
    return super(NinjoTIFFWriter, self).save_dataset(
  File "/data/gholl/checkouts/satpy/satpy/writers/__init__.py", line 809, in save_dataset
    return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
  File "/data/gholl/checkouts/satpy/satpy/writers/ninjotiff.py", line 178, in save_image
    return nt.save(img, filename, data_is_scaled_01=True, compute=compute, **kwargs)
  File "/data/gholl/checkouts/pyninjotiff/pyninjotiff/ninjotiff.py", line 560, in save
    return write(data, filename, area_def, ninjo_product_name, **kwargs)
  File "/data/gholl/checkouts/pyninjotiff/pyninjotiff/ninjotiff.py", line 665, in write
    ninjo_nav_parameters(options, area_def)
  File "/data/gholl/checkouts/pyninjotiff/pyninjotiff/ninjotiff.py", line 577, in ninjo_nav_parameters
    options.setdefault('projection', _get_projection_name(area_def))
  File "/data/gholl/checkouts/pyninjotiff/pyninjotiff/ninjotiff.py", line 289, in _get_projection_name
    return area_def.proj_id.split('_')[-1]
AttributeError: 'NoneType' object has no attribute 'split'

It seems that pyninjotiff wants to access the proj_id and expects it to be a str, and fails when this is instead None.

@djhoese
Copy link
Member

djhoese commented Sep 27, 2021

This is an interesting error as this is the first case I've seen in "modern" code where proj_id is actually used for something. In pyresample 2.0 I think we had the idea to remove this attribute entirely.

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