pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.05k stars 289 forks source link

Images are slightly different between scn.crop() and original one #2135

Closed yukaribbba closed 2 years ago

yukaribbba commented 2 years ago

Describe the bug Just as the title reads.

To Reproduce

scn = scn.crop(ll_bbox=(69, -3, 206, 56))

Nothing else special.

Expected behavior Shoud be the same.

Actual results

original cropped

These two 100%-zoomed results come from a red channel file on GK-2A. Both of them are:

However, you can tell the original one is a little brighter.

Environment Info:

djhoese commented 2 years ago

Can you provide the code that generated these and can you turn on debug messages and paste them here? My guess is different enhancements are being applied.

yukaribbba commented 2 years ago

The python script:

files = find_files_and_readers(base_dir="C:/Users/45107/Downloads/Sat/GK2A/", reader='ami_l1b')

scn = Scene(filenames=files)
scn.load(["Rdaynight"])
scn = scn.crop(xy_bbox=(-4967000, -287000, 5175000, 4815000))
scn.save_dataset("Rdaynight", filename='gk2a_{name}_{start_time:%Y%m%d_%H%M}.tif', writer='geotiff',
                 base_dir="C:/Users/45107/Downloads/Sat/GK2A/", compress=None)

The composite:

Rsingle:
  compositor: !!python/name:satpy.composites.GenericCompositor
  prerequisites:
    - name: VI006
      modifiers: [sunz_corrected, rayleigh_corrected]
  standard_name: true_color_crefl2

Rdaynight:
  compositor: !!python/name:satpy.composites.DayNightCompositor
  prerequisites:
    - name: Rsingle
  lim_low: 74
  lim_hight: 88
  day_night: "day_only"         
  standard_name: Rdaynight

The enhancement:

true_color_crefl2:
  standard_name: true_color_crefl2
  operations:
  - name: reflectance_range
    method: !!python/name:satpy.enhancements.stretch
    kwargs: {stretch: 'crude', min_stretch: 0., max_stretch: 100.}
  - name: linear interpolation
    method: !!python/name:satpy.enhancements.piecewise_linear_stretch
    kwargs:
      xp: [0., 25., 55., 100., 255.]
      fp: [0., 90., 140., 175., 255.]
      reference_scale_factor: 255

Debug WITH scn.crop():

