[PYTHON] I made a plug-in from the Japan Meteorological Agency GPV to easily create an animated contour diagram with QGIS.

Introduction

I told you that I made such a plug-in ezgif.com-gif-maker (1).gif

Plugin file from github Animations are only available from QGIS version 3.14, so please use 3.14 or above when using plugins

What is GPV

Grid Point Value. It stores the data of the physical quantity of the atmosphere for each grid point several hours ahead, which was obtained by running a forecast program called a numerical weather prediction model using the results of meteorological observation. The weather forecast is made based on this GPV.

GPV type

There are several types of GPV forecast models depending on the type of weather forecast to be forecast, and the main ones are as follows.

Model type Forecast area Lattice spacing Main forecast
Full holiday model(GSM) The whole earth About 20km(0.2 degrees x 0.25 degrees) Prefectural weather forecast,
Weekly weather forecast, etc.
Meso model(MSM) Around Japan About 5km(0.1 degree x 0.125 degrees) Precipitation short-term forecast,
Disaster prevention weather information, etc.
Local model (LFM) Around Japan About 2km (0.02 degrees x 0.025 degrees) Precipitation short-term forecast,
Disaster prevention weather information, etc.

These GPVs are provided by the Japan Meteorological Agency, and if you want to use them for business, you need to purchase them through the Meteorological Business Support Center, but this time, plug them using sample data (the ground surface of the MSM model). I verified the inn. List of GPV sample data from Japan Meteorological Agency

Data naming convention

In the case of MSM, it is "Z__C_RJTD_yyyyMMddhhmmss_MSM_GPV_Rjp _Lsurf_FHhh-hh_grib2.bin", MSM is the mesomodel, Lsurf is the ground surface, and FH is the forecast period. What is L-pall instead of Lsurf indicates that it is pressure level data. For Lsurf, the predicted value is stored every hour, and for L-pall, the predicted value every 3 hours (up to 15 hours ahead) is also stored.

Open GPV in QGIS

GPV data is provided in Grib2 format, and I use wgrib2 etc. to retrieve the data while hitting a command. Do you know that you can open it with QGIS without any complicated things? Yes, just drag and drop what to hide.

ezgif.com-gif-maker.gif

This GPV data. If you add it in QGIS, it will be treated as multi-band raster data, and in the first state you add it, the rendering will be set to multi-band. Values ​​such as barometric pressure, wind, and temperature for each altitude are stored in each band. You can see what element values ​​are stored in the GPV sample data list page above. This time, I am using GPV on the ground surface of MSM, so elements such as sea level correction pressure, wind vector, and temperature are packed, but I can not understand anything by looking at the band. image.png

Therefore, if you look at the "information" of the property, you can see the information of each band. For example, in band 1, it can be seen that Pressure reduced to MSL (sea level correction pressure). Also, as you can see that there is FORECAST_SECONDS in the information, the predicted value is also stored in another band. In the case of sea level correction pressure, band 1 (initial value), 11 (1 hour ahead), 23 (2 hours ahead), 35 (3 hours ahead), 47 (4 hours ahead), and so on, up to 14 hours ahead. It is designed to include forecast values. image.png

So, I made contour lines for each of the initial and predicted values ​​for a specific element in QGIS, and then made a plug-in that makes it easy to create animations using the Temporal Controller installed in QGIS ver.3.14.

About plugins

How to use

--Download the plugin from github and install it by specifying the zip from "Manage and install plugins" in QGIS. image.png

--The icon will be added when you install it. It ’s a contour-like icon.

--Click the icon to launch the plugin. image.png

--Select the target GPV data and the element to create the contour. At present, you can specify the sea level correction pressure and ground pressure for the ground surface, and each pressure level altitude for the pressure level. image.png

--When executed, contours are created. Since all the contours for each predicted time are output, it may be difficult to mess up something. image.png

--Start the Temporal controller installed from QGIS ver.3.14 and set the animation. If you set Step to 30 minutes for Lsurf and 1.5 hours for L-pall, you will get a nice animation. image.png

--Press the play button to play the animation. ezgif.com-gif-maker.gif

Output contour layer name

The layer name of the output contour is as follows. image.png

What you are doing with PyQGIS

Batch creation of contours

You can create contours by selecting "Raster"-> "Extract"-> "Contours" on the QGIS toolbar, but if you write in pyQGIS it will look like this.

processing.run("gdal:contour", {'INPUT':Input raster layer, 'BAND':Band to contour, 'INTERVAL': interval, 'FIELD_NAME': 'Contour','CREATE_3D': False, 'IGNORE_NODATA': False, 'NODATA': None, 'OFFSET': 0, 'EXTRA': '', 'OUTPUT': 'TEMPORARY_OUTPUT'})

Processing is executed by looping the band specified by BAND with the band of the initial value and the predicted value of the element to be contoured. For example, in the case of the mesomodel ground surface Sea level correction pressure band 1,11,23,35,47,59,71,83,95,107,119,131,143,155,167,179 Ground pressure band 1,11,23,35,47,59,71,83,95,107,119,131,143,155,167,179 In the case of barometric pressure I am trying to specify the band 1,93,185,277,369,461 at an altitude of 1000hPa.

Animation settings

The output contour is set to Temporal Controller.

