pygmt.xyz2grd: Allow more flexible ways to pass x/y/z arrays
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginnen Sie mit der API-Dokumentation von pygmt.xyz2grd und der aktuellen Verarbeitung der Eingaben. Prüfen Sie, wie 1-D- und 2-D-x/y/z-Arrays, region, spacing und registration derzeit interpretiert werden. Als erledigt gilt die Aufgabe, wenn die vorgeschlagenen flexiblen Eingabeformen funktionieren und bestehende Eingaben weiterhin unterstützt werden, einschließlich der angegebenen Standardwerte und des registration-Verhaltens.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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:
- Internally we should do something like before passing data to the
xyz2grdmodule: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 - The
-Ioption (spacingparameter) is required forxyz2grd. The spacings can be obtained byspacing = (x[1] - x[0], y[1] - y[0])assuming thatxandyare equal-spaced. - For case 2, a special case is, only the 2-D z array is given and
region/spacingare not given, thenregionis default to [0, nx-1, 0, ny-1], and spacing is default to[1, 1] - In all cases, we need to be careful with the
registrationparameter.
Comments?
- Vorherrschende Sprache
- Python
- Sterne
- 882
- Forks
- 261
- Ø Merge
- 1 T. 3 Std.
- Gemergte PRs (30 T.)
- 29
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus GenericMappingTools/pygmt
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
GenericMappingTools/pygmt#5014 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
discussions documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
GenericMappingTools/pygmt#4992 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Improve reporting the GMT version via "pygmt.show_versions()"Evtl. vergeben @yvonnefroehlich hat das vor 113 Tagen übernommen. Offenmaintenance
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
GenericMappingTools/pygmt#4812 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
GenericMappingTools/pygmt#4765 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add an AGENTS.md fileEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offendiscussions
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
GenericMappingTools/pygmt#4677 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in GenericMappingTools/pygmt
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
TigreGotico/orthography2ipa#2950 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Unstructured-IO/unstructured#4876 ·
Maintainer antworten meist innerhalb von 6 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
openfoodfacts/openfoodfacts-python#579 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
fairagro/m4.2_sql_to_arc#388 ·
Maintainer antworten meist innerhalb von 1 Tag