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

plot grids #96

Open
larsbuntemeyer opened this issue Aug 24, 2022 · 0 comments
Open

plot grids #96

larsbuntemeyer opened this issue Aug 24, 2022 · 0 comments

Comments

@larsbuntemeyer
Copy link
Contributor

larsbuntemeyer commented Aug 24, 2022

some code to plot grids:

import xarray as xr
import numpy as np

surflib = xr.open_dataset("/work/ch0636/g300099/PREPRO/domain/SGAR0275/lib_SGAR0275_frac.nc")
surflib
tfile = xr.open_dataset("/work/ch0636/g300099/SIMULATIONS/remo_results/067015/2017/xt/e067015t2017060100.nc")
tfile

# select small region around lower left
n=2
d=0.11
subset = {"rlon":slice(surflib.rlon.min()-n*d, surflib.rlon.min()+n*d), "rlat":slice(surflib.rlat.min()-n*d, surflib.rlat.min()+n*d)}
tsub = tfile.sel(**subset)
ssub = surflib.sel(**subset)
tsub


#ssub['rlon'] = ssub.rlon - 0.5*0.0275
#ssub['rlat'] = ssub.rlat - 0.5*0.0275

from matplotlib import pyplot as plt

fig = plt.figure()
ax = fig.add_subplot()

# arange ticks to be on cell edges
major_xticks = np.arange(tsub.rlon.min()-0.5*0.11, tsub.rlon.max()+0.5*0.11, 0.11)
major_yticks = np.arange(tsub.rlat.min()-0.5*0.11, tsub.rlat.max()+0.5*0.11, 0.11)
minor_xticks = np.arange(ssub.rlon.min()-0.5*0.0275, ssub.rlon.max()+0.5*0.0275, 0.0275)
minor_yticks = np.arange(ssub.rlat.min()-0.5*0.0275, ssub.rlat.max()+0.5*0.0275, 0.0275)
#minor_ticks = np.arange(0, 101, 5)

ax.set_xticks(major_xticks)
ax.set_xticks(minor_xticks, minor=True)
ax.set_yticks(major_yticks)
ax.set_yticks(minor_yticks, minor=True)

ax.grid(which='both')

ax.grid(which='minor', alpha=0.5, color='r')
ax.grid(which='major', alpha=0.8, color='b')

xr.plot.scatter(tsub, x='rlon', y='rlat', ax=ax, color='b')
xr.plot.scatter(ssub, x='rlon', y='rlat', ax=ax, color='r')
plt.axis([tsub.rlon.min(), tsub.rlon.max(), tsub.rlat.min(), tsub.rlat.max()])

plt.grid(True)

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant