Weather data conversion method and system

文档序号:1490582 发布日期:2020-02-04 浏览:8次 中文

阅读说明:本技术 天气数据转换方法和系统 (Weather data conversion method and system ) 是由 刘海岚 于 2019-10-14 设计创作,主要内容包括:本发明涉及一种天气数据转换方法和系统,该方法包括以下步骤:S1,拉取GRIB天气数据:通过NOAA网站开放的GRIB数据下载路径自动下载GRIB数据并保存到本地;S2,GRIB数据解析:解析所下载的GRIB数据文件byte数据,得到分散的单量中间数据文件;S3,中间数据合并:读取需要合并数据的相应的文件头,读取文件数据体,生成字符串后保存到相应的中间文件,并将相应的中间文件按需求合并成一个文件;S4,生成JSON文件:根据web约定,生成JSON文件对应的KEY、VALUE,对应生成JSON信息,并保存到相应的JSON文件,web端根据约定协议读取相应的JSON文件,将GRIB天气数据文件转换为JSON数据文件,用于在web端显示。(The invention relates to a weather data conversion method and a system, wherein the method comprises the following steps: s1, pull GRIB weather data: automatically downloading GRIB data through a GRIB data downloading path opened by an NOAA website and storing the GRIB data to the local; s2, GRIB data analysis: analyzing the downloaded byte data of the GRIB data file to obtain a dispersed single-amount intermediate data file; s3, merging intermediate data: reading a corresponding file header of data to be combined, reading a file data body, generating character strings, storing the character strings in a corresponding intermediate file, and combining the corresponding intermediate files into a file according to requirements; s4, generating a JSON file: and generating KEY and VALUE corresponding to the JSON file according to the web agreement, correspondingly generating JSON information, storing the JSON information into the corresponding JSON file, reading the corresponding JSON file by the web end according to the agreement protocol, and converting the GRIB weather data file into the JSON data file for displaying on the web end.)

1. A weather data conversion method is characterized in that the weather data conversion method is used for converting GRIB weather data files into JSON data files for displaying on a web end, and comprises the following steps:

s1, pull GRIB weather data: automatically downloading GRIB data through a GRIB data downloading path opened by an NOAA website and storing the GRIB data to the local;

s2, GRIB data analysis: analyzing the downloaded byte data of the GRIB data file to obtain a dispersed single-amount intermediate data file;

s3, merging intermediate data: reading a corresponding file header of data to be combined, reading a file data body, generating character strings, storing the character strings in a corresponding intermediate file, and combining the corresponding intermediate files into a file according to requirements;

s4, generating a JSON file: and generating KEY and VALUE corresponding to the JSON file according to the web agreement, correspondingly generating JSON information, storing the JSON information into the corresponding JSON file, and reading the corresponding JSON file by the web terminal according to the agreement protocol.

2. The weather data conversion method of claim 1, wherein the pulling the GRIB weather data comprises the steps of:

adding a weather task: when the web end needs a corresponding weather JSON file, the web end adds a corresponding data generation task according to a time range;

and (3) decomposing a weather task: when the weather task is added, determining to download each detailed information of the weather task from an NOAA website according to the optional information of the weather task, decomposing the weather task, and generating a detailed download task;

performing a weather task: the web side selects the precision required to be downloaded according to the decomposed detailed task and the coding protocol document opened by the NOAA website, and automatically downloads the required GRIB file from the NOAA website according to the time range of the weather task;

obtaining a GRIB file: and storing the downloaded GRIB file to the local, and recording that the file of the required weather task is downloaded and completed.

3. A weather data conversion method as claimed in claim 2, wherein the parsing of the GRIB data further includes reading the downloaded file via the encoding protocol of the GRIB data, and obtaining a single data intermediate file of the required parameters and the specified type after parsing the byte data corresponding to the file according to the encoding specification and bit specification of the corresponding parameters by the file protocol of the GRIB data.

4. A weather data conversion method as claimed in claim 3, wherein the encoding protocol includes protocols for parameter type, location, start and data format of the GRIB data.

5. A weather data conversion method as claimed in claim 3, wherein the single volume data intermediate file includes a data header and a data body.

6. A weather data conversion method as claimed in claim 1, wherein the intermediate file contains a plurality of weather parameters, and the header and the body of the data to be merged are read to generate a new character string.

7. A weather data conversion method as claimed in claim 6, wherein in step S3, the file is converted from an invisible GRIB binary file into a string, and a JSON file is generated according to a web contract.

8. A weather data conversion system, comprising:

the GRIB data pulling module is used for connecting to the NOAA website, automatically downloading GRIB data files through an open GRIB data downloading path on the NOAA website, and storing the downloaded GRIB data to the local;

