viscid.mapfield module¶
utility for translating spherical fields (theta, phi) <-> (lat, lon)
-
viscid.mapfield.
as_mapfield
(fld, order=('lon', 'lat'), units='')[source]¶ Make sure a field has (lon, lat) coordinates
Parameters: - fld (Field) – some field to transform
- order (tuple, optional) – Desired axes of the result
- units (str, optional) – units of the result (deg/rad)
Returns: a field with (lon, lat) coordinates. The data will be loaded into memory if not already.
Return type: Viscid.Field
-
viscid.mapfield.
as_spherefield
(fld, order=('phi', 'theta'), units='')[source]¶ Make sure fld has (phi, theta) coordinates
fld (Field): some field to transform order (tuple, optional): Desired axes of the result units (str, optional): units of the result (deg/rad)Returns: a field with (lon, lat) coordinates. The data will be loaded into memory if not already. Return type: Viscid.Field
-
viscid.mapfield.
as_polar_mapfield
(fld, bounding_lat=None, hemisphere='north', make_periodic=False)[source]¶ Prepare a theta/phi or lat/lon field for polar projection
Parameters: - fld (Field) – Some scalar or vector field
- bounding_lat (float, optional) – Used to slice the field, i.e., gives data from the pole to bounding_lat degrees equator-ward of the pole
- hemisphere (str, optional) – ‘north’ or ‘south’
Returns: a field that can be mapfield plotted on polar axes
Return type: Field
Raises: ValueError
– on bad hemisphere
-
viscid.mapfield.
pts2polar_mapfield
(pts, pts_axes, pts_unit='deg', hemisphere='north')[source]¶ Prepare theta/phi or lat/lon points for a polar plot
Parameters: - pts (ndarray) – A 2xN array of N points where the spatial dimensions encode phi, theta, lat, or lon.
- pts_axes (sequence) – sequence of strings that say what each axis of pts encodes, i.e., (‘theta’, ‘phi’).
- pts_unit (str, optional) – units of pts (‘deg’ or ‘rad’)
- hemisphere (str, optional) – ‘north’ or ‘south’
Returns: 2xN array of N points in radians where the axes are (‘lon’, ‘lat’), such that they can be given straight to matplotlib.pyplot.plot()
Return type: ndarray
Raises: ValueError
– On bad pts_axesExample
This example plots total field align currents in the northern hemisphere, then plots a curve onto the same plot
>>> f = viscid.load_file("$SRC/Viscid/sample/*_xdmf.iof.*.xdmf") >>> vlt.plot(1e9 * f['fac_tot'], symmetric=True) >>> # now make a curve from dawn to dusk spanning 20deg in lat >>> N = 64 >>> pts = np.vstack([np.linspace(-90, 90, N), np.linspace(10, 30, N)]) >>> pts_polar = viscid.pts2polar_mapfield(pts, ('phi', 'theta'), pts_unit='deg') >>> plt.plot(pts_polar[0], pts_polar[1]) >>> vlt.show()
-
viscid.mapfield.
convert_coordinates
(fld, order, crd_mapping, units='')[source]¶ Convert a Field’s coordinates
Parameters: - fld (Field) – Description
- order (sequence) – target coordinates
- crd_mapping (dict) – summarizes functions that go from base -> target
- units (str, optional) – Additional info if you need to convert units too
Raises: RuntimeError
– If no mapping is found to go base -> target
-
viscid.mapfield.
lon2phi
(lon, unit='deg')[source]¶ spherical longitude -> phi transform; currently a no-op
-
viscid.mapfield.
phi2lon
(phi, unit='deg')[source]¶ spherical phi -> longitude transform; currently a no-op
-
viscid.mapfield.
cart2sph
(arr, deg=False)[source]¶ Convert cartesian points to spherical (rad by default)
Parameters: - arr (sequence) – shaped (3, ) or (3, N) for N xyz points
- deg (bool) – if result should be in degrees
Returns: - shaped (3, ) or (3, N) r, theta, phi points in radians
by default
Return type: ndarray
-
viscid.mapfield.
cart2latlon
(arr, deg=True)[source]¶ Convert latitude longitude (deg by default) to cartesian
Parameters: - arr (sequence) – shaped (3, ) or (3, N) for N r, theta, phi points in radians by default
- deg (bool) – if arr is in dergrees
Returns: shaped (2, ) or (2, N) xyz
Return type: ndarray
-
viscid.mapfield.
sph2cart
(arr, deg=False)[source]¶ Convert cartesian points to spherical (rad by default)
Parameters: - arr (sequence) – shaped (3, ) or (3, N) for N r, theta, phi points in radians by default
- deg (bool) – if arr is in dergrees
Returns: shaped (3, ) or (3, N) xyz
Return type: ndarray
-
viscid.mapfield.
latlon2cart
(arr, r=1.0, deg=True)[source]¶ Convert cartesian points to latitude longitude (deg by default)
Parameters: - arr (sequence) – shaped (2, ) or (2, N) for N r, theta, phi points in radians by default
- deg (bool) – if arr is in dergrees
Returns: shaped (3, ) or (3, N) xyz
Return type: ndarray
-
viscid.mapfield.
great_circle
(p1, p2, origin=(0, 0, 0), n=32)[source]¶ Get great circle path between two points in 3d
Parameters: - p1 (sequence) – first point as [x, y, z]
- p2 (sequence) – second point as [x, y, z]
- origin (sequence) – origin of the sphere
- n (int) – Number of line segments along the great circle
Returns: 3xN ndarray