### Install Cubedsphere (Pre-packaged) Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Install the cubedsphere package from the conda-forge channel. ```bash conda install -c conda-forge cubedsphere ``` -------------------------------- ### Install Cubedsphere (Development Version) Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Install the cubedsphere package in editable mode from the local repository. ```bash pip install -e . ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Install the necessary dependencies for the development version of cubedsphere using conda. ```bash conda install -c conda-forge xesmf esmpy xgcm xmitgcm matplotlib-base xarray ``` -------------------------------- ### Update xmitgcm from GitHub Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Ensure you have the latest version of xmitgcm by installing it directly from its GitHub repository. ```bash pip install git+https://github.com/MITgcm/xmitgcm.git ``` -------------------------------- ### Activate Conda Environment Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Activate the 'mitgcm' conda environment before proceeding with installations. ```bash conda activate mitgcm ``` -------------------------------- ### Clone Cubedsphere Repository Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Clone the cubedsphere repository to your local machine for development installation. ```bash git clone https://github.com/AaronDavidSchneider/cubedsphere.git ``` -------------------------------- ### Navigate to Cubedsphere Directory Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Change your current directory to the cloned cubedsphere repository. ```bash cd cubedsphere ``` -------------------------------- ### Download and Prepare Data Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Downloads a gzipped tar file containing model data using wget and then extracts it. Specifies the output directory for the extracted data. ```python !wget -O HD2.tar.gz https://figshare.com/ndownloader/files/36234516 !tar -xf HD2.tar.gz outdir_ascii = 'HD2_test/run' # path to data ``` -------------------------------- ### Load and Process Custom ASCII Dataset Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Loads a custom ASCII dataset using `cs.open_ascii_dataset`, specifying iterators, prefixes, and extra variables. It then regrids the dataset and applies post-processing for exorad. ```python # open Dataset using xmitgcm (see docs for xmitgcm.open_mdsdataset for more details) ds_ascii, grid = cs.open_ascii_dataset(outdir_ascii, iters=[41472000], prefix = ["EXOBFPla"], extra_variables=extra_variables) # regrid dataset regrid = cs.Regridder(ds_ascii, grid) ds = regrid() # (optional) converts wind, temperature and stuff ds = cs.exorad_postprocessing(ds, outdir=outdir_ascii) ``` -------------------------------- ### Load and Regrid Dataset Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Opens an ASCII dataset using cubedsphere's open_ascii_dataset function and then regrids it to a specified grid. Includes optional post-processing steps. ```python # open Dataset using xmitgcm (see docs for xmitgcm.open_mdsdataset for more details) ds_ascii, grid = cs.open_ascii_dataset(outdir_ascii, iters=[41472000], prefix = ["T","U","V","W"]) # regrid dataset regrid = cs.Regridder(ds_ascii, grid) ds = regrid() # (optional) converts wind, temperature and stuff ds = cs.exorad_postprocessing(ds, outdir=outdir_ascii) ``` -------------------------------- ### Create Conda Environment Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/installation.md Use this command to create a new conda environment named 'mitgcm'. ```bash conda create -n mitgcm ``` -------------------------------- ### Perform Back Regridding Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Initializes a Regridder object and performs back regridding on a dataset. This is useful for transforming data to a different grid. ```python regrid = cs.Regridder(ds, grid, input_type='ll') ds_regback = regrid() ``` -------------------------------- ### Basic Temperature Plot with Winds Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Generates a basic plot of temperature data from a selected horizontal slice and time, with wind vectors overlaid. Requires matplotlib and cubedsphere. ```python plt.figure() # Select horizontal slice at latest time: data = ds.isel(time=-1,Z=-20) # Plot temperature: data.T.plot() # Overplot winds: cs.overplot_wind(ds, data.U.values, data.V.values) plt.show() ``` -------------------------------- ### Import Libraries Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Imports the required Python libraries for data manipulation, plotting, and cubed sphere operations. Cartopy is optional and used for enhanced map projections. ```python import numpy as np import cubedsphere as cs import matplotlib.pyplot as plt import matplotlib.colors as mcolors import cartopy.crs as ccrs # optional, only needed for nicer projections ``` -------------------------------- ### Compare Original vs. Regridded Data Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Compares the original data with the regridded data using Cartopy projections. Plots temperature on both, with titles indicating the data source. ```python data_orig = ds_ascii.isel(time=-1,Z=-20) fig, ax = plt.subplots(2,1, subplot_kw={"projection":ccrs.Robinson()}) # Do the plots cs.plotCS(data_orig.T, data_orig, transform=ccrs.PlateCarree(), ax = ax[0]) ax[1].pcolormesh(data.lon, data.lat, data.T, transform = ccrs.PlateCarree()) ax[0].set_title('original data') ax[1].set_title('regridded') plt.show() ``` -------------------------------- ### Plot Globally Averaged Temperature Profile Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Plots the globally averaged temperature-pressure profile on a log-log scale. This helps in analyzing the vertical structure of the atmosphere. ```python plt.figure() T_global = (ds.T.isel(time=-1)*ds.area_c).sum(dim=['lon','lat'])/ds.area_c.sum(dim=['lon','lat']) plt.loglog(T_global, ds.Z) plt.ylim(700,1e-4) plt.title('globally averaged temperature pressure profile') plt.ylabel('p / bar') plt.xlabel('T / K') plt.show() ``` -------------------------------- ### Plot Planetary Emission Data Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Plots the 'EXOBFPla' variable from a dataset onto a Robinson projection. Requires Cartopy and Matplotlib. The plot displays the emission at the last time step and a specific pressure level. ```python plt.figure() ax = plt.axes(projection=ccrs.Robinson()) ds.EXOBFPla.isel(time=-1, Zp1=-1).plot(transform = ccrs.PlateCarree(), ax=ax, cmap=plt.get_cmap('inferno')) ax.set_title('planetary emission at {:.0f} d'.format(data.time.values)) plt.show() ``` -------------------------------- ### Add Grid Information to Dataset Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Adds longitude and latitude boundary information to the regridded dataset. This is a preparatory step for further regridding operations. ```python # Add some info to the regridded dataset reg_grid = regrid._build_output_grid(5, 4) ds["lon_b"] = reg_grid["lon_b"] ds["lat_b"] = reg_grid["lat_b"] ``` -------------------------------- ### Display Dataset Information Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Prints the structure and coordinates of an xarray Dataset. Useful for inspecting the data after operations like regridding. ```python ds ``` -------------------------------- ### Plot Regridded Data on Cubed Sphere Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Visualizes regridded data (temperature) on a cubed sphere projection using Robinson projection. Requires matplotlib and cartopy. ```python plt.figure() data_reg_back = ds_regback.isel(time=-1, Z=-20) ax = plt.axes(projection=ccrs.Robinson()) ax.set_title('time: {:.0f} d, Z={:.1e} bar'.format(data.time.values,data.Z.values)) cs.plotCS(data_reg_back.T, data_reg_back, transform=ccrs.PlateCarree(), ax = ax) plt.show() ``` -------------------------------- ### Temperature Plot with Winds using Cartopy Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Creates a more visually appealing plot using Cartopy for projections. Overplots temperature and wind data on a Robinson projection, with a custom title. ```python plt.figure() ax = plt.axes(projection=ccrs.Robinson()) # Plot temperature: data.T.plot(transform = ccrs.PlateCarree(), ax=ax) # Overplot winds: cs.overplot_wind(ds, data.U.values, data.V.values, ax=ax, transform=ccrs.PlateCarree(), stepsize=2) ax.set_title('time: {:.0f} d, Z={:.1e} bar'.format(data.time.values,data.Z.values)) plt.show() ``` -------------------------------- ### Define Extra Variables for Custom Datasets Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Defines a dictionary of extra variables to be loaded from custom datasets, specifying their dimensions and attributes. This is used with `cs.open_ascii_dataset`. ```python # Note: Not needed, since already part of cubedsphere package, this is shown only to demonstrate how it works extra_variables = dict(EXOBFPla=dict(dims=['k_p1', 'j', 'i'], attrs=dict(standard_name='EXOBFPla', long_name='Bolometric Planetary Flux', units='W/m2'))) ``` -------------------------------- ### Zonal Mean Wind Plot Source: https://github.com/aarondavidschneider/cubedsphere/blob/main/doc/source/notebooks/example.ipynb Generates a log-scale plot of the zonal mean wind. Sets specific y-axis limits for better visualization. ```python plt.figure() zmean = ds.U.isel(time=-1).mean(dim='lon') zmean.plot() plt.yscale('log') plt.ylim([700,1e-4]) plt.show() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.