pygmt.xyz2grd: Allow more flexible ways to pass x/y/z arrays

オープン
#2,852 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
numpy, python
領域
api

調査の方向性

pygmt.xyz2grd API ドキュメントと現在の入力処理から始めます。1-D および 2-D の x/y/z 配列、region、spacing、registration が現在どのように解釈されているかを確認します。提案された柔軟な入力形式が機能し、指定されたデフォルト値と registration の動作を含め、既存の入力が引き続きサポートされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement

The pygmt.xyz2grd function accepts 1-D x/y/z arrays as input and produces a grid. Here, x/y are the x- and y-coordinates of grid nodes and z is the data values on grid nodes. Thus, for a 3x4 grid, x/y/z arrays all have 12 values (assuming it's gridline-registrated).

The pygmt.xyz2grd API documentation provides a simple example showing how we should prepare the x/y/z arrays.

import numpy as np
import pygmt

def func(x, y): 
    return x**2 + y**2

x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5])
z = func(x, y)
xx, yy, zz = x.flatten(), y.flatten(), z.flatten()
grid = pygmt.xyz2grd(x=xx, y=yy, z=zz, spacing=(1.0, 0.5), region=[0, 3, 10, 13])

As you can see, we have to use np.meshgrid to generate the 2-D x/y arrays, call a function (here z=x**2+y**2) to produce the 2-D z array, and use the flatten() method to convert the 2-D arrays into 1-D arrays. It's not straightforward and sometimes difficult to understand.

Here I propose to provide two more flexible ways to pass x/y/z arrays. The expected syntaxes are:

x = [0, 1, 2, 3]
y = [10.5, 11.0, 11.5, 12.0, 12.5]
z = func(*np.meshgrid(x, y))

# Case 1: 2-D z array + 1-D x/y arrays
grid = pygmt.grid(x=x, y=y, z=z)  # spacing and region are no longer needed

# Case 2: 2-D z array + region + spacing
grid = pygmt.grid(z=z, region=[0, 3, 10.5, 12.5], spacing=(1, 0.5))

Some notes:

  1. Internally we should do something like before passing data to the xyz2grd module:
    x = np.arange(region[0], region[1], spacing[0])  # required for case 2
    y = np.arange(region[2], region[3], spacing[1])  # required for case 2
    xx, yy = np.meshgrid(x, y)
    xx, yy, zz = xx.flatten(), yy.flatten(), z.flatten()
    # now pass xx/yy/zz to xyz2grd
    
  2. The -I option (spacing parameter) is required for xyz2grd. The spacings can be obtained by spacing = (x[1] - x[0], y[1] - y[0]) assuming that x and y are equal-spaced.
  3. For case 2, a special case is, only the 2-D z array is given and region/spacing are not given, then region is default to [0, nx-1, 0, ny-1], and spacing is default to [1, 1]
  4. In all cases, we need to be careful with the registration parameter.

Comments?

主要言語
Python
スター
882
フォーク
261
平均マージ
1日 3時間
マージ済み PR(30日)
29

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

GenericMappingTools/pygmt のほかの issue

GenericMappingTools/pygmt の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。