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

variable from python to composite #1832

Closed
gersmit opened this issue Sep 23, 2021 · 6 comments
Closed

variable from python to composite #1832

gersmit opened this issue Sep 23, 2021 · 6 comments

Comments

@gersmit
Copy link

gersmit commented Sep 23, 2021

Is it possible to use an varaibale in Python to use in generic.yaml composite.
For example:
colorized_ir_clouds:
standard_name: colorized_ir_clouds
operations:
- name: colorize
method: !!python/name:satpy.enhancements.colorize
kwargs:
palettes:
- {colors: rainbow, min_value: 190.15, max_value: 310.14}
- {colors: blues, min_value: 310.15, max_value: 350.15}

Is it possible to use a variable in Python that change the min_value and max_value of the palettes -> colors from the script.
When yes, can you tell me how to handle.

@djhoese
Copy link
Member

djhoese commented Sep 23, 2021

Not really. The information in the YAML is meant to be static (unchanging). You could convert your DataArray to an image and do the enhancement yourself. Something like this:

scn = Scene(...)
# load some channels and do some resampling...or whatever

from satpy.writers import to_image
from trollimage.colormaps import rainbow, blues

rainbow.set_range(190.15, 310.14)
blues.set_range(310.15, 350.15)
my_cmap = rainbow + blues

img = to_image(scn['my_channel'])
img.colorize(my_cmap)

scn['my_channel'] = img.data
scn.save_datasets(enhance=False)

We set enhance=False so that Satpy doesn't try to re-enhance the data. I'm 80% sure the above should work.

@gersmit
Copy link
Author

gersmit commented Sep 24, 2021

@djhoese work perfect, see image when i do img.show()
Only one small error, the save_datasets works normaly good.
Now i get error on save_datasets:
Traceback (most recent call last):
File "/home/pi/a-satpy-testen/cursus2_seviri.py", line 241, in
local_scn.save_datasets(enhance=False)
File "/home/pi/.local/lib/python3.7/site-packages/xarray/core/common.py", line 229, in getattr
"{!r} object has no attribute {!r}".format(type(self).name, name)
AttributeError: 'DataArray' object has no attribute 'save_datasets'

@djhoese
Copy link
Member

djhoese commented Sep 24, 2021

Double check what you did with local_scn. You probably did local_scn = img.data but you were supposed to do the equivalent of local_scn['my_channel'] = img.data.

@gersmit
Copy link
Author

gersmit commented Sep 26, 2021

@djhoese thanks, I did both, now again as you say
Error =
Traceback (most recent call last):
File "rasterio/_crs.pyx", line 253, in rasterio._crs._CRS.from_dict
File "rasterio/_err.pyx", line 194, in rasterio._err.exc_wrap_ogrerr
rasterio._err.CPLE_BaseError: OGR Error code 7

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/a-satpy-testen/cursus2_seviri.py", line 242, in
local_scn.save_datasets(enhance=False)
File "/home/pi/.local/lib/python3.7/site-packages/satpy/scene.py", line 1368, in save_datasets
return writer.save_datasets(datasets, compute=compute, **save_kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/satpy/writers/init.py", line 697, in save_datasets
results.append(self.save_dataset(ds, compute=False, **kwargs))
File "/home/pi/.local/lib/python3.7/site-packages/satpy/writers/init.py", line 829, in save_dataset
return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/satpy/writers/geotiff.py", line 219, in save_image
**gdal_options)
File "/home/pi/.local/lib/python3.7/site-packages/trollimage/xrimage.py", line 422, in save
**format_kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/trollimage/xrimage.py", line 517, in rio_save
crs = rasterio.crs.CRS(data.attrs['area'].proj_dict)
File "/usr/lib/python3/dist-packages/rasterio/crs.py", line 70, in init
self._crs = _CRS.from_dict(data)
File "rasterio/_crs.pyx", line 255, in rasterio._crs._CRS.from_dict
rasterio.errors.CRSError: The PROJ4 dict could not be understood. OGR Error code 7

@gersmit
Copy link
Author

gersmit commented Sep 26, 2021

@djhoese I have it now and is looking good, thanks for sofar

local_scn['my_channel'] = img.data
color_transp = 'my_channel'
img.show()
local_scn.save_dataset(color_transp, writer='simple_image',
enhance=False, # zonder maakt kleur harder
filename='/home/pi/a-satpy-testen/images/'+ file_name + 'color_scn.png',
overlay={'coast_dir': '/home/pi/a-satpy-testen/GSHHS_DATA_ROOT/',
'overlays': {'grid': grid,
'coasts': coast,
'borders': borders,
'rivers': rivers
}})

@djhoese
Copy link
Member

djhoese commented Sep 27, 2021

Sounds like you were able to make it work. If so, I'm going to close this. If not, please comment and we can reopen this.

@djhoese djhoese closed this as completed Sep 27, 2021
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