Skip to content

Instantly share code, notes, and snippets.

@okadate
okadate / add_depth.py
Created October 23, 2024 01:09
Add z_rho & depth_rho into xr.Dataset
# add_depth.py (c) 2021-01-28 OKADA Teruhisa
import xarray as xr
def add_depth(ds):
"""
Add z_rho & depth_rho into xr.Dataset
"""
if not hasattr(ds, 'Vtransform'):
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[::-1], labels[::-1], bbox_to_anchor=[1,1], loc=2)
from matplotlib import dates
def set_xdate(ax):
ax[-1].set_xlabel('')
# major
ax[-1].xaxis.set_major_locator(dates.MonthLocator())
ax[-1].xaxis.set_major_formatter('')
# minor
loc = dates.MonthLocator(bymonthday=16)
fmt = dates.ConciseDateFormatter(loc, zero_formats=['','%b\n%Y','%b','%b-%d','%H:%M','%H:%M'], show_offset=False)
@okadate
okadate / interp_multi-mesh_for_ROMS.py
Last active November 14, 2021 05:30
[xarray] 可変メッシュのNetCDFを等間隔に抜き出す関数
import numpy as np
def interp(x_rho, y_rho, nc):
"""Interpolate multi-interval mesh into equal interval mesh for ROMS
(c) 2021-11-14 OKADA Teruhisa
Parameters:
x_rho: array-like of x_rho-points for interpolated points
y_rho: array-like of y_rho-points for interpolated points
nc: xr.Dataset for ROMS with multi-interval mesh
@okadate
okadate / time_contour_obweb_4figs.ipynb
Last active October 28, 2021 02:50
Time-depth contour plots for Osaka Bay Monitoring Post data.
We couldn’t find that file to show.
class C:
@property
def x(self):
return self.__x
@x.setter
def x(self, value):
self.__x = value
if __name__ == "__main__":
c = C()
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def __len__(self):
return len(self.__dict__)
def __repr__(self):
return str(self.__dict__)
def __str__(self):
return str(self.__dict__)
@okadate
okadate / command_tips
Last active February 18, 2019 10:01
Command tips
# ディレクトリは755、ファイルは644
chmod -R a=rX,u+w .
@okadate
okadate / vim_tips.txt
Created February 1, 2019 10:02
vim tips
[c]heck しながら置換
:%s/置換前文字列/置換後文字列/gc
@okadate
okadate / matplotlib_tips.py
Created January 22, 2019 10:28
matplotlib tips
# Hatched Rectangle
import matplotlib.patches as patches
p = patches.Rectangle((0,-17), 8, 17-df.depth.iloc[-1], linewidth=0, fill=None, hatch='/')
ax.add_patch(p)