the GRIB data analysis module is connected with the GRIB data pulling module and is used for analyzing the downloaded GRIB data file and decomposing the GRIB data file into a single amount of dispersed intermediate data files;

the intermediate data merging module is connected with the GRIB data analysis module and is used for merging the intermediate files to be merged into one file according to the requirement;

and the JSON file generating module is connected with the intermediate data merging module and is connected with the web end network so as to generate KEY and VALUE corresponding to the JSON file according to the web agreement, correspondingly generate JSON information and store the JSON information into the corresponding JSON file.

9. A weather data conversion system as claimed in claim 8, wherein the GRIB data pull module comprises:

the task adding unit is used for being connected with the web end network so as to add corresponding data to generate a task when the web end needs a corresponding weather JSON file;

the task decomposing unit is connected with the task adding unit and is used for downloading the detailed details of the required weather task from the NOAA website and generating a detailed downloading task;

the task execution unit is connected with the task decomposition unit and is used for downloading the needed GRIB file according to the detailed downloading task and the coding protocol opened by the NOAA website;

and the GRIB file generating unit is connected with the task executing unit and is used for storing the downloaded GRIB file to the local and recording the completion of the downloading of the task.

10. A weather data conversion system as claimed in claim 9, wherein the GRIB file generation unit is connected to the GRIB data parsing module to facilitate the GRIB data parsing module to read and parse the locally stored GRIB file.

Technical Field

The invention relates to the technical field of data conversion, in particular to a weather data conversion method and system.

Background

The JSON format is a subset of the 1999 JavaScript Programming Language, Standard ECMA-2623rd Edition, so it can be read in JavaScript as an eval () function. This does not, however, mean that JSON cannot be used in other languages, and in fact, almost all languages relevant to web page development have a JSON function library.

GRIB is a concise data format commonly used in meteorology for storing historical and forecasted weather data. It is standardized by the basic system committee of the world weather organization. At present, the GRIB has three versions, the version 0 is used by items such as TOGA and the like to a certain extent and is not used for operation any more; the first edition (Current sub-version is 2) is used by most weather centers worldwide for numerical weather forecast output (NWP); a new generation, called the second edition of GRIB, was introduced later, and data is slowly being converted to this format. However, GRIB is a practical storage standard for weather data, and the analysis is complex.

Disclosure of Invention

In view of this, it is necessary to provide a method and a system for converting weather data by parsing a complex GRIB file into a general JSON format, which is convenient for using the weather data.

A weather data conversion method converts GRIB weather data files into JSON data files for displaying on a web end, and comprises the following steps:

s1, pull GRIB weather data: automatically downloading GRIB data through a GRIB data downloading path opened by an NOAA website and storing the GRIB data to the local;

s2, GRIB data analysis: analyzing the downloaded byte data of the GRIB data file to obtain a dispersed single-amount intermediate data file;

s3, merging intermediate data: reading a corresponding file header of data to be combined, reading a file data body, generating character strings, storing the character strings in a corresponding intermediate file, and combining the corresponding intermediate files into a file according to requirements;

s4, generating a JSON file: and generating KEY and VALUE corresponding to the JSON file according to the web agreement, correspondingly generating JSON information, storing the JSON information into the corresponding JSON file, and reading the corresponding JSON file by the web terminal according to the agreement protocol.

Preferably, the pulling the GRIB weather data comprises the steps of:

adding a weather task: when the web end needs a corresponding weather JSON file, the web end adds a corresponding data generation task according to a time range;

and (3) decomposing a weather task: when the weather task is added, determining to download each detailed information of the weather task from an NOAA website according to the optional information of the weather task, decomposing the weather task, and generating a detailed download task;

performing a weather task: the web terminal selects the precision required to be downloaded according to the decomposed detailed task, and automatically downloads the required GRIB file from the NOAA website according to the time range of the weather task;

obtaining a GRIB file: and storing the downloaded GRIB file to the local, and recording that the file of the required weather task is downloaded and completed.

Preferably, the analyzing of the GRIB data further includes reading a corresponding file through an encoding protocol of the GRIB data, and acquiring a single data intermediate file of a required parameter and a specified type after analyzing the byte data corresponding to the file according to an encoding specification and a bit specification of the corresponding parameter by the file protocol of the GRIB data.

Preferably, the encoding protocol includes a protocol of parameter type, position, start and data format of the GRIB data.

Preferably, the single-volume data intermediate file comprises a data header and a data body.

Preferably, the intermediate file contains a plurality of weather parameters, and the data header and the data body of the data to be combined are respectively read to generate a new character string.

Preferably, in step S3, the file is converted from an invisible GRIB binary file into a character string, and a JSON file is generated according to a web contract.

And, a weather data conversion system, comprising:

the GRIB data pulling module is used for connecting to the NOAA website, automatically downloading GRIB data files through an open GRIB data downloading path on the NOAA website, and storing the downloaded GRIB data to the local;

the GRIB data analysis module is connected with the GRIB data pulling module and is used for analyzing the downloaded GRIB data file and decomposing the GRIB data file into a single amount of dispersed intermediate data files;

the intermediate data merging module is connected with the GRIB data analysis module and is used for merging the intermediate files to be merged into one file according to the requirement;

and the JSON file generating module is connected with the intermediate data merging module and is connected with the web end network so as to generate KEY and VALUE corresponding to the JSON file according to the web agreement, correspondingly generate JSON information and store the JSON information into the corresponding JSON file.

Preferably, the GRIB data pulling module includes:

the task adding unit is used for being connected with the web end network so as to add corresponding data to generate a task when the web end needs a corresponding weather JSON file;

the task decomposing unit is connected with the task adding unit and is used for downloading the detailed details of the required weather task from the NOAA website and generating a detailed downloading task;

the task execution unit is connected with the task decomposition unit and is used for downloading the needed GRIB file according to the detailed downloading task and the coding protocol opened by the NOAA website;

and the GRIB file generating unit is connected with the task executing unit and is used for storing the downloaded GRIB file to the local and recording the completion of the downloading of the task.

Preferably, the GRIB file generating unit is connected to the GRIB data parsing module, so that the GRIB data parsing module reads and parses the locally stored GRIB file.

In the weather data conversion method and system, GRIB data are automatically downloaded through a GRIB data download path opened by an NOAA website, and the complicated GRIB file is analyzed into a JSON file which is universal, practical and convenient to use at a web end through the method, is used for corresponding weather forecast, provides actual available data for the weather forecast at the web end, facilitates the use of the weather data, and is simple and convenient in whole analysis and wide in application prospect.

Drawings

Fig. 1 is a method step diagram of a weather data conversion method and system according to an embodiment of the invention.

Fig. 2 is a system module diagram of a weather data conversion method and system according to an embodiment of the present invention.

Fig. 3 is a schematic block diagram of a GRIB data pull module of the weather data conversion method and system according to the embodiment of the present invention.

Detailed Description

The present invention will be described in detail below with reference to specific embodiments and the accompanying drawings.

Referring to fig. 1, a weather data conversion method for converting a GRIB weather data file into a JSON data file for display on a web site according to an embodiment of the present invention is shown, and includes the following steps:

s1, pull GRIB weather data: automatically downloading GRIB data through a GRIB data downloading path opened by an NOAA website and storing the GRIB data to the local;

s2, GRIB data analysis: analyzing the downloaded byte data of the GRIB data file to obtain a dispersed single-amount intermediate data file;

s3, merging intermediate data: reading a corresponding file header of data to be combined, reading a file data body, generating character strings, storing the character strings in a corresponding intermediate file, and combining the corresponding intermediate files into a file according to requirements;

s4, generating a JSON file: and generating KEY and VALUE corresponding to the JSON file according to the web agreement, correspondingly generating JSON information, storing the JSON information into the corresponding JSON file, and reading the corresponding JSON file by the web terminal according to the agreement protocol.

Preferably, the step of pulling the GRIB weather data specifically comprises an add weather task S11, a decompose weather task S12, an execute weather task S13 and a get GRIB file S14;

add weather task S11: when the web end needs a corresponding weather JSON file, the web end adds a corresponding data generation task according to a time range;

decompose weather task S12: when the weather task is added, determining to download each detailed information of the weather task from an NOAA website according to the optional information of the weather task, decomposing the weather task, and generating a detailed download task;

performing weather task S13: the web terminal selects the precision required to be downloaded according to the decomposed detailed task, and automatically downloads the required GRIB file from the NOAA website according to the time range of the weather task;

obtain the GRIB file S14: and storing the downloaded GRIB file to the local, and recording that the file of the required weather task is downloaded and completed.

Further, the NOAA website provides the GRIB file download path with the precision of 0.25, 0.5 and 1.

Preferably, the analyzing of the GRIB data further includes reading a corresponding file through an encoding protocol of the GRIB data, and acquiring a single-quantity data intermediate file of the required parameters and the specified type of data after analyzing the byte data corresponding to the file according to the encoding specification and bit specification of the corresponding parameters by the file protocol of the GRIB data, for example, acquiring a single-quantity data intermediate file capable of reading the specified type parameters of the file, such as temperature, U component of wind power, V component of wind power, and the like, through configuration parameters.

Preferably, the coding protocol comprises protocols of parameter type, position, beginning and data format of GRIB data provided by NOAA website.

Preferably, the single data intermediate file includes a data header and a data body, and generates corresponding data.

Preferably, the intermediate file contains a plurality of weather parameters, and the data header and the data body of the data to be combined are respectively read to generate a new character string. Further, after acquiring corresponding parameters according to the requirement configuration, acquiring parameters required by a head part of weather parameters in a file, reading corresponding GRIB file data and writing the GRIB file data into a corresponding data file to generate a required intermediate file, wherein the files are scattered, if wind power data is two files, whether the corresponding file data is a final result or not is determined through corresponding file operation configuration, if the corresponding file data is required to be combined, momentum data such as the wind power file and the like is read, a corresponding file data head and a corresponding file data body are read, character strings are generated according to a head-tail sequence, a field sequence and the like and are stored in the corresponding intermediate file, and the corresponding intermediate file is combined according to the requirement and is stored in the same file to generate an intermediate result file.

Preferably, in the intermediate data merging step S3, the file is converted from an invisible GRIB binary file into a character string, a JSON file is generated according to a web contract, and the web end directly reads the corresponding JSON file according to a contract protocol for display.

Preferably, the downloaded GRIB data file byte data is parsed by using the following parsing language:

Figure BDA0002233356990000051

Figure BDA0002233356990000061

preferably, the following codes are used for generating the JSON file from the intermediate result file:

referring to fig. 2, a weather data conversion system 100 according to an embodiment of the invention is shown, which includes:

the GRIB data pulling module 1 is used for connecting to an NOAA website, automatically downloading GRIB data files through an open GRIB data downloading path on the NOAA website, and storing the downloaded GRIB data to the local;

the GRIB data analysis module 2 is connected with the GRIB data pulling module 1, and the GRIB data analysis module 2 is used for analyzing the downloaded GRIB data file and decomposing the GRIB data file into a dispersed single-amount intermediate data file; further, the GRIB data analysis module 2 reads the corresponding file through the encoding protocol of the GRIB data, and obtains a single data intermediate file of the required parameters and the specified type data after analyzing the byte data corresponding to the file according to the encoding specification and the bit specification of the corresponding parameters by the file protocol of the GRIB data. The single data intermediate file comprises a data head and a data body and generates corresponding data;

the intermediate data merging module 3 is connected with the GRIB data analyzing module 2, and the intermediate data merging module 3 is used for merging the dispersed intermediate data files needing to be merged into an intermediate result file as required and converting the data from the invisible GRIB binary file into a character string;

and the JSON file generating module 4 is connected with the intermediate data merging module 3, and the JSON file generating module 4 is connected with a web end network to generate KEY and VALUE corresponding to the JSON file according to a web agreement, correspondingly generate JSON information and store the JSON information in the corresponding JSON file.

Referring to fig. 3, the GRIB data pull module 1 includes:

the task adding unit 11 is connected with the web end network and is used for adding corresponding data to generate a task when the web end needs a corresponding weather JSON file;

the task decomposition unit 12 is connected with the task adding unit 11, and the task decomposition unit 12 is used for downloading the detailed details of the required weather task from the NOAA website and generating a detailed downloading task;

the task execution unit 13 is connected with the task decomposition unit 12, and the task execution unit 13 is used for downloading the required GRIB file according to the detailed downloading task and the coding protocol opened by the NOAA website;

and the GRIB file generating unit 14 is connected to the task executing unit 13, and is configured to store the downloaded GRIB file locally, and record that the task is downloaded completely.

Preferably, the GRIB file generating unit 14 is connected to the GRIB data parsing module, so that the GRIB data parsing module 2 reads and parses the locally stored GRIB file. It should be understood that each unit in the GRIB data pulling module 1 is consistent with the corresponding step characteristics in the foregoing weather data conversion method, and details are not repeated herein.

According to the weather data conversion method and system, the downloaded GRIB data file byte data is analyzed through the independently edited programming language, the GRIB data is analyzed, the required parameters and the data of the specified type are obtained, and the scattered intermediate data are obtained; according to a corresponding coding protocol, the intermediate data are combined into intermediate result data, and the intermediate result data are converted into general JSON data through an independently edited programming language, so that the weather data can be conveniently analyzed, the web side can conveniently extract and use, and actual available data can be provided for the weather forecast of the web side.

It should be noted that the present invention is not limited to the above-mentioned embodiments, and other changes and modifications can be made by those skilled in the art according to the spirit of the present invention, and these changes and modifications made according to the spirit of the present invention should be included in the scope of the present invention as claimed.

13页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种新闻文档去重的方法、装置及存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!