### Install FARGOpy and Setup Environment Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-vector_fields.ipynb Installs the FARGOpy library and sets up the environment. It includes conditional installation for Google Colab and loads autoreload for development. ```python try: from google.colab import drive %pip install -Uq git+https://github.com/seap-udea/fargopy except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p ./gallery/ ``` -------------------------------- ### Install FARGOpy from Source Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Installs FARGOpy by cloning the GitHub repository and then running the pip installation command from the cloned directory. This method is suitable for installing from a local copy of the source code. ```bash git clone https://github.com/seap-udea/fargopy cd fargopy pip install . ``` -------------------------------- ### List Available FARGO3D Setups Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-control.ipynb Retrieves and displays a list of all available simulation setups within the FARGO3D directory. This helps in choosing the appropriate setup for a simulation. ```python fp.Simulation.list_setups() ``` -------------------------------- ### Set FARGO3D Simulation Setup Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-control.ipynb Sets the simulation's setup to a specific configuration, in this case, 'p3diso'. This prepares the simulation environment for compilation and execution with the chosen setup. ```python sim.set_setup('p3diso') ``` -------------------------------- ### Load fargopy Simulation Setup Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-control.ipynb Loads an existing fargopy simulation setup from a JSON file. This allows you to reconnect to a previously saved simulation state, including its configuration, domain, and loaded variables. It requires the setup name and the 'load=True' argument. ```python sim = fp.Simulation(setup='p3diso',load=True) ``` -------------------------------- ### Initialize and verify FARGOpy installation Source: https://github.com/seap-udea/fargopy/blob/main/README.md The `ifargopy` command initializes FARGOpy in an IPython environment and can be used to verify the installation. Upon first run, it creates a configuration directory and file. ```bash $ ifargopy ``` ```bash $ ifargopy --verify ``` ```bash Running FARGOpy version X.Y.Z fargopy X.Y.Z is successfully installed. Location: /usr/local/lib/pythonX.X/site-packages/fargopy ``` -------------------------------- ### Install and Import FARGOpy Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Installs the latest version of FARGOpy from GitHub and imports the library. Includes conditional logic for Colab environments. ```python try: from google.colab import drive %pip install -Uq git+https://github.com/seap-udea/fargopy except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 import fargopy as fp ``` -------------------------------- ### Verify FARGOpy Installation Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Checks if FARGOpy is installed correctly by running the `--verify` command. It outputs the installed version and its location. ```bash $ ifargopy --verify ``` -------------------------------- ### Install Latest FARGOpy from GitHub Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Installs the latest development version of FARGOpy directly from its GitHub repository. This is useful for accessing the newest features, which may be unstable. ```bash $ pip install git+https://github.com/seap-udea/fargopy ``` -------------------------------- ### Install FARGOpy using pip Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Installs the FARGOpy package from the Python Package Index (PyPI). This command also installs all necessary dependencies, except for FARGO3D which needs to be installed separately. ```bash $ pip install fargopy ``` -------------------------------- ### Install FARGOpy using pip Source: https://github.com/seap-udea/fargopy/blob/main/README.md Installs the FARGOpy package from the Python Package Index (PyPI). This command also installs necessary dependencies. For the latest development version, a direct GitHub installation is provided. ```bash pip install fargopy ``` ```bash pip install git+https://github.com/seap-udea/fargopy ``` -------------------------------- ### Download and Initialize Simulation Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Downloads a pre-computed simulation dataset and initializes a FARGOpy Simulation object. Handles existing directories and loads simulation properties. ```python simpath = fp.Simulation.download_precomputed('fargo') sim = fp.Simulation(output_dir=simpath) ``` -------------------------------- ### Load All Fields (Previous Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Illustrates the command used in previous FARGOpy versions to load all available fields with a single call. ```python gasdens_all = sim.load_allfields('gasdens') ``` -------------------------------- ### Fargo3D Simulation Initialization (fid3) Source: https://github.com/seap-udea/fargopy/blob/main/science/pds70c-isothermal/notebooks/pds70iso-fargopy-scripts.ipynb Connects to a third Fargo3D simulation run (fid3), loads its parameters, and displays the simulation domain and planet information. This is a standard setup procedure for each simulation. ```text Your simulation is now connected with '/home/alejo/fargo3d/' Now you are connected with output directory '/home/alejo/fargo3d/outputs/pds70hr_fid3_rs' Found a variables.par file in '/home/alejo/fargo3d/outputs/pds70hr_fid3_rs', loading properties Loading variables 85 variables loaded Simulation in 3 dimensions Loading domain in spherical coordinates: Variable phi: 544 [[0, np.float64(-3.133244137592831)], [-1, np.float64(3.133244137592804)]] Variable r: 320 [[0, np.float64(0.40328254528735263)], [-1, np.float64(1.9838523013242646)]] Variable theta: 96 [[0, np.float64(1.4008895642020311)], [-1, np.float64(1.5699067625879688)]] Number of snapshots in output directory: 201 Planets found in summary.dat: Name: PDS70c, Initial pos: [1.0, 0.010048, 0.0], Mass: 0.010048 Units set to CGS. ``` -------------------------------- ### List and Download Precomputed Simulations Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-basics.ipynb Demonstrates how to list available precomputed simulations using `fp.Simulation.list_precomputed()` and download a specific simulation, such as the 'fargo' 2D Jovian planet simulation, using `fp.Simulation.download_precomputed()`. ```python fp.Simulation.list_precomputed() simpath = fp.Simulation.download_precomputed('fargo') ``` -------------------------------- ### Load Fields in Cartesian and Cylindrical Coordinates (New Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb The new version requires explicitly loading fields for each coordinate system if simultaneous plotting is needed. This example loads 'gasdens' in both cartesian and cylindrical coordinates for a specified snapshot range and slice. ```python fields_cyl = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cyllindrical', slice='z=0' ) fields_cartesian = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cartesian', slice='z=0' ) gasdens_plane = np.array(fields_cartesian.gasdens_mesh[20]) mesh = fp.Dictobj( x=np.array(fields_cartesian.var1_mesh[20]), y=np.array(fields_cartesian.var2_mesh[20]), phi=np.array(fields_cyl.var1_mesh[20]), r=np.array(fields_cyl.var2_mesh[20]) ) ``` -------------------------------- ### List and Download Precomputed FARGOpy Simulations Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-vector_fields.ipynb Demonstrates how to list available precomputed simulations and download a specific one, such as 'p3disoj', which represents a protoplanetary disk with a Jovian planet. ```python # List available precomputed simulations fp.Simulation.list_precomputed() # Download a specific simulation (e.g., 'p3disoj') fp.Simulation.download_precomputed('p3disoj') ``` -------------------------------- ### Download and load FARGO3D simulation data Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-time_interpolation.ipynb Downloads a pre-computed 3D simulation of a disk with a Jovian planet and initializes the fargopy Simulation object. Connects to the simulation output directory. ```python PATH = fp.Simulation.download_precomputed('p3disoj') sim = fp.Simulation(output_dir=PATH) ``` -------------------------------- ### List and Download Precomputed Simulations Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-flux.ipynb Demonstrates how to list available precomputed simulations using `fp.Simulation.list_precomputed()` and download a specific simulation, such as 'p3disoj', using `fp.Simulation.download_precomputed()`. The download path is stored in the `PATH` variable. ```python # List available precomputed simulations (interactive) fp.Simulation.list_precomputed() # Download an example 3D simulation (p3disoj) and set PATH PATH = fp.Simulation.download_precomputed('p3disoj') ``` -------------------------------- ### List and Download Precomputed FARGOpy Simulations Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-vector_fields.ipynb Shows how to list available precomputed simulation datasets and download a specific one. This is useful for obtaining sample data for analysis. ```python fp.Simulation.list_precomputed() fp.Simulation.download_precomputed('p3disoj') ``` -------------------------------- ### Install FARGOpy in Development Mode Source: https://github.com/seap-udea/fargopy/blob/main/CONTRIBUTING.md Installs the FARGOpy package in editable mode, allowing for direct code changes without reinstallation. It also installs development dependencies. ```bash pip install -e . pip install -r requirements-dev.txt ``` -------------------------------- ### Connect to Simulation Output Directory Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Initializes a `fp.Simulation` object by connecting it to a specified output directory. This loads simulation properties, domain information, and identifies any planets present. ```python sim = fp.Simulation(output_dir='/tmp/fargo') ``` -------------------------------- ### Install FARGOpy in Google Colab Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Installs the latest version of FARGOpy within a Google Colab environment. It includes a check to ensure the code only runs when actually in Colab and skips installation otherwise. ```python try: from google.colab import drive %pip install -Uq git+https://github.com/seap-udea/fargopy except ImportError: print("Not running in Colab, skipping installation") %mkdir -p ./gallery/ ``` -------------------------------- ### Initialize FARGOpy and Download FARGO3D Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-control.ipynb Initializes the FARGOpy environment and downloads the FARGO3D simulation code. The 'force=True' option ensures that the latest version is downloaded, overwriting any existing files. ```python fp.initialize('download', force=True) ``` -------------------------------- ### Download a Precomputed FARGO3D Simulation Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-interpolation.ipynb Downloads a specified precomputed simulation dataset (e.g., 'p3disoj') from the cloud. The data is saved to a temporary directory. Dependencies: fargopy. ```python PATH = fp.Simulation.download_precomputed('p3disoj') ``` -------------------------------- ### Initialize FARGOpy Environment Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Initializes the FARGOpy environment using the `ifargopy` command. The first run creates a configuration directory `~/.fargopy` containing configuration files and an IPython initialization script. ```bash $ ifargopy ``` -------------------------------- ### Editable Installation for Development Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Installs FARGOpy in an editable mode from the source directory. This allows changes made to the source code to be reflected immediately without needing to reinstall the package. ```bash cd fargopy pip install -e . ``` -------------------------------- ### Connect to and Load FARGOpy Simulation Data Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-basics.ipynb Connects a FARGOpy Simulation object to the downloaded simulation data directory and loads simulation properties. It then loads the gas density field in both cylindrical and Cartesian coordinates for a specified range of snapshots and a slice at z=0. ```python sim = fp.Simulation(output_dir=simpath) fields_cyl = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cyllindrical', slice='z=0' ) fields_cartesian = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cartesian', slice='z=0' ) ``` -------------------------------- ### Install FARGOpy in Google Colab Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-control.ipynb Installs the latest version of the FARGOpy package. This is typically the first step when using FARGOpy in a Google Colab environment. ```python import fargopy as fp import numpy as np import matplotlib.pyplot as plt import pandas as pd ``` -------------------------------- ### Load Planet Data and Properties in Python Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-flux.ipynb Loads planet data from a simulation snapshot and accesses its orbital properties like Hill radius, position, velocity, and mass. Requires the 'fargopy' library and a simulation object. ```python SNAP = 10 planets = sim.load_planets(snapshot = SNAP) jupiter = planets[0] type(jupiter) r_hill = jupiter.hill_radius #Positions and velocities of the planet at snapshot SNAP xp, yp, zp = jupiter.pos.x, jupiter.pos.y, jupiter.pos.z vxp, vyp, vzp = jupiter.vel.x, jupiter.vel.y, jupiter.vel.z Mass = jupiter.mass ``` -------------------------------- ### Download and Initialize Fargo 3D Simulation Source: https://github.com/seap-udea/fargopy/blob/main/README.ipynb Downloads a pre-computed 3D simulation dataset ('p3disoj') and initializes the FargoPy Simulation object. This sets up the simulation environment for further analysis and visualization. ```python fp.Simulation.download_precomputed('p3disoj') sim = fp.Simulation(output_dir='/tmp/p3disoj') ``` -------------------------------- ### Slice Field (Previous Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Illustrates how to slice a loaded field to obtain a 2D plane ('z=0') and its corresponding meshgrid in older FARGOpy versions. ```python gasdens_plane, mesh = gasdens.meshslice(slice='z=0') ``` -------------------------------- ### List Available Precomputed FARGO3D Simulations Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-interpolation.ipynb Lists the precomputed simulation datasets available for download via FARGOpy. This function helps users choose which simulation to download for analysis. Dependencies: fargopy. ```python fp.Simulation.list_precomputed() ``` -------------------------------- ### Load Field (Previous Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Demonstrates how to load a specific field ('gasdens') from a given snapshot (20) in previous versions of FARGOpy, with the option to interpolate. ```python gasdens = sim.load_field('gasdens', snapshot=20, interpolate=False) ``` -------------------------------- ### Connect to Simulation Data Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-basics.ipynb Connects the FARGOpy `Simulation` object to the downloaded simulation data directory. It loads simulation properties, including dimensions, coordinate systems, and detected planets. ```python sim = fp.Simulation(output_dir=simpath) ``` -------------------------------- ### 3D Visualization of Interpolated Density in Python Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-flux.ipynb Creates an interactive 3D scatter plot of surface centers colored by the logarithm of the interpolated gas density. Uses Plotly for rendering and displays axes in astronomical units. ```python import plotly.graph_objects as go import numpy as np fig = go.Figure(data=go.Scatter3d( x=xcs.flatten()*sim.UL/fp.AU, y=ycs.flatten()*sim.UL/fp.AU, z=zcs.flatten()*sim.UL/fp.AU, mode='markers', marker=dict(size=2, color=np.log(rho.flatten()*sim.URHO), colorscale='Spectral_r', opacity=1, colorbar=dict(title='log10(ρ) [g cm−3]')) )) fig.update_layout(scene=dict(xaxis_title='X [au]', yaxis_title='Y [au]', zaxis_title='Z [au]', aspectmode='data'), title='Interpolation on Sphere Surface Centers in 3D Gas Density Field') fig.show() ``` -------------------------------- ### Plot Field Slice (Deprecated Style) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Demonstrates plotting a 2D field slice using matplotlib with deprecated styles, suitable for older versions or minimal adaptations. ```python import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(6,6)) ax.pcolormesh(mesh.x, mesh.y, gasdens_plane, cmap='prism') ax.axis('equal') ax.set_xlabel('x [au]') ax.set_ylabel('y [au]') mark = fp.Plot.fargopy_mark(ax) ``` -------------------------------- ### Load Field (New Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Shows the updated method for loading a field in newer FARGOpy versions, requiring explicit slicing (e.g., 'z=0') instead of an 'interpolate' option. ```python gasdens = sim.load_field('gasdens', snapshot=20, slice='z=0') ``` -------------------------------- ### Import Core Libraries Source: https://github.com/seap-udea/fargopy/blob/main/examples/fargopy-tutorial-flux.ipynb Imports essential libraries for data analysis and visualization, including fargopy, numpy, matplotlib, pandas, and plotly. It also includes a check for the FARGOpy configuration file version. ```python import sys import fargopy as fp import numpy as np import matplotlib.pyplot as plt import pandas as pd import plotly.graph_objects as go ``` -------------------------------- ### Load Specific Fields (New Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Demonstrates the updated method in newer FARGOpy versions for loading specific fields (e.g., 'gasdens', 'gasv') across a range of snapshots, with slicing. ```python gasdens_all = sim.load_field(['gasdens','gasv'], snapshot=[0, sim.nsnaps-1], slice='z=0') ``` -------------------------------- ### Load Velocity and Density Fields from Simulation Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-vector_fields.ipynb Loads specific fields ('gasv' for gas velocity and 'gasdens' for gas density) from a chosen snapshot (e.g., snapshot 10) of the simulation. It allows specifying coordinate systems and slicing planes. ```python fields = sim.load_field( fields=['gasv','gasdens'], snapshot=10, coords='cartesian', slice="phi=0" ) ``` -------------------------------- ### Import Libraries and Set Plotting Style Source: https://github.com/seap-udea/fargopy/blob/main/science/pds70c-isothermal/notebooks/pds70iso-fargopy-scripts.ipynb Imports necessary libraries (fargopy, numpy, matplotlib) and sets a specific plotting style ('seaborn-v0_8-paper'). This is a standard setup for plotting scripts. ```python import fargopy as fp import numpy as np import matplotlib.pyplot as plt from matplotlib.lines import Line2D plt.style.use('seaborn-v0_8-paper') ``` -------------------------------- ### Prepare for time interpolation visualization Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-time_interpolation.ipynb Loads the 'gasdens' field for a specific slice and snapshots, extracts simulation mesh coordinates, and defines time steps for interpolation. Sets up plotting environment. ```python fields = sim.load_field( fields='gasdens', slice="phi=0,theta= 89 deg", snapshot=[0,10]) xsim = fields.var1_mesh[0] ysim = fields.var2_mesh[0] zsim = fields.var3_mesh[0] rsim = np.sqrt(xsim**2 + ysim**2 + zsim**2) times = np.linspace(0, 1.0, 100) # 100 timesteps ``` -------------------------------- ### Get Shape of 1D Field Data Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-interpolation.ipynb Retrieves and prints the shape of the loaded 1D field data ('gasdens_mesh'). This confirms that the data is indeed one-dimensional, as expected from a 1D slice. ```python fields.gasdens_mesh[0].shape ``` -------------------------------- ### Plot Field Slice (Best Practice - New Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Shows the best practice for plotting a field slice in the new FARGOpy version, loading fields with specified coordinates and slicing, then plotting with matplotlib. ```python fields_cartesian = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cartesian', slice='z=0' ) snapshot = 20 gasdens_plane = fields_cartesian.gasdens_mesh[snapshot] x = fields_cartesian.var1_mesh[snapshot] y = fields_cartesian.var2_mesh[snapshot] fig, ax = plt.subplots(figsize=(6,6)) ax.pcolormesh(x, y, gasdens_plane, cmap='prism') ax.axis('equal') ax.set_xlabel('x [au]') ax.set_ylabel('y [au]') mark = fp.Plot.fargopy_mark(ax) ``` -------------------------------- ### Initialize FARGOpy Simulation Object Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-vector_fields.ipynb Connects a FARGOpy Simulation object to the downloaded simulation data by specifying the output directory. It loads simulation properties and identifies planets. ```python sim = fp.Simulation(output_dir='/tmp/p3disoj') ``` -------------------------------- ### Minimal Solution for Field Slicing (New Version) Source: https://github.com/seap-udea/fargopy/blob/main/REFACTORING.ipynb Provides a minimal code modification to achieve similar results to previous field slicing methods by accessing raw data and mesh from the field handler. ```python raw_data = sim.field_handler.get_raw_data() gasdens_plane, mesh = raw_data.data, raw_data.mesh ``` -------------------------------- ### Load Gas Density Field Source: https://github.com/seap-udea/fargopy/blob/main/docs/examples/fargopy-tutorial-basics.ipynb Loads the gas density field from the simulation data for a specified range of snapshots. It demonstrates loading the field in both cylindrical and Cartesian coordinates, focusing on the z=0 slice. ```python fields_cyl = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cyllindrical', slice='z=0' ) fields_cartesian = sim.load_field( fields='gasdens', snapshot=[1, sim.nsnaps-1], coords='cartesian', slice='z=0' ) ``` -------------------------------- ### Fargo3D Simulation Initialization (fid2) Source: https://github.com/seap-udea/fargopy/blob/main/science/pds70c-isothermal/notebooks/pds70iso-fargopy-scripts.ipynb Connects to a second Fargo3D simulation run (fid2), loads its properties, and displays domain and planet information. This is similar to the initial setup but for a different simulation instance. ```text Your simulation is now connected with '/home/alejo/fargo3d/' Now you are connected with output directory '/home/alejo/fargo3d/outputs/pds70hr_fid2_rs' Found a variables.par file in '/home/alejo/fargo3d/outputs/pds70hr_fid2_rs', loading properties Loading variables 85 variables loaded Simulation in 3 dimensions Loading domain in spherical coordinates: Variable phi: 544 [[0, np.float64(-3.133244137592831)], [-1, np.float64(3.133244137592804)]] Variable r: 320 [[0, np.float64(0.40328254528735263)], [-1, np.float64(1.9838523013242646)]] Variable theta: 96 [[0, np.float64(1.4008895642020311)], [-1, np.float64(1.5699067625879688)]] Number of snapshots in output directory: 201 Planets found in summary.dat: Name: PDS70c, Initial pos: [1.0, 0.005024, 0.0], Mass: 0.005024 Units set to CGS. ```