satpy.readers.utils module

Helper functions for satpy readers.

satpy.readers.utils._get_geostationary_height(geos_area)[source]
satpy.readers.utils._get_geostationary_reference_longitude(geos_area)[source]
satpy.readers.utils._get_geostationary_semi_axes(geos_area)[source]
satpy.readers.utils._lonlat_from_geos_angle(x, y, geos_area)[source]

Get lons and lats from x, y in projection coordinates.

satpy.readers.utils._unzip_FSFile(filename: FSFile, prefix=None)[source]

Open and Unzip remote FSFile ending with ‘bz2’.

Parameters:
  • filename – The FSFile to unzip.

  • prefix (str, optional) – If file is one of many segments of data, prefix random filename

  • number. (for correct sorting. This is normally the segment)

Returns:

Temporary filename path for decompressed file or None.

satpy.readers.utils._unzip_local_file(filename: str, prefix=None)[source]

Unzip the file ending with ‘bz2’. Initially with pbzip2 if installed or bz2.

Parameters:
  • filename – The file to unzip.

  • prefix (str, optional) – If file is one of many segments of data, prefix random filename

  • number. (for correct sorting. This is normally the segment)

Returns:

Temporary filename path for decompressed file or None.

satpy.readers.utils._unzip_with_bz2(filename, tmpfilepath)[source]
satpy.readers.utils._unzip_with_pbzip(filename, tmpfilepath, fdn)[source]
satpy.readers.utils._write_uncompressed_file(content, fdn, filename, tmpfilepath)[source]
satpy.readers.utils.apply_earthsun_distance_correction(reflectance, utc_date=None)[source]

Correct reflectance data to account for changing Earth-Sun distance.

satpy.readers.utils.apply_rad_correction(data, slope, offset)[source]

Apply GSICS-like correction factors to radiance data.

satpy.readers.utils.bbox(img)[source]

Find the bounding box around nonzero elements in the given array.

Copied from https://stackoverflow.com/a/31402351/5703449 .

Returns:

rowmin, rowmax, colmin, colmax

satpy.readers.utils.generic_open(filename, *args, **kwargs)[source]

Context manager for opening either a regular file or a bzip2 file.

Returns a file-like object.

satpy.readers.utils.get_array_date(scn_data, utc_date=None)[source]

Get start time from a channel data array.

satpy.readers.utils.get_earth_radius(lon, lat, a, b)[source]

Compute radius of the earth ellipsoid at the given longitude and latitude.

Parameters:
  • lon – Geodetic longitude (degrees)

  • lat – Geodetic latitude (degrees)

  • a – Semi-major axis of the ellipsoid (meters)

  • b – Semi-minor axis of the ellipsoid (meters)

Returns:

Earth Radius (meters)

satpy.readers.utils.get_geostationary_angle_extent(geos_area)[source]

Get the max earth (vs space) viewing angles in x and y.

satpy.readers.utils.get_geostationary_bounding_box(geos_area, nb_points=50)[source]

Get the bbox in lon/lats of the valid pixels inside geos_area.

Parameters:
  • geos_area – The geostationary area to analyse.

  • nb_points – Number of points on the polygon

satpy.readers.utils.get_geostationary_mask(area, chunks=None)[source]

Compute a mask of the earth’s shape as seen by a geostationary satellite.

Parameters:
Returns:

Boolean mask, True inside the earth’s shape, False outside.

satpy.readers.utils.get_sub_area(area, xslice, yslice)[source]

Apply slices to the area_extent and size of the area.

satpy.readers.utils.get_user_calibration_factors(band_name, correction_dict)[source]

Retrieve radiance correction factors from user-supplied dict.

satpy.readers.utils.np2str(value)[source]

Convert an numpy.string_ to str.

Parameters:

value (ndarray) – scalar or 1-element numpy array to convert

Raises:

ValueError – if value is array larger than 1-element, or it is not of type numpy.string_ or it is not a numpy array

satpy.readers.utils.reduce_mda(mda, max_size=100)[source]

Recursively remove arrays with more than max_size elements from the given metadata dictionary.

satpy.readers.utils.remove_earthsun_distance_correction(reflectance, utc_date=None)[source]

Remove the sun-earth distance correction.

satpy.readers.utils.unzip_context(filename)[source]

Context manager for decompressing a .bz2 file on the fly.

Uses unzip_file. Removes the uncompressed file on exit of the context manager.

Returns: the filename of the uncompressed file or of the original file if it was not compressed.

satpy.readers.utils.unzip_file(filename: str | FSFile, prefix=None)[source]

Unzip the local/remote file ending with ‘bz2’.

Parameters:
  • filename – The local/remote file to unzip.

  • prefix (str, optional) – If file is one of many segments of data, prefix random filename

  • number. (for correct sorting. This is normally the segment)

Returns:

Temporary filename path for decompressed file or None.