Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D Globe Map showing a specie's concentration #13

Open
nicodgomez opened this issue Jun 24, 2024 · 0 comments
Open

3D Globe Map showing a specie's concentration #13

nicodgomez opened this issue Jun 24, 2024 · 0 comments
Labels
feature New feature or request

Comments

@nicodgomez
Copy link

Hello GeosChem community. I have found this tutorial very useful to analyze GeosChem outputs. Also I have learned a lot about python programming and data types that can be treated. Recently I have been trying to illustrate species concentration in a 3D Interactive Globe Map. I have been trying the following code without success:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
import xarray as xr # the major tool to work with NetCDF data!
import plotly.graph_objects as go
import plotly.express as px

ds = xr.open_dataset("initial_GEOSChem_rst.4x5_tropchem.nc")
dr = ds['TRC_O3']
dr_surf = dr.isel(time=0, lev=0)

latitudes = dr_surf['lat'].values
longitudes = dr_surf['lon'].values
concentracion = dr_surf.values

fig = go.Figure()
fig.add_trace(go.Contour(
z=concentracion,
x=longitudes,
y=latitudes,
colorscale='Viridis',
colorbar=dict(title='Concentración de Ozono')
))

fig.update_geos(
projection_type="orthographic",
showcountries=True, countrycolor="Black",
showcoastlines=True, coastlinecolor="Black"
)

fig.update_layout(
title="Concentración de Ozono en un Mapa Esférico Interactivo",
geo=dict(
showland=True,
landcolor="white",
showocean=True,
oceancolor="LightBlue"
)
)

The code runs without error, but it only draws a contour map without coastlines, or the orthographic projection. I have used the same test archive as the tutorial, "initial_GEOSChem_rst.4x5_tropchem.nc".

I was able to reproduce a 3D Globe Map, in static format, using the following code:

import xarray as xr
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import numpy as np

from gamap_colormap import WhGrYlRd

archivo_nc = 'initial_GEOSChem_rst.4x5_tropchem.nc'
datos = xr.open_dataset(archivo_nc)

ozono = datos['TRC_O3']

ozono_surf = ozono.isel(time=0, lev=46)

latitudes = ozono_surf['lat'].values
longitudes = ozono_surf['lon'].values
concentracion_ozono = ozono_surf.values

fig = plt.figure(figsize=(10, 5))
ax = plt.axes(projection=ccrs.Orthographic(central_longitude=50, central_latitude=40))

ax.coastlines()
ax.gridlines(linestyle='--')

lon_grid, lat_grid = np.meshgrid(longitudes, latitudes)
mesh = ax.pcolormesh(lon_grid, lat_grid, concentracion_ozono, transform=ccrs.PlateCarree(), cmap=WhGrYlRd)

cbar = plt.colorbar(mesh, orientation='horizontal', pad=0.05)
cbar.set_label('Concentración de Ozono')

plt.title('Concentración de Ozono en un Mapa Esférico')

plt.show()

I would like to do an equivalent thing, but with the capability of rotating the globe.

Thank you in advance.

@nicodgomez nicodgomez added the feature New feature or request label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant