satpy.writers.ninjogeotiff module

Writer for GeoTIFF images with tags for the NinJo visualization tool.

Starting with NinJo 7, NinJo is able to read standard GeoTIFF images, with required metadata encoded as a set of XML tags in the GDALMetadata TIFF tag. Each of the XML tags must be prepended with 'NINJO_'. For NinJo delivery, these GeoTIFF files supersede the old NinJoTIFF format. The NinJoGeoTIFFWriter therefore supersedes the old Satpy NinJoTIFF writer and the pyninjotiff package.

The reference documentation for valid NinJo tags and their meaning is contained in NinJoPedia. Since this page is not in the public web, there is a (possibly outdated) mirror.

There are some user-facing differences between the old NinJoTIFF writer and the new NinJoGeoTIFF writer. Most notably, keyword arguments that correspond to tags directly passed by the user are now identical, including case, to how they will be written to the GDALMetaData and interpreted by NinJo. That means some keyword arguments have changed, such as summarised in this table:

Migrating to NinJoGeoTIFF, keyword arguments for the writer

ninjotiff (old)

ninjogeotiff (new)

Notes

chan_id

ChannelID

mandatory

data_cat

DataType

mandatory

physic_unit

PhysicUnit

mandatory

physic_val

PhysicValue

mandatory

sat_id

SatelliteNameID

mandatory

data_source

DataSource

optional

Moreover, two keyword arguments are no longer supported because their functionality has become redundant. This applies to ch_min_measurement_unit and ch_max_measurement_unit. Instead, pass those values in source units to the stretch() enhancement with the min_stretch and max_stretch arguments.

For images where the pixel value corresponds directly to a physical value, NinJo has a functionality to read the corresponding quantity (example: brightness temperature or reflectance). To make this possible, the writer adds the tags Gradient and AxisIntercept. Those tags are added if and only if the image has mode L or LA and PhysicUnit is not set to "N/A". In other words, to suppress those tags for images with mode L or LA (for example, for the composite vis_with_ir, where the physical interpretation of individual pixels is lost), one should set PhysicUnit to "N/A", "n/a", "1", or "" (empty string).

class satpy.writers.ninjogeotiff.NinJoGeoTIFFWriter(dtype=None, tags=None, **kwargs)[source]

Bases: GeoTIFFWriter

Writer for GeoTIFFs with NinJo tags.

This writer is experimental. API may be subject to change.

For information, see module docstring and documentation for save_image().

Init the writer.

_check_include_scale_offset(image, unit)[source]

Check if scale-offset tags should be included.

_fix_units(image, quantity, unit)[source]

Adapt units between °C and K.

This will return a new XRImage, to make sure the old data and enhancement history aren’t touched.

save_image(image, filename=None, fill_value=None, compute=True, keep_palette=False, cmap=None, overviews=None, overviews_minsize=256, overviews_resampling=None, tags=None, config_files=None, *, ChannelID, DataType, PhysicUnit, PhysicValue, SatelliteNameID, **kwargs)[source]

Save image along with NinJo tags.

Save image along with NinJo tags. Interface as for GeoTIFF, except NinJo expects some additional tags. Those tags will be prepended with ninjo_ and added as GDALMetaData.

Writing such images requires trollimage 1.16 or newer.

Importing such images with NinJo requires NinJo 7 or newer.

Parameters:
  • image (XRImage) – Image to save.

  • filename (str) – Where to save the file.

  • fill_value (int) – Which pixel value is fill value?

  • compute (bool) – To compute or not to compute, that is the question.

  • keep_palette (bool) – As for parent GeoTIFF save_image().

  • cmap (trollimage.colormap.Colormap) – As for parent save_image().

  • overviews (list) – As for save_image().

  • overviews_minsize (int) – As for save_image().

  • overviews_resampling (str) – As for save_image().

  • tags (dict) – Extra (not NinJo) tags to add to GDAL MetaData

  • config_files (Any) – Not directly used by this writer, supported for compatibility with other writers.

Remaining keyword arguments are either passed as GDAL options, if contained in self.GDAL_OPTIONS, or they are passed to NinJoTagGenerator, which will include them as NinJo tags in GDALMetadata. Supported tags are defined in NinJoTagGenerator.optional_tags. The meaning of those (and other) tags are defined in the NinJo documentation (see module documentation for a link to NinJoPedia). The following tags are mandatory and must be provided as keyword arguments:

ChannelID (int)

NinJo Channel ID

DataType (int)

NinJo Data Type

SatelliteNameID (int)

NinJo Satellite ID

PhysicUnit (str)

NinJo label for unit (example: “C”). If PhysicValue is set to “Temperature”, PhysicUnit is set to “C”, but data attributes incidate the data have unit “K”, then the writer will adapt the header ninjo_AxisIntercept such that data are interpreted in units of “C”. If PhysicUnit is set to “N/A”, no AxisIntercept and Gradient tags will be written.

PhysicValue (str)

NinJo label for quantity (example: “temperature”)

scale_offset_tag_names = ('ninjo_Gradient', 'ninjo_AxisIntercept')
class satpy.writers.ninjogeotiff.NinJoTagGenerator(image, fill_value, filename, **kwargs)[source]

Bases: object

