Skip to content

plot grids #96

@larsbuntemeyer

Description

@larsbuntemeyer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions