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

Question (maybe a bug): Why does RBG array exported with scn.save_dataset contain values greater than 255 ? #710

Closed
isobelrlawrence opened this issue Apr 10, 2019 · 4 comments
Labels
component:writers enhancement code enhancements, features, improvements help wanted

Comments

@isobelrlawrence
Copy link

isobelrlawrence commented Apr 10, 2019

Hello,

When I export my 'true_color' satellite image as a netcdf file containing RGB values of each pixel I end up with individual values for R,G or B greater than 255. Surely output RGB values should be between 0 and 255 or 0 and 1. Perhaps there is a scaling factor missing from the netcdf header?

Here is my code:

from satpy.scene import Scene
from satpy import find_files_and_readers
from datetime import datetime
from netCDF4 import Dataset
import numpy as np
 
files = find_files_and_readers(sensor='olci', 
              start_time=datetime(2019, 3, 15, 4, 28),
              end_time=datetime(2019, 3, 15, 4, 30),
              base_dir="/Users/il/Downloads/",
              reader='olci_l1b')
 
scn = Scene(filenames=files)
scn.load(['true_color'])
scn.save_dataset('true_color', writer='cf', filename='true_color.nc')

OLCI_data=Dataset('true_color.nc')
OLCI_z=np.asarray(OLCI_data['true_color'])
print(np.nanmax(OLCI_z))

Returns:
351.80767121471672

Here is the netcdf header:

float64 true_color(bands, y, x)
    _FillValue: nan
    platform_name: Sentinel-3A
    sensor: olci
    ancillary_variables: []
    optional_datasets: []
    standard_name: true_color
    prerequisites: ["DatasetID(name='Oa08', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=('effective_solar_pathlength_corrected', 'rayleigh_corrected'))", "DatasetID(name='Oa06', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=('effective_solar_pathlength_corrected', 'rayleigh_corrected'))", "DatasetID(name='Oa03', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=('effective_solar_pathlength_corrected', 'rayleigh_corrected'))"]
    optional_prerequisites: []
    mode: RGB
    coordinates: longitude latitude
    long_name: true_color
unlimited dimensions: 
current shape = (3, 4091, 4865)
filling on

Many thanks,

  • I
@mraspaud
Copy link
Member

Hi,

Thanks for reporting this. Saving an RGB image to netcdf will not apply the enhancements, so the data you have then are the untouched physical values read from the files, in this case reflectances. In turn these are more that 100% sometimes because of sun zenith angle normalisation for example. Usually for RGB, we use GeoTiffs or other image formats here, but do you plan to visualise RGBs in netcdf in your case ?

@isobelrlawrence
Copy link
Author

Hi,

Yes that was my intention - I wanted to avoid working with GeoTiffs mainly just because I never have before and thought this could be a quicker way of doing things. Looks like I might have to though?
Perhaps it ought to be changed in the output netcdf so it doesn't say 'R', 'G', 'B' in the 'bands' parameter as this is a little misleading.

Many thanks for responding so promptly!
Isobel

@mraspaud
Copy link
Member

Hi,

At the moment, having enhanced RGBs (stretched to 0-255) isn't implemented for netcdf saving, but it shouldn't be to difficult to implement. If you feel like you want to give it a try, be sure to join us on the pytroll slack if you need some guidance (see pytroll.org to find out how to connect to slack).

@mraspaud mraspaud added component:writers enhancement code enhancements, features, improvements help wanted labels Apr 10, 2019
@isobelrlawrence
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:writers enhancement code enhancements, features, improvements help wanted
Projects
None yet
Development

No branches or pull requests

2 participants