[DEBUG: 2022-06-29 00:14:12 : satpy.readers.yaml_reader] Reading ('C:\\Users\\45107\\miniconda3\\Lib\\site-packages\\satpy\\etc\\readers\\ami_l1b.yaml',)
[DEBUG: 2022-06-29 00:14:12 : satpy.readers.yaml_reader] Reading ('C:\\Users\\45107\\miniconda3\\Lib\\site-packages\\satpy\\etc\\readers\\ami_l1b.yaml',)
[DEBUG: 2022-06-29 00:14:12 : satpy.readers.yaml_reader] Assigning to ami_l1b: ['C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_ir105_fd020ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_ir123_fd020ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_sw038_fd020ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi004_fd010ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi005_fd010ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi006_fd005ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi008_fd010ge_202206220230.nc']
[DEBUG: 2022-06-29 00:14:13 : satpy.composites.config_loader] Looking for composites config file ami.yaml
[DEBUG: 2022-06-29 00:14:13 : satpy.composites.config_loader] Looking for composites config file visir.yaml
[DEBUG: 2022-06-29 00:14:13 : satpy.node] Skipping optional DataQuery(name='solar_zenith_angle', calibration='reflectance'): Unknown dataset DataQuery(name='solar_zenith_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:14:13 : satpy.node] Skipping optional DataQuery(name='satellite_azimuth_angle', calibration='reflectance'): Unknown dataset DataQuery(name='satellite_azimuth_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:14:13 : satpy.node] Skipping optional DataQuery(name='satellite_zenith_angle', calibration='reflectance'): Unknown dataset DataQuery(name='satellite_zenith_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:14:13 : satpy.node] Skipping optional DataQuery(name='solar_azimuth_angle', calibration='reflectance'): Unknown dataset DataQuery(name='solar_azimuth_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:14:13 : satpy.node] Skipping optional DataQuery(name='solar_zenith_angle', calibration='reflectance'): Unknown dataset DataQuery(name='solar_zenith_angle', calibration='reflectance')
C:\Users\45107\miniconda3\lib\site-packages\satpy\readers\ami_l1b.py:165: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  sc_position = pyproj.transform(
[DEBUG: 2022-06-29 00:14:13 : satpy.modifiers.geometry] Applying sun zen correction
[DEBUG: 2022-06-29 00:14:13 : satpy.modifiers.geometry] Computing sun zenith angles.
[DEBUG: 2022-06-29 00:14:13 : satpy.modifiers.geometry] Apply the standard sun-zenith correction [1/cos(sunz)]
[DEBUG: 2022-06-29 00:14:13 : h5py._conv] Creating converter from 7 to 5
[DEBUG: 2022-06-29 00:14:13 : h5py._conv] Creating converter from 5 to 7
[DEBUG: 2022-06-29 00:14:13 : h5py._conv] Creating converter from 7 to 5
[DEBUG: 2022-06-29 00:14:13 : h5py._conv] Creating converter from 5 to 7
[INFO: 2022-06-29 00:14:13 : satpy.modifiers.atmosphere] Removing Rayleigh scattering with atmosphere 'us-standard' and aerosol type 'rayleigh_only' for 'VI006'
[INFO: 2022-06-29 00:14:13 : pyspectral.rayleigh] Atmosphere chosen: us-standard
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rayleigh] LUT filename: C:\Users\45107\AppData\Local\pytroll\pyspectral\rayleigh_only\rayleigh_lut_us-standard.h5
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] Filename: C:\Users\45107\AppData\Local\pytroll\pyspectral\rsr_ami_GEO-KOMPSAT-2A.h5
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] Filename: C:\Users\45107\AppData\Local\pytroll\pyspectral\rsr_ami_GEO-KOMPSAT-2A.h5
[DEBUG: 2022-06-29 00:14:13 : h5py._conv] Creating converter from 3 to 5
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:14:13 : pyspectral.rayleigh] Band name: ch3  Effective wavelength: 0.635127um
[DEBUG: 2022-06-29 00:14:13 : satpy.composites] Computing sun zenith angles.
[DEBUG: 2022-06-29 00:14:13 : satpy.writers] Enhancement configuration options: [{'name': 'reflectance_range', 'method': <function stretch at 0x0000016C039D7A60>, 'kwargs': {'stretch': 'crude', 'min_stretch': 0.0, 'max_stretch': 100.0}}, {'name': 'linear interpolation', 'method': <function piecewise_linear_stretch at 0x0000016C03A843A0>, 'kwargs': {'xp': [0.0, 25.0, 55.0, 100.0, 255.0], 'fp': [0.0, 90.0, 140.0, 175.0, 255.0], 'reference_scale_factor': 255}}]
[DEBUG: 2022-06-29 00:14:13 : trollimage.xrimage] Applying stretch crude with parameters {'min_stretch': 0.0, 'max_stretch': 100.0}
[DEBUG: 2022-06-29 00:14:13 : satpy.enhancements] Applying the piecewise_linear_stretch
[DEBUG: 2022-06-29 00:14:13 : satpy.scene] Unloading dataset: DataID(name='VI006', wavelength=WavelengthRange(min=0.599, central=0.639, max=0.679, unit='µm'), resolution=500, calibration=<calibration.reflectance>, modifiers=())
[DEBUG: 2022-06-29 00:14:13 : satpy.scene] Unloading dataset: DataID(name='VI006', wavelength=WavelengthRange(min=0.599, central=0.639, max=0.679, unit='µm'), resolution=500, calibration=<calibration.reflectance>, modifiers=('sunz_corrected',))
[DEBUG: 2022-06-29 00:14:13 : satpy.scene] Unloading dataset: DataID(name='VI006', wavelength=WavelengthRange(min=0.599, central=0.639, max=0.679, unit='µm'), resolution=500, calibration=<calibration.reflectance>, modifiers=('sunz_corrected', 'rayleigh_corrected'))
[DEBUG: 2022-06-29 00:14:13 : satpy.scene] Unloading dataset: DataID(name='Rsingle', resolution=500)
[DEBUG: 2022-06-29 00:14:13 : pyresample.geometry] Projections for data and slice areas are identical: PROJCRS["unknown",BASEGEOGCRS["unknown",DATUM["unknown",ELLIPSOID["unknown",6378137,298.257024882273,LENGTHUNIT["metre",1,ID["EPSG",9001]]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],CONVERSION["unknown",METHOD["Geostationary Satellite (Sweep Y)"],PARAMETER["Longitude of natural origin",128.2,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["Satellite Height",35785863,LENGTHUNIT["metre",1,ID["EPSG",9001]]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]
[DEBUG: 2022-06-29 00:14:13 : satpy.writers] Reading ['C:\\Users\\45107\\miniconda3\\Lib\\site-packages\\satpy\\etc\\writers\\geotiff.yaml']
[DEBUG: 2022-06-29 00:14:13 : satpy.writers] Enhancement configuration options: [{'name': 'stretch', 'method': <function stretch at 0x0000016C039D7A60>, 'kwargs': {'stretch': 'linear'}}]
[DEBUG: 2022-06-29 00:14:13 : trollimage.xrimage] Applying stretch linear with parameters {}
[DEBUG: 2022-06-29 00:14:13 : trollimage.xrimage] Perform a linear contrast stretch.
[DEBUG: 2022-06-29 00:14:13 : trollimage.xrimage] Calculate the histogram quantiles: 
[DEBUG: 2022-06-29 00:14:13 : trollimage.xrimage] Left and right quantiles: 0.005 0.005
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Entering env context: <rasterio.env.Env object at 0x0000016C02E54790>
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Starting outermost env
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] No GDAL environment exists
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] New GDAL environment <rasterio._env.GDALEnv object at 0x0000016C02E9A070> created
[DEBUG: 2022-06-29 00:14:13 : rasterio._env] GDAL_DATA found in environment.
[DEBUG: 2022-06-29 00:14:13 : rasterio._env] PROJ_LIB found in environment.
[DEBUG: 2022-06-29 00:14:13 : rasterio._env] Started GDALEnv: self=<rasterio._env.GDALEnv object at 0x0000016C02E9A070>.
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Entered env context: <rasterio.env.Env object at 0x0000016C02E54790>
[DEBUG: 2022-06-29 00:14:13 : rasterio._io] Path: ParsedPath(path='C:/Users/45107/Downloads/Sat/GK2A/gk2a_Rdaynight_20220622_0230.tif', archive=None, scheme=None), mode: w, driver: GTiff
[DEBUG: 2022-06-29 00:14:13 : rasterio._io] Option: ('COMPRESS', b'None')
[DEBUG: 2022-06-29 00:14:13 : rasterio._io] Option: ('ZLEVEL', b'6')
[DEBUG: 2022-06-29 00:14:13 : rasterio._io] Option: ('TILED', b'TRUE')
[DEBUG: 2022-06-29 00:14:13 : rasterio._io] Skipped delete for overwrite. Dataset does not exist: 'C:/Users/45107/Downloads/Sat/GK2A/gk2a_Rdaynight_20220622_0230.tif'
[DEBUG: 2022-06-29 00:14:13 : rasterio._base] Nodata success: 0, Nodata value: 0.000000
[DEBUG: 2022-06-29 00:14:13 : rasterio._base] Nodata success: 0, Nodata value: 0.000000
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Exiting env context: <rasterio.env.Env object at 0x0000016C02E54790>
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Cleared existing <rasterio._env.GDALEnv object at 0x0000016C02E9A070> options
[DEBUG: 2022-06-29 00:14:13 : rasterio._env] Stopped GDALEnv <rasterio._env.GDALEnv object at 0x0000016C02E9A070>.
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Exiting outermost env
[DEBUG: 2022-06-29 00:14:13 : rasterio.env] Exited env context: <rasterio.env.Env object at 0x0000016C02E54790>
[DEBUG: 2022-06-29 00:15:21 : trollimage.xrimage] Interval: left=<xarray.DataArray (bands: 2)>
array([0.03172001, 1.        ])
Coordinates:
    quantile  float64 0.005
Dimensions without coordinates: bands, right=<xarray.DataArray (bands: 2)>
array([0.98774499, 1.        ])
Coordinates:
    quantile  float64 0.995
Dimensions without coordinates: bands

Debug WITHOUT scn.crop():

[DEBUG: 2022-06-29 00:16:33 : satpy.readers.yaml_reader] Reading ('C:\\Users\\45107\\miniconda3\\Lib\\site-packages\\satpy\\etc\\readers\\ami_l1b.yaml',)
[DEBUG: 2022-06-29 00:16:33 : satpy.readers.yaml_reader] Reading ('C:\\Users\\45107\\miniconda3\\Lib\\site-packages\\satpy\\etc\\readers\\ami_l1b.yaml',)
[DEBUG: 2022-06-29 00:16:33 : satpy.readers.yaml_reader] Assigning to ami_l1b: ['C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_ir105_fd020ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_ir123_fd020ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_sw038_fd020ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi004_fd010ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi005_fd010ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi006_fd005ge_202206220230.nc', 'C:/Users/45107/Downloads/Sat/GK2A\\gk2a_ami_le1b_vi008_fd010ge_202206220230.nc']
[DEBUG: 2022-06-29 00:16:33 : satpy.composites.config_loader] Looking for composites config file ami.yaml
[DEBUG: 2022-06-29 00:16:33 : satpy.composites.config_loader] Looking for composites config file visir.yaml
[DEBUG: 2022-06-29 00:16:33 : satpy.node] Skipping optional DataQuery(name='solar_zenith_angle', calibration='reflectance'): Unknown dataset DataQuery(name='solar_zenith_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:16:33 : satpy.node] Skipping optional DataQuery(name='satellite_azimuth_angle', calibration='reflectance'): Unknown dataset DataQuery(name='satellite_azimuth_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:16:33 : satpy.node] Skipping optional DataQuery(name='satellite_zenith_angle', calibration='reflectance'): Unknown dataset DataQuery(name='satellite_zenith_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:16:33 : satpy.node] Skipping optional DataQuery(name='solar_azimuth_angle', calibration='reflectance'): Unknown dataset DataQuery(name='solar_azimuth_angle', calibration='reflectance')
[DEBUG: 2022-06-29 00:16:33 : satpy.node] Skipping optional DataQuery(name='solar_zenith_angle', calibration='reflectance'): Unknown dataset DataQuery(name='solar_zenith_angle', calibration='reflectance')
C:\Users\45107\miniconda3\lib\site-packages\satpy\readers\ami_l1b.py:165: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  sc_position = pyproj.transform(
[DEBUG: 2022-06-29 00:16:33 : satpy.modifiers.geometry] Applying sun zen correction
[DEBUG: 2022-06-29 00:16:33 : satpy.modifiers.geometry] Computing sun zenith angles.
[DEBUG: 2022-06-29 00:16:33 : satpy.modifiers.geometry] Apply the standard sun-zenith correction [1/cos(sunz)]
[DEBUG: 2022-06-29 00:16:33 : h5py._conv] Creating converter from 7 to 5
[DEBUG: 2022-06-29 00:16:33 : h5py._conv] Creating converter from 5 to 7
[DEBUG: 2022-06-29 00:16:33 : h5py._conv] Creating converter from 7 to 5
[DEBUG: 2022-06-29 00:16:33 : h5py._conv] Creating converter from 5 to 7
[INFO: 2022-06-29 00:16:33 : satpy.modifiers.atmosphere] Removing Rayleigh scattering with atmosphere 'us-standard' and aerosol type 'rayleigh_only' for 'VI006'
[INFO: 2022-06-29 00:16:33 : pyspectral.rayleigh] Atmosphere chosen: us-standard
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rayleigh] LUT filename: C:\Users\45107\AppData\Local\pytroll\pyspectral\rayleigh_only\rayleigh_lut_us-standard.h5
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] Filename: C:\Users\45107\AppData\Local\pytroll\pyspectral\rsr_ami_GEO-KOMPSAT-2A.h5
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] Filename: C:\Users\45107\AppData\Local\pytroll\pyspectral\rsr_ami_GEO-KOMPSAT-2A.h5
[DEBUG: 2022-06-29 00:16:33 : h5py._conv] Creating converter from 3 to 5
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rsr_reader] No detectors found - assume only one...
[DEBUG: 2022-06-29 00:16:33 : pyspectral.rayleigh] Band name: ch3  Effective wavelength: 0.635127um
[DEBUG: 2022-06-29 00:16:33 : satpy.composites] Computing sun zenith angles.
[DEBUG: 2022-06-29 00:16:34 : satpy.writers] Enhancement configuration options: [{'name': 'reflectance_range', 'method': <function stretch at 0x0000017B4F426A60>, 'kwargs': {'stretch': 'crude', 'min_stretch': 0.0, 'max_stretch': 100.0}}, {'name': 'linear interpolation', 'method': <function piecewise_linear_stretch at 0x0000017B4F4D63A0>, 'kwargs': {'xp': [0.0, 25.0, 55.0, 100.0, 255.0], 'fp': [0.0, 90.0, 140.0, 175.0, 255.0], 'reference_scale_factor': 255}}]
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Applying stretch crude with parameters {'min_stretch': 0.0, 'max_stretch': 100.0}
[DEBUG: 2022-06-29 00:16:34 : satpy.enhancements] Applying the piecewise_linear_stretch
[DEBUG: 2022-06-29 00:16:34 : satpy.scene] Unloading dataset: DataID(name='VI006', wavelength=WavelengthRange(min=0.599, central=0.639, max=0.679, unit='µm'), resolution=500, calibration=<calibration.reflectance>, modifiers=())
[DEBUG: 2022-06-29 00:16:34 : satpy.scene] Unloading dataset: DataID(name='VI006', wavelength=WavelengthRange(min=0.599, central=0.639, max=0.679, unit='µm'), resolution=500, calibration=<calibration.reflectance>, modifiers=('sunz_corrected',))
[DEBUG: 2022-06-29 00:16:34 : satpy.scene] Unloading dataset: DataID(name='VI006', wavelength=WavelengthRange(min=0.599, central=0.639, max=0.679, unit='µm'), resolution=500, calibration=<calibration.reflectance>, modifiers=('sunz_corrected', 'rayleigh_corrected'))
[DEBUG: 2022-06-29 00:16:34 : satpy.scene] Unloading dataset: DataID(name='Rsingle', resolution=500)
[DEBUG: 2022-06-29 00:16:34 : satpy.writers] Reading ['C:\\Users\\45107\\miniconda3\\Lib\\site-packages\\satpy\\etc\\writers\\geotiff.yaml']
[DEBUG: 2022-06-29 00:16:34 : satpy.writers] Enhancement configuration options: [{'name': 'stretch', 'method': <function stretch at 0x0000017B4F426A60>, 'kwargs': {'stretch': 'linear'}}]
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Applying stretch linear with parameters {}
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Perform a linear contrast stretch.
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Calculate the histogram quantiles: 
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Left and right quantiles: 0.005 0.005
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Entering env context: <rasterio.env.Env object at 0x0000017B4F4ED970>
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Starting outermost env
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] No GDAL environment exists
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] New GDAL environment <rasterio._env.GDALEnv object at 0x0000017B4F4ED9A0> created
[DEBUG: 2022-06-29 00:16:34 : rasterio._env] GDAL_DATA found in environment.
[DEBUG: 2022-06-29 00:16:34 : rasterio._env] PROJ_LIB found in environment.
[DEBUG: 2022-06-29 00:16:34 : rasterio._env] Started GDALEnv: self=<rasterio._env.GDALEnv object at 0x0000017B4F4ED9A0>.
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Entered env context: <rasterio.env.Env object at 0x0000017B4F4ED970>
[DEBUG: 2022-06-29 00:16:34 : rasterio._io] Path: ParsedPath(path='C:/Users/45107/Downloads/Sat/GK2A/gk2a_Rdaynight_20220622_0230.tif', archive=None, scheme=None), mode: w, driver: GTiff
[DEBUG: 2022-06-29 00:16:34 : rasterio._io] Option: ('COMPRESS', b'None')
[DEBUG: 2022-06-29 00:16:34 : rasterio._io] Option: ('ZLEVEL', b'6')
[DEBUG: 2022-06-29 00:16:34 : rasterio._io] Option: ('TILED', b'TRUE')
[DEBUG: 2022-06-29 00:16:34 : rasterio._io] Skipped delete for overwrite. Dataset does not exist: 'C:/Users/45107/Downloads/Sat/GK2A/gk2a_Rdaynight_20220622_0230.tif'
[DEBUG: 2022-06-29 00:16:34 : rasterio._base] Nodata success: 0, Nodata value: 0.000000
[DEBUG: 2022-06-29 00:16:34 : rasterio._base] Nodata success: 0, Nodata value: 0.000000
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Exiting env context: <rasterio.env.Env object at 0x0000017B4F4ED970>
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Cleared existing <rasterio._env.GDALEnv object at 0x0000017B4F4ED9A0> options
[DEBUG: 2022-06-29 00:16:34 : rasterio._env] Stopped GDALEnv <rasterio._env.GDALEnv object at 0x0000017B4F4ED9A0>.
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Exiting outermost env
[DEBUG: 2022-06-29 00:16:34 : rasterio.env] Exited env context: <rasterio.env.Env object at 0x0000017B4F4ED970>
[DEBUG: 2022-06-29 00:18:33 : trollimage.xrimage] Interval: left=<xarray.DataArray (bands: 2)>
array([0., 0.])
Coordinates:
    quantile  float64 0.005
