Uploaded image for project: 'JASMIN CIS'
  1. JASMIN CIS
  2. JASCIS-334

Add metadata to created images

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Plotting
    • Labels:
      None

      Description

      This could be done with PIL.

      More details in email from Dr David Hooper:

      Dear All

      Following on from yesterday's NCAS observations meeting, here are a couple of examples of how metadata can be embedded in image files - see attached. I'm happy to make my (python) scripting software available for others to use.

      I'm relying on the Dublin Core metadata scheme, which defines just 15 generic fields, which can be applied to a wide range of electronic resources:

        http://dublincore.org/documents/dces/

      The metadata are embedded using the Extensible Metadata Platform (XMP), which can be applied to a wide range of file types including JPG, PNG, GIF, PostScript, and PDF. This works on similar principles to the Exif (Exchangeable image file format) data that digital cameras embed in images (e.g. recording shutter speed, aperture size, and focal length) at creation time.

      I'll start with a png format quick-look plot, nerc-mstrf-radar-mst_capel-dewi_20160427_st300_wind.png, since it contains only XMP data. Windows Photo Viewer (the default viewer on my Windows machine) is rather restrictive in how much metadata it makes visible (right click on the image and select "Properties"). It shows none of the Dublin Core fields for the attached png image and only a subset of them for the jpg image. Linux software is typically better in this regard e.g.:

      • for the "eog" viewer, right-click on the image and select "Properties". Only a subset of the Dublin Core fields are shown through the "Metadata" tab, but you can see then all by selecting the "Details" tab and expanding the "XMP IPTC" collection.
      • for the "gwenview" viewer, click on the "Information" tab (bottom-left) and then select "more" in the "Meta information" area (top-left).
      • type "exiftool <file-path>" at the command line. This is the utility that my software is based around and CEDA have installed it (by request) on the jasmin platform.

      I've included below the contents of the files that I use to define the metadata for both image files. Note that

      • although these are based on config file syntax, a standard config file reader will only show you the last instance of fields such as "Contributor" that can have multiple values. My software therefore contains a bespoke parser.
      • this is a "template" file, which contains python variable formatting commands within curly braces: https://docs.python.org/2/library/string.html#format-string-syntax . The necessary variables must be passed to my software so that specific values can be substituted.

      The jpg image is taken by the Noctilucent Cloud camera that I operate at the Chilbolton Observatory. This camera happens to be a DSLR and so contains a large amount of Exif data. However, you'll find the Dublin Core metadata fields buried in there amongst them. Some other points to note:

      • The original date-time Exif information is provided by the camera's free-running internal clock, which is obviously prone to drifting. Consequently I overwrite these fields with date-time information taken from the acquisition PC, which is running NTP.
      • I have included the instrument location information within the Dublin Core "Coverage" field. However, in the case of jpg images (I haven't tried this on png images, but suspect that it might work) I could have put it within the XMP IPTC Core "Location" field or the Exif GPS fields. However, since I don't have a GPS-enabled camera, I had no examples to work from in the latter case and decided to stick to Dublin Core. If you're interested in all of the XMP/Exif fields available, look up the man page for Image::ExifTool::TagNames .
      • The attached image is a scaled-down ("standard resolution") version of the original ("high resolution") image. This has been produced by a script that makes use of the Python Imaging Library (PIL) - http://effbot.org/imagingbook/pil-index.htm - which, I believe, has now been superseded by pillow - http://pillow.readthedocs.io/en/3.2.x/ . I also used PIL to overlay the text at the top of the image. I use my metadata tool to copy across all of the metadata from the original to the scaled image.

      Finally, on a bit of tangent, although I determined the locations of both the MST Radar and the NLC camera using GPS devices that rely on multiple overpasses, Google maps is also quite handy. The two methods agree to within about 5 m. In order to demonstrate this, try typing the following into Google:

        51.145168, -1.4397500

        52.424526, -4.0054698

      I've truncated the values to fit within a float32 numbers, which still permits an accuracy to within (an estimated) 5 m.

      David


      #################################################
      # Template of metadata for quick-look plots from the NERC MST Radar's ST-mode
      # Cartesian data
      #
      [nerc-mstrf_mst_st_plots]

      Title: NERC MST Radar Facility/MST Radar/ST mode/Cartesian data/{data_date:%Y-%m-%d}/{range_resolution_string} m range resolution/{plot_type} plot

      Subject: MST Radar

      Description: This plot is one of three (wind, turbulence, and diagnostics)
        derived from the daily NERC MST Radar (version
        {processing_version_number}.{processing_sub_version_number}) ST-mode
        Cartesian data file. The horizontal wind components have been averaged over
        a nominal period of {nominal_wind_smoothing_interval_minutes:.1f} minutes in
        order to improve their representativeness. These values have been used to
        derive the horizontal wind speed, magnitude of vertical shear of horizontal
        wind vector, and beam broadening corrected vertical beam spectral width. All
        other values represent unaveraged data. Vertical beam secondary signals are
        only shown to belong to a radial chain where the same condition exists for
        adjacent cycles. This improves the clarity of the plot.

      Type: Image

      Coverage:
        The data cover the date {data_date:%Y-%m-%d} in Coordinated Universal Time.

      Creator: Hooper, David A.

      Publisher: The Centre for Environmental Data Analysis (CEDA),
        http://www.ceda.ac.uk/

      Contributor: The Natural Environment Research Council (NERC)
        Mesosphere-Stratosphere-Troposphere (MST) Radar Facility at Aberystwyth,
        http://mst.nerc.ac.uk

      Contributor: The National Centre for Atmospheric Science (NCAS),
        https://www.ncas.ac.uk/

      Contributor: STFC RAL Space, Rutherford Appleton Laboratory,
        http://www.ralspace.stfc.ac.uk/

      Rights:
        Copyright {data_date:%Y} NERC MST Radar Facility. Use of this
        plot is covered by the (UK) Open Government Licence,
        http://www.nationalarchives.gov.uk/doc/open-government-licence/.

      Date: {data_date:%Y-%m-%d}

      Format: image/png

      Language: en-GB
      #
      ####################################################
      # Template of metadata for images from the NERC MSTRF's NLC Camera at Chilbolton
      #
      [nerc-mstrf_nlc-camera_chilbolton]

      Title: NERC MST Radar Facility/NLC Camera/Chilbolton Observatory/{image_capture_datetime:%Y-%m-%d/%H:%M:%S}/{image_resolution:s} resolution

      Subject: Natural Environment Research Council

      Subject: Noctilucent Cloud

      Description:
        Image from the Natural Environment Research Council (NERC)
        Mesosphere-Stratosphere-Troposphere (MST) Radar Facility's Noctilucent Cloud
        (NLC) Camera at the Chilbolton Observatory. The camera is operated between
        dusk and dawn during the mid-summer months (principally June and July) with
        the aim of observing NLCs for scientific study. The high-resolution images
        might only be kept for those cases when they have captured something
        interesting. The standard data product is a scaled-down version. Camera
        location and pointing details are contained within the Coverage metadata
        element.

      Type: Image

      Coverage:
        The camera is located within the Receive Cabin of the Chilbolton
        Observatory, Hampshire, UK (51.145168°N,-1.4397500°E). It is approximately
        4.3 m above the ground level, which is approximately 84 m above mean sea
        level. The field of view (taking the 1.6 crop factor of the camera into
        account) is 67.9° in the horizontal and 45.3° in the vertical. The pointing
        direction may occasionally change slightly and so must be estimated from the
        images. The skyline is at an elevation of +0.4°. The bearing at which stars
        reach their lowest elevation indicates true north. This has been used to
        estimate the bearing of where the mast in the foreground crosses the
        skyline: 17.6° east of north. Date-time information is derived from the
        image capture computer and given in UTC. Images are typically captured at 5
        minute intervals.

      Creator: Hooper, David A.

      Publisher: NCAS British Atmospheric Data Centre

      Contributor: The Natural Environment Research Council (NERC)
        Mesosphere-Stratosphere-Troposphere (MST) Radar Facility at Aberystwyth,
        http://mst.nerc.ac.uk

      Contributor: The Chilbolton Facility for Atmospheric and Radio Research
        (CFARR), http://www.stfc.ac.uk/chilbolton

      Rights:
        Copyright {image_capture_datetime:%Y} NERC MST Radar Facility. Use of this
        image is covered by the (UK) Open Government Licence,
        http://www.nationalarchives.gov.uk/doc/open-government-licence/

      Date: {image_capture_datetime:%Y-%m-%d}

      Format: image/jpeg

      Language: en-GB



      ModifyDate: {image_capture_datetime:%Y:%m:%d %H:%M:%S}

      SubSecTime: 0

      DateTimeOriginal: {image_capture_datetime:%Y:%m:%d %H:%M:%S}

      SubSecTimeOriginal: 0

      CreateDate: {image_capture_datetime:%Y:%m:%d %H:%M:%S}

      SubSecTimeDigitized: 0
      #
      ###############################################################

        Attachments

          Activity

            People

            Assignee:
            duncan.watson-parris@physics.ox.ac.uk Duncan Watson-Parris
            Reporter:
            duncan.watson-parris@physics.ox.ac.uk Duncan Watson-Parris
            Participants:
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated: