├── .gitignore ├── .readthedocs.yml ├── LICENSE ├── MANIFEST.in ├── README.md ├── apiinterface.proto ├── conf ├── client.config └── config.yaml ├── docs ├── Makefile ├── environment.yml ├── make.bat └── source │ ├── conf.py │ ├── guide │ └── station.rst │ ├── index.rst │ └── usage │ ├── example.rst │ ├── installation.rst │ └── quickstart.rst ├── example ├── README.md ├── config │ └── client.config.example ├── nuwe_cmadaas_example │ ├── __init__.py │ ├── music │ │ ├── __init__.py │ │ ├── array_2d.py │ │ ├── download.py │ │ ├── file_info_search │ │ │ ├── __init__.py │ │ │ ├── file_info_search_download_file.py │ │ │ ├── file_info_search_file_list.py │ │ │ ├── file_info_search_serialized_str_html.py │ │ │ ├── file_info_search_serialized_str_json.py │ │ │ ├── file_info_search_serialized_str_text.py │ │ │ └── file_info_search_serialized_str_xml.py │ │ ├── filelist.py │ │ ├── grid_array_2d.py │ │ ├── grid_element_point_search │ │ │ ├── __init__.py │ │ │ ├── grid_element_point_search_array_2d.py │ │ │ ├── grid_element_point_search_save_as_file_html.py │ │ │ ├── grid_element_point_search_save_as_file_json.py │ │ │ ├── grid_element_point_search_save_as_file_text.py │ │ │ ├── grid_element_point_search_save_as_file_xml.py │ │ │ ├── grid_element_point_search_serialized_str_html.py │ │ │ ├── grid_element_point_search_serialized_str_json.py │ │ │ ├── grid_element_point_search_serialized_str_text.py │ │ │ └── grid_element_point_search_serialized_str_xml.py │ │ ├── grid_element_rect_search │ │ │ ├── __init__.py │ │ │ ├── grid_element_rect_search_grid_array_2d.py │ │ │ ├── grid_element_rect_search_grid_verctor_2d.py │ │ │ ├── grid_element_rect_search_save_as_file_html.py │ │ │ ├── grid_element_rect_search_save_as_file_json.py │ │ │ ├── grid_element_rect_search_save_as_file_text.py │ │ │ ├── grid_element_rect_search_save_as_file_xml.py │ │ │ ├── grid_element_rect_search_serialized_str_html.py │ │ │ ├── grid_element_rect_search_serialized_str_json.py │ │ │ ├── grid_element_rect_search_serialized_str_text.py │ │ │ └── grid_element_rect_search_serialized_str_xml.py │ │ ├── save_as_file.py │ │ ├── serialized_str.py │ │ ├── station_element_search │ │ │ ├── __init__.py │ │ │ ├── station_element_search_array_2d.py │ │ │ ├── station_element_search_save_as_file_html.py │ │ │ ├── station_element_search_save_as_file_json.py │ │ │ ├── station_element_search_save_as_file_text.py │ │ │ ├── station_element_search_save_as_file_xml.py │ │ │ ├── station_element_search_serialized_str_html.py │ │ │ ├── station_element_search_serialized_str_json.py │ │ │ ├── station_element_search_serialized_str_text.py │ │ │ └── station_element_search_serialized_str_xml.py │ │ ├── station_element_statistics │ │ │ ├── __init__.py │ │ │ ├── station_element_statistics_array_2d.py │ │ │ ├── station_element_statistics_save_as_file_html.py │ │ │ ├── station_element_statistics_save_as_file_json.py │ │ │ ├── station_element_statistics_save_as_file_text.py │ │ │ ├── station_element_statistics_save_as_file_xml.py │ │ │ ├── station_element_statistics_serialized_str_html.py │ │ │ ├── station_element_statistics_serialized_str_json.py │ │ │ ├── station_element_statistics_serialized_str_text.py │ │ │ └── station_element_statistics_serialized_str_xml.py │ │ └── station_info_search │ │ │ ├── __init__.py │ │ │ ├── station_info_search_array_2d.py │ │ │ ├── station_info_search_save_as_file_html.py │ │ │ ├── station_info_search_save_as_file_json.py │ │ │ ├── station_info_search_save_as_file_text.py │ │ │ ├── station_info_search_save_as_file_xml.py │ │ │ ├── station_info_search_serialized_str_html.py │ │ │ ├── station_info_search_serialized_str_json.py │ │ │ ├── station_info_search_serialized_str_text.py │ │ │ └── station_info_search_serialized_str_xml.py │ ├── nuwe │ │ ├── __init__.py │ │ └── model │ │ │ ├── __init__.py │ │ │ └── cma_gfs │ │ │ ├── __init__.py │ │ │ └── gfs_grid.py │ └── util.py └── pyproject.toml ├── nuwe_cmadaas ├── __init__.py ├── _log.py ├── config.py ├── data │ └── datasets │ │ ├── station.yaml │ │ └── upper_air.yaml ├── dataset.py ├── model │ ├── __init__.py │ ├── file.py │ ├── grid.py │ └── point.py ├── music │ ├── __init__.py │ ├── apiinterface_pb2.py │ ├── client.py │ ├── connection.py │ └── data.py ├── obs │ ├── __init__.py │ ├── file.py │ ├── grid.py │ ├── station.py │ ├── upper_air.py │ └── util.py └── util.py ├── pyproject.toml └── tests ├── __init__.py ├── model ├── __init__.py └── grid │ ├── __init__.py │ ├── conftest.py │ └── test_cma_reps.py └── obs ├── __init__.py ├── grid ├── __init__.py ├── conftest.py ├── test_getSurfEleGridByTime.py └── test_getSurfEleGridByTimeAndRect.py └── station ├── __init__.py ├── conftest.py ├── test_getSurfEleByTime.py ├── test_getSurfEleByTimeAndStaID.py ├── test_getSurfEleByTimeAndStaIdRange.py ├── test_getSurfEleByTimeRange.py ├── test_getSurfEleByTimeRangeAndStaID.py ├── test_getSurfEleByTimeRangeAndStaIDRange.py ├── test_getSurfEleInBasinByTime.py ├── test_getSurfEleInBasinByTimeRange.py ├── test_getSurfEleInRectByTime.py ├── test_getSurfEleInRectByTimeRange.py ├── test_getSurfEleInRegionByTime.py ├── test_getSurfEleInRegionByTimeRange.py └── test_getSurfLatestTime.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | .idea/ 161 | 162 | nuwe_cmadaas/_version.py 163 | 164 | # example 165 | /example/output 166 | /example/config/client.config 167 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | formats: 4 | - epub 5 | - pdf 6 | 7 | build: 8 | os: "ubuntu-20.04" 9 | tools: 10 | python: "mambaforge-4.10" 11 | 12 | conda: 13 | environment: docs/environment.yml -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include nuwe_cmadaas/data * -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nuwe-cmadaas-python 2 | 3 | [![Documentation Status](https://readthedocs.org/projects/nuwe-cmadaas-python/badge/?version=latest)](https://nuwe-cmadaas-python.readthedocs.io/zh_CN/latest/?badge=latest) 4 | 5 | 为 CMADaaS MUSIC 接口封装 Python API,提供仿 MUSIC 原生接口及高层 API 接口,支持 Python 3 和 Windows。 6 | 7 | 文档:https://nuwe-cmadaas-python.readthedocs.io 8 | 9 | ## 安装 10 | 11 | 克隆源码,使用 `pip` 命令安装 nuwe-cmadaas 包。 12 | 13 | ``` 14 | git clone https://github.com/perillaroc/nuwe-cmadaas-python.git 15 | cd nuwe-cmadaas-python 16 | pip install . 17 | ``` 18 | 19 | ## 开始使用 20 | 21 | MUSIC 接口仅适用于 CMA 内网用户,使用前请先申请账户。 22 | 23 | 使用 `nuwe_cmadaas.CMADaaSClient` 类从 CMADaaS 中检索数据。 24 | 25 | 需要提供 MUSIC 服务的相关参数,可以保存在当前目录 `client.conf` 文件中, 26 | 或者在创建 `nuwe_cmadaas.CMADaaSClient` 对象显式指定。参数包括: 27 | 28 | - `music_server`: MUSIC 接口 ip 地址,必须指定 29 | - `music_port`:MUSIC 接口端口号,必须指定 30 | - `music_connTimeout`:连接超时,秒,可选 31 | - `music_readTimeout`:数据读取超时,秒,可选 32 | - `music_ServiceId`:默认服务节点 id 33 | 34 | 下面的示例展示如何检索地面观测资料。 35 | 36 | ```python 37 | from nuwe_cmadaas import CMADaaSClient 38 | 39 | client_config_path = "path/to/client.config" 40 | user = "user name" 41 | password = "user password" 42 | server_id = "server id" 43 | 44 | interface_id = "getSurfEleByTimeRange" 45 | 46 | params = { 47 | "dataCode": "SURF_CHN_MUL_HOR", 48 | "elements": "Station_Id_d,Lat,Lon,Alti,Day,Hour,PRS_Sea,TEM,DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS", 49 | "timeRange": "[20190817000000,20190817020000)", 50 | "orderby": "Station_ID_d:ASC", 51 | "limitCnt": "10", 52 | } 53 | 54 | client = CMADaaSClient( 55 | user=user, 56 | password=password, 57 | config_file=client_config_path 58 | ) 59 | result = client.callAPI_to_array2D(interface_id, params) 60 | ``` 61 | 62 | 更详细的接口使用方法请访问 CMADaaS 官网。 63 | 64 | ## 示例 65 | 66 | 请访问 `example` 目录查看示例。 67 | 68 | ## License 69 | 70 | `nuwe-cmadaas-python` 未做特殊声明部分代码由 Wang Dapeng (CEMC/CMA) 开发,并采用 Apache License 2.0 协议。 71 | -------------------------------------------------------------------------------- /apiinterface.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package cma.music.pb; 4 | 5 | message RequestInfo{ 6 | int32 errorCode = 1; 7 | string errorMessage =2; 8 | string requestElems = 3; 9 | string requestParams = 4; 10 | string requestTime = 5; 11 | string responseTime = 6; 12 | int32 rowCount = 7; 13 | int32 takeTime = 8; 14 | int32 colCount = 9; 15 | } 16 | 17 | message RetArray2D{ 18 | repeated string data = 1; 19 | RequestInfo request = 2; 20 | repeated string elementNames = 3; 21 | } 22 | 23 | message RetGridArray2D{ 24 | repeated float data = 1; 25 | RequestInfo request = 2; 26 | float startLat = 3; 27 | float startLon = 4; 28 | float endLat = 5; 29 | float endLon = 6; 30 | int32 latCount = 7; 31 | int32 lonCount = 8; 32 | float lonStep = 9; 33 | float latStep = 10; 34 | repeated float lats = 11; 35 | repeated float lons = 12; 36 | string units = 13; 37 | string userEleName = 14; 38 | } 39 | 40 | message FileInfo{ 41 | string fileName = 1; 42 | string savePath = 2; 43 | string suffix = 3; 44 | string size = 4; 45 | string fileUrl = 5; 46 | string imgBase64 = 6; 47 | repeated string attributes = 7; 48 | } 49 | 50 | message RetFilesInfo{ 51 | repeated FileInfo fileInfos = 1; 52 | RequestInfo request = 2; 53 | } 54 | 55 | message StoreArray2D{ 56 | repeated string data = 1; 57 | int32 row = 2; 58 | int32 col = 3; 59 | int32 fileflag = 4; 60 | repeated string filenames = 5; 61 | int32 is_backstage = 6; 62 | string client_mount_path = 7; 63 | string server_mount_path = 8; 64 | } 65 | 66 | message RetDataBlock{ 67 | string dataName = 1; 68 | bytes byteArray = 2; 69 | RequestInfo request = 3; 70 | } 71 | 72 | message RetGridVector2D{ 73 | repeated float u_datas = 1; 74 | repeated float v_datas = 2; 75 | RequestInfo request = 3; 76 | float startLat = 4; 77 | float startLon = 5; 78 | float endLat = 6; 79 | float endLon = 7; 80 | int32 latCount = 8; 81 | int32 lonCount = 9; 82 | float lonStep = 10; 83 | float latStep = 11; 84 | repeated float lats = 12; 85 | repeated float lons = 13; 86 | string u_EleName = 14; 87 | string v_EleName = 15; 88 | } 89 | 90 | message RetGridScalar2D{ 91 | repeated float datas = 1; 92 | RequestInfo request = 2; 93 | float startLat = 3; 94 | float startLon = 4; 95 | float endLat = 5; 96 | float endLon = 6; 97 | int32 latCount = 7; 98 | int32 lonCount = 8; 99 | float lonStep = 9; 100 | float latStep = 10; 101 | repeated float lats = 11; 102 | repeated float lons = 12; 103 | string units = 13; 104 | string userEleName = 14; 105 | } 106 | 107 | message StoreGridData{ 108 | repeated string attributes = 1; 109 | int32 pointflag = 2; 110 | repeated float Lats = 3; 111 | repeated float Lons = 4; 112 | repeated float datas = 5; 113 | } 114 | 115 | message StoreBlockData{ 116 | repeated string attributes = 1; 117 | bytes data = 2; 118 | } 119 | 120 | -------------------------------------------------------------------------------- /conf/client.config: -------------------------------------------------------------------------------- 1 | # This is a sample config file for low level API. 2 | # Please see CMADaaS MUSIC API document for detail. 3 | 4 | [Pb] 5 | music_server=music host 6 | music_port=music port 7 | 8 | music_connTimeout=3 # connection timeout, seconds 9 | music_readTimeout=3000 # read timeout, seconds 10 | music_ServiceId=service id # service id -------------------------------------------------------------------------------- /conf/config.yaml: -------------------------------------------------------------------------------- 1 | # This is a config sample file for high level API. 2 | # Please create the config file in $HOME/.config/cedarkit.yaml 3 | # Or set environment variable CEDARKIT_CONFIG for its path. 4 | 5 | cmadaas: 6 | auth: 7 | user: user name 8 | password: user password 9 | server: 10 | music_server: music server ip 11 | music_port: music server port 12 | music_connTimeout: 3 # connection time out, seconds 13 | music_readTimeout: 3000 # read time out, seconds 14 | music_ServiceId: music service id 15 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/environment.yml: -------------------------------------------------------------------------------- 1 | name: rtd311 2 | channels: 3 | - conda-forge 4 | - defaults 5 | dependencies: 6 | - python=3.11 7 | - ipython 8 | - sphinx 9 | - sphinx-book-theme>=1 10 | - pip 11 | - pip: 12 | - .. 13 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | # import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'nuwe-cmadaas-python' 21 | copyright = '2019-2024, Wang Dapeng at cemc-oper' 22 | author = 'perillaroc' 23 | 24 | 25 | # -- General configuration --------------------------------------------------- 26 | 27 | # Add any Sphinx extension module names here, as strings. They can be 28 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 29 | # ones. 30 | extensions = [ 31 | 'IPython.sphinxext.ipython_console_highlighting', 32 | 'IPython.sphinxext.ipython_directive', 33 | 34 | 'sphinx.ext.napoleon', 35 | 'sphinx.ext.autodoc', 36 | # 'sphinx_autodoc_typehints', 37 | ] 38 | 39 | # Add any paths that contain templates here, relative to this directory. 40 | templates_path = ['_templates'] 41 | 42 | # The language for content autogenerated by Sphinx. Refer to documentation 43 | # for a list of supported languages. 44 | # 45 | # This is also used if you do content translation via gettext catalogs. 46 | # Usually you set "language" from the command line for these cases. 47 | language = 'zh_CN' 48 | 49 | # List of patterns, relative to source directory, that match files and 50 | # directories to ignore when looking for source files. 51 | # This pattern also affects html_static_path and html_extra_path. 52 | exclude_patterns = [] 53 | 54 | 55 | # -- Options for HTML output ------------------------------------------------- 56 | 57 | # The theme to use for HTML and HTML Help pages. See the documentation for 58 | # a list of builtin themes. 59 | # 60 | # html_theme = 'alabaster' 61 | html_theme = 'sphinx_book_theme' 62 | 63 | html_theme_options = { 64 | "repository_url": "https://github.com/perillaroc/nuwe-cmadaas-python", 65 | "use_repository_button": True, 66 | "home_page_in_toc": False, 67 | } 68 | html_title = "nuwe-cmadaas" 69 | 70 | # Add any paths that contain custom static files (such as style sheets) here, 71 | # relative to this directory. They are copied after the builtin static files, 72 | # so a file named "default.css" will overwrite the builtin "default.css". 73 | html_static_path = ['_static'] 74 | 75 | 76 | ipython_savefig_dir = os.path.join( 77 | os.path.dirname(os.path.abspath(__file__)), "_build", "html", "_static" 78 | ) 79 | if not os.path.exists(ipython_savefig_dir): 80 | os.makedirs(ipython_savefig_dir) 81 | -------------------------------------------------------------------------------- /docs/source/guide/station.rst: -------------------------------------------------------------------------------- 1 | ********** 2 | 站点数据 3 | ********** 4 | 5 | .. currentmodule:: nuwe_cmadaas.obs 6 | 7 | :py:class:`retrieve_obs_station` 函数用于获取地面站点观测数据。 8 | 9 | 10 | .. code-block:: python 11 | 12 | >>> import pandas as pd 13 | >>> from nuwe_cmadaas.obs import retrieve_obs_station 14 | >>> table = retrieve_obs_station( 15 | ... "SURF_CHN_MUL_HOR", 16 | ... time=[ 17 | ... pd.to_datetime("2021-01-01 00:00:00"), 18 | ... pd.to_datetime("2021-01-02 00:00:00") 19 | ... ], 20 | ... config_file="cedarkit.yaml" 21 | ... ) 22 | >>> table 23 | Station_Id_d Lat Lon Alti ... PRE_1h PRE_6h PRE_24h PRS 24 | 0 631 37.9167 102.6667 1531.5 ... 0 0 0 850.4 25 | 1 631 37.9167 102.6667 1531.5 ... 0 0 0 851.7 26 | 2 7129 44.85 84.7 455 ... 0 999999 999999 999999 27 | 3 7129 44.85 84.7 455 ... 0 999999 999999 999999 28 | 4 9168 46.8472 84.1847 891 ... 0 999999 999999 999999 29 | ... ... ... ... ... ... ... ... ... 30 | 126047 999999 24.6462 121.0829 718 ... 0 0 0 999998 31 | 126048 999999 23.0817 120.5825 298 ... 0 0 0 986.3 32 | 126049 999999 22.8596 120.5086 44 ... 0 0 0 999998 33 | 126050 999999 24.2965 120.6431 130 ... 0 0 0 999999 34 | 126051 999999 23.0739 120.5289 274 ... 0 0 0 999998 35 | [126052 rows x 17 columns] 36 | 37 | 38 | 39 | 40 | API 41 | =========== 42 | 43 | .. autofunction:: retrieve_obs_station -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. nuwe-cmadaas-python documentation master file, created by 2 | sphinx-quickstart on Wed Mar 31 15:51:42 2021. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | nuwe-cmadaas-python 文档 7 | ================================================== 8 | 9 | 为 CMADaaS 的 MUSIC 接口封装 Python API,支持 Python 3 和 Windows。 10 | 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | :hidden: 15 | :caption: 使用 16 | 17 | usage/installation 18 | usage/quickstart 19 | usage/example 20 | 21 | 22 | .. toctree:: 23 | :maxdepth: 2 24 | :hidden: 25 | :caption: 指南 26 | 27 | guide/station 28 | 29 | 30 | 索引和表格 31 | ================== 32 | 33 | * :ref:`genindex` 34 | * :ref:`modindex` 35 | * :ref:`search` 36 | -------------------------------------------------------------------------------- /docs/source/usage/example.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | 示例 3 | ******* 4 | 5 | 请访问 ``example`` 目录查看示例。 -------------------------------------------------------------------------------- /docs/source/usage/installation.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | 安装 3 | ********* 4 | 5 | 从 Github 下载源码,项目地址 6 | 7 | https://github.com/perillaroc/nuwe-cmadaas-python 8 | 9 | 使用如下命令安装 `nuwe_cmadaas` 包。 10 | 11 | .. code-block:: bash 12 | 13 | pip install . 14 | -------------------------------------------------------------------------------- /docs/source/usage/quickstart.rst: -------------------------------------------------------------------------------- 1 | ******** 2 | 开始使用 3 | ******** 4 | 5 | MUSIC 接口仅适用于 CMA 内网用户,使用前请先申请账户。 6 | 7 | 使用 :py:class:`nuwe_cmadaas.CMADaaSClient` 类从 CMADaaS 中检索数据。 8 | 9 | 需要提供 CMADaaS 服务的相关参数,可以保存在当前目录 ``client.conf`` 文件中, 10 | 或者在创建 :py:class:`nuwe_cmadaas.CMADaasClient` 对象显式指定。参数包括: 11 | 12 | - ``music_server``: MUSIC接口ip地址,必须指定 13 | - ``music_port``:MUSIC接口端口号,必须指定 14 | - ``music_connTimeout``:连接超时,秒,可选 15 | - ``music_readTimeout``:数据读取超时,秒,可选 16 | - ``music_ServiceId``:默认服务节点id 17 | 18 | 下面的示例展示如何检索地面观测资料。 19 | 20 | .. code-block:: python 21 | 22 | from nuwe_cmadaas import CMADaaSClient 23 | 24 | client_config_path="path/to/client/config/file" 25 | user="user name" 26 | password="user password" 27 | server_id = "server id" 28 | 29 | interface_id = "getSurfEleByTimeRange" 30 | 31 | params = { 32 | "dataCode": "SURF_CHN_MUL_HOR", 33 | "elements": "Station_Id_d,Lat,Lon,Alti,Day,Hour,PRS_Sea,TEM,DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS", 34 | "timeRange": "[20190817000000,20190817020000)", 35 | "orderby": "Station_ID_d:ASC", 36 | "limitCnt": "10", 37 | } 38 | 39 | client = CMADaaSClient( 40 | user=user, 41 | password=password, 42 | config_file=client_config_path 43 | ) 44 | result = client.callAPI_to_array2D(interface_id, params) 45 | 46 | 更详细的接口使用方法请访问 CMADaaS 官网。 -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # nuwe-cmadaas-python 示例 2 | 3 | 仿照 CMADaaS MUSIC Python SDK Demo 的示例代码。 4 | 5 | ## 安装 6 | 7 | 下载 nuwe-cmadaas-python 源码,安装 nuwe-cmadaas 和 nuwe-cmadass-example 包。 8 | 9 | ```bash 10 | git clone https://github.com/perillaroc/nuwe-cmadaas-python.git 11 | cd nuwe-cmadaas-python 12 | pip intsall . 13 | cd example 14 | pip install . 15 | ``` 16 | 17 | ## 配置 18 | 19 | 创建配置文件 `./config/client.config` 20 | 21 | 可选:创建输出文件目录 `./output` 22 | 23 | ## 运行 24 | 25 | 每个示例脚本均可独立运行。 -------------------------------------------------------------------------------- /example/config/client.config.example: -------------------------------------------------------------------------------- 1 | # This is a sample config file for low level API. 2 | # Please see CMADaaS MUSIC API document for detail. 3 | 4 | [Pb] 5 | music_server=music host 6 | music_port=music port 7 | 8 | music_connTimeout=3 # connection timeout, seconds 9 | music_readTimeout=3000 # read timeout, seconds 10 | music_ServiceId=service id # service id -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/array_2d.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | import click 3 | 4 | from nuwe_cmadaas import CMADaaSClient 5 | 6 | 7 | @click.command() 8 | @click.option("--user", help="user name", required=True) 9 | @click.option("--password", help="password name", required=True) 10 | @click.option("--client-config", help="client config file") 11 | def cli(user, password, client_config=None): 12 | 13 | interface_id = "getSurfEleByTimeRange" 14 | 15 | server_id = "NMIC_MUSIC_CMADAAS" 16 | 17 | params = { 18 | "dataCode": "SURF_CHN_MUL_HOR", 19 | "elements": "Station_Id_d,Lat,Lon,Alti,Day,Hour,PRS_Sea,TEM," 20 | "DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS", 21 | "timeRange": "[20210110000000,20210110020000)", 22 | "orderby": "Station_ID_d:ASC", 23 | "limitCnt": "10", 24 | } 25 | 26 | client = CMADaaSClient( 27 | user=user, 28 | password=password, 29 | config_file=client_config) 30 | result = client.callAPI_to_array2D(interface_id, params, server_id) 31 | 32 | print(result) 33 | 34 | 35 | if __name__ == "__main__": 36 | cli() 37 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/download.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | from nuwe_cmadaas import CMADaaSClient 3 | import click 4 | import pathlib 5 | 6 | 7 | @click.command() 8 | @click.option("--user", help="user name", required=True) 9 | @click.option("--password", help="password name", required=True) 10 | @click.option("--client-config", help="client config file") 11 | @click.option("--output-dir", help="client config file") 12 | def cli(user, password, output_dir, client_config=None): 13 | 14 | interface_id = "getNafpFileByTime" 15 | 16 | server_id = "NMIC_MUSIC_CMADAAS" 17 | 18 | params = { 19 | "dataCode": "NAFP_FOR_FTM_KWBC_GLB", 20 | "time": "20190917000000", 21 | } 22 | 23 | output_path = pathlib.Path(output_dir) 24 | output_path.mkdir(parents=True, exist_ok=True) 25 | 26 | client = CMADaaSClient( 27 | user=user, 28 | password=password, 29 | config_file=client_config 30 | ) 31 | result = client.callAPI_to_downFile( 32 | interface_id, params, output_dir 33 | ) 34 | 35 | print(result) 36 | 37 | 38 | if __name__ == "__main__": 39 | cli() 40 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/file_info_search/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/file_info_search_download_file.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getRadaFileByTimeRangeAndStaId" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_01utc = yesterday + pd.Timedelta(hours=1) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_01utc_time = get_time_string(yesterday_01utc) 19 | 20 | params = { 21 | "dataCode": "RADA_L2_UFMT", 22 | "timeRange": f"[{yesterday_time},{yesterday_01utc_time})", 23 | "staIds": "Z9210,Z9024,Z9010", 24 | } 25 | 26 | file_dir = get_output_directory() 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_downFile(interface_id, params, file_dir, server_id) 33 | 34 | print("return code:", result.request.error_code) 35 | print("return message:", result.request.error_message) 36 | 37 | for file_info in result.files_info: 38 | print(file_info.file_url) 39 | 40 | 41 | @click.command() 42 | @click.option("--user", help="user name") 43 | @click.option("--password", help="password name") 44 | @click.option("--server-id", help="server id") 45 | @click.option("--client-config", help="client config file path") 46 | def cli(user=None, password=None, server_id=None, client_config=None): 47 | if user is None or password is None: 48 | config = load_cmadaas_config() 49 | if user is None: 50 | user = config["auth"]["user"] 51 | if password is None: 52 | password = config["auth"]["password"] 53 | if server_id is None: 54 | server_id = config["server"]["music_ServiceId"] 55 | 56 | if client_config is None: 57 | client_config = get_client_config_path() 58 | 59 | query(username=user, password=password, server_id=server_id, client_config=client_config) 60 | 61 | 62 | if __name__ == "__main__": 63 | cli() 64 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/file_info_search_file_list.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getRadaFileByTimeRangeAndStaId" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_01utc = yesterday + pd.Timedelta(hours=1) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_01utc_time = get_time_string(yesterday_01utc) 19 | 20 | params = { 21 | "dataCode": "RADA_L2_UFMT", 22 | "timeRange": f"[{yesterday_time},{yesterday_01utc_time})", 23 | "staIds": "Z9210,Z9024,Z9010", 24 | } 25 | 26 | client = CMADaaSClient( 27 | user=username, 28 | password=password, 29 | config_file=client_config) 30 | result = client.callAPI_to_fileList(interface_id, params, server_id) 31 | 32 | print("return code:", result.request.error_code) 33 | print("return message:", result.request.error_message) 34 | 35 | for file_info in result.files_info: 36 | print(file_info.file_url) 37 | 38 | 39 | @click.command() 40 | @click.option("--user", help="user name") 41 | @click.option("--password", help="password name") 42 | @click.option("--server-id", help="server id") 43 | @click.option("--client-config", help="client config file path") 44 | def cli(user=None, password=None, server_id=None, client_config=None): 45 | if user is None or password is None: 46 | config = load_cmadaas_config() 47 | if user is None: 48 | user = config["auth"]["user"] 49 | if password is None: 50 | password = config["auth"]["password"] 51 | if server_id is None: 52 | server_id = config["server"]["music_ServiceId"] 53 | 54 | if client_config is None: 55 | client_config = get_client_config_path() 56 | 57 | query(username=user, password=password, server_id=server_id, client_config=client_config) 58 | 59 | 60 | if __name__ == "__main__": 61 | cli() 62 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/file_info_search_serialized_str_html.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getRadaFileByTimeRangeAndStaId" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_01utc = yesterday + pd.Timedelta(hours=1) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_01utc_time = get_time_string(yesterday_01utc) 19 | 20 | params = { 21 | "dataCode": "RADA_L2_UFMT", 22 | "timeRange": f"[{yesterday_time},{yesterday_01utc_time})", 23 | "staIds": "Z9210,Z9024,Z9010", 24 | } 25 | 26 | data_format = "html" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/file_info_search_serialized_str_json.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getRadaFileByTimeRangeAndStaId" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_01utc = yesterday + pd.Timedelta(hours=1) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_01utc_time = get_time_string(yesterday_01utc) 19 | 20 | params = { 21 | "dataCode": "RADA_L2_UFMT", 22 | "timeRange": f"[{yesterday_time},{yesterday_01utc_time})", 23 | "staIds": "Z9210,Z9024,Z9010", 24 | } 25 | 26 | data_format = "json" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/file_info_search_serialized_str_text.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getRadaFileByTimeRangeAndStaId" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_01utc = yesterday + pd.Timedelta(hours=1) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_01utc_time = get_time_string(yesterday_01utc) 19 | 20 | params = { 21 | "dataCode": "RADA_L2_UFMT", 22 | "timeRange": f"[{yesterday_time},{yesterday_01utc_time})", 23 | "staIds": "Z9210,Z9024,Z9010", 24 | } 25 | 26 | data_format = "text" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/file_info_search/file_info_search_serialized_str_xml.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getRadaFileByTimeRangeAndStaId" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_01utc = yesterday + pd.Timedelta(hours=1) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_01utc_time = get_time_string(yesterday_01utc) 19 | 20 | params = { 21 | "dataCode": "RADA_L2_UFMT", 22 | "timeRange": f"[{yesterday_time},{yesterday_01utc_time})", 23 | "staIds": "Z9210,Z9024,Z9010", 24 | } 25 | 26 | data_format = "xml" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/filelist.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | from nuwe_cmadaas import CMADaaSClient 3 | import click 4 | 5 | 6 | @click.command() 7 | @click.option("--user", help="user name", required=True) 8 | @click.option("--password", help="password name", required=True) 9 | @click.option("--client-config", help="client config file") 10 | def cli(user, password, client_config=None): 11 | 12 | interface_id = "getNafpFileByTime" 13 | 14 | server_id = "NMIC_MUSIC_CMADAAS" 15 | 16 | params = { 17 | "dataCode": "NAFP_FOR_FTM_KWBC_GLB", 18 | "time": "20190922000000", 19 | } 20 | 21 | client = CMADaaSClient( 22 | user=user, 23 | password=password, 24 | config_file=client_config 25 | ) 26 | result = client.callAPI_to_fileList(interface_id, params) 27 | 28 | print(result) 29 | 30 | 31 | if __name__ == "__main__": 32 | cli() 33 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_array_2d.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | from nuwe_cmadaas import CMADaaSClient 3 | import click 4 | import pathlib 5 | 6 | 7 | @click.command() 8 | @click.option("--user", help="user name", required=True) 9 | @click.option("--password", help="password name", required=True) 10 | @click.option("--client-config", help="client config file") 11 | def cli(user, password, client_config=None): 12 | 13 | interface_id = "getNafpEleGridByTimeAndLevelAndValidtime" 14 | 15 | server_id = "NAFP_FOR_FTM_KWBC_GLB" 16 | 17 | params = { 18 | "dataCode": "NAFP_FOR_FTM_KWBC_GLB", 19 | "time": "20190921000000", 20 | "fcstEle": "TEM", 21 | "levelType": "1", 22 | "fcstLevel": "0", 23 | "validTime": "0", 24 | } 25 | 26 | client = CMADaaSClient( 27 | user=user, 28 | password=password, 29 | config_file=client_config) 30 | result = client.callAPI_to_gridArray2D( 31 | interface_id, params 32 | ) 33 | 34 | print(result) 35 | 36 | 37 | if __name__ == "__main__": 38 | cli() 39 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/grid_element_point_search/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_array_2d.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_time = get_time_string(yesterday) 17 | 18 | params = { 19 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 20 | 'time': yesterday_time, 21 | 'minVT': "0", 22 | 'maxVT': "12", 23 | 'latLons': "39.8/116.4667,31.2/121.4333", 24 | 'fcstEle': "TEM", 25 | 'levelType': "100", 26 | 'fcstLevel': "850", 27 | } 28 | 29 | client = CMADaaSClient( 30 | user=username, 31 | password=password, 32 | config_file=client_config) 33 | result = client.callAPI_to_array2D(interface_id, params, server_id) 34 | 35 | print("return code:", result.request.error_code) 36 | print("return message:", result.request.error_message) 37 | 38 | print(np.array(result.data)) 39 | 40 | 41 | @click.command() 42 | @click.option("--user", help="user name") 43 | @click.option("--password", help="password name") 44 | @click.option("--server-id", help="server id") 45 | @click.option("--client-config", help="client config file path") 46 | def cli(user=None, password=None, server_id=None, client_config=None): 47 | if user is None or password is None: 48 | config = load_cmadaas_config() 49 | if user is None: 50 | user = config["auth"]["user"] 51 | if password is None: 52 | password = config["auth"]["password"] 53 | if server_id is None: 54 | server_id = config["server"]["music_ServiceId"] 55 | 56 | if client_config is None: 57 | client_config = get_client_config_path() 58 | 59 | query(username=user, password=password, server_id=server_id, client_config=client_config) 60 | 61 | 62 | if __name__ == "__main__": 63 | cli() 64 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_save_as_file_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "html" 32 | 33 | save_path = str(Path(get_output_directory(), "./output.html")) 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 40 | 41 | print("return code:", result.request.error_code) 42 | print("return message:", result.request.error_message) 43 | 44 | for file_info in result.files_info: 45 | print(file_info.file_url) 46 | 47 | 48 | @click.command() 49 | @click.option("--user", help="user name") 50 | @click.option("--password", help="password name") 51 | @click.option("--server-id", help="server id") 52 | @click.option("--client-config", help="client config file path") 53 | def cli(user=None, password=None, server_id=None, client_config=None): 54 | if user is None or password is None: 55 | config = load_cmadaas_config() 56 | if user is None: 57 | user = config["auth"]["user"] 58 | if password is None: 59 | password = config["auth"]["password"] 60 | if server_id is None: 61 | server_id = config["server"]["music_ServiceId"] 62 | 63 | if client_config is None: 64 | client_config = get_client_config_path() 65 | 66 | query(username=user, password=password, server_id=server_id, client_config=client_config) 67 | 68 | 69 | if __name__ == "__main__": 70 | cli() 71 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_save_as_file_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "json" 32 | 33 | save_path = str(Path(get_output_directory(), "./output.json")) 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 40 | 41 | print("return code:", result.request.error_code) 42 | print("return message:", result.request.error_message) 43 | 44 | for file_info in result.files_info: 45 | print(file_info.file_url) 46 | 47 | 48 | @click.command() 49 | @click.option("--user", help="user name") 50 | @click.option("--password", help="password name") 51 | @click.option("--server-id", help="server id") 52 | @click.option("--client-config", help="client config file path") 53 | def cli(user=None, password=None, server_id=None, client_config=None): 54 | if user is None or password is None: 55 | config = load_cmadaas_config() 56 | if user is None: 57 | user = config["auth"]["user"] 58 | if password is None: 59 | password = config["auth"]["password"] 60 | if server_id is None: 61 | server_id = config["server"]["music_ServiceId"] 62 | 63 | if client_config is None: 64 | client_config = get_client_config_path() 65 | 66 | query(username=user, password=password, server_id=server_id, client_config=client_config) 67 | 68 | 69 | if __name__ == "__main__": 70 | cli() 71 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_save_as_file_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "text" 32 | 33 | save_path = str(Path(get_output_directory(), "./output.txt")) 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 40 | 41 | print("return code:", result.request.error_code) 42 | print("return message:", result.request.error_message) 43 | 44 | for file_info in result.files_info: 45 | print(file_info.file_url) 46 | 47 | 48 | @click.command() 49 | @click.option("--user", help="user name") 50 | @click.option("--password", help="password name") 51 | @click.option("--server-id", help="server id") 52 | @click.option("--client-config", help="client config file path") 53 | def cli(user=None, password=None, server_id=None, client_config=None): 54 | if user is None or password is None: 55 | config = load_cmadaas_config() 56 | if user is None: 57 | user = config["auth"]["user"] 58 | if password is None: 59 | password = config["auth"]["password"] 60 | if server_id is None: 61 | server_id = config["server"]["music_ServiceId"] 62 | 63 | if client_config is None: 64 | client_config = get_client_config_path() 65 | 66 | query(username=user, password=password, server_id=server_id, client_config=client_config) 67 | 68 | 69 | if __name__ == "__main__": 70 | cli() 71 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_save_as_file_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "xml" 32 | 33 | save_path = str(Path(get_output_directory(), "./output.xml")) 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 40 | 41 | print("return code:", result.request.error_code) 42 | print("return message:", result.request.error_message) 43 | 44 | for file_info in result.files_info: 45 | print(file_info.file_url) 46 | 47 | 48 | @click.command() 49 | @click.option("--user", help="user name") 50 | @click.option("--password", help="password name") 51 | @click.option("--server-id", help="server id") 52 | @click.option("--client-config", help="client config file path") 53 | def cli(user=None, password=None, server_id=None, client_config=None): 54 | if user is None or password is None: 55 | config = load_cmadaas_config() 56 | if user is None: 57 | user = config["auth"]["user"] 58 | if password is None: 59 | password = config["auth"]["password"] 60 | if server_id is None: 61 | server_id = config["server"]["music_ServiceId"] 62 | 63 | if client_config is None: 64 | client_config = get_client_config_path() 65 | 66 | query(username=user, password=password, server_id=server_id, client_config=client_config) 67 | 68 | 69 | if __name__ == "__main__": 70 | cli() 71 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_serialized_str_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "html" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_serialized_str_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "json" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_serialized_str_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "text" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_point_search/grid_element_point_search_serialized_str_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleAtPointByTimeAndLevelAndValidtimeRange" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | 'dataCode': "NAFP_ANA_FTM_GRAPES_GFS_NEHE", 22 | 'time': yesterday_time, 23 | 'minVT': "0", 24 | 'maxVT': "12", 25 | 'latLons': "39.8/116.4667,31.2/121.4333", 26 | 'fcstEle': "TEM", 27 | 'levelType': "100", 28 | 'fcstLevel': "850", 29 | } 30 | 31 | data_format = "xml" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/grid_element_rect_search/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_grid_array_2d.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getNafpEleGridByTimeAndLevelAndValidtime" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_time = get_time_string(yesterday) 17 | 18 | params = { 19 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 20 | "time": yesterday_time, 21 | "validTime": "24", 22 | "fcstEle": "TEM", 23 | "fcstLevel": "850", 24 | "levelType": "100", 25 | } 26 | 27 | client = CMADaaSClient( 28 | user=username, 29 | password=password, 30 | config_file=client_config) 31 | result = client.callAPI_to_gridArray2D(interface_id, params, server_id) 32 | 33 | print("return code:", result.request.error_code) 34 | print("return message:", result.request.error_message) 35 | 36 | print(np.array(result.data)) 37 | 38 | 39 | @click.command() 40 | @click.option("--user", help="user name") 41 | @click.option("--password", help="password name") 42 | @click.option("--server-id", help="server id") 43 | @click.option("--client-config", help="client config file path") 44 | def cli(user=None, password=None, server_id=None, client_config=None): 45 | if user is None or password is None: 46 | config = load_cmadaas_config() 47 | if user is None: 48 | user = config["auth"]["user"] 49 | if password is None: 50 | password = config["auth"]["password"] 51 | if server_id is None: 52 | server_id = config["server"]["music_ServiceId"] 53 | 54 | if client_config is None: 55 | client_config = get_client_config_path() 56 | 57 | query(username=user, password=password, server_id=server_id, client_config=client_config) 58 | 59 | 60 | if __name__ == "__main__": 61 | cli() 62 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_grid_verctor_2d.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getNafpVectorEleGridByTimeAndLevelAndValidtime" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_time = get_time_string(yesterday) 17 | 18 | params = { 19 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 20 | "time": yesterday_time, 21 | "validTime": "24", 22 | "fcstuele": "WIU", 23 | "fcstvele": "WIV", 24 | "fcstLevel": "850", 25 | "levelType": "100", 26 | } 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_gridVector2D(interface_id, params, server_id) 33 | 34 | print("return code:", result.request.error_code) 35 | print("return message:", result.request.error_message) 36 | 37 | print(np.array(result.u_datas)) 38 | print(np.array(result.v_datas)) 39 | 40 | 41 | @click.command() 42 | @click.option("--user", help="user name") 43 | @click.option("--password", help="password name") 44 | @click.option("--server-id", help="server id") 45 | @click.option("--client-config", help="client config file path") 46 | def cli(user=None, password=None, server_id=None, client_config=None): 47 | if user is None or password is None: 48 | config = load_cmadaas_config() 49 | if user is None: 50 | user = config["auth"]["user"] 51 | if password is None: 52 | password = config["auth"]["password"] 53 | if server_id is None: 54 | server_id = config["server"]["music_ServiceId"] 55 | 56 | if client_config is None: 57 | client_config = get_client_config_path() 58 | 59 | query(username=user, password=password, server_id=server_id, client_config=client_config) 60 | 61 | 62 | if __name__ == "__main__": 63 | cli() 64 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_save_as_file_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "html" 34 | 35 | save_path = str(Path(get_output_directory(), "./output.html")) 36 | 37 | client = CMADaaSClient( 38 | user=username, 39 | password=password, 40 | config_file=client_config) 41 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 42 | 43 | print("return code:", result.request.error_code) 44 | print("return message:", result.request.error_message) 45 | 46 | for file_info in result.files_info: 47 | print(file_info.file_url) 48 | 49 | 50 | @click.command() 51 | @click.option("--user", help="user name") 52 | @click.option("--password", help="password name") 53 | @click.option("--server-id", help="server id") 54 | @click.option("--client-config", help="client config file path") 55 | def cli(user=None, password=None, server_id=None, client_config=None): 56 | if user is None or password is None: 57 | config = load_cmadaas_config() 58 | if user is None: 59 | user = config["auth"]["user"] 60 | if password is None: 61 | password = config["auth"]["password"] 62 | if server_id is None: 63 | server_id = config["server"]["music_ServiceId"] 64 | 65 | if client_config is None: 66 | client_config = get_client_config_path() 67 | 68 | query(username=user, password=password, server_id=server_id, client_config=client_config) 69 | 70 | 71 | if __name__ == "__main__": 72 | cli() 73 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_save_as_file_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "json" 34 | 35 | save_path = str(Path(get_output_directory(), "./output.json")) 36 | 37 | client = CMADaaSClient( 38 | user=username, 39 | password=password, 40 | config_file=client_config) 41 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 42 | 43 | print("return code:", result.request.error_code) 44 | print("return message:", result.request.error_message) 45 | 46 | for file_info in result.files_info: 47 | print(file_info.file_url) 48 | 49 | 50 | @click.command() 51 | @click.option("--user", help="user name") 52 | @click.option("--password", help="password name") 53 | @click.option("--server-id", help="server id") 54 | @click.option("--client-config", help="client config file path") 55 | def cli(user=None, password=None, server_id=None, client_config=None): 56 | if user is None or password is None: 57 | config = load_cmadaas_config() 58 | if user is None: 59 | user = config["auth"]["user"] 60 | if password is None: 61 | password = config["auth"]["password"] 62 | if server_id is None: 63 | server_id = config["server"]["music_ServiceId"] 64 | 65 | if client_config is None: 66 | client_config = get_client_config_path() 67 | 68 | query(username=user, password=password, server_id=server_id, client_config=client_config) 69 | 70 | 71 | if __name__ == "__main__": 72 | cli() 73 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_save_as_file_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "text" 34 | 35 | save_path = str(Path(get_output_directory(), "./output.txt")) 36 | 37 | client = CMADaaSClient( 38 | user=username, 39 | password=password, 40 | config_file=client_config) 41 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 42 | 43 | print("return code:", result.request.error_code) 44 | print("return message:", result.request.error_message) 45 | 46 | for file_info in result.files_info: 47 | print(file_info.file_url) 48 | 49 | 50 | @click.command() 51 | @click.option("--user", help="user name") 52 | @click.option("--password", help="password name") 53 | @click.option("--server-id", help="server id") 54 | @click.option("--client-config", help="client config file path") 55 | def cli(user=None, password=None, server_id=None, client_config=None): 56 | if user is None or password is None: 57 | config = load_cmadaas_config() 58 | if user is None: 59 | user = config["auth"]["user"] 60 | if password is None: 61 | password = config["auth"]["password"] 62 | if server_id is None: 63 | server_id = config["server"]["music_ServiceId"] 64 | 65 | if client_config is None: 66 | client_config = get_client_config_path() 67 | 68 | query(username=user, password=password, server_id=server_id, client_config=client_config) 69 | 70 | 71 | if __name__ == "__main__": 72 | cli() 73 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_save_as_file_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "xml" 34 | 35 | save_path = str(Path(get_output_directory(), "./output.xml")) 36 | 37 | client = CMADaaSClient( 38 | user=username, 39 | password=password, 40 | config_file=client_config) 41 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 42 | 43 | print("return code:", result.request.error_code) 44 | print("return message:", result.request.error_message) 45 | 46 | for file_info in result.files_info: 47 | print(file_info.file_url) 48 | 49 | 50 | @click.command() 51 | @click.option("--user", help="user name") 52 | @click.option("--password", help="password name") 53 | @click.option("--server-id", help="server id") 54 | @click.option("--client-config", help="client config file path") 55 | def cli(user=None, password=None, server_id=None, client_config=None): 56 | if user is None or password is None: 57 | config = load_cmadaas_config() 58 | if user is None: 59 | user = config["auth"]["user"] 60 | if password is None: 61 | password = config["auth"]["password"] 62 | if server_id is None: 63 | server_id = config["server"]["music_ServiceId"] 64 | 65 | if client_config is None: 66 | client_config = get_client_config_path() 67 | 68 | query(username=user, password=password, server_id=server_id, client_config=client_config) 69 | 70 | 71 | if __name__ == "__main__": 72 | cli() 73 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_serialized_str_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "html" 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 40 | 41 | print(result) 42 | 43 | 44 | @click.command() 45 | @click.option("--user", help="user name") 46 | @click.option("--password", help="password name") 47 | @click.option("--server-id", help="server id") 48 | @click.option("--client-config", help="client config file path") 49 | def cli(user=None, password=None, server_id=None, client_config=None): 50 | if user is None or password is None: 51 | config = load_cmadaas_config() 52 | if user is None: 53 | user = config["auth"]["user"] 54 | if password is None: 55 | password = config["auth"]["password"] 56 | if server_id is None: 57 | server_id = config["server"]["music_ServiceId"] 58 | 59 | if client_config is None: 60 | client_config = get_client_config_path() 61 | 62 | query(username=user, password=password, server_id=server_id, client_config=client_config) 63 | 64 | 65 | if __name__ == "__main__": 66 | cli() 67 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_serialized_str_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "json" 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 40 | 41 | print(result) 42 | 43 | 44 | @click.command() 45 | @click.option("--user", help="user name") 46 | @click.option("--password", help="password name") 47 | @click.option("--server-id", help="server id") 48 | @click.option("--client-config", help="client config file path") 49 | def cli(user=None, password=None, server_id=None, client_config=None): 50 | if user is None or password is None: 51 | config = load_cmadaas_config() 52 | if user is None: 53 | user = config["auth"]["user"] 54 | if password is None: 55 | password = config["auth"]["password"] 56 | if server_id is None: 57 | server_id = config["server"]["music_ServiceId"] 58 | 59 | if client_config is None: 60 | client_config = get_client_config_path() 61 | 62 | query(username=user, password=password, server_id=server_id, client_config=client_config) 63 | 64 | 65 | if __name__ == "__main__": 66 | cli() 67 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_serialized_str_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "text" 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 40 | 41 | print(result) 42 | 43 | 44 | @click.command() 45 | @click.option("--user", help="user name") 46 | @click.option("--password", help="password name") 47 | @click.option("--server-id", help="server id") 48 | @click.option("--client-config", help="client config file path") 49 | def cli(user=None, password=None, server_id=None, client_config=None): 50 | if user is None or password is None: 51 | config = load_cmadaas_config() 52 | if user is None: 53 | user = config["auth"]["user"] 54 | if password is None: 55 | password = config["auth"]["password"] 56 | if server_id is None: 57 | server_id = config["server"]["music_ServiceId"] 58 | 59 | if client_config is None: 60 | client_config = get_client_config_path() 61 | 62 | query(username=user, password=password, server_id=server_id, client_config=client_config) 63 | 64 | 65 | if __name__ == "__main__": 66 | cli() 67 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/grid_element_rect_search/grid_element_rect_search_serialized_str_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getNafpEleGridInRectByTimeAndLevelAndValidtime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_time = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "NAFP_FOR_FTM_LOW_EC_GLB", 22 | "time": yesterday_time, 23 | "validTime": "24", 24 | "minLat": "39", 25 | "maxLat": "42", 26 | "minLon": "115", 27 | "maxLon": "117", 28 | "fcstEle": "TEM", 29 | "levelType": "100", 30 | "fcstLevel": "850" 31 | } 32 | 33 | data_format = "xml" 34 | 35 | client = CMADaaSClient( 36 | user=username, 37 | password=password, 38 | config_file=client_config) 39 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 40 | 41 | print(result) 42 | 43 | 44 | @click.command() 45 | @click.option("--user", help="user name") 46 | @click.option("--password", help="password name") 47 | @click.option("--server-id", help="server id") 48 | @click.option("--client-config", help="client config file path") 49 | def cli(user=None, password=None, server_id=None, client_config=None): 50 | if user is None or password is None: 51 | config = load_cmadaas_config() 52 | if user is None: 53 | user = config["auth"]["user"] 54 | if password is None: 55 | password = config["auth"]["password"] 56 | if server_id is None: 57 | server_id = config["server"]["music_ServiceId"] 58 | 59 | if client_config is None: 60 | client_config = get_client_config_path() 61 | 62 | query(username=user, password=password, server_id=server_id, client_config=client_config) 63 | 64 | 65 | if __name__ == "__main__": 66 | cli() 67 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/save_as_file.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | from nuwe_cmadaas import CMADaaSClient 3 | import click 4 | 5 | 6 | @click.command() 7 | @click.option("--user", help="user name", required=True) 8 | @click.option("--password", help="password name", required=True) 9 | @click.option("--client-config", help="client config file") 10 | @click.option("--output-file", help="client config file", required=True) 11 | def cli(user, password, output_file, client_config=None): 12 | 13 | interface_id = "getSurfEleByTimeRange" 14 | 15 | server_id = "NMIC_MUSIC_CMADAAS" 16 | 17 | params = { 18 | "dataCode": "SURF_CHN_MUL_HOR", 19 | "elements": "Station_Id_d,Lat,Lon,Alti,Day,Hour,PRS_Sea,TEM," 20 | "DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS", 21 | "timeRange": "[20190817000000,20190817020000)", 22 | "orderby": "Station_ID_d:ASC", 23 | "limitCnt": "10", 24 | } 25 | 26 | client = CMADaaSClient( 27 | user=user, 28 | password=password, 29 | config_file=client_config 30 | ) 31 | result = client.callAPI_to_saveAsFile( 32 | interface_id, 33 | params, 34 | data_format="json", 35 | file_name=output_file 36 | ) 37 | 38 | print(result) 39 | 40 | 41 | if __name__ == "__main__": 42 | cli() 43 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/serialized_str.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | from nuwe_cmadaas import CMADaaSClient 3 | import click 4 | 5 | 6 | @click.command() 7 | @click.option("--user", help="user name", required=True) 8 | @click.option("--password", help="password name", required=True) 9 | @click.option("--client-config", help="client config file") 10 | def cli(user, password, client_config=None): 11 | 12 | interface_id = "getSurfEleByTimeRange" 13 | 14 | server_id = "NMIC_MUSIC_CMADAAS" 15 | 16 | params = { 17 | "dataCode": "SURF_CHN_MUL_HOR", 18 | "elements": "Station_Id_d,Lat,Lon,Alti,Day,Hour,PRS_Sea,TEM," 19 | "DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS", 20 | "timeRange": "[20190817000000,20190817020000)", 21 | "orderby": "Station_ID_d:ASC", 22 | "limitCnt": "10", 23 | } 24 | 25 | client = CMADaaSClient( 26 | user=user, 27 | password=password, 28 | config_file=client_config 29 | ) 30 | result = client.callAPI_to_serializedStr(interface_id, params, data_format="json") 31 | 32 | print(result) 33 | 34 | 35 | if __name__ == "__main__": 36 | cli() 37 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/station_element_search/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_array_2d.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getSurfEleByTime" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | times = get_time_string(yesterday) 17 | 18 | params = { 19 | "dataCode": "SURF_CHN_MUL_HOR", 20 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 21 | "times": times, 22 | "orderby": "Station_ID_d:ASC", 23 | "limitCnt": "10", 24 | } 25 | 26 | client = CMADaaSClient( 27 | user=username, 28 | password=password, 29 | config_file=client_config) 30 | result = client.callAPI_to_array2D(interface_id, params, server_id) 31 | 32 | print("return code:", result.request.error_code) 33 | print("return message:", result.request.error_message) 34 | 35 | print(np.array(result.data)) 36 | 37 | 38 | @click.command() 39 | @click.option("--user", help="user name") 40 | @click.option("--password", help="password name") 41 | @click.option("--server-id", help="server id") 42 | @click.option("--client-config", help="client config file path") 43 | def cli(user=None, password=None, server_id=None, client_config=None): 44 | if user is None or password is None: 45 | config = load_cmadaas_config() 46 | if user is None: 47 | user = config["auth"]["user"] 48 | if password is None: 49 | password = config["auth"]["password"] 50 | if server_id is None: 51 | server_id = config["server"]["music_ServiceId"] 52 | 53 | if client_config is None: 54 | client_config = get_client_config_path() 55 | 56 | query(username=user, password=password, server_id=server_id, client_config=client_config) 57 | 58 | 59 | if __name__ == "__main__": 60 | cli() 61 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_save_as_file_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "html" 29 | 30 | save_path = str(Path(get_output_directory(), "./output.html")) 31 | 32 | client = CMADaaSClient( 33 | user=username, 34 | password=password, 35 | config_file=client_config) 36 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 37 | 38 | print("return code:", result.request.error_code) 39 | print("return message:", result.request.error_message) 40 | 41 | for file_info in result.files_info: 42 | print(file_info.file_url) 43 | 44 | 45 | @click.command() 46 | @click.option("--user", help="user name") 47 | @click.option("--password", help="password name") 48 | @click.option("--server-id", help="server id") 49 | @click.option("--client-config", help="client config file path") 50 | def cli(user=None, password=None, server_id=None, client_config=None): 51 | if user is None or password is None: 52 | config = load_cmadaas_config() 53 | if user is None: 54 | user = config["auth"]["user"] 55 | if password is None: 56 | password = config["auth"]["password"] 57 | if server_id is None: 58 | server_id = config["server"]["music_ServiceId"] 59 | 60 | if client_config is None: 61 | client_config = get_client_config_path() 62 | 63 | query(username=user, password=password, server_id=server_id, client_config=client_config) 64 | 65 | 66 | if __name__ == "__main__": 67 | cli() 68 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_save_as_file_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "json" 29 | 30 | save_path = str(Path(get_output_directory(), "./output.json")) 31 | 32 | client = CMADaaSClient( 33 | user=username, 34 | password=password, 35 | config_file=client_config) 36 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 37 | 38 | print("return code:", result.request.error_code) 39 | print("return message:", result.request.error_message) 40 | 41 | for file_info in result.files_info: 42 | print(file_info.file_url) 43 | 44 | 45 | @click.command() 46 | @click.option("--user", help="user name") 47 | @click.option("--password", help="password name") 48 | @click.option("--server-id", help="server id") 49 | @click.option("--client-config", help="client config file path") 50 | def cli(user=None, password=None, server_id=None, client_config=None): 51 | if user is None or password is None: 52 | config = load_cmadaas_config() 53 | if user is None: 54 | user = config["auth"]["user"] 55 | if password is None: 56 | password = config["auth"]["password"] 57 | if server_id is None: 58 | server_id = config["server"]["music_ServiceId"] 59 | 60 | if client_config is None: 61 | client_config = get_client_config_path() 62 | 63 | query(username=user, password=password, server_id=server_id, client_config=client_config) 64 | 65 | 66 | if __name__ == "__main__": 67 | cli() 68 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_save_as_file_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "text" 29 | 30 | save_path = str(Path(get_output_directory(), "./output.txt")) 31 | 32 | client = CMADaaSClient( 33 | user=username, 34 | password=password, 35 | config_file=client_config) 36 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 37 | 38 | print("return code:", result.request.error_code) 39 | print("return message:", result.request.error_message) 40 | 41 | for file_info in result.files_info: 42 | print(file_info.file_url) 43 | 44 | 45 | @click.command() 46 | @click.option("--user", help="user name") 47 | @click.option("--password", help="password name") 48 | @click.option("--server-id", help="server id") 49 | @click.option("--client-config", help="client config file path") 50 | def cli(user=None, password=None, server_id=None, client_config=None): 51 | if user is None or password is None: 52 | config = load_cmadaas_config() 53 | if user is None: 54 | user = config["auth"]["user"] 55 | if password is None: 56 | password = config["auth"]["password"] 57 | if server_id is None: 58 | server_id = config["server"]["music_ServiceId"] 59 | 60 | if client_config is None: 61 | client_config = get_client_config_path() 62 | 63 | query(username=user, password=password, server_id=server_id, client_config=client_config) 64 | 65 | 66 | if __name__ == "__main__": 67 | cli() 68 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_save_as_file_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "xml" 29 | 30 | save_path = str(Path(get_output_directory(), "./output.xml")) 31 | 32 | client = CMADaaSClient( 33 | user=username, 34 | password=password, 35 | config_file=client_config) 36 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 37 | 38 | print("return code:", result.request.error_code) 39 | print("return message:", result.request.error_message) 40 | 41 | for file_info in result.files_info: 42 | print(file_info.file_url) 43 | 44 | 45 | @click.command() 46 | @click.option("--user", help="user name") 47 | @click.option("--password", help="password name") 48 | @click.option("--server-id", help="server id") 49 | @click.option("--client-config", help="client config file path") 50 | def cli(user=None, password=None, server_id=None, client_config=None): 51 | if user is None or password is None: 52 | config = load_cmadaas_config() 53 | if user is None: 54 | user = config["auth"]["user"] 55 | if password is None: 56 | password = config["auth"]["password"] 57 | if server_id is None: 58 | server_id = config["server"]["music_ServiceId"] 59 | 60 | if client_config is None: 61 | client_config = get_client_config_path() 62 | 63 | query(username=user, password=password, server_id=server_id, client_config=client_config) 64 | 65 | 66 | if __name__ == "__main__": 67 | cli() 68 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_serialized_str_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "html" 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 35 | 36 | print(result) 37 | 38 | 39 | @click.command() 40 | @click.option("--user", help="user name") 41 | @click.option("--password", help="password name") 42 | @click.option("--server-id", help="server id") 43 | @click.option("--client-config", help="client config file path") 44 | def cli(user=None, password=None, server_id=None, client_config=None): 45 | if user is None or password is None: 46 | config = load_cmadaas_config() 47 | if user is None: 48 | user = config["auth"]["user"] 49 | if password is None: 50 | password = config["auth"]["password"] 51 | if server_id is None: 52 | server_id = config["server"]["music_ServiceId"] 53 | 54 | if client_config is None: 55 | client_config = get_client_config_path() 56 | 57 | query(username=user, password=password, server_id=server_id, client_config=client_config) 58 | 59 | 60 | if __name__ == "__main__": 61 | cli() 62 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_serialized_str_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "json" 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 35 | 36 | print(result) 37 | 38 | 39 | @click.command() 40 | @click.option("--user", help="user name") 41 | @click.option("--password", help="password name") 42 | @click.option("--server-id", help="server id") 43 | @click.option("--client-config", help="client config file path") 44 | def cli(user=None, password=None, server_id=None, client_config=None): 45 | if user is None or password is None: 46 | config = load_cmadaas_config() 47 | if user is None: 48 | user = config["auth"]["user"] 49 | if password is None: 50 | password = config["auth"]["password"] 51 | if server_id is None: 52 | server_id = config["server"]["music_ServiceId"] 53 | 54 | if client_config is None: 55 | client_config = get_client_config_path() 56 | 57 | query(username=user, password=password, server_id=server_id, client_config=client_config) 58 | 59 | 60 | if __name__ == "__main__": 61 | cli() 62 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_serialized_str_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "text" 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 35 | 36 | print(result) 37 | 38 | 39 | @click.command() 40 | @click.option("--user", help="user name") 41 | @click.option("--password", help="password name") 42 | @click.option("--server-id", help="server id") 43 | @click.option("--client-config", help="client config file path") 44 | def cli(user=None, password=None, server_id=None, client_config=None): 45 | if user is None or password is None: 46 | config = load_cmadaas_config() 47 | if user is None: 48 | user = config["auth"]["user"] 49 | if password is None: 50 | password = config["auth"]["password"] 51 | if server_id is None: 52 | server_id = config["server"]["music_ServiceId"] 53 | 54 | if client_config is None: 55 | client_config = get_client_config_path() 56 | 57 | query(username=user, password=password, server_id=server_id, client_config=client_config) 58 | 59 | 60 | if __name__ == "__main__": 61 | cli() 62 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_search/station_element_search_serialized_str_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getSurfEleByTime" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | times = get_time_string(yesterday) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,PRE_1h,PRS,RHU,VIS,WIN_S_Avg_2mi,WIN_D_Avg_2mi,Q_PRS", 23 | "times": times, 24 | "orderby": "Station_ID_d:ASC", 25 | "limitCnt": "10", 26 | } 27 | 28 | data_format = "xml" 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 35 | 36 | print(result) 37 | 38 | 39 | @click.command() 40 | @click.option("--user", help="user name") 41 | @click.option("--password", help="password name") 42 | @click.option("--server-id", help="server id") 43 | @click.option("--client-config", help="client config file path") 44 | def cli(user=None, password=None, server_id=None, client_config=None): 45 | if user is None or password is None: 46 | config = load_cmadaas_config() 47 | if user is None: 48 | user = config["auth"]["user"] 49 | if password is None: 50 | password = config["auth"]["password"] 51 | if server_id is None: 52 | server_id = config["server"]["music_ServiceId"] 53 | 54 | if client_config is None: 55 | client_config = get_client_config_path() 56 | 57 | query(username=user, password=password, server_id=server_id, client_config=client_config) 58 | 59 | 60 | if __name__ == "__main__": 61 | cli() 62 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/station_element_statistics/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_array_2d.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "statSurfEle" 14 | 15 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 16 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 17 | yesterday_time = get_time_string(yesterday) 18 | yesterday_utc01_time = get_time_string(yesterday_utc01) 19 | 20 | params = { 21 | "dataCode": "SURF_CHN_MUL_HOR", 22 | "elements": "Station_ID_C,Station_Name", 23 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 24 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 25 | "orderBy": "SUM_PRE_1h:desc", 26 | "limitCnt": "10", 27 | } 28 | 29 | client = CMADaaSClient( 30 | user=username, 31 | password=password, 32 | config_file=client_config) 33 | result = client.callAPI_to_array2D(interface_id, params, server_id) 34 | 35 | print("return code:", result.request.error_code) 36 | print("return message:", result.request.error_message) 37 | 38 | print(np.array(result.data)) 39 | 40 | 41 | @click.command() 42 | @click.option("--user", help="user name") 43 | @click.option("--password", help="password name") 44 | @click.option("--server-id", help="server id") 45 | @click.option("--client-config", help="client config file path") 46 | def cli(user=None, password=None, server_id=None, client_config=None): 47 | if user is None or password is None: 48 | config = load_cmadaas_config() 49 | if user is None: 50 | user = config["auth"]["user"] 51 | if password is None: 52 | password = config["auth"]["password"] 53 | if server_id is None: 54 | server_id = config["server"]["music_ServiceId"] 55 | 56 | if client_config is None: 57 | client_config = get_client_config_path() 58 | 59 | query(username=user, password=password, server_id=server_id, client_config=client_config) 60 | 61 | 62 | if __name__ == "__main__": 63 | cli() 64 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_save_as_file_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | } 29 | 30 | data_format = "html" 31 | 32 | save_path = str(Path(get_output_directory(), "./output.html")) 33 | 34 | client = CMADaaSClient( 35 | user=username, 36 | password=password, 37 | config_file=client_config) 38 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 39 | 40 | print("return code:", result.request.error_code) 41 | print("return message:", result.request.error_message) 42 | 43 | for file_info in result.files_info: 44 | print(file_info.file_url) 45 | 46 | 47 | @click.command() 48 | @click.option("--user", help="user name") 49 | @click.option("--password", help="password name") 50 | @click.option("--server-id", help="server id") 51 | @click.option("--client-config", help="client config file path") 52 | def cli(user=None, password=None, server_id=None, client_config=None): 53 | if user is None or password is None: 54 | config = load_cmadaas_config() 55 | if user is None: 56 | user = config["auth"]["user"] 57 | if password is None: 58 | password = config["auth"]["password"] 59 | if server_id is None: 60 | server_id = config["server"]["music_ServiceId"] 61 | 62 | if client_config is None: 63 | client_config = get_client_config_path() 64 | 65 | query(username=user, password=password, server_id=server_id, client_config=client_config) 66 | 67 | 68 | if __name__ == "__main__": 69 | cli() 70 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_save_as_file_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | } 29 | 30 | data_format = "json" 31 | 32 | save_path = str(Path(get_output_directory(), "./output.json")) 33 | 34 | client = CMADaaSClient( 35 | user=username, 36 | password=password, 37 | config_file=client_config) 38 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 39 | 40 | print("return code:", result.request.error_code) 41 | print("return message:", result.request.error_message) 42 | 43 | for file_info in result.files_info: 44 | print(file_info.file_url) 45 | 46 | 47 | @click.command() 48 | @click.option("--user", help="user name") 49 | @click.option("--password", help="password name") 50 | @click.option("--server-id", help="server id") 51 | @click.option("--client-config", help="client config file path") 52 | def cli(user=None, password=None, server_id=None, client_config=None): 53 | if user is None or password is None: 54 | config = load_cmadaas_config() 55 | if user is None: 56 | user = config["auth"]["user"] 57 | if password is None: 58 | password = config["auth"]["password"] 59 | if server_id is None: 60 | server_id = config["server"]["music_ServiceId"] 61 | 62 | if client_config is None: 63 | client_config = get_client_config_path() 64 | 65 | query(username=user, password=password, server_id=server_id, client_config=client_config) 66 | 67 | 68 | if __name__ == "__main__": 69 | cli() 70 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_save_as_file_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | } 29 | 30 | data_format = "text" 31 | 32 | save_path = str(Path(get_output_directory(), "./output.txt")) 33 | 34 | client = CMADaaSClient( 35 | user=username, 36 | password=password, 37 | config_file=client_config) 38 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 39 | 40 | print("return code:", result.request.error_code) 41 | print("return message:", result.request.error_message) 42 | 43 | for file_info in result.files_info: 44 | print(file_info.file_url) 45 | 46 | 47 | @click.command() 48 | @click.option("--user", help="user name") 49 | @click.option("--password", help="password name") 50 | @click.option("--server-id", help="server id") 51 | @click.option("--client-config", help="client config file path") 52 | def cli(user=None, password=None, server_id=None, client_config=None): 53 | if user is None or password is None: 54 | config = load_cmadaas_config() 55 | if user is None: 56 | user = config["auth"]["user"] 57 | if password is None: 58 | password = config["auth"]["password"] 59 | if server_id is None: 60 | server_id = config["server"]["music_ServiceId"] 61 | 62 | if client_config is None: 63 | client_config = get_client_config_path() 64 | 65 | query(username=user, password=password, server_id=server_id, client_config=client_config) 66 | 67 | 68 | if __name__ == "__main__": 69 | cli() 70 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_save_as_file_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | } 29 | 30 | data_format = "xml" 31 | 32 | save_path = str(Path(get_output_directory(), "./output.xml")) 33 | 34 | client = CMADaaSClient( 35 | user=username, 36 | password=password, 37 | config_file=client_config) 38 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 39 | 40 | print("return code:", result.request.error_code) 41 | print("return message:", result.request.error_message) 42 | 43 | for file_info in result.files_info: 44 | print(file_info.file_url) 45 | 46 | 47 | @click.command() 48 | @click.option("--user", help="user name") 49 | @click.option("--password", help="password name") 50 | @click.option("--server-id", help="server id") 51 | @click.option("--client-config", help="client config file path") 52 | def cli(user=None, password=None, server_id=None, client_config=None): 53 | if user is None or password is None: 54 | config = load_cmadaas_config() 55 | if user is None: 56 | user = config["auth"]["user"] 57 | if password is None: 58 | password = config["auth"]["password"] 59 | if server_id is None: 60 | server_id = config["server"]["music_ServiceId"] 61 | 62 | if client_config is None: 63 | client_config = get_client_config_path() 64 | 65 | query(username=user, password=password, server_id=server_id, client_config=client_config) 66 | 67 | 68 | if __name__ == "__main__": 69 | cli() 70 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_serialized_str_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | "limitCnt": "10", 29 | } 30 | 31 | data_format = "html" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_serialized_str_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | "limitCnt": "10", 29 | } 30 | 31 | data_format = "json" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_serialized_str_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | "limitCnt": "10", 29 | } 30 | 31 | data_format = "text" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_element_statistics/station_element_statistics_serialized_str_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "statSurfEle" 16 | 17 | yesterday = pd.Timestamp.now().floor(freq="D") - pd.Timedelta(days=1) 18 | yesterday_utc01 = yesterday + pd.Timedelta(hours=6) 19 | yesterday_time = get_time_string(yesterday) 20 | yesterday_utc01_time = get_time_string(yesterday_utc01) 21 | 22 | params = { 23 | "dataCode": "SURF_CHN_MUL_HOR", 24 | "elements": "Station_ID_C,Station_Name", 25 | "statEles": "SUM_PRE_1h,AVG_PRE_1h,SUM_TEM,AVG_TEM", 26 | "timeRange": f"[{yesterday_time},{yesterday_utc01_time}]", 27 | "orderBy": "SUM_PRE_1h:desc", 28 | "limitCnt": "10", 29 | } 30 | 31 | data_format = "xml" 32 | 33 | client = CMADaaSClient( 34 | user=username, 35 | password=password, 36 | config_file=client_config) 37 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 38 | 39 | print(result) 40 | 41 | 42 | @click.command() 43 | @click.option("--user", help="user name") 44 | @click.option("--password", help="password name") 45 | @click.option("--server-id", help="server id") 46 | @click.option("--client-config", help="client config file path") 47 | def cli(user=None, password=None, server_id=None, client_config=None): 48 | if user is None or password is None: 49 | config = load_cmadaas_config() 50 | if user is None: 51 | user = config["auth"]["user"] 52 | if password is None: 53 | password = config["auth"]["password"] 54 | if server_id is None: 55 | server_id = config["server"]["music_ServiceId"] 56 | 57 | if client_config is None: 58 | client_config = get_client_config_path() 59 | 60 | query(username=user, password=password, server_id=server_id, client_config=client_config) 61 | 62 | 63 | if __name__ == "__main__": 64 | cli() 65 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/music/station_info_search/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_array_2d.py: -------------------------------------------------------------------------------- 1 | import click 2 | import pandas as pd 3 | import numpy as np 4 | 5 | from nuwe_cmadaas import CMADaaSClient 6 | from nuwe_cmadaas.config import load_cmadaas_config 7 | from nuwe_cmadaas.util import get_time_string 8 | 9 | from nuwe_cmadaas_example.util import get_client_config_path 10 | 11 | 12 | def query(username: str, password: str, server_id: str, client_config: str): 13 | interface_id = "getStaInfoInRect" 14 | 15 | params = { 16 | "dataCode": "STA_INFO_SURF_CHN", 17 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 18 | "minLat": "39", 19 | "maxLat": "42", 20 | "minLon": "115", 21 | "maxLon": "117" 22 | } 23 | 24 | client = CMADaaSClient( 25 | user=username, 26 | password=password, 27 | config_file=client_config) 28 | result = client.callAPI_to_array2D(interface_id, params, server_id) 29 | 30 | print("return code:", result.request.error_code) 31 | print("return message:", result.request.error_message) 32 | 33 | print(np.array(result.data)) 34 | 35 | 36 | @click.command() 37 | @click.option("--user", help="user name") 38 | @click.option("--password", help="password name") 39 | @click.option("--server-id", help="server id") 40 | @click.option("--client-config", help="client config file path") 41 | def cli(user=None, password=None, server_id=None, client_config=None): 42 | if user is None or password is None: 43 | config = load_cmadaas_config() 44 | if user is None: 45 | user = config["auth"]["user"] 46 | if password is None: 47 | password = config["auth"]["password"] 48 | if server_id is None: 49 | server_id = config["server"]["music_ServiceId"] 50 | 51 | if client_config is None: 52 | client_config = get_client_config_path() 53 | 54 | query(username=user, password=password, server_id=server_id, client_config=client_config) 55 | 56 | 57 | if __name__ == "__main__": 58 | cli() 59 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_save_as_file_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "html" 27 | 28 | save_path = str(Path(get_output_directory(), "./output.html")) 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 35 | 36 | print("return code:", result.request.error_code) 37 | print("return message:", result.request.error_message) 38 | 39 | for file_info in result.files_info: 40 | print(file_info.file_url) 41 | 42 | 43 | @click.command() 44 | @click.option("--user", help="user name") 45 | @click.option("--password", help="password name") 46 | @click.option("--server-id", help="server id") 47 | @click.option("--client-config", help="client config file path") 48 | def cli(user=None, password=None, server_id=None, client_config=None): 49 | if user is None or password is None: 50 | config = load_cmadaas_config() 51 | if user is None: 52 | user = config["auth"]["user"] 53 | if password is None: 54 | password = config["auth"]["password"] 55 | if server_id is None: 56 | server_id = config["server"]["music_ServiceId"] 57 | 58 | if client_config is None: 59 | client_config = get_client_config_path() 60 | 61 | query(username=user, password=password, server_id=server_id, client_config=client_config) 62 | 63 | 64 | if __name__ == "__main__": 65 | cli() 66 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_save_as_file_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "json" 27 | 28 | save_path = str(Path(get_output_directory(), "./output.json")) 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 35 | 36 | print("return code:", result.request.error_code) 37 | print("return message:", result.request.error_message) 38 | 39 | for file_info in result.files_info: 40 | print(file_info.file_url) 41 | 42 | 43 | @click.command() 44 | @click.option("--user", help="user name") 45 | @click.option("--password", help="password name") 46 | @click.option("--server-id", help="server id") 47 | @click.option("--client-config", help="client config file path") 48 | def cli(user=None, password=None, server_id=None, client_config=None): 49 | if user is None or password is None: 50 | config = load_cmadaas_config() 51 | if user is None: 52 | user = config["auth"]["user"] 53 | if password is None: 54 | password = config["auth"]["password"] 55 | if server_id is None: 56 | server_id = config["server"]["music_ServiceId"] 57 | 58 | if client_config is None: 59 | client_config = get_client_config_path() 60 | 61 | query(username=user, password=password, server_id=server_id, client_config=client_config) 62 | 63 | 64 | if __name__ == "__main__": 65 | cli() 66 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_save_as_file_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "text" 27 | 28 | save_path = str(Path(get_output_directory(), "./output.txt")) 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 35 | 36 | print("return code:", result.request.error_code) 37 | print("return message:", result.request.error_message) 38 | 39 | for file_info in result.files_info: 40 | print(file_info.file_url) 41 | 42 | 43 | @click.command() 44 | @click.option("--user", help="user name") 45 | @click.option("--password", help="password name") 46 | @click.option("--server-id", help="server id") 47 | @click.option("--client-config", help="client config file path") 48 | def cli(user=None, password=None, server_id=None, client_config=None): 49 | if user is None or password is None: 50 | config = load_cmadaas_config() 51 | if user is None: 52 | user = config["auth"]["user"] 53 | if password is None: 54 | password = config["auth"]["password"] 55 | if server_id is None: 56 | server_id = config["server"]["music_ServiceId"] 57 | 58 | if client_config is None: 59 | client_config = get_client_config_path() 60 | 61 | query(username=user, password=password, server_id=server_id, client_config=client_config) 62 | 63 | 64 | if __name__ == "__main__": 65 | cli() 66 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_save_as_file_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "xml" 27 | 28 | save_path = str(Path(get_output_directory(), "./output.xml")) 29 | 30 | client = CMADaaSClient( 31 | user=username, 32 | password=password, 33 | config_file=client_config) 34 | result = client.callAPI_to_saveAsFile(interface_id, params, data_format, save_path, server_id) 35 | 36 | print("return code:", result.request.error_code) 37 | print("return message:", result.request.error_message) 38 | 39 | for file_info in result.files_info: 40 | print(file_info.file_url) 41 | 42 | 43 | @click.command() 44 | @click.option("--user", help="user name") 45 | @click.option("--password", help="password name") 46 | @click.option("--server-id", help="server id") 47 | @click.option("--client-config", help="client config file path") 48 | def cli(user=None, password=None, server_id=None, client_config=None): 49 | if user is None or password is None: 50 | config = load_cmadaas_config() 51 | if user is None: 52 | user = config["auth"]["user"] 53 | if password is None: 54 | password = config["auth"]["password"] 55 | if server_id is None: 56 | server_id = config["server"]["music_ServiceId"] 57 | 58 | if client_config is None: 59 | client_config = get_client_config_path() 60 | 61 | query(username=user, password=password, server_id=server_id, client_config=client_config) 62 | 63 | 64 | if __name__ == "__main__": 65 | cli() 66 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_serialized_str_html.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "html" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_serialized_str_json.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "json" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_serialized_str_text.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "text" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/music/station_info_search/station_info_search_serialized_str_xml.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import click 4 | import pandas as pd 5 | import numpy as np 6 | 7 | from nuwe_cmadaas import CMADaaSClient 8 | from nuwe_cmadaas.config import load_cmadaas_config 9 | from nuwe_cmadaas.util import get_time_string 10 | 11 | from nuwe_cmadaas_example.util import get_client_config_path, get_output_directory 12 | 13 | 14 | def query(username: str, password: str, server_id: str, client_config: str): 15 | interface_id = "getStaInfoInRect" 16 | 17 | params = { 18 | "dataCode": "STA_INFO_SURF_CHN", 19 | "elements": "Station_ID_C,Station_Name,Lat,Lon,Alti", 20 | "minLat": "39", 21 | "maxLat": "42", 22 | "minLon": "115", 23 | "maxLon": "117" 24 | } 25 | 26 | data_format = "xml" 27 | 28 | client = CMADaaSClient( 29 | user=username, 30 | password=password, 31 | config_file=client_config) 32 | result = client.callAPI_to_serializedStr(interface_id, params, data_format, server_id) 33 | 34 | print(result) 35 | 36 | 37 | @click.command() 38 | @click.option("--user", help="user name") 39 | @click.option("--password", help="password name") 40 | @click.option("--server-id", help="server id") 41 | @click.option("--client-config", help="client config file path") 42 | def cli(user=None, password=None, server_id=None, client_config=None): 43 | if user is None or password is None: 44 | config = load_cmadaas_config() 45 | if user is None: 46 | user = config["auth"]["user"] 47 | if password is None: 48 | password = config["auth"]["password"] 49 | if server_id is None: 50 | server_id = config["server"]["music_ServiceId"] 51 | 52 | if client_config is None: 53 | client_config = get_client_config_path() 54 | 55 | query(username=user, password=password, server_id=server_id, client_config=client_config) 56 | 57 | 58 | if __name__ == "__main__": 59 | cli() 60 | -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/nuwe/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/nuwe/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/nuwe/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/nuwe/model/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/nuwe/model/cma_gfs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/nuwe/model/cma_gfs/__init__.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/nuwe/model/cma_gfs/gfs_grid.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/example/nuwe_cmadaas_example/nuwe/model/cma_gfs/gfs_grid.py -------------------------------------------------------------------------------- /example/nuwe_cmadaas_example/util.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | 4 | def get_output_directory() -> Path: 5 | output_directory = Path(Path(__file__).parent.parent, "./output") 6 | output_directory.mkdir(parents=True, exist_ok=True) 7 | return output_directory 8 | 9 | 10 | def get_client_config_path() -> Path: 11 | config_file_path = Path(Path(__file__).parent.parent, "./config/client.config") 12 | if not config_file_path.exists(): 13 | raise FileNotFoundError(f"client.config is not found, create the file in {config_file_path}") 14 | return config_file_path 15 | -------------------------------------------------------------------------------- /example/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=64"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "nuwe-cmadaas-example" 7 | authors = [ 8 | {name="Wang Dapeng", email="perillaroc@gmail.com"} 9 | ] 10 | description = "An example project for nuwe-cmadaas-python." 11 | readme = "README.md" 12 | keywords = ["music", "cmadaas"] 13 | classifiers = [ 14 | "Development Status :: 3 - Alpha", 15 | 16 | "Intended Audience :: Developers", 17 | 18 | 'License :: OSI Approved :: Apache Software License', 19 | 20 | "Programming Language :: Python :: 3.11", 21 | "Programming Language :: Python :: 3.12", 22 | ] 23 | dependencies = [ 24 | "nuwe-cmadaas", 25 | "click", 26 | 'importlib-metadata; python_version<"3.8"', 27 | ] 28 | version = "2024.1" 29 | 30 | [project.urls] 31 | Homepage = "https://github.com/perillaroc/nuwe-cmadaas-python" 32 | Repository = "https://github.com/perillaroc/nuwe-cmadaas-python.git" 33 | 34 | [tool.setuptools.packages.find] 35 | where = ["."] 36 | exclude = [ 37 | "tests", 38 | "*.tests", 39 | "*.tests.*", 40 | "tests.*", 41 | "docs", 42 | "conf", 43 | ] 44 | namespaces = false 45 | 46 | [tool.setuptools] 47 | include-package-data = true 48 | -------------------------------------------------------------------------------- /nuwe_cmadaas/__init__.py: -------------------------------------------------------------------------------- 1 | from .music import ( 2 | Array2D, 3 | GridArray2D, 4 | FilesInfo, 5 | FileInfo, 6 | GridScalar2D, 7 | GridVector2D, 8 | DataBlock, 9 | CMADaaSClient 10 | ) 11 | 12 | from .config import CMADaasConfig 13 | 14 | from .obs import ( 15 | retrieve_obs_station 16 | ) 17 | from .model import ( 18 | retrieve_model_point, 19 | retrieve_model_grid, 20 | ) 21 | 22 | from importlib.metadata import version, PackageNotFoundError 23 | 24 | try: 25 | __version__ = version("nuwe-cmadaas") 26 | except PackageNotFoundError: 27 | # package is not installed 28 | pass 29 | -------------------------------------------------------------------------------- /nuwe_cmadaas/_log.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | 4 | def get_logger(name): 5 | try: 6 | from loguru import logger 7 | return logger 8 | except ImportError: 9 | logger = logging.getLogger(name) 10 | return logger 11 | 12 | logger = get_logger(__name__) 13 | -------------------------------------------------------------------------------- /nuwe_cmadaas/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import Optional, Dict, Union, TypedDict 3 | from pathlib import Path 4 | 5 | import yaml 6 | 7 | 8 | CONFIG_ENV_NAME = "CEDARKIT_CONFIG" 9 | 10 | 11 | class AuthItem(TypedDict): 12 | user: str 13 | password: str 14 | 15 | 16 | class ServerItem(TypedDict): 17 | music_server: str 18 | music_port: int 19 | music_connTimeout: int 20 | music_readTimeout: int 21 | music_ServiceId: int 22 | 23 | 24 | class CMADaasConfig(TypedDict): 25 | auth: AuthItem 26 | server: ServerItem 27 | 28 | 29 | def load_cmadaas_config(file_path: Optional[Union[str, Path]] = None) -> CMADaasConfig: 30 | path = _get_cedarkit_config_path(file_path) 31 | with open(path) as f: 32 | config = yaml.safe_load(f) 33 | return config["cmadaas"] 34 | 35 | 36 | def _get_cedarkit_config_path(file_path: Optional[Union[str, Path]] = None) -> Union[str, Path]: 37 | if file_path is None: 38 | if CONFIG_ENV_NAME in os.environ: 39 | return os.environ[CONFIG_ENV_NAME] 40 | path = Path(Path.home(), ".config/cedarkit.yaml") 41 | return path 42 | else: 43 | return file_path 44 | -------------------------------------------------------------------------------- /nuwe_cmadaas/data/datasets/station.yaml: -------------------------------------------------------------------------------- 1 | SURF_CHN_MUL_HOR: 2 | long_name: "中国地面逐小时资料" 3 | elements: "Station_Id_d,Lat,Lon,Alti,Year,Mon,Day,Hour,PRS_Sea,TEM,DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS" 4 | 5 | SURF_CHN_MUL_HOR_N: 6 | long_name: "中国地面逐小时资料(国家站)" 7 | elements: "Station_Id_d,Lat,Lon,Alti,Year,Mon,Day,Hour,PRS_Sea,TEM,DPT,WIN_D_INST,WIN_S_INST,PRE_1h,PRE_6h,PRE_24h,PRS" 8 | 9 | SURF_CHN_MUL_DAY: 10 | long_name: "中国地面日值数据" 11 | elements: "Station_Id_d,Lat,Lon,Alti,Year,Mon,Day,PRS_Sea_Avg,TEM_Avg,TEM_Max,TEM_Min" 12 | 13 | SURF_CHN_MUL_MON: 14 | long_name: "中国地面月值数据(区域站)" 15 | elements: "Station_Id_d,Lat,Lon,Alti,Year,Mon,PRS_Sea_Avg,TEM_Avg,TEM_Max_Avg,TEM_Min_Avg" 16 | -------------------------------------------------------------------------------- /nuwe_cmadaas/data/datasets/upper_air.yaml: -------------------------------------------------------------------------------- 1 | UPAR_GLB_MUL_FTM: 2 | long_name: "全球高空定时值资料" 3 | elements: "Station_Id_d,Lat,Lon,Alti,Day,Hour,Min,PRS_HWC,EVSS,GPH,TEM,DPT,WIN_D,WIN_S,Time_Dev_WQ,Lat_Dev,Lon_Dev,Q_PRS_HWC,Q_GPH,Q_TEM,Q_DPT,Q_WIN_D,Q_WIN_S" 4 | order_by: "Station_Id_d:asc" 5 | 6 | UPAR_CHN_MUL_FTM: 7 | long_name: "中国高空定时值资料" 8 | elements: "Station_Id_d,Lat,Lon,Alti,Day,Hour,Min,PRS_HWC,EVSS,GPH,TEM,DPT,WIN_D,WIN_S,Time_Dev_WQ,Lat_Dev,Lon_Dev,Q_PRS_HWC,Q_GPH,Q_TEM,Q_DPT,Q_WIN_D,Q_WIN_S" 9 | order_by: "Station_Id_d:asc" 10 | 11 | UPAR_ARD_G_MUT_AMD: 12 | long_name: "全球飞机高空探测资料" 13 | elements: "Lat,Lon,Day,Hour,Min,Flight_Stat,Flight_Heigh,TEM,WIN_D,WIN_S,Q_Flight_Heigh,Q_TEM,Q_WIN_D,Q_WIN_S,Station_Id_C" 14 | 15 | UPAR_ARD_GLB_MUT_AMD_BUFR: 16 | long_name: "全球飞机高空探测资料 (BUFR格式)" 17 | elements: "Lat,Lon,Day,Hour,Min,Flight_Stat,Flight_Heigh,TEM,WIN_D,WIN_S,Q_Flight_Heigh,Q_TEM,Q_WIN_D,Q_WIN_S,Station_Id_C" 18 | 19 | UPAR_GLB_MUL_MON: 20 | long_name: "全球高空月值数据" 21 | elements: "Station_Id_d,Lat,Lon,Alti,Year,Mon,PRS_HWC,EVSS,GPH,TEM_Avg" 22 | order_by: "Station_Id_d:asc" 23 | 24 | UPAR_GLB_MUL_TEN: 25 | long_name: "全球高空旬值数据" 26 | elements: "Station_Id_d,Lat,Lon,Alti,Year,Mon,PRS_HWC,EVSS,GPH,TEM_Avg" 27 | order_by: "Station_Id_d:asc" 28 | 29 | UPAR_CHN_GPSMET_MUL: 30 | long_name: "中国GPS/MET数据要素" 31 | elements: "Station_Id_C,Lat,Lon,Alti,Year,Mon,Day,Hour,Station_Id_d,Min,PRS,TEM,RHU" 32 | interface_data_type: "UparGps" 33 | 34 | UPAR_ADTD_CHN_LIS: 35 | long_name: "国家雷电探测系统闪电定位数据" 36 | elements: "D_SOURCE_ID,DATA_ID,IYMDHM,RYMDHM,UPDATE_TIME,Datetime,Lat,Lon,Year,Mon,Day,Hour,Min,Second,MSecond,Layer_Num,Pois_Err,Lit_Current,MARS_3,Pois_Type,Lit_Prov,Lit_City,Lit_Cnty,REP_CORR_ID,V33257,Equp_Model,V25300,Alti,V25301,V73001" 37 | interface_data_type: "UparLight" 38 | 39 | UPAR_WPR_HOR: 40 | long_name: "风廓线雷达小时平均产品文件" 41 | elements: "Station_Id_C,Lat,Lon,Alti,D_FILE_ID,DATA_ID,IYMDHM,D_SOURCE_ID,RYMDHM,Datetime,File_URL,FILE_SIZE,D_FILE_SAVE_HIERARCHY,V_FNTIME,RADA_MODEL,PROD_CATE,PROD_CONT,FORMAT,V_COMPRESS_METHOD,FILE_NAME,V_RETAIN1_C,V_RETAIN2_C,V_RETAIN3_C" 42 | interface_data_type: "Upar" -------------------------------------------------------------------------------- /nuwe_cmadaas/dataset.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from typing import Dict 3 | 4 | import yaml 5 | 6 | 7 | DEFAULT_DATASETS_CONFIG_PATH = Path(Path(__file__).parent, "data/datasets") 8 | 9 | 10 | def load_dataset_config(dataset_type: str) -> Dict: 11 | config_file_path = Path(DEFAULT_DATASETS_CONFIG_PATH, f"{dataset_type}.yaml") 12 | if not config_file_path.exists(): 13 | raise FileNotFoundError(f"dataset file is not found: {config_file_path.absolute()}") 14 | 15 | with open(config_file_path, "r", encoding="utf-8") as f: 16 | dataset_config = yaml.safe_load(f) 17 | return dataset_config 18 | -------------------------------------------------------------------------------- /nuwe_cmadaas/model/__init__.py: -------------------------------------------------------------------------------- 1 | from .grid import retrieve_model_grid 2 | from .point import retrieve_model_point 3 | from .file import download_model_file 4 | -------------------------------------------------------------------------------- /nuwe_cmadaas/model/file.py: -------------------------------------------------------------------------------- 1 | from typing import Union, Optional, Dict, List, TypedDict 2 | from pathlib import Path 3 | 4 | import pandas as pd 5 | 6 | from nuwe_cmadaas.util import ( 7 | get_time_string, 8 | get_time_range_string, 9 | get_region_params, 10 | ) 11 | from nuwe_cmadaas.music import MusicError, get_or_create_client, CMADaaSClient 12 | from nuwe_cmadaas.config import CMADaasConfig 13 | from nuwe_cmadaas._log import logger 14 | 15 | 16 | class InterfaceConfig(TypedDict): 17 | name: str 18 | element: Optional[str] 19 | region: Optional[str] 20 | time: Optional[str] 21 | level: Optional[str] 22 | valid_time: Optional[str] 23 | 24 | 25 | def download_model_file( 26 | data_code: str, 27 | parameter: Optional[Union[str, List[str]]] = None, 28 | start_time: Optional[Union[pd.Interval, pd.Timestamp, List, pd.Timedelta]] = None, 29 | forecast_time: Optional[Union[str, pd.Timedelta]] = None, 30 | level_type: Optional[Union[str, int]] = None, 31 | level: Optional[Union[int, float]] = None, 32 | region: Optional[Dict] = None, 33 | data_type: Optional[str] = None, 34 | output_dir: Optional[Union[Path, str]] = None, 35 | config: Optional[Union[CMADaasConfig, str, Path]] = None, 36 | client: Optional[CMADaaSClient] = None, 37 | ) -> Union[List[Path], MusicError]: 38 | interface_config = InterfaceConfig( 39 | name="getNafpFile", 40 | element=None, 41 | region=None, 42 | time=None, 43 | level=None, 44 | valid_time=None, 45 | ) 46 | 47 | if output_dir is None: 48 | output_dir = "./" 49 | 50 | if data_type is None: 51 | data_type = "forecast" 52 | # data_type_mapper = { 53 | # "forecast": "getNafpEleGrid", 54 | # "analysis": "getNafpAnaEleGrid", 55 | # } 56 | # interface_config["name"] = data_type_mapper.get(data_type) 57 | 58 | params = { 59 | "dataCode": data_code, 60 | } 61 | 62 | if isinstance(parameter, str): 63 | params["fcstEle"] = parameter 64 | interface_config["element"] = "Element" 65 | elif isinstance(parameter, List): 66 | params["elements"] = ".".join(parameter) 67 | 68 | if level_type is not None: 69 | params["levelType"] = str(level_type) 70 | interface_config["level"] = "Level" 71 | if level is not None: 72 | params["fcstLevel"] = str(level) 73 | 74 | if isinstance(start_time, pd.Interval): 75 | interface_config["time"] = "TimeRange" 76 | params["timeRange"] = get_time_range_string(start_time) 77 | elif isinstance(start_time, pd.Timestamp): 78 | interface_config["time"] = "Time" 79 | params["time"] = get_time_string(start_time) 80 | elif isinstance(start_time, List): 81 | interface_config["time"] = "Time" 82 | params["times"] = ",".join([get_time_string(t) for t in start_time]) 83 | elif isinstance(start_time, pd.Timedelta): 84 | interface_config["name"] = "getNafpLatestTime" 85 | params["latestTime"] = str(int(start_time / pd.to_timedelta("1h"))) 86 | # del params["orderby"] 87 | del params["elements"] 88 | 89 | if forecast_time is not None: 90 | if isinstance(forecast_time, str): 91 | forecast_time = pd.to_timedelta(forecast_time) 92 | valid_time = int(forecast_time / pd.Timedelta(hours=1)) 93 | if parameter is None and level_type is None and level is None: 94 | # Typically for NWP files which all fields of one time step are stored together. 95 | # There is no getNafpFileByTimeAndValidtime interface. 96 | # So use getNafpFileByTime instead, and set valid time condition in eleValueRanges. 97 | params["eleValueRanges"] = f"Validtime_C:'{valid_time:03d}'" 98 | else: 99 | interface_config["valid_time"] = "Validtime" 100 | params["validTime"] = str(valid_time) 101 | 102 | if region is not None: 103 | get_region_params(region, params, interface_config) 104 | 105 | interface_id = _get_interface_id(interface_config) 106 | logger.info(f"interface_id: {interface_id}") 107 | 108 | cmadaas_client = get_or_create_client(config, client) 109 | result = cmadaas_client.callAPI_to_downFile(interface_id, params, file_dir=output_dir) 110 | 111 | if result.request.error_code != 0: 112 | logger.warning(f"request error {result.request.error_code}: {result.request.error_message}") 113 | music_error = MusicError(code=result.request.error_code, message=result.request.error_message) 114 | return music_error 115 | 116 | files_info = result.files_info 117 | file_list = [] 118 | for f in files_info: 119 | file_list.append(Path(output_dir, f.file_name)) 120 | 121 | return file_list 122 | 123 | 124 | def _get_interface_id(interface_config: InterfaceConfig) -> str: 125 | interface_id = interface_config["name"] 126 | 127 | region_part = interface_config["region"] 128 | if region_part is not None: 129 | interface_id += "In" + region_part 130 | 131 | condition_part = "And".join(filter(None, [ 132 | interface_config["element"], 133 | interface_config["time"], 134 | interface_config["level"], 135 | interface_config["valid_time"] 136 | ])) 137 | if len(condition_part) > 0: 138 | interface_id += "By" + condition_part 139 | 140 | return _fix_interface_id(interface_id) 141 | 142 | 143 | def _fix_interface_id(interface_id: str) -> str: 144 | fix_mapper = { 145 | "getNafpFileByElementAndTimeRangeAndLevel": "getNafpFileByElementAndTimeRange", 146 | "getNafpFileByElementAndTimeAndLevel": "getNafpFileByElementAndTime", 147 | } 148 | return fix_mapper.get(interface_id, interface_id) 149 | -------------------------------------------------------------------------------- /nuwe_cmadaas/model/grid.py: -------------------------------------------------------------------------------- 1 | from typing import Union, Optional, Dict, Literal, TypedDict 2 | from pathlib import Path 3 | 4 | import pandas as pd 5 | import xarray as xr 6 | 7 | from nuwe_cmadaas.util import get_time_string, get_region_params 8 | from nuwe_cmadaas.music import MusicError, get_or_create_client, CMADaaSClient 9 | from nuwe_cmadaas.config import CMADaasConfig 10 | from nuwe_cmadaas._log import logger 11 | 12 | 13 | class InterfaceConfig(TypedDict): 14 | name: str 15 | region: Optional[str] 16 | time: Optional[str] 17 | level: Optional[str] 18 | valid_time: Optional[str] 19 | number: Optional[str] 20 | 21 | 22 | def retrieve_model_grid( 23 | data_code: str, 24 | parameter: str, 25 | start_time: Optional[pd.Timestamp] = None, 26 | forecast_time: Optional[Union[str, pd.Timedelta]] = None, 27 | level_type: Optional[Union[str, int]] = None, 28 | level: Optional[Union[int, float]] = None, 29 | region: Optional[Dict] = None, 30 | number: Optional[int] = None, 31 | data_type: Optional[Literal["analysis", "forecast"]] = None, 32 | config: Optional[Union[CMADaasConfig, str, Path]] = None, 33 | client: Optional[CMADaaSClient] = None, 34 | ) -> Union[xr.DataArray, MusicError]: 35 | """ 36 | 获取数值模式的二维网格数据 37 | 38 | Parameters 39 | ---------- 40 | data_code 41 | CMADaaS 数据编码,例如 `NAFP_FOR_FTM_GRAPES_GFS_25KM_GLB` 表示“中国气象局全球天气模式CMA-GFS原始分辨率全球预报产品(0.25×0.25)” 42 | parameter 43 | 要素名称 44 | start_time 45 | 起报时间 46 | forecast_time 47 | 预报时效,``pandas.Timedelta`` 支持的字符串,例如 `"24h"` 48 | level_type 49 | 层次类型 50 | level 51 | 层次值 52 | region 53 | 区域 54 | number 55 | 集合预报成员编号 56 | data_type 57 | 数据类型,预报场 (`forecast`) 或者分析场 (`analysis`) 58 | config 59 | 配置,配置对象或配置文件路径。默认自动查找配置文件 60 | client 61 | 客户端对象,默认新建。如果设置,则直接使用该对象,会导致 config 参数被忽略 62 | 63 | Returns 64 | ------- 65 | Union[xr.DataArray, MusicError] 66 | 检索成功返回 ``xarray.DataArray`` 格式的要素场,检索失败返回包含错误信息的 ``MusicError`` 对象。 67 | """ 68 | interface_config = InterfaceConfig( 69 | name="getNafpEleGrid", 70 | region=None, 71 | time=None, 72 | level=None, 73 | valid_time=None, 74 | number=None, 75 | ) 76 | 77 | if data_type is None: 78 | data_type = "forecast" 79 | data_type_mapper = { 80 | "forecast": "getNafpEleGrid", 81 | "analysis": "getNafpAnaEleGrid", 82 | } 83 | interface_config["name"] = data_type_mapper.get(data_type) 84 | 85 | params = { 86 | "dataCode": data_code, 87 | "fcstEle": parameter, 88 | } 89 | 90 | if level_type is not None: 91 | params["levelType"] = str(level_type) 92 | interface_config["level"] = "Level" 93 | 94 | if level is not None: 95 | params["fcstLevel"] = str(level) 96 | 97 | if start_time is not None: 98 | interface_config["time"] = "Time" 99 | time = get_time_string(start_time) 100 | params["time"] = time 101 | 102 | if forecast_time is not None: 103 | interface_config["valid_time"] = "Validtime" 104 | if isinstance(forecast_time, str): 105 | forecast_time = pd.to_timedelta(forecast_time) 106 | valid_time = int(forecast_time / pd.Timedelta(hours=1)) 107 | params["validTime"] = str(valid_time) 108 | 109 | if region is not None: 110 | get_region_params(region, params, interface_config) 111 | 112 | if number is not None: 113 | interface_config["number"] = "FcstMember" 114 | params["fcstMember"] = number 115 | 116 | interface_id = _get_interface_id(interface_config) 117 | logger.info(f"interface_id: {interface_id}") 118 | 119 | cmadaas_client = get_or_create_client(config, client) 120 | result = cmadaas_client.callAPI_to_gridArray2D(interface_id, params) 121 | 122 | if result.request.error_code != 0: 123 | logger.warning(f"request error {result.request.error_code}: {result.request.error_message}") 124 | music_error = MusicError(code=result.request.error_code, message=result.request.error_message) 125 | return music_error 126 | 127 | field = result.to_xarray() 128 | return field 129 | 130 | 131 | def _get_interface_id(interface_config: InterfaceConfig) -> str: 132 | """ 133 | 根据接口各组成部分的名称返回接口的名称 134 | 135 | Parameters 136 | ---------- 137 | interface_config 138 | 接口各组成部分的名称 139 | 140 | .. code-block:: python 141 | 142 | interface_config = { 143 | "name": "getNafpEleGrid", 144 | "region": "Rect", 145 | "time": "Time", 146 | "level": "Level", 147 | "valid_time": "Validtime", 148 | "number": "FcstMember", 149 | } 150 | 151 | Returns 152 | ------- 153 | str 154 | 拼接后的 CMADaaS 接口名称 155 | 156 | Examples 157 | -------- 158 | 按起报时间、预报层次、预报时效检索预报要素场 159 | 160 | >>> _get_interface_id( 161 | ... interface_config={ 162 | ... "name": "getNafpEleGrid", 163 | ... "region": None, 164 | ... "time": "Time", 165 | ... "level": "Level", 166 | ... "valid_time": "Validtime", 167 | ... "number": None 168 | ... } 169 | ... ) 170 | getNafpEleGridByTimeAndLevelAndValidtime 171 | 172 | 按经纬范围、起报时间、预报层次、预报时效、集合预报成员检索预报要素场 173 | 174 | >>> _get_interface_id( 175 | ... interface_config={ 176 | ... "name": "getNafpEleGrid", 177 | ... "region": "Rect", 178 | ... "time": "Time", 179 | ... "level": "Level", 180 | ... "valid_time": "Validtime", 181 | ... "number": "FcstMember" 182 | ... } 183 | ... ) 184 | getNafpEleGridInRectByTimeAndLevelAndValidtimeAndFcstMember 185 | 186 | """ 187 | interface_id = interface_config["name"] 188 | 189 | region_part = interface_config["region"] 190 | if region_part is not None: 191 | interface_id += "In" + region_part 192 | 193 | condition_part = "And".join(filter(None, [ 194 | interface_config["time"], 195 | interface_config["level"], 196 | interface_config["valid_time"], 197 | interface_config["number"], 198 | ])) 199 | if len(condition_part) > 0: 200 | interface_id += "By" + condition_part 201 | 202 | return interface_id 203 | -------------------------------------------------------------------------------- /nuwe_cmadaas/model/point.py: -------------------------------------------------------------------------------- 1 | from typing import Union, Optional, Dict, List, Tuple, TypedDict 2 | from pathlib import Path 3 | 4 | import pandas as pd 5 | 6 | from nuwe_cmadaas.util import get_time_string 7 | from nuwe_cmadaas.music import MusicError, get_or_create_client, CMADaaSClient 8 | from nuwe_cmadaas.config import CMADaasConfig 9 | from nuwe_cmadaas._log import logger 10 | 11 | 12 | class InterfaceConfig(TypedDict): 13 | name: str 14 | point: Optional[str] 15 | time: str 16 | level: str 17 | valid_time: str 18 | station: Optional[str] 19 | 20 | 21 | def retrieve_model_point( 22 | data_code: str, 23 | parameter: str, 24 | start_time: pd.Timestamp, 25 | forecast_time: Union[str, pd.Timedelta, Tuple], 26 | level_type: Union[str, int], 27 | level: Union[int, float], 28 | point: Union[Tuple[float, float], List[Tuple[float, float]]] = None, 29 | station: Union[List[str], str] = None, 30 | config: Optional[Union[CMADaasConfig, str, Path]] = None, 31 | client: Optional[CMADaaSClient] = None, 32 | ) -> Union[pd.DataFrame, MusicError]: 33 | interface_config = InterfaceConfig( 34 | name="getNafpEle", 35 | point=None, 36 | time="Time", 37 | level="Level", 38 | valid_time="Validtime", 39 | station=None, 40 | ) 41 | 42 | params = { 43 | "dataCode": data_code, 44 | "fcstEle": parameter, 45 | "levelType": str(level_type), 46 | "fcstLevel": str(level) 47 | } 48 | 49 | time = get_time_string(start_time) 50 | params["time"] = time 51 | 52 | def _get_valid_time(f): 53 | if isinstance(f, str): 54 | f = pd.to_timedelta(f) 55 | return int(f / pd.Timedelta(hours=1)) 56 | 57 | if isinstance(forecast_time, str or pd.Timedelta): 58 | valid_time = _get_valid_time(forecast_time) 59 | params["validTime"] = str(valid_time) 60 | interface_config["valid_time"] = "Validtime" 61 | elif isinstance(forecast_time, Tuple): 62 | interface_config["valid_time"] = "ValidtimeRange" 63 | params["minVT"] = str(_get_valid_time(forecast_time[0])) 64 | params["maxVT"] = str(_get_valid_time(forecast_time[1])) 65 | 66 | if point is not None: 67 | _get_point_params(point, params, interface_config) 68 | if station is not None: 69 | _get_station_params(station, params, interface_config) 70 | 71 | interface_id = _get_interface_id(interface_config) 72 | logger.info(f"interface_id: {interface_id}") 73 | 74 | cmadaas_client = get_or_create_client(config, client) 75 | result = cmadaas_client.callAPI_to_array2D(interface_id, params) 76 | 77 | if result.request.error_code != 0: 78 | logger.warning(f"request error {result.request.error_code}: {result.request.error_message}") 79 | music_error = MusicError(code=result.request.error_code, message=result.request.error_message) 80 | return music_error 81 | 82 | df = result.to_pandas() 83 | return df 84 | 85 | 86 | def _get_interface_id(interface_config: InterfaceConfig) -> str: 87 | interface_id = interface_config["name"] 88 | 89 | point_part = interface_config["point"] 90 | if point_part is not None: 91 | interface_id += "At" + point_part 92 | 93 | condition_part = "And".join(filter(None, [ 94 | interface_config["time"], 95 | interface_config["level"], 96 | interface_config["valid_time"], 97 | interface_config["station"] 98 | ])) 99 | if len(condition_part) > 0: 100 | interface_id += "By" + condition_part 101 | 102 | return interface_id 103 | 104 | 105 | def _get_point_params( 106 | point: Union[Tuple[float, float], List[Tuple[float, float]]], 107 | params: Dict, 108 | interface_config: Dict 109 | ): 110 | interface_config["point"] = "Point" 111 | if isinstance(point, Tuple): 112 | params["latLons"] = f"{point[0]}/{point[1]}" 113 | elif isinstance(point, List): 114 | lat_lons = [] 115 | for p in point: 116 | lat_lons.append(f"{p[0]}/{p[1]}") 117 | params["latLons"] = ",".join(lat_lons) 118 | 119 | 120 | def _get_station_params( 121 | station: Union[List[str], str], 122 | params: Dict, 123 | interface_config: Dict 124 | ): 125 | interface_config["station"] = "StaID" 126 | if isinstance(station, List): 127 | params["staIds"] = ",".join(station) 128 | elif isinstance(station, str): 129 | params["staIds"] = station 130 | else: 131 | raise TypeError(f"station type is not support: {type(station)}") 132 | -------------------------------------------------------------------------------- /nuwe_cmadaas/music/__init__.py: -------------------------------------------------------------------------------- 1 | from typing import Optional, Union 2 | from pathlib import Path 3 | 4 | from .data import ( 5 | Array2D, 6 | GridArray2D, 7 | FilesInfo, 8 | FileInfo, 9 | GridScalar2D, 10 | GridVector2D, 11 | DataBlock, 12 | MusicError, 13 | ) 14 | 15 | from .client import CMADaaSClient 16 | 17 | from nuwe_cmadaas.config import load_cmadaas_config, CMADaasConfig 18 | from nuwe_cmadaas._log import logger 19 | 20 | 21 | def create_client(config: Optional[Union[CMADaasConfig, str, Path]]) -> CMADaaSClient: 22 | """ 23 | 从配置中创建客户端 CMADaaSClient 24 | 25 | Parameters 26 | ---------- 27 | config 28 | 配置,配置对象或配置文件路径 29 | 30 | Returns 31 | ------- 32 | CMADaaSClient 33 | CMADaaS 访问客户端 34 | """ 35 | if isinstance(config, dict): 36 | cmadaas_config = config 37 | else: 38 | cmadaas_config = load_cmadaas_config(config) 39 | 40 | cmadaas_client = CMADaaSClient(config=cmadaas_config) 41 | return cmadaas_client 42 | 43 | 44 | def get_or_create_client( 45 | config: Optional[Union[CMADaasConfig, str, Path]] = None, 46 | client: Optional[CMADaaSClient] = None 47 | ) -> CMADaaSClient: 48 | if client is None: 49 | cmadaas_client = create_client(config) 50 | else: 51 | if config is not None: 52 | logger.warning("client is set, use client in argument, config is ignored.") 53 | cmadaas_client = client 54 | return cmadaas_client 55 | -------------------------------------------------------------------------------- /nuwe_cmadaas/music/apiinterface_pb2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by the protocol buffer compiler. DO NOT EDIT! 3 | # source: apiinterface.proto 4 | """Generated protocol buffer code.""" 5 | from google.protobuf import descriptor as _descriptor 6 | from google.protobuf import descriptor_pool as _descriptor_pool 7 | from google.protobuf import symbol_database as _symbol_database 8 | from google.protobuf.internal import builder as _builder 9 | # @@protoc_insertion_point(imports) 10 | 11 | _sym_db = _symbol_database.Default() 12 | 13 | 14 | 15 | 16 | DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x12\x61piinterface.proto\x12\x0c\x63ma.music.pb\"\xc4\x01\n\x0bRequestInfo\x12\x11\n\terrorCode\x18\x01 \x01(\x05\x12\x14\n\x0c\x65rrorMessage\x18\x02 \x01(\t\x12\x14\n\x0crequestElems\x18\x03 \x01(\t\x12\x15\n\rrequestParams\x18\x04 \x01(\t\x12\x13\n\x0brequestTime\x18\x05 \x01(\t\x12\x14\n\x0cresponseTime\x18\x06 \x01(\t\x12\x10\n\x08rowCount\x18\x07 \x01(\x05\x12\x10\n\x08takeTime\x18\x08 \x01(\x05\x12\x10\n\x08\x63olCount\x18\t \x01(\x05\"\\\n\nRetArray2D\x12\x0c\n\x04\x64\x61ta\x18\x01 \x03(\t\x12*\n\x07request\x18\x02 \x01(\x0b\x32\x19.cma.music.pb.RequestInfo\x12\x14\n\x0c\x65lementNames\x18\x03 \x03(\t\"\x94\x02\n\x0eRetGridArray2D\x12\x0c\n\x04\x64\x61ta\x18\x01 \x03(\x02\x12*\n\x07request\x18\x02 \x01(\x0b\x32\x19.cma.music.pb.RequestInfo\x12\x10\n\x08startLat\x18\x03 \x01(\x02\x12\x10\n\x08startLon\x18\x04 \x01(\x02\x12\x0e\n\x06\x65ndLat\x18\x05 \x01(\x02\x12\x0e\n\x06\x65ndLon\x18\x06 \x01(\x02\x12\x10\n\x08latCount\x18\x07 \x01(\x05\x12\x10\n\x08lonCount\x18\x08 \x01(\x05\x12\x0f\n\x07lonStep\x18\t \x01(\x02\x12\x0f\n\x07latStep\x18\n \x01(\x02\x12\x0c\n\x04lats\x18\x0b \x03(\x02\x12\x0c\n\x04lons\x18\x0c \x03(\x02\x12\r\n\x05units\x18\r \x01(\t\x12\x13\n\x0buserEleName\x18\x0e \x01(\t\"\x84\x01\n\x08\x46ileInfo\x12\x10\n\x08\x66ileName\x18\x01 \x01(\t\x12\x10\n\x08savePath\x18\x02 \x01(\t\x12\x0e\n\x06suffix\x18\x03 \x01(\t\x12\x0c\n\x04size\x18\x04 \x01(\t\x12\x0f\n\x07\x66ileUrl\x18\x05 \x01(\t\x12\x11\n\timgBase64\x18\x06 \x01(\t\x12\x12\n\nattributes\x18\x07 \x03(\t\"e\n\x0cRetFilesInfo\x12)\n\tfileInfos\x18\x01 \x03(\x0b\x32\x16.cma.music.pb.FileInfo\x12*\n\x07request\x18\x02 \x01(\x0b\x32\x19.cma.music.pb.RequestInfo\"\xa7\x01\n\x0cStoreArray2D\x12\x0c\n\x04\x64\x61ta\x18\x01 \x03(\t\x12\x0b\n\x03row\x18\x02 \x01(\x05\x12\x0b\n\x03\x63ol\x18\x03 \x01(\x05\x12\x10\n\x08\x66ileflag\x18\x04 \x01(\x05\x12\x11\n\tfilenames\x18\x05 \x03(\t\x12\x14\n\x0cis_backstage\x18\x06 \x01(\x05\x12\x19\n\x11\x63lient_mount_path\x18\x07 \x01(\t\x12\x19\n\x11server_mount_path\x18\x08 \x01(\t\"_\n\x0cRetDataBlock\x12\x10\n\x08\x64\x61taName\x18\x01 \x01(\t\x12\x11\n\tbyteArray\x18\x02 \x01(\x0c\x12*\n\x07request\x18\x03 \x01(\x0b\x32\x19.cma.music.pb.RequestInfo\"\xab\x02\n\x0fRetGridVector2D\x12\x0f\n\x07u_datas\x18\x01 \x03(\x02\x12\x0f\n\x07v_datas\x18\x02 \x03(\x02\x12*\n\x07request\x18\x03 \x01(\x0b\x32\x19.cma.music.pb.RequestInfo\x12\x10\n\x08startLat\x18\x04 \x01(\x02\x12\x10\n\x08startLon\x18\x05 \x01(\x02\x12\x0e\n\x06\x65ndLat\x18\x06 \x01(\x02\x12\x0e\n\x06\x65ndLon\x18\x07 \x01(\x02\x12\x10\n\x08latCount\x18\x08 \x01(\x05\x12\x10\n\x08lonCount\x18\t \x01(\x05\x12\x0f\n\x07lonStep\x18\n \x01(\x02\x12\x0f\n\x07latStep\x18\x0b \x01(\x02\x12\x0c\n\x04lats\x18\x0c \x03(\x02\x12\x0c\n\x04lons\x18\r \x03(\x02\x12\x11\n\tu_EleName\x18\x0e \x01(\t\x12\x11\n\tv_EleName\x18\x0f \x01(\t\"\x96\x02\n\x0fRetGridScalar2D\x12\r\n\x05\x64\x61tas\x18\x01 \x03(\x02\x12*\n\x07request\x18\x02 \x01(\x0b\x32\x19.cma.music.pb.RequestInfo\x12\x10\n\x08startLat\x18\x03 \x01(\x02\x12\x10\n\x08startLon\x18\x04 \x01(\x02\x12\x0e\n\x06\x65ndLat\x18\x05 \x01(\x02\x12\x0e\n\x06\x65ndLon\x18\x06 \x01(\x02\x12\x10\n\x08latCount\x18\x07 \x01(\x05\x12\x10\n\x08lonCount\x18\x08 \x01(\x05\x12\x0f\n\x07lonStep\x18\t \x01(\x02\x12\x0f\n\x07latStep\x18\n \x01(\x02\x12\x0c\n\x04lats\x18\x0b \x03(\x02\x12\x0c\n\x04lons\x18\x0c \x03(\x02\x12\r\n\x05units\x18\r \x01(\t\x12\x13\n\x0buserEleName\x18\x0e \x01(\t\"a\n\rStoreGridData\x12\x12\n\nattributes\x18\x01 \x03(\t\x12\x11\n\tpointflag\x18\x02 \x01(\x05\x12\x0c\n\x04Lats\x18\x03 \x03(\x02\x12\x0c\n\x04Lons\x18\x04 \x03(\x02\x12\r\n\x05\x64\x61tas\x18\x05 \x03(\x02\"2\n\x0eStoreBlockData\x12\x12\n\nattributes\x18\x01 \x03(\t\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x62\x06proto3') 17 | 18 | _globals = globals() 19 | _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) 20 | _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'apiinterface_pb2', _globals) 21 | if _descriptor._USE_C_DESCRIPTORS == False: 22 | DESCRIPTOR._options = None 23 | _globals['_REQUESTINFO']._serialized_start=37 24 | _globals['_REQUESTINFO']._serialized_end=233 25 | _globals['_RETARRAY2D']._serialized_start=235 26 | _globals['_RETARRAY2D']._serialized_end=327 27 | _globals['_RETGRIDARRAY2D']._serialized_start=330 28 | _globals['_RETGRIDARRAY2D']._serialized_end=606 29 | _globals['_FILEINFO']._serialized_start=609 30 | _globals['_FILEINFO']._serialized_end=741 31 | _globals['_RETFILESINFO']._serialized_start=743 32 | _globals['_RETFILESINFO']._serialized_end=844 33 | _globals['_STOREARRAY2D']._serialized_start=847 34 | _globals['_STOREARRAY2D']._serialized_end=1014 35 | _globals['_RETDATABLOCK']._serialized_start=1016 36 | _globals['_RETDATABLOCK']._serialized_end=1111 37 | _globals['_RETGRIDVECTOR2D']._serialized_start=1114 38 | _globals['_RETGRIDVECTOR2D']._serialized_end=1413 39 | _globals['_RETGRIDSCALAR2D']._serialized_start=1416 40 | _globals['_RETGRIDSCALAR2D']._serialized_end=1694 41 | _globals['_STOREGRIDDATA']._serialized_start=1696 42 | _globals['_STOREGRIDDATA']._serialized_end=1793 43 | _globals['_STOREBLOCKDATA']._serialized_start=1795 44 | _globals['_STOREBLOCKDATA']._serialized_end=1845 45 | # @@protoc_insertion_point(module_scope) 46 | -------------------------------------------------------------------------------- /nuwe_cmadaas/music/connection.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pathlib 3 | from typing import Callable, Any, Union, Tuple, Optional 4 | 5 | import requests 6 | 7 | from nuwe_cmadaas._log import logger 8 | 9 | from .data import ( 10 | ResponseData 11 | ) 12 | 13 | 14 | class Connection: 15 | """ 16 | 连接类 17 | 18 | Attributes 19 | ---------- 20 | connect_timeout : float 21 | 连接超时,单位秒 22 | read_timeout : float 23 | 读取超时,单位秒 24 | """ 25 | getwayFlag = b'"flag":"slb"' 26 | otherError = -10001 27 | 28 | def __init__( 29 | self, 30 | connect_timeout: float, 31 | read_timeout: float, 32 | ): 33 | self.connect_timeout = connect_timeout 34 | self.read_timeout = read_timeout 35 | 36 | def make_request( 37 | self, 38 | fetch_url: str, 39 | success_handler: Callable[[bytes], ResponseData], 40 | failure_handler: Callable[[bytes], ResponseData], 41 | exception_handler: Callable[[Exception], Any], 42 | ) -> ResponseData: 43 | """ 44 | 从URL获取响应并处理结果。 45 | 46 | Parameters 47 | ---------- 48 | fetch_url 49 | 由``CMADaaSClient``生成的URL 50 | success_handler 51 | 成功回调函数 52 | failure_handler 53 | 失败回调函数 54 | exception_handler 55 | 异常回调函数 56 | 57 | Returns 58 | ------- 59 | ResponseData 60 | """ 61 | try: 62 | response = requests.get( 63 | fetch_url, 64 | timeout=(self.connect_timeout, self.read_timeout), 65 | stream=True, 66 | ) 67 | response_content = response.content 68 | 69 | except requests.exceptions.RequestException as e: # http error 70 | return exception_handler(e) 71 | 72 | if self._check_getway_flag(response_content): 73 | return failure_handler(response_content) 74 | 75 | return success_handler(response_content) 76 | 77 | def download_file( 78 | self, file_url: str, save_file: Union[str, pathlib.Path] 79 | ) -> Tuple[int, Optional[str]]: 80 | try: 81 | response = requests.get(file_url, stream=True) 82 | response_content = response.content 83 | if self._check_getway_flag(response_content): 84 | getway_info = json.loads(response_content) 85 | if getway_info is None: 86 | return Connection.otherError, "parse getway return string error!" 87 | else: 88 | return getway_info["returnCode"], getway_info["returnMessage"] 89 | 90 | with open(save_file, "wb") as f: 91 | f.write(response_content) 92 | 93 | except requests.exceptions.RequestException as e: # http error 94 | return Connection.otherError, "request error" 95 | except IOError: 96 | return Connection.otherError, "create file error" 97 | 98 | return 0, None 99 | 100 | @classmethod 101 | def generate_pack_failure_handler( 102 | cls, 103 | response_data: ResponseData, 104 | ) -> Callable[[bytes], ResponseData]: 105 | """ 106 | 出错返回消息示例: 107 | {"returnCode":-1004,"flag":"slb","returnMessage":"Password Error"} 108 | """ 109 | 110 | def failure_handler(response_content: bytes) -> ResponseData: 111 | getway_info = json.loads(response_content) 112 | if getway_info is None: 113 | response_data.request.errorCode = Connection.otherError 114 | response_data.request.errorMessage = ( 115 | "parse getway return string error:" + response_content.decode('utf-8') 116 | ) 117 | else: 118 | response_data.request.errorCode = getway_info["returnCode"] 119 | response_data.request.errorMessage = getway_info["returnMessage"] 120 | return response_data 121 | 122 | return failure_handler 123 | 124 | @classmethod 125 | def generate_exception_handler( 126 | cls, 127 | response_data: ResponseData, 128 | ) -> Callable[[Exception], ResponseData]: 129 | def handle_exception(e: Exception) -> ResponseData: 130 | logger.warning(f"Error retrieving data: {e}") 131 | response_data.request.errorCode = Connection.otherError 132 | response_data.request.errorMessage = "Error retrieving data" 133 | return response_data 134 | 135 | return handle_exception 136 | 137 | @classmethod 138 | def generate_pack_success_handler( 139 | cls, 140 | response_data: ResponseData, 141 | ) -> Callable[[bytes], ResponseData]: 142 | """ 143 | 生成处理返回结果的回调函数。 144 | 该函数将反序列化protobuf字节流并填充到响应数据对象中。 145 | 146 | Parameters 147 | ---------- 148 | response_data 149 | 响应数据对象 150 | 151 | Returns 152 | ------- 153 | Callable[[bytes], ResponseData] 154 | """ 155 | def handle_success(response_content: bytes) -> ResponseData: 156 | response_data.load_from_protobuf_content(response_content) 157 | return response_data 158 | 159 | return handle_success 160 | 161 | @classmethod 162 | def _check_getway_flag(cls, response_data: bytes) -> bool: 163 | return Connection.getwayFlag in response_data 164 | -------------------------------------------------------------------------------- /nuwe_cmadaas/obs/__init__.py: -------------------------------------------------------------------------------- 1 | from .station import retrieve_obs_station 2 | from .upper_air import retrieve_obs_upper_air, download_obs_upper_air_file 3 | from .file import download_obs_file 4 | from .grid import retrieve_obs_grid 5 | -------------------------------------------------------------------------------- /nuwe_cmadaas/obs/grid.py: -------------------------------------------------------------------------------- 1 | from typing import Union, List, Optional, Dict 2 | from pathlib import Path 3 | 4 | import pandas as pd 5 | import xarray as xr 6 | 7 | from nuwe_cmadaas._log import logger 8 | from nuwe_cmadaas.util import ( 9 | get_time_string, 10 | get_time_range_string, 11 | get_region_params, 12 | ) 13 | from nuwe_cmadaas.config import CMADaasConfig 14 | from nuwe_cmadaas.music import get_or_create_client, CMADaaSClient, MusicError 15 | 16 | from .util import _get_interface_id, InterfaceConfig 17 | 18 | 19 | def retrieve_obs_grid( 20 | data_code: str, 21 | parameter: Optional[str] = None, 22 | time: Optional[Union[pd.Interval, pd.Timestamp, List]] = None, 23 | region: Optional[Dict] = None, 24 | config: Optional[Union[CMADaasConfig, str, Path]] = None, 25 | client: Optional[CMADaaSClient] = None, 26 | **kwargs, 27 | ) -> Union[xr.DataArray, MusicError]: 28 | """ 29 | 获取实况格点场要素 30 | 31 | 对应 CMADaaS 中以 `getSurfEleGrid` 开头的一系列数据接口 32 | 33 | **区域筛选条件** 34 | 35 | - 经纬度范围 36 | 37 | .. code-block:: python 38 | 39 | { 40 | "type": "rect", 41 | "start_longitude": 115.7, 42 | "end_longitude": 117.4, 43 | "start_latitude": 41.6, 44 | "end_latitude": 39.4, 45 | } 46 | 47 | 48 | Parameters 49 | ---------- 50 | data_code 51 | 数据种类,即 CMADaaS 中的资料代码 52 | parameter 53 | 要素字段代码 54 | time 55 | 时间筛选条件,支持单个时间,时间列表,时间段和时间间隔 56 | 57 | - 时间对象:``pd.Timestamp`` 类型,单个时间点,对应接口的 times 参数 58 | - 时间列表:``typing.List[pd.Timestamp]`` 类型,多个时间列表,对应接口的 times 参数 59 | - 时间段:``pd.Interval`` 类型,起止时间,定义区间端点是否闭合,对应接口的 timeRange 参数 60 | region 61 | 区域筛选条件: 62 | - 经纬度范围 (rect) 63 | config 64 | 配置。配置文件路径或配置对象 65 | client 66 | 客户端对象,默认新建。如果设置则直接使用,忽略 config 参数 67 | kwargs 68 | 其他需要传递给 MUSIC 接口的参数 69 | 70 | Returns 71 | ------- 72 | xr.DataArray or None 73 | 检索成功则返回 ``xarray.DataArray`` 对象,否则返回 None 74 | """ 75 | interface_config = InterfaceConfig( 76 | name="getSurfEleGrid", 77 | region=None, 78 | time=None, 79 | level=None, 80 | station=None, 81 | ) 82 | 83 | params = { 84 | "dataCode": data_code, 85 | } 86 | 87 | if isinstance(parameter, str): 88 | params["fcstEle"] = parameter 89 | 90 | if isinstance(time, pd.Interval): 91 | interface_config["time"] = "TimeRange" 92 | params["timeRange"] = get_time_range_string(time) 93 | elif isinstance(time, pd.Timestamp): 94 | interface_config["time"] = "Time" 95 | params["time"] = get_time_string(time) 96 | elif isinstance(time, List): 97 | interface_config["time"] = "Time" 98 | params["times"] = ",".join([get_time_string(t) for t in time]) 99 | 100 | if region is not None: 101 | get_region_params(region, params, interface_config) 102 | 103 | params.update(**kwargs) 104 | 105 | interface_id = _get_interface_id(interface_config) 106 | logger.info(f"interface_id: {interface_id}") 107 | 108 | cmadaas_client = get_or_create_client(config, client) 109 | result = cmadaas_client.callAPI_to_gridArray2D(interface_id, params) 110 | 111 | if result.request.error_code != 0: 112 | logger.warning(f"request error {result.request.error_code}: {result.request.error_message}") 113 | music_error = MusicError(code=result.request.error_code, message=result.request.error_message) 114 | return music_error 115 | 116 | field = result.to_xarray() 117 | return field 118 | -------------------------------------------------------------------------------- /nuwe_cmadaas/obs/util.py: -------------------------------------------------------------------------------- 1 | from typing import TypedDict, Optional 2 | 3 | from nuwe_cmadaas._log import logger 4 | 5 | 6 | class InterfaceConfig(TypedDict): 7 | name: str 8 | region: Optional[str] 9 | time: Optional[str] 10 | station: Optional[str] 11 | level: Optional[str] 12 | 13 | 14 | def _get_interface_id(interface_config: InterfaceConfig) -> str: 15 | interface_id = interface_config["name"] 16 | 17 | region_part = interface_config["region"] 18 | if region_part is not None: 19 | interface_id += "In" + region_part 20 | 21 | condition_part = "" 22 | 23 | if "time" in interface_config and interface_config["time"] is not None: 24 | condition_part = "And".join(filter(None, [condition_part, interface_config["time"]])) 25 | 26 | if "station" in interface_config and interface_config["station"] is not None: 27 | condition_part = "And".join(filter(None, [condition_part, interface_config["station"]])) 28 | 29 | if "level" in interface_config and interface_config["level"] is not None: 30 | condition_part = "And".join(filter(None, [condition_part, interface_config["level"]])) 31 | 32 | if len(condition_part) > 0: 33 | interface_id += "By" + condition_part 34 | 35 | fixed_interface_id = _fix_interface_id(interface_id) 36 | 37 | return fixed_interface_id 38 | 39 | 40 | def _fix_interface_id(interface_id: str) -> str: 41 | mapper = { 42 | "getSurfEleByTimeRangeAndStaIdRange": "getSurfEleByTimeRangeAndStaIDRange" 43 | } 44 | return mapper.get(interface_id, interface_id) 45 | 46 | 47 | def _fix_params(interface_id, params): 48 | if interface_id in ( 49 | "getUparGpsEleByTimeAndStaID", 50 | "getUparGpsEleInRectByTime", 51 | "not_getUparGpsEleInRegionByTime" 52 | ): 53 | logger.warning("UparGps don't use dataCode!") 54 | del params["dataCode"] 55 | return params 56 | -------------------------------------------------------------------------------- /nuwe_cmadaas/util.py: -------------------------------------------------------------------------------- 1 | import typing 2 | 3 | import pandas as pd 4 | 5 | 6 | def get_time_string(time: pd.Timestamp) -> str: 7 | return time.strftime("%Y%m%d%H%M%S") 8 | 9 | 10 | def get_time_range_string(time_interval: pd.Interval) -> str: 11 | left = "[" if time_interval.closed_left else ")" 12 | start = get_time_string(time_interval.left) 13 | right = "[" if time_interval.closed_right else ")" 14 | end = get_time_string(time_interval.right) 15 | return f"{left}{start},{end}{right}" 16 | 17 | 18 | def get_region_params(region: typing.Dict, params: typing.Dict, interface_config: typing.Dict): 19 | region_type = region["type"] 20 | if region_type == "region": 21 | interface_config["region"] = "Region" 22 | v = region["admin_codes"] 23 | if isinstance(v, typing.List): 24 | v = ",".join(v) 25 | elif isinstance(v, int): 26 | v = str(v) 27 | params["adminCodes"] = v 28 | elif region_type == "rect": 29 | interface_config["region"] = "Rect" 30 | start_lat = region["start_latitude"] 31 | end_lat = region["end_latitude"] 32 | start_lon = region["start_longitude"] 33 | end_lon = region["end_longitude"] 34 | min_lat, max_lat = sorted([start_lat, end_lat]) 35 | min_lon, max_lon = sorted([start_lon, end_lon]) 36 | params.update({ 37 | "minLat": f"{min_lat}", 38 | "minLon": f"{min_lon}", 39 | "maxLat": f"{max_lat}", 40 | "maxLon": f"{max_lon}", 41 | }) 42 | elif region_type == "basin": 43 | interface_config["region"] = "Basin" 44 | v = region["basin_codes"] 45 | if isinstance(v, typing.List): 46 | v = ",".join(v) 47 | params["basinCodes"] = v 48 | else: 49 | raise ValueError(f"region type is not supported: {region_type}") 50 | 51 | return params, interface_config 52 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=64", "setuptools_scm>=8"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "nuwe-cmadaas" 7 | authors = [ 8 | {name="Wang Dapeng", email="perillaroc@gmail.com"} 9 | ] 10 | description = "A python API for CMADaaS MUSIC." 11 | readme = "README.md" 12 | keywords = ["music", "cmadaas"] 13 | classifiers = [ 14 | "Development Status :: 3 - Alpha", 15 | 16 | "Intended Audience :: Developers", 17 | 18 | 'License :: OSI Approved :: Apache Software License', 19 | 20 | "Programming Language :: Python :: 3.11", 21 | "Programming Language :: Python :: 3.12", 22 | ] 23 | dependencies = [ 24 | "requests", 25 | "numpy", 26 | "pandas", 27 | "pyyaml", 28 | "protobuf", 29 | "xarray", 30 | 'importlib-metadata; python_version<"3.8"', 31 | ] 32 | dynamic = ["version"] 33 | 34 | [project.urls] 35 | Homepage = "https://github.com/perillaroc/nuwe-cmadaas-python" 36 | Repository = "https://github.com/perillaroc/nuwe-cmadaas-python.git" 37 | 38 | [project.optional-dependencies] 39 | test = ["pytest"] 40 | cov = ["pytest-cov", "codecov"] 41 | example = ["click"] 42 | 43 | [tool.setuptools.packages.find] 44 | where = ["."] 45 | exclude = [ 46 | "example", 47 | "tests", 48 | "*.tests", 49 | "*.tests.*", 50 | "tests.*", 51 | "docs", 52 | "conf", 53 | ] 54 | namespaces = false 55 | 56 | [tool.setuptools] 57 | include-package-data = true 58 | 59 | [tool.setuptools_scm] 60 | version_file = "nuwe_cmadaas/_version.py" 61 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/tests/__init__.py -------------------------------------------------------------------------------- /tests/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/tests/model/__init__.py -------------------------------------------------------------------------------- /tests/model/grid/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/tests/model/grid/__init__.py -------------------------------------------------------------------------------- /tests/model/grid/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import pandas as pd 3 | 4 | 5 | @pytest.fixture 6 | def start_date(): 7 | s = (pd.Timestamp.now() - pd.offsets.Day()).normalize() - pd.Timedelta(days=2) 8 | return s 9 | 10 | 11 | @pytest.fixture 12 | def future_start_date(): 13 | s = (pd.Timestamp.now() - pd.offsets.Day()).normalize() + pd.Timedelta(days=365) 14 | return s 15 | 16 | 17 | @pytest.fixture 18 | def end_date(): 19 | s = pd.Timestamp.now().normalize() 20 | return s 21 | 22 | 23 | @pytest.fixture 24 | def invalid_forecast_time(): 25 | forecast_time = pd.Timedelta(hours=888) 26 | return forecast_time 27 | 28 | 29 | @pytest.fixture 30 | def non_exist_ens_member_number(): 31 | return 99 32 | -------------------------------------------------------------------------------- /tests/model/grid/test_cma_reps.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import xarray as xr 3 | 4 | from nuwe_cmadaas.model import retrieve_model_grid 5 | from nuwe_cmadaas.music import MusicError 6 | 7 | 8 | REPS_CONTROL_NAME = "NAFP_GRAPESREPS_FOR_FTM_CHN" 9 | REPS_MEMBER_NAME = "NAFP_GRAPESREPS_FOR_FTM_DIS_CHN" 10 | 11 | TEMPERATURE_NAME_FOR_CMADAAS = "TEM" 12 | 13 | 14 | def test_control_field(start_date): 15 | field = retrieve_model_grid( 16 | REPS_CONTROL_NAME, 17 | start_time=start_date, 18 | forecast_time=pd.Timedelta(hours=24), 19 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 20 | level_type=100, 21 | level=850, 22 | number=0, 23 | ) 24 | 25 | assert isinstance(field, xr.DataArray) 26 | 27 | 28 | def test_member_field(start_date): 29 | field = retrieve_model_grid( 30 | REPS_MEMBER_NAME, 31 | start_time=start_date, 32 | forecast_time=pd.Timedelta(hours=24), 33 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 34 | level_type=100, 35 | level=850, 36 | number=10, 37 | ) 38 | 39 | assert isinstance(field, xr.DataArray) 40 | 41 | 42 | def test_control_field_future_date(future_start_date): 43 | field = retrieve_model_grid( 44 | REPS_CONTROL_NAME, 45 | start_time=future_start_date, 46 | forecast_time=pd.Timedelta(hours=24), 47 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 48 | level_type=100, 49 | level=850, 50 | number=0, 51 | ) 52 | 53 | assert isinstance(field, MusicError) 54 | assert field.code == -1 55 | assert field.message == "query success , but no record in database. detail: Query Success,but no record is in database" 56 | 57 | 58 | def test_control_field_non_exist_forecast_time(start_date, invalid_forecast_time): 59 | field = retrieve_model_grid( 60 | REPS_CONTROL_NAME, 61 | start_time=start_date, 62 | forecast_time=invalid_forecast_time, 63 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 64 | level_type=100, 65 | level=850, 66 | number=0, 67 | ) 68 | 69 | assert isinstance(field, MusicError) 70 | assert field.code == -9002 71 | assert field.message == ". detail: The input parameters are not within the range of datasets" 72 | 73 | 74 | def test_member_field_non_exist_member(start_date, non_exist_ens_member_number): 75 | field = retrieve_model_grid( 76 | REPS_MEMBER_NAME, 77 | start_time=start_date, 78 | forecast_time=pd.Timedelta(hours=24), 79 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 80 | level_type=100, 81 | level=850, 82 | number=non_exist_ens_member_number, 83 | ) 84 | 85 | assert isinstance(field, MusicError) 86 | assert field.code == -9002 87 | assert field.message == ". detail: The input parameters are not within the range of datasets" 88 | 89 | 90 | def test_member_field_non_exist_parameter(start_date, non_exist_ens_member_number): 91 | parameter = "NON_EXIST" 92 | level = 100 93 | field = retrieve_model_grid( 94 | REPS_MEMBER_NAME, 95 | start_time=start_date, 96 | forecast_time=pd.Timedelta(hours=24), 97 | parameter=parameter, 98 | level_type=level, 99 | level=850, 100 | number=non_exist_ens_member_number, 101 | ) 102 | 103 | assert isinstance(field, MusicError) 104 | assert field.code == -3001 105 | assert field.message == f". detail: The fsctele:'{parameter}_{level}' is not config in {REPS_MEMBER_NAME}" 106 | 107 | 108 | def test_member_field_non_exist_field(start_date, non_exist_ens_member_number): 109 | field = retrieve_model_grid( 110 | REPS_MEMBER_NAME, 111 | start_time=start_date, 112 | forecast_time=pd.Timedelta(hours=24), 113 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 114 | level_type=103, 115 | level=100, 116 | number=non_exist_ens_member_number, 117 | ) 118 | 119 | assert isinstance(field, MusicError) 120 | assert field.code == -9002 121 | assert field.message == ". detail: The input parameters are not within the range of datasets" 122 | 123 | 124 | def test_member_field_non_exist_level(start_date, non_exist_ens_member_number): 125 | field = retrieve_model_grid( 126 | REPS_MEMBER_NAME, 127 | start_time=start_date, 128 | forecast_time=pd.Timedelta(hours=24), 129 | parameter=TEMPERATURE_NAME_FOR_CMADAAS, 130 | level_type=100, 131 | level=851, 132 | number=non_exist_ens_member_number, 133 | ) 134 | 135 | assert isinstance(field, MusicError) 136 | assert field.code == -9002 137 | assert field.message == ". detail: The input parameters are not within the range of datasets" 138 | -------------------------------------------------------------------------------- /tests/obs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/tests/obs/__init__.py -------------------------------------------------------------------------------- /tests/obs/grid/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/tests/obs/grid/__init__.py -------------------------------------------------------------------------------- /tests/obs/grid/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import pandas as pd 3 | 4 | 5 | @pytest.fixture 6 | def start_date(): 7 | s = (pd.Timestamp.now() - pd.offsets.Day()).normalize() - pd.Timedelta(days=2) 8 | return s 9 | 10 | 11 | @pytest.fixture 12 | def end_date(): 13 | s = pd.Timestamp.now().normalize() 14 | return s 15 | -------------------------------------------------------------------------------- /tests/obs/grid/test_getSurfEleGridByTime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间、要素获取实况格点场要素 3 | 4 | getSurfEleGridByTime 5 | """ 6 | import xarray as xr 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_grid 9 | 10 | 11 | def test_cmpas_chn_1km_rt(start_date): 12 | parameter = "PRE" 13 | 14 | data_code = "SURF_CMPAS_CHN_1KM_RT" 15 | 16 | field = retrieve_obs_grid( 17 | data_code, 18 | parameter=parameter, 19 | time=start_date, 20 | ) 21 | 22 | assert isinstance(field, xr.DataArray) 23 | -------------------------------------------------------------------------------- /tests/obs/grid/test_getSurfEleGridByTimeAndRect.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间、要素获取实况格点场要素 3 | 4 | getSurfEleGridInRectByTime 5 | """ 6 | import xarray as xr 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_grid 9 | 10 | 11 | def test_cmpas_chn_1km_rt(start_date): 12 | parameter = "PRE" 13 | 14 | data_code = "SURF_CMPAS_CHN_1KM_RT" 15 | 16 | field = retrieve_obs_grid( 17 | data_code, 18 | parameter=parameter, 19 | time=start_date, 20 | region=dict( 21 | type="rect", 22 | start_longitude=115.7, 23 | end_longitude=117.4, 24 | start_latitude=41.6, 25 | end_latitude=39.4, 26 | ) 27 | ) 28 | 29 | assert isinstance(field, xr.DataArray) 30 | -------------------------------------------------------------------------------- /tests/obs/station/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perillaroc/nuwe-cmadaas-python/d74d34154fc553ed8ae637d4f6383661e5799be9/tests/obs/station/__init__.py -------------------------------------------------------------------------------- /tests/obs/station/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import pandas as pd 3 | 4 | 5 | @pytest.fixture 6 | def start_date(): 7 | s = (pd.Timestamp.now() - pd.offsets.Day()).normalize() 8 | return s 9 | 10 | 11 | @pytest.fixture 12 | def end_date(): 13 | s = pd.Timestamp.now().normalize() 14 | return s 15 | 16 | 17 | @pytest.fixture 18 | def time_list(): 19 | today = pd.Timestamp.now().normalize() 20 | return [today - pd.offsets.Day(), today] 21 | 22 | 23 | @pytest.fixture 24 | def start_station_id(): 25 | return "53592" 26 | 27 | 28 | @pytest.fixture 29 | def end_station_id(): 30 | return "54511" 31 | 32 | 33 | @pytest.fixture 34 | def station_id(): 35 | return "54533" # Beijing 36 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleByTime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间检索地面数据要素 3 | 4 | getSurfEleByTime 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date, end_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=[start_date, end_date] 15 | ) 16 | assert isinstance(table, pd.DataFrame) 17 | assert table.shape[0] > 0 18 | return 19 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleByTimeAndStaID.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、站号检索地面数据要素 3 | 4 | getSurfEleByTimeRangeAndStaID 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly_station_list(start_date, end_date, start_station_id, end_station_id): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=pd.Interval(start_date, end_date, closed="left"), 15 | station=[start_station_id, end_station_id] 16 | ) 17 | assert isinstance(table, pd.DataFrame) 18 | assert table.shape[0] > 0 19 | 20 | 21 | def test_hourly_station(start_date, end_date, station_id): 22 | table = retrieve_obs_station( 23 | "SURF_CHN_MUL_HOR", 24 | time=pd.Interval(start_date, end_date, closed="left"), 25 | station=station_id, 26 | ) 27 | assert isinstance(table, pd.DataFrame) 28 | assert table.shape[0] > 0 29 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleByTimeAndStaIdRange.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、站号段检索地面数据要素 3 | 4 | getSurfEleByTimeRangeAndStaIDRange 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date, end_date, start_station_id, end_station_id): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=[start_date, end_date], 15 | station=(start_station_id, end_station_id), 16 | ) 17 | assert isinstance(table, pd.DataFrame) 18 | assert table.shape[0] > 0 19 | return 20 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleByTimeRange.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段检索地面数据要素 3 | 4 | getSurfEleByTimeRange 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=pd.Interval( 15 | start_date, 16 | start_date + pd.Timedelta(hours=1), 17 | closed="left", 18 | ), 19 | ) 20 | assert isinstance(table, pd.DataFrame) 21 | assert table.shape[0] > 0 22 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleByTimeRangeAndStaID.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、站号检索地面数据要素 3 | 4 | getSurfEleByTimeRangeAndStaID 5 | """ 6 | 7 | import pandas as pd 8 | 9 | from nuwe_cmadaas.obs import retrieve_obs_station 10 | 11 | 12 | def test_hourly(start_date, end_date, start_station_id, end_station_id): 13 | table = retrieve_obs_station( 14 | "SURF_CHN_MUL_HOR", 15 | time=pd.Interval( 16 | start_date, end_date, 17 | closed="left", 18 | ), 19 | station=[start_station_id, end_station_id] 20 | ) 21 | assert isinstance(table, pd.DataFrame) 22 | assert table.shape[0] > 0 23 | 24 | 25 | def test_hourly_station_id(start_date, end_date, station_id): 26 | table = retrieve_obs_station( 27 | "SURF_CHN_MUL_HOR", 28 | time=[start_date, end_date], 29 | station=station_id, 30 | ) 31 | assert isinstance(table, pd.DataFrame) 32 | assert table.shape[0] > 0 33 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleByTimeRangeAndStaIDRange.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、站号段检索地面数据要素 3 | 4 | getSurfEleByTimeRangeAndStaIDRange 5 | """ 6 | 7 | import pandas as pd 8 | 9 | from nuwe_cmadaas.obs import retrieve_obs_station 10 | 11 | 12 | def test_hourly(start_date, end_date, start_station_id, end_station_id): 13 | table = retrieve_obs_station( 14 | "SURF_CHN_MUL_HOR", 15 | time=pd.Interval( 16 | start_date, start_date + pd.Timedelta(hours=6), 17 | closed="left", 18 | ), 19 | station=(start_station_id, end_station_id), 20 | ) 21 | assert isinstance(table, pd.DataFrame) 22 | assert table.shape[0] > 0 23 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleInBasinByTime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间、流域检索地面数据要素 3 | 4 | getSurfEleInBasinByTime 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date, end_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=[start_date, end_date], 15 | region={ 16 | "type": "basin", 17 | "basin_codes": "CJLY" 18 | }, 19 | ) 20 | assert isinstance(table, pd.DataFrame) 21 | assert table.shape[0] > 0 22 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleInBasinByTimeRange.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、流域检索地面数据要素 3 | 4 | getSurfEleInBasinByTimeRange 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=pd.Interval( 15 | start_date, start_date + pd.Timedelta(hours=6), 16 | closed="left", 17 | ), 18 | region={ 19 | "type": "basin", 20 | "basin_codes": "CJLY" 21 | }, 22 | ) 23 | assert isinstance(table, pd.DataFrame) 24 | assert table.shape[0] > 0 25 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleInRectByTime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间、经纬度范围检索地面数据要素 3 | 4 | getSurfEleInRectByTime 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date, end_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=[start_date, end_date], 15 | region={ 16 | "type": "rect", 17 | "start_longitude": 115.7, 18 | "end_longitude": 117.4, 19 | "start_latitude": 41.6, 20 | "end_latitude": 39.4, 21 | } 22 | ) 23 | assert isinstance(table, pd.DataFrame) 24 | assert table.shape[0] > 0 25 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleInRectByTimeRange.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、经纬度范围检索地面要素资料 3 | 4 | getSurfEleInRectByTimeRange 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=pd.Interval( 15 | start_date, 16 | start_date + pd.Timedelta(hours=1), 17 | closed="left", 18 | ), 19 | region={ 20 | "type": "rect", 21 | "start_longitude": 115.7, 22 | "end_longitude": 117.4, 23 | "start_latitude": 41.6, 24 | "end_latitude": 39.4, 25 | }, 26 | ) 27 | assert isinstance(table, pd.DataFrame) 28 | assert table.shape[0] > 0 29 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleInRegionByTime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间、地区检索地面要素数据 3 | 4 | getSurfEleInRegionByTime 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date, end_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=[start_date, end_date], 15 | region={ 16 | "type": "region", 17 | "admin_codes": "110000" 18 | }, 19 | ) 20 | assert isinstance(table, pd.DataFrame) 21 | assert table.shape[0] > 0 22 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfEleInRegionByTimeRange.py: -------------------------------------------------------------------------------- 1 | """ 2 | 按时间段、地区检索地面要素数据 3 | 4 | getSurfEleInRegionByTimeRange 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(start_date, end_date): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR", 14 | time=pd.Interval( 15 | start_date, end_date, 16 | closed="left", 17 | ), 18 | region={ 19 | "type": "region", 20 | "admin_codes": "110000" 21 | } 22 | ) 23 | assert isinstance(table, pd.DataFrame) 24 | assert table.shape[0] > 0 25 | -------------------------------------------------------------------------------- /tests/obs/station/test_getSurfLatestTime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 获取地面资料最新时次 3 | 4 | getSurfLatestTime 5 | """ 6 | import pandas as pd 7 | 8 | from nuwe_cmadaas.obs import retrieve_obs_station 9 | 10 | 11 | def test_hourly(): 12 | table = retrieve_obs_station( 13 | "SURF_CHN_MUL_HOR_N", 14 | time=pd.to_timedelta("1h"), 15 | ) 16 | assert isinstance(table, pd.DataFrame) 17 | assert table.shape[0] > 0 18 | --------------------------------------------------------------------------------