Skip to content

Commit

Permalink
Merge branch 'main' into add-testing-reader-utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud authored Jul 19, 2024
2 parents caceae3 + 3b6608e commit 63e0581
Show file tree
Hide file tree
Showing 40 changed files with 1,546 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
shell: bash -l {0}
run: |
export LD_PRELOAD=${{ env.LD_PRELOAD }};
pytest --cov=satpy satpy/tests --cov-report=xml --cov-report=
pytest -n auto --cov=satpy satpy/tests --cov-report=xml --cov-report=
- name: Upload unittest coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-sdist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Publish package to PyPI
if: github.event.action == 'published'
uses: pypa/gh-action-pypi-publish@v1.8.14
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
user: __token__
password: ${{ secrets.pypi_password }}
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fail_fast: false
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.4.7'
rev: 'v0.5.0'
hooks:
- id: ruff
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -14,12 +14,12 @@ repos:
- id: check-yaml
args: [--unsafe]
- repo: https://github.com/PyCQA/bandit
rev: '1.7.8' # Update me!
rev: '1.7.9' # Update me!
hooks:
- id: bandit
args: [--ini, .bandit]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0' # Use the sha / tag you want to point at
rev: 'v1.10.1' # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies:
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ The following people have made contributions to this project:
- [Sara Hörnquist (shornqui)](https://github.com/shornqui)
- [Antonio Valentino](https://github.com/avalentino)
- [Pouria Khalaj](https://github.com/pkhalaj)
- [Clément (ludwigvonkoopa)](https://github.com/ludwigVonKoopa)
3 changes: 2 additions & 1 deletion continuous_integration/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ dependencies:
- pint-xarray
- ephem
- bokeh
- pytest-xdist
- pip:
- pytest-lazy-fixtures
- trollsift
- trollimage>=1.23
- trollimage>=1.24
- pyspectral
- pyorbital
9 changes: 9 additions & 0 deletions doc/source/enhancements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ the example here::
- {colors: spectral, min_value: 193.15, max_value: 253.149999}
- {colors: greys, min_value: 253.15, max_value: 303.15}

In addition, it is also possible to add a linear alpha channel to the colormap, as in the
following example::

- name: colorize
method: !!python/name:satpy.enhancements.colorize
kwargs:
palettes:
- {colors: ylorrd, min_alpha: 100, max_alpha: 255}

It is also possible to provide your own custom defined color mapping by
specifying a list of RGB values and the corresponding min and max values
between which to apply the colors. This is for instance a common use case for
Expand Down
4 changes: 2 additions & 2 deletions doc/source/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ around your code:

.. code-block:: python
with dask.config.set("array.chunk-size": "32MiB"):
with dask.config.set({"array.chunk-size": "32MiB"}):
# your code here
Or by using:

.. code-block:: python
dask.config.set("array.chunk-size": "32MiB")
dask.config.set({"array.chunk-size": "32MiB"})
at the top of your code.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"pyproj>=2.2",
"pyresample>=1.24.0",
"pyyaml>=5.1",
"trollimage>=1.23",
"trollimage>=1.24",
"trollsift",
"xarray>=0.14.1",
"zarr",
Expand Down
8 changes: 4 additions & 4 deletions satpy/composites/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ def _get_coszen_blending_weights(
self,
projectables: Sequence[xr.DataArray],
) -> xr.DataArray:
lim_low = np.cos(np.deg2rad(self.lim_low))
lim_high = np.cos(np.deg2rad(self.lim_high))
lim_low = float(np.cos(np.deg2rad(self.lim_low)))
lim_high = float(np.cos(np.deg2rad(self.lim_high)))
try:
coszen = np.cos(np.deg2rad(projectables[2 if self.day_night == "day_night" else 1]))
self._has_sza = True
Expand All @@ -775,8 +775,8 @@ def _get_coszen_blending_weights(
# Get chunking that matches the data
coszen = get_cos_sza(projectables[0])
# Calculate blending weights
coszen -= np.min((lim_high, lim_low))
coszen /= np.abs(lim_low - lim_high)
coszen -= min(lim_high, lim_low)
coszen /= abs(lim_low - lim_high)
return coszen.clip(0, 1)

def _get_data_for_single_side_product(
Expand Down
8 changes: 4 additions & 4 deletions satpy/composites/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ def __init__(self, name, min_highlight=0.0, max_highlight=10.0, # noqa: D417
Args:
min_highlight (float): Minimum raw value of the "highlight" data
that will be used for linearly scaling the data along with
``max_hightlight``.
``max_highlight``.
max_highlight (float): Maximum raw value of the "highlight" data
that will be used for linearly scaling the data along with
``min_hightlight``.
``min_highlight``.
max_factor (tuple): Maximum effect that the highlight data can
have on each channel of the primary image data. This will be
multiplied by the linearly scaled highlight data and then
added or subtracted from the highlight channels. See class
docstring for more information. By default this is set to
``(0.8, 0.8, -0.8, 0)`` meaning the Red and Green channel
will be added to by at most 0.8, the Blue channel will be
subtracted from by at most 0.8, and the Alpha channel will
not be effected.
subtracted from by at most 0.8 (resulting in yellow highlights),
and the Alpha channel will not be affected.
"""
self.min_highlight = min_highlight
Expand Down
40 changes: 29 additions & 11 deletions satpy/enhancements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def create_colormap(palette, img=None): # noqa: D417
Colormaps can be loaded from lists of colors provided by the ``colors``
key in the provided dictionary. Each element in the list represents a
single color to be mapped to and can be 3 (RGB) or 4 (RGBA) elements long.
By default the value or control point for a color is determined by the
By default, the value or control point for a color is determined by the
index in the list (0, 1, 2, ...) divided by the total number of colors
to produce a number between 0 and 1. This can be overridden by providing a
``values`` key in the provided dictionary. See the "Set Range" section
Expand Down Expand Up @@ -455,12 +455,37 @@ def create_colormap(palette, img=None): # noqa: D417
``max_value``. See :meth:`trollimage.colormap.Colormap.set_range` for more
information.
**Set Alpha Range**
The alpha channel of a created colormap can be added and/or modified by
specifying ``min_alpha`` and ``max_alpha``.
See :meth:`trollimage.colormap.Colormap.set_alpha_range` for more info.
"""
# are colors between 0-255 or 0-1
color_scale = palette.get("color_scale", 255)
cmap = _get_cmap_from_palette_info(palette, img, color_scale)

if palette.get("reverse", False):
cmap.reverse()
if "min_value" in palette and "max_value" in palette:
cmap.set_range(palette["min_value"], palette["max_value"])
elif "min_value" in palette or "max_value" in palette:
raise ValueError("Both 'min_value' and 'max_value' must be specified (or neither).")

if "min_alpha" in palette and "max_alpha" in palette:
cmap.set_alpha_range(palette["min_alpha"] / color_scale,
palette["max_alpha"] / color_scale)
elif "min_alpha" in palette or "max_alpha" in palette:
raise ValueError("Both 'min_alpha' and 'max_alpha' must be specified (or neither).")

return cmap


def _get_cmap_from_palette_info(palette, img, color_scale):
fname = palette.get("filename", None)
colors = palette.get("colors", None)
dataset = palette.get("dataset", None)
# are colors between 0-255 or 0-1
color_scale = palette.get("color_scale", 255)
if fname:
if not os.path.exists(fname):
fname = get_config_path(fname)
Expand All @@ -473,17 +498,10 @@ def create_colormap(palette, img=None): # noqa: D417
cmap = _create_colormap_from_dataset(img, dataset, color_scale)
else:
raise ValueError("Unknown colormap format: {}".format(palette))

if palette.get("reverse", False):
cmap.reverse()
if "min_value" in palette and "max_value" in palette:
cmap.set_range(palette["min_value"], palette["max_value"])
elif "min_value" in palette or "max_value" in palette:
raise ValueError("Both 'min_value' and 'max_value' must be specified (or neither)")

return cmap



def _create_colormap_from_dataset(img, dataset, color_scale):
"""Create a colormap from an auxiliary variable in a source file."""
match = find_in_ancillary(img.data, dataset)
Expand Down
160 changes: 160 additions & 0 deletions satpy/etc/composites/mersi-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
sensor_name: visir/mersi-3

modifiers:
rayleigh_corrected:
modifier: !!python/name:satpy.modifiers.PSPRayleighReflectance
atmosphere: us-standard
aerosol_type: rayleigh_only
prerequisites:
- name: '3'
modifiers: [sunz_corrected]
optional_prerequisites:
- name: satellite_azimuth_angle
- name: satellite_zenith_angle
- name: solar_azimuth_angle
- name: solar_zenith_angle
sunz_corrected:
modifier: !!python/name:satpy.modifiers.SunZenithCorrector
prerequisites:
- solar_zenith_angle

nir_reflectance:
modifier: !!python/name:satpy.modifiers.NIRReflectance
prerequisites:
- name: '24'
optional_prerequisites:
- solar_zenith_angle


composites:

ash:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- compositor: !!python/name:satpy.composites.DifferenceCompositor
prerequisites:
- name: '25'
- name: '24'
- compositor: !!python/name:satpy.composites.DifferenceCompositor
prerequisites:
- name: '24'
- name: '23'
- name: '24'
standard_name: ash

true_color_raw:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- '3'
- '2'
- '1'
standard_name: true_color

true_color:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '3' # 0.65
modifiers: [sunz_corrected, rayleigh_corrected]
- name: '2'
modifiers: [sunz_corrected, rayleigh_corrected]
- name: '1' # 0.47
modifiers: [sunz_corrected, rayleigh_corrected]
standard_name: true_color

natural_color:
compositor: !!python/name:satpy.composites.RatioSharpenedRGB
prerequisites:
- name: '6'
modifiers: [sunz_corrected]
- name: '15'
modifiers: [sunz_corrected]
- name: '3'
modifiers: [sunz_corrected]
optional_prerequisites:
- name: '4'
modifiers: [sunz_corrected]
standard_name: natural_color
high_resolution_band: green

natural_color_lowres:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '6'
modifiers: [sunz_corrected]
- name: '15'
modifiers: [sunz_corrected]
- name: '12'
modifiers: [sunz_corrected]
standard_name: natural_color

overview_raw:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '12'
- name: '15'
- name: '24'
standard_name: overview

overview:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '12'
modifiers: [sunz_corrected]
- name: '15'
modifiers: [sunz_corrected]
- name: '24'
standard_name: overview

cloudtop:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '20'
- name: '24'
- name: '25'
standard_name: cloudtop

day_microphysics:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '15'
modifiers: [sunz_corrected]
- name: '20'
modifiers: [nir_reflectance]
- name: '24'
standard_name: day_microphysics

night_fog:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- compositor: !!python/name:satpy.composites.DifferenceCompositor
prerequisites:
- name: '25'
- name: '24'
- compositor: !!python/name:satpy.composites.DifferenceCompositor
prerequisites:
- name: '24'
- name: '20'
- name: '24'
standard_name: night_fog

fog:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- compositor: !!python/name:satpy.composites.DifferenceCompositor
prerequisites:
- name: '25'
- name: '24'
- compositor: !!python/name:satpy.composites.DifferenceCompositor
prerequisites:
- name: '24'
- name: '23'
- name: '24'
standard_name: fog

green_snow:
compositor: !!python/name:satpy.composites.GenericCompositor
prerequisites:
- name: '6'
- name: '3'
- name: '24'
standard_name: green_snow
Loading

0 comments on commit 63e0581

Please sign in to comment.