vlayer =Specify layer
mode = QgsVectorLayerTemporalProperties.ModeFixedTemporalRange
tprops = vlayer.temporalProperties()
tprops.setMode(mode)
tprops.setFixedTemporalRange(QgsDateTimeRange(
    QDateTime(QDate(YYYY, MM, DD), QTime(start hh, 0, 0, 0), Qt.UTC), 
    QDateTime(QDate(YYYY, MM, DD), QTime(end hh, 0, 0, 0), Qt.UTC)))
tprops.setIsActive(True)

In addition to ModeFixedTemporalRange (Fixed Time Range in Configuration), mode can be specified such as ModeFeatureDateTimeInstantFromField (Single Field with Date/Time) and ModeFeatureDateTimeStartAndEndFromFields (Separate Fields for Start and End Date/Time).

label

Labels are set every 20hPa for the isobars and every 60m for the contour lines of the barometric pressure surface.


# set labeling
pal_layer = QgsPalLayerSettings()
pal_layer.isExpression = True
pal_layer.fieldName = labelSetting[0]
pal_layer.enabled = True
pal_layer.placement = QgsPalLayerSettings.Line
# Create and append a new rule
root = QgsRuleBasedLabeling.Rule(QgsPalLayerSettings())
rule = QgsRuleBasedLabeling.Rule(pal_layer)
rule.setDescription('Label description')
rule.setFilterExpression(Specify label field)
root.appendChild(rule)
# Apply label configuration
vlayer.setLabelsEnabled(True)
rules = QgsRuleBasedLabeling(root)
vlayer.setLabeling(rules)
vlayer.triggerRepaint()

Symbol setting

The contour lines are set to light gray. Currently, all contour lines have the same thickness, but in the future we would like to make the contour lines thicker every 20hPa.

# set symbol
single_symbol_renderer = vlayer.renderer()
symbol = single_symbol_renderer.symbol()
# Set stroke colour
symbol.setColor(QColor.fromRgb(100, 100, 100))
# Refresh
vlayer.triggerRepaint()
iface.layerTreeView().refreshLayerSymbology(vlayer.id())

For the future

If you want to use GPV properly for business, you have to purchase it from the Meteorological Business Support Center, but for research purposes, you can use it from the following.

In addition to atmospheric pressure, GPV contains wind vectors, temperature, cloud cover, and various values, so I would like to implement visualization of these values ​​as well.

Recommended Posts

I made a plug-in from the Japan Meteorological Agency GPV to easily create an animated contour diagram with QGIS.
I made a plug-in "EZPrinter" that easily outputs map PDF with QGIS.
I made a package to create an executable file from Hy source code
How to create a submenu with the [Blender] plugin
I made a tool to create a word cloud from wikipedia
I made a library to easily read config files with Python
I made a POST script to create an issue on Github and register it in the Project
I made a plugin to generate Markdown table from csv in Vim
[Django] I made a field to enter the date with 4 digit numbers
I tried to create a plug-in with HULFT IoT Edge Streaming [Development] (2/3)
I tried to create a plug-in with HULFT IoT Edge Streaming [Execution] (3/3)
I tried to create a plug-in with HULFT IoT Edge Streaming [Setup] (1/3)
I want to create an API that returns a model with a recursive relationship in the Django REST Framework
I tried to easily create a high-precision 3D image with one photo [-1]. (Is the hidden area really visible?)
I made an appdo command to execute a command in the context of the app
I tried to easily create a fully automatic attendance system with Selenium + Python
I tried to extract a line art from an image with Deep Learning
I made a tool to generate Markdown from the exported Scrapbox JSON file
I tried to create a model with the sample of Amazon SageMaker Autopilot
I want to easily create a Noise Model
I want to create a plug-in type implementation
I tried to easily create a high-precision 3D image with one photo [0]. (Confirmed how to capture the space, put a net)
Try to create a battle record table with matplotlib from the data of "Schedule-kun"
[Python] I made a system to introduce "recipes I really want" from the recipe site!
How to use NUITKA-Utilities hinted-compilation to easily create an executable file from a Python script
How to test the current time with Go (I made a very thin library)
I wrote Python code to create a table (view) dependency diagram (PlantUML) from SQL
How to create an article from the command line
I tried to create a table only with Django
I want to manually create a legend with matplotlib
I made a command to markdown the table clipboard
I came up with a way to create a 3D model from a photo Part 04 Polygon generation
I made a class to get the analysis result by MeCab in ndarray with python
I made a server with Python socket and ssl and tried to access it from a browser
Create a 2D array by adding a row to the end of an empty array with numpy
A story that I had a hard time trying to create an "app that converts images like paintings" with the first web application
I tried to automatically create a report with Markov chain
I made a package to filter time series with python
Probably the easiest way to create a pdf with Python3
Read the GRIB2 file of the Japan Meteorological Agency with pygrib
I made a function to check the model of DCGAN
I want to install a package from requirements.txt with poetry
I made an animation to return Othello stones with POV-Ray
Create a correlation diagram from the conversation history of twitter
I made a plug-in that can "Daruma-san fell" with Minecraft
I want to create a Dockerfile for the time being.
I tried to create an article in Wiki.js with SQLAlchemy
I have created a plugin to download Geospatial Information Authority of Japan vector tiles in QGIS
I made a Line bot that guesses the gender and age of a person from an image
I want to extract an arbitrary URL from the character string of the html source with python
I made something with python that NOW LOADING moves from left to right on the terminal
I want to create a graph with wavy lines omitted in the middle with matplotlib (I want to manipulate the impression)