Dimensions without coordinates: bands, right=<xarray.DataArray (bands: 2)>
array([0.9795989, 1.       ])
Coordinates:
    quantile  float64 0.995
Dimensions without coordinates: bands
djhoese commented 2 years ago

You can see this in the log output of both:

[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Applying stretch linear with parameters {}
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Perform a linear contrast stretch.
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Calculate the histogram quantiles: 

This is what is messing up your composites. The DayNightCompositor will pre-enhance the true_color and that is being enhanced fine:

[DEBUG: 2022-06-29 00:16:34 : satpy.writers] Enhancement configuration options: [{'name': 'reflectance_range', 'method': <function stretch at 0x0000017B4F426A60>, 'kwargs': {'stretch': 'crude', 'min_stretch': 0.0, 'max_stretch': 100.0}}, {'name': 'linear interpolation', 'method': <function piecewise_linear_stretch at 0x0000017B4F4D63A0>, 'kwargs': {'xp': [0.0, 25.0, 55.0, 100.0, 255.0], 'fp': [0.0, 90.0, 140.0, 175.0, 255.0], 'reference_scale_factor': 255}}]
[DEBUG: 2022-06-29 00:16:34 : trollimage.xrimage] Applying stretch crude with parameters {'min_stretch': 0.0, 'max_stretch': 100.0}
[DEBUG: 2022-06-29 00:16:34 : satpy.enhancements] Applying the piecewise_linear_stretch

However, the final result of that compositor will then also be enhanced when it is saved to disk with the writer (save_dataset). You should specify an additional enhancement configuration section for Rdaynight where you set operations: [] which will stop any enhancement from being performed. The default enhancement that is currently being used is using the min/max of the data being processed. For a cropped versus full scene these will include different numbers of pixels.

yukaribbba commented 2 years ago

Got it. Thanks! I'm closing now.