### Install ctplanet using pip Source: https://github.com/markwieczorek/ctplanet/blob/master/README.md Instructions for cloning the ctplanet repository and installing it using pip. It also mentions the possibility of using python3 and pip3 depending on system setup. ```bash git clone https://github.com/MarkWieczorek/ctplanet.git pip install . ``` -------------------------------- ### Execute ctplanet example scripts Source: https://github.com/markwieczorek/ctplanet/blob/master/README.md Demonstrates how to navigate to the examples directory and execute a Python script, such as 'Moon-Crust.py'. It notes that 'python3' and 'pip3' might be necessary. ```bash cd examples python Moon-Crust.py ``` -------------------------------- ### Create Mars Crust Thickness Map with InSight Constraint (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Generates a crustal thickness map of Mars using gravity and topography, incorporating the InSight crustal thickness constraint. ```python import numpy as np def create_mars_crust_insight(gravity_field, topography, insight_constraint): """ Creates a crustal thickness map of Mars using the InSight constraint. Args: gravity_field (np.ndarray): Gravitational field data. topography (np.ndarray): Topography data. insight_constraint (dict): InSight crustal thickness constraint data. Returns: np.ndarray: Martian crust thickness map. """ # Implementation details using InSight constraint # ... pass ``` -------------------------------- ### Compute Mars J2 Gravitational Contribution (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Calculates the contribution of hydrostatic interfaces beneath the lithosphere to the gravitational J2 coefficient of Mars. ```python import numpy as np def compute_mars_j2_contribution(lithosphere_data, hydrostatic_interfaces): """ Computes the J2 gravitational contribution from hydrostatic interfaces. Args: lithosphere_data (np.ndarray): Lithosphere data. hydrostatic_interfaces (np.ndarray): Data on hydrostatic interfaces. Returns: float: Contribution to Mars' J2 coefficient. """ # Implementation for J2 calculation # ... pass ``` -------------------------------- ### Calculate Moon Crust Thickness (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Calculates the thickness of the lunar crust, supporting both constant and variable density models. The variable density model can reproduce specific research findings. ```python import numpy as np def calculate_moon_crust_thickness(density_crust, gravity_field, topography): """ Calculates the thickness of the lunar crust. Args: density_crust (float or np.ndarray): Density of the lunar crust. gravity_field (np.ndarray): Gravitational field data. topography (np.ndarray): Topography data. Returns: np.ndarray: Lunar crust thickness. """ # Implementation details for constant or variable density crust # ... pass ``` -------------------------------- ### Calculate Moon Core Hydrostatic Relief (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Computes the hydrostatic relief of the lunar core, taking into account the non-hydrostatic potential originating from the lithosphere. ```python import numpy as np def calculate_moon_core_relief(lithosphere_potential, core_properties): """ Calculates the hydrostatic relief of the lunar core. Args: lithosphere_potential (np.ndarray): Non-hydrostatic potential from the lithosphere. core_properties (dict): Properties of the lunar core. Returns: np.ndarray: Lunar core hydrostatic relief. """ # Implementation details for core relief calculation # ... pass ``` -------------------------------- ### Calculate Mars Crust Thickness (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Calculates the thickness of the Martian crust, supporting constant and variable density models. For variable density, density changes are assumed across the dichotomy boundary. ```python import numpy as np def calculate_mars_crust_thickness(density_crust, gravity_field, topography, dichotomy_boundary=None): """ Calculates the thickness of the Martian crust. Args: density_crust (float or np.ndarray): Density of the Martian crust. gravity_field (np.ndarray): Gravitational field data. topography (np.ndarray): Topography data. dichotomy_boundary (np.ndarray, optional): Mask for the dichotomy boundary. Returns: np.ndarray: Martian crust thickness. """ # Implementation details for constant or variable density crust # ... pass ``` -------------------------------- ### Compare Mars Crust Thickness with/without Hydrostatic Interfaces (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Generates a crustal thickness map for Mars from gravity and topography data. It compares results with and without considering hydrostatic interfaces. ```python import numpy as np def compare_mars_crust_hydrostatic(gravity_field, topography, use_hydrostatic=True): """ Compares Mars crustal thickness maps with and without hydrostatic interfaces. Args: gravity_field (np.ndarray): Gravitational field data. topography (np.ndarray): Topography data. use_hydrostatic (bool): Whether to account for hydrostatic interfaces. Returns: np.ndarray: Crustal thickness map. """ # Implementation details for comparison # ... pass ``` -------------------------------- ### Create Mars Crust Thickness Map with InSight and Dichotomy (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Generates a crustal thickness map of Mars using gravity, topography, and the InSight constraint, considering different densities across the dichotomy boundary. ```python import numpy as np def create_mars_crust_insight_dichotomy(gravity_field, topography, insight_constraint, density_contrast): """ Creates a crustal thickness map of Mars with InSight constraint and dichotomy density contrast. Args: gravity_field (np.ndarray): Gravitational field data. topography (np.ndarray): Topography data. insight_constraint (dict): InSight crustal thickness constraint data. density_contrast (dict): Density differences across the dichotomy. Returns: np.ndarray: Martian crust thickness map. """ # Implementation details considering dichotomy # ... pass ``` -------------------------------- ### Compute Earth Hydrostatic Relief (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Calculates the hydrostatic relief of Earth using the Preliminary Reference Earth Model (PREM). This involves applying hydrostatic principles to Earth's structure. ```python import numpy as np def compute_earth_hydrostatic_relief(prem_data): """ Computes the hydrostatic relief of Earth using PREM. Args: prem_data (dict): Data from the Preliminary Reference Earth Model. Returns: np.ndarray: Earth's hydrostatic relief. """ # Implementation using PREM data # ... pass ``` -------------------------------- ### Compute Mars Free Core Nutation Period (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Computes the free core nutation period of Mars. This calculation typically involves parameters related to Mars' core and rotational dynamics. ```python import numpy as np def compute_mars_fcn_period(core_properties, rotation_rate): """ Computes the free core nutation period of Mars. Args: core_properties (dict): Properties of Mars' core (e.g., density, moment of inertia). rotation_rate (float): Mars' rotation rate. Returns: float: Free core nutation period. """ # Implementation details for FCN period calculation # ... pass ``` -------------------------------- ### Calculate Ceres Hydrostatic Shape (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Calculates the hydrostatic shape of Ceres. This involves applying hydrostatic equilibrium principles to Ceres' physical properties. ```python import numpy as np def calculate_ceres_hydrostatic_shape(ceres_properties): """ Calculates the hydrostatic shape of Ceres. Args: ceres_properties (dict): Physical properties of Ceres (e.g., mass, radius, density). Returns: np.ndarray: Ceres' hydrostatic shape parameters. """ # Implementation for Ceres hydrostatic shape calculation # ... pass ``` -------------------------------- ### Create Mars Shape Images (Python) Source: https://github.com/markwieczorek/ctplanet/blob/master/docs/examples.md Generates images related to Mars' shape, referencing specific findings from Wieczorek et al. (2019). This likely involves processing shape models or related data. ```python import matplotlib.pyplot as plt import numpy as np def create_mars_shape_images(shape_data): """ Creates images related to Mars' shape. Args: shape_data (np.ndarray): Data representing Mars' shape. """ # Implementation for generating shape-related images # ... pass ``` -------------------------------- ### Calculate Inertia Tensor from Polar Moment (Mars Example) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Derives the full inertia tensor from the polar moment of inertia (C) and the planet's gravity field coefficients. This method assumes the coordinate system is aligned with the principal moment C and is demonstrated using Mars' gravity data. ```python import pyshtools as pysh from ctplanet import InertiaTensor_from_C # Load Mars gravity field potential = pysh.datasets.Mars.GMM3() # Known polar moment of inertia for Mars (from precession observations) C_mars = 2.536e37 # kg m^2 # Calculate full inertia tensor from C and gravity coefficients II, A, B, C_out, vec = InertiaTensor_from_C( C_mars, potential, normalize=False, quiet=False ) print(f"Inertia tensor:\n{II}") print(f"Principal moments: A={A:.4e}, B={B:.4e}, C={C_out:.4e}") ``` -------------------------------- ### Calculate Hydrostatic Shape Beneath Lithosphere (Mars Example) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Calculates the hydrostatic shape beneath a rigid lithospheric shell for Mars. It loads Mars' gravity field and topography data, reads a reference interior model, and then uses the HydrostaticShapeLith function. The output includes core shape coefficients and relief range. ```python import numpy as np import pyshtools as pysh from ctplanet import HydrostaticShapeLith, ReadRefModel # Load Mars data potential = pysh.datasets.Mars.GMM3() omega = pysh.constants.Mars.angular_velocity.value potential.omega = omega topo = pysh.datasets.Mars.MOLA_shape(lmax=359) topo.r0 = topo.coeffs[0, 0, 0] # Read 1D reference interior model radius, rho, i_crust, i_core, i_lith = ReadRefModel( 'Data/Mars-reference-interior-models/Smrekar/TAYAK.deck', depth=150.e3 # lithosphere thickness ) # Parameters d_lith = 150.e3 # lithosphere thickness (m) rho_crust = 2900. # effective surface density (kg/m^3) d_sigma = 45.e3 # depth of mass sheet source (m) lmax_hydro = 50 # maximum degree for hydrostatic calculation r_sigma = topo.r0 - d_sigma # Compute hydrostatic shape beneath lithosphere hlm, clm_hydro, mass_model = HydrostaticShapeLith( radius, rho, i_lith, potential, topo, rho_crust, r_sigma, omega, lmax_hydro ) # Access core-mantle boundary shape print("Core shape coefficients:") for l in range(0, 5): for m in range(0, l+1): print(f" l={l}, m={m}: {hlm[i_core].coeffs[0, l, m]:.6e}") # Expand to grid and analyze core_grid = hlm[i_core].expand(grid='DH2', lmax=359) print(f"Core relief range: {core_grid.min()/1.e3:.2f} to {core_grid.max()/1.e3:.2f} km") ``` -------------------------------- ### Calculate Moho Relief with Variable Crustal Density (Python) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Calculates Moho relief using a constant density mantle but with laterally varying crustal density. It accounts for spatial variations in crustal composition by accepting density as a spherical harmonic expansion, suitable for regions with known density heterogeneity. ```python import pyshtools as pysh from ctplanet import pyMohoRho # Load gravity, topography, and density data pot = pysh.datasets.Moon.GRGM900C() topo = pysh.datasets.Moon.LDEM_shape_pa(lmax=900) topo.r0 = topo.coeffs[0, 0, 0] # Load crustal grain density model (spherical harmonic coefficients) density = pysh.SHCoeffs.from_file('Data/density_no_mare_n3000_f3050_719.sh', lmax=719) rho_c0 = density.coeffs[0, 0, 0] # average grain density # Parameters lmax = 900 lmax_calc = 600 porosity = 0.12 # crustal porosity (0 to 1) rho_m = 3220.0 # mantle density (kg/m^3) thickave = 35.0e3 # average crustal thickness (m) filter_type = 1 # minimum amplitude filter half = 80 # filter half-wavelength degree # Calculate Moho with variable density crust moho = pyMohoRho( pot, topo, density, porosity, lmax, rho_m, thickave, filter_type=filter_type, half=half, lmax_calc=lmax_calc, quiet=False, delta_max=50. ) # Compute and visualize crustal thickness thick_grid = (topo - moho.pad(topo.lmax)).expand(grid='DH2') / 1.e3 thick_grid.plot(colorbar='bottom', cb_label='Crustal thickness, km') # Query specific locations lat, lon = -3.345, -20.45 thickness = (topo - moho.pad(topo.lmax)).expand(lat=lat, lon=lon) / 1.e3 print(f"Crustal thickness at ({lat}, {lon}): {thickness:.2f} km") ``` -------------------------------- ### Read Planetary Reference Interior Model (Python) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Parses a reference interior model file in deck format, converting it into arrays suitable for HydrostaticShapeLith. This function reads seismological reference models and can optionally specify lithosphere thickness. ```python from ctplanet import ReadRefModel # Read a Mars interior model radius, rho, i_crust, i_core = ReadRefModel( 'Data/Mars-reference-interior-models/Smrekar/TAYAK.deck', quiet=False ) print(f"Number of layers: {len(radius) - 1}") print(f"Surface radius: {radius[-1]/1.e3:.2f} km") print(f"Crust-mantle boundary index: {i_crust}") print(f"Core-mantle boundary index: {i_core}") print(f"Core radius: {radius[i_core]/1.e3:.2f} km") print(f"Mantle density: {rho[i_crust-1]:.0f} kg/m^3") print(f"Core density: {rho[i_core-1]:.0f} kg/m^3") # Read with lithosphere depth specification radius, rho, i_crust, i_core, i_lith = ReadRefModel( 'Data/Mars-reference-interior-models/Smrekar/TAYAK.deck', depth=150.e3, # lithosphere thickness in meters quiet=True ) print(f"Lithosphere base index: {i_lith}") print(f"Lithosphere base radius: {radius[i_lith]/1.e3:.2f} km") print(f"Lithosphere thickness: {(radius[-1] - radius[i_lith])/1.e3:.2f} km") # Access density profile for plotting import numpy as np for i in range(len(radius) - 1): print(f"Layer {i}: r={radius[i]/1.e3:.1f}-{radius[i+1]/1.e3:.1f} km, " f"rho={rho[i]:.0f} kg/m^3") ``` -------------------------------- ### Calculate Normalized Moments of Inertia (Python) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Calculates normalized inertia tensor components (A, B, C) and eigenvectors from a density model. Requires a density model (e.g., C_mars), potential data, and normalization radius. Outputs normalized moments and eigenvectors. ```python r_mean = 3389.5e3 # Mars mean radius (m) II_norm, A_norm, B_norm, C_norm, vec = InertiaTensor_from_C( C_mars, potential, normalize=True, r_norm=r_mean, quiet=True ) print(f"Normalized moments (I/MR^2):") print(f" A = {A_norm:.6f}") print(f" B = {B_norm:.6f}") print(f" C = {C_norm:.6f}") ``` -------------------------------- ### Calculate Mean Normalized Moment of Inertia (Python) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Computes the mean normalized moment of inertia (I/MR^2) for a 1D density profile up to a specified radius index. Supports both normalized and unnormalized calculations. Useful for estimating I/MR^2 for spherically symmetric models. ```python import numpy as np from ctplanet import moi # Define a simple 3-layer model (core, mantle, crust) radius = np.array([0., 1800.e3, 3200.e3, 3400.e3]) rho = np.array([7500., 3500., 2900., 0.]) n = len(radius) - 1 # surface index # Calculate normalized moment of inertia moi_normalized = moi(radius, rho, n, normalized=True) print(f"Normalized moment of inertia (I/MR^2): {moi_normalized:.6f}") # Calculate unnormalized moment moi_unnorm = moi(radius, rho, n, normalized=False) print(f"Unnormalized moment of inertia: {moi_unnorm:.4e} kg m^2") # Compare with different interior structures # More centrally condensed (larger core) radius_dense = np.array([0., 2200.e3, 3200.e3, 3400.e3]) rho_dense = np.array([8500., 3200., 2900., 0.]) moi_dense = moi(radius_dense, rho_dense, n, normalized=True) print(f"Dense core model I/MR^2: {moi_dense:.6f}") # Homogeneous sphere comparison radius_homo = np.array([0., 3400.e3]) rho_homo = np.array([3500., 0.]) moi_homo = moi(radius_homo, rho_homo, 1, normalized=True) print(f"Homogeneous sphere I/MR^2: {moi_homo:.6f}") # Should be ~0.4 ``` -------------------------------- ### Compute Surface Shape Coefficients and Flattening Source: https://context7.com/markwieczorek/ctplanet/llms.txt Extracts surface shape coefficients (hlm) and computes the flattening of a celestial body. It prints specific coefficients and the pole-to-equator elevation difference in kilometers. This functionality is useful for characterizing the shape of planets and moons. ```python n = len(radius) - 1 print(f"Surface h20 coefficient: {hlm[n].coeffs[0, 2, 0]:.6e}") print(f"Surface h40 coefficient: {hlm[n].coeffs[0, 4, 0]:.6e}") # Compute flattening (pole-to-equator difference) hydro_surface = hlm[n].expand() flattening_km = (hydro_surface.max() - hydro_surface.min()) / 1.e3 print(f"Pole-equator elevation difference: {flattening_km:.2f} km") ``` -------------------------------- ### Calculate Moho Relief with Constant Crustal Density (Python) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Calculates the relief along the crust-mantle interface (Moho) assuming constant crustal and mantle densities. This function iteratively inverts gravitational potential and topography data. It supports optional downward continuation filters for stabilization at high spherical harmonic degrees. ```python import pyshtools as pysh from ctplanet import pyMoho # Load lunar gravity and topography data pot = pysh.datasets.Moon.GRGM900C() topo = pysh.datasets.Moon.LDEM_shape_pa(lmax=900) topo.r0 = topo.coeffs[0, 0, 0] # Define crustal parameters lmax = 900 # spatial resolution of grids lmax_calc = 600 # maximum degree in calculations rho_c = 2550.0 # crustal density (kg/m^3) rho_m = 3220.0 # mantle density (kg/m^3) thickave = 35.0e3 # average crustal thickness (m) filter_type = 1 # minimum amplitude filter half = 80 # filter half-wavelength degree # Calculate Moho relief moho = pyMoho( pot, topo, lmax, rho_c, rho_m, thickave, filter_type=filter_type, half=half, lmax_calc=lmax_calc, quiet=False, delta_max=50. ) # Compute crustal thickness grid thick_grid = (topo.pad(lmax) - moho.pad(lmax)).expand(grid='DH2') / 1.e3 # Get thickness at specific location (Apollo 12/14 landing site) thickness_apollo = (topo.pad(lmax) - moho.pad(lmax)).expand( lat=-3.345, lon=-20.45 ) / 1.e3 print(f"Crustal thickness at Apollo 12/14 (km): {thickness_apollo:.2f}") # Plot results thick_grid.plot(colorbar='bottom', cb_label='Crustal thickness, km') ``` -------------------------------- ### Calculate Hydrostatic Shape of a Rotating Planet (Python) Source: https://context7.com/markwieczorek/ctplanet/llms.txt Computes the hydrostatic shape of a rotating planet or moon, including the total gravitational potential. This function calculates the equilibrium figure for a fully fluid body with a given radial density profile, with options for tidal effects in synchronously rotating satellites. ```python import numpy as np import pyshtools as pysh from ctplanet import HydrostaticShape # Define Earth parameters using PREM-like structure r_ref = pysh.constants.Earth.wgs84.a.value gm = pysh.constants.Earth.wgs84.gm.value omega = pysh.constants.Earth.wgs84.omega.value # Simple 4-layer model: inner core, outer core, mantle, crust radius = np.array([0., 1221.5e3, 3480.e3, 5701.e3, 6371.e3]) rho = np.array([13000., 11000., 5000., 3300., 0.]) # density between interfaces # Compute hydrostatic shape hlm, clm_hydro, mass_model = HydrostaticShape( radius, rho, omega, gm, r_ref ) ``` -------------------------------- ### Calculate Inertia Tensor from Shape Model Source: https://context7.com/markwieczorek/ctplanet/llms.txt Computes the inertia tensor (principal moments A, B, C) and their orientation from a planetary shape model and density profile. It can calculate the full tensor or normalized moments, and can be applied to the entire planet or specific layers like the core. ```python import numpy as np import pyshtools as pysh from ctplanet import HydrostaticShape, InertiaTensor_from_shape # Create a simple planetary model radius = np.array([0., 1500.e3, 3000.e3, 3400.e3]) rho = np.array([8000., 4000., 2900., 0.]) omega = 7.088e-5 # angular velocity (rad/s) gm = 4.28e13 # GM (m^3/s^2) r_ref = 3400.e3 # reference radius (m) # Compute hydrostatic shape hlm, clm_hydro, mass_model = HydrostaticShape(radius, rho, omega, gm, r_ref) n = len(radius) - 1 # surface index i_core = 1 # core index # Calculate inertia tensor for entire planet II, A, B, C, mass, R, vec = InertiaTensor_from_shape( hlm, rho, n, normalize=False, quiet=False ) print(f"Inertia tensor:\n{II}") print(f"Principal moments: A={A:.4e}, B={B:.4e}, C={C:.4e}") print(f"Total mass: {mass:.4e} kg") print(f"Surface radius: {R/1.e3:.2f} km") # Get normalized moments (I/MR^2) II_norm, A_norm, B_norm, C_norm, mass, R, vec = InertiaTensor_from_shape( hlm, rho, n, normalize=True, quiet=True ) print(f"Normalized: A/MR^2={A_norm:.6f}, B/MR^2={B_norm:.6f}, C/MR^2={C_norm:.6f}") # Calculate inertia tensor for core only II_core, A_core, B_core, C_core, mass_core, R_core, vec_core = InertiaTensor_from_shape( hlm, rho, i_core, normalize=True, quiet=True ) print(f"Core moments: A={A_core:.6f}, B={B_core:.6f}, C={C_core:.6f}") ``` -------------------------------- ### Calculate Hydrostatic Shape for Tidally Locked Moon Source: https://context7.com/markwieczorek/ctplanet/llms.txt Computes the hydrostatic shape of a celestial body, considering tidal locking. It uses constants for the Moon's angular velocity and semi-major axis, and Earth's mass. This function is essential for modeling the shape of synchronously rotating bodies. ```python # For a tidally locked moon (e.g., lunar case) omega_moon = pysh.constants.Moon.angular_velocity.value rem = pysh.constants.Moon.orbit_semimajor_axis.value mass_earth = pysh.constants.Earth.egm2008.mass.value hlm_tidal, clm_tidal, mass_tidal = HydrostaticShape( radius, rho, omega_moon, gm, r_ref, rp=rem, mp=mass_earth # include tidal potential ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.