Class to collect NinJo tags.

This class is used by NinJoGeoTIFFWriter to collect NinJo tags. Most end-users will not need to create instances of this class directly.

Tags are gathered from three sources:

  • Fixed tags, contained in the attribute fixed_tags. The value of those tags is hardcoded and never changes.

  • Tags passed by the user, contained in the attribute passed_tags. Those tags must be passed by the user as arguments to the writer, which will pass them on when instantiating this class.

  • Tags calculated from data and metadata. Those tags are defined in the attribute dynamic_tags. They are either calculated from image data, from image metadata, or from arguments passed by the user to the writer.

Some tags are mandatory (defined in mandatory_tags). All tags that are not mandatory are optional. By default, optional tags are generated if and only if the required information is available.

Initialise tag generator.

Parameters:
  • image (trollimage.xrimage.XRImage) – XRImage for which NinJo tags should be calculated.

  • fill_value (int) – Fill value corresponding to image.

  • filename (str) – Filename to be written.

  • **kwargs – Any additional tags to be included as-is.

_epoch = datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
dynamic_tags = {'CentralMeridian': 'central_meridian', 'ColorDepth': 'color_depth', 'CreationDateID': 'creation_date_id', 'DateID': 'date_id', 'EarthRadiusLarge': 'earth_radius_large', 'EarthRadiusSmall': 'earth_radius_small', 'FileName': 'filename', 'MaxGrayValue': 'max_gray_value', 'MinGrayValue': 'min_gray_value', 'Projection': 'projection', 'ReferenceLatitude1': 'ref_lat_1', 'TransparentPixel': 'transparent_pixel', 'XMaximum': 'xmaximum', 'YMaximum': 'ymaximum'}
fixed_tags = {'HeaderVersion': 2, 'Magic': 'NINJO', 'XMinimum': 1, 'YMinimum': 1}
get_all_tags()[source]

Get a dictionary with all tags for NinJo.

get_central_meridian()[source]

Calculate central meridian.

get_color_depth()[source]

Return the color depth.

get_creation_date_id()[source]

Calculate the creation date ID.

That’s seconds since UNIX Epoch for the time the image is created.

get_date_id()[source]

Calculate the date ID.

That’s seconds since UNIX Epoch for the time corresponding to the satellite image start of measurement time.

get_earth_radius_large()[source]

Return the Earth semi-major axis in metre.

get_earth_radius_small()[source]

Return the Earth semi-minor axis in metre.

get_filename()[source]

Return the filename.

get_max_gray_value()[source]

Calculate maximum gray value.

get_meridian_east()[source]

Get the easternmost longitude of the area.

Currently not implemented. In pyninjotiff it was implemented but the answer was incorrect.

get_meridian_west()[source]

Get the westernmost longitude of the area.

Currently not implemented. In pyninjotiff it was implemented but the answer was incorrect.

get_min_gray_value()[source]

Calculate minimum gray value.

get_projection()[source]

Get NinJo projection string.

From the documentation, valid values are:

  • NPOL/SPOL: polar-sterographic North/South

  • PLAT: „Plate Carrée“, equirectangular projection

  • MERC: Mercator projection

Derived from AreaDefinition.

get_ref_lat_1()[source]

Get reference latitude one.

Derived from area definition.

get_ref_lat_2()[source]

Get reference latitude two.

This is not implemented and never was correctly implemented in pyninjotiff either. It doesn’t appear to be used by NinJo.

get_tag(tag)[source]

Get value for NinJo tag.

get_transparent_pixel()[source]

Get the transparent pixel value, also known as the fill value.

When the no fill value is defined (value None), such as for RGBA or LA images, returns -1, in accordance with the file format specification.

get_xmaximum()[source]

Get the maximum value of x, i.e. the meridional extent of the image in pixels.

get_ymaximum()[source]

Get the maximum value of y, i.e. the zonal extent of the image in pixels.

mandatory_tags = {'AxisIntercept', 'ChannelID', 'ColorDepth', 'CreationDateID', 'DataType', 'DateID', 'Gradient', 'HeaderVersion', 'MaxGrayValue', 'MinGrayValue', 'PhysicUnit', 'PhysicValue', 'Projection', 'SatelliteNameID', 'SatelliteNumber', 'TransparentPixel', 'XMaximum', 'XMinimum', 'YMaximum', 'YMinimum'}
optional_tags = {'AOSAzimuth', 'Altitude', 'CentralMeridian', 'ColorTable', 'DataSource', 'Description', 'EarthRadiusLarge', 'EarthRadiusSmall', 'GeoLatitude', 'GeoLongitude', 'GeodeticDate', 'IsAtmosphereCorrected', 'IsBlackLinesCorrection', 'IsCalibrated', 'IsNormalized', 'IsValueTableAvailable', 'LOSAzimuth', 'MaxElevation', 'MeridianEast', 'MeridianWest', 'OriginalHeader', 'OverFlightTime', 'OverflightDirection', 'ReferenceLatitude1', 'ReferenceLatitude2', 'ValueTableFloatField'}
passed_tags = {'ChannelID', 'DataType', 'PhysicUnit', 'PhysicValue', 'SatelliteNameID'}
postponed_tags = {'AxisIntercept', 'Gradient'}