def plot_style(name, path): print("plot_style", name, file=sys.stderr) yaml = climetlab.plotting.style(name).data data = None gallery = yaml.get("gallery", {}) if "sample" in gallery: sample = gallery["sample"] if "source" in sample: source = sample["source"] data = get_source(source["name"], source.get("to_pandas"), **source.get("args", {})) else: dataset = sample["dataset"] data = get_dataset(dataset["name"], dataset.get("to_pandas"), **dataset.get("args", {})) else: if "msymb" in yaml["magics"]: data = get_dataset( "sample-bufr-data", to_pandas={ "columns": ("latitude", "longitude"), "filters": {} }, ) if "mcont" in yaml["magics"]: data = get_dataset("sample-grib-data") extra = gallery.get("plot_map", {}) climetlab.plot_map(data, style=name, path=path, **extra) print("done", name, file=sys.stderr)
def test_wrapper_xarray_grib(): source = load_source("dummy-source", kind="grib", date=20000101) ds = source.to_xarray() lat, lon = find_lat_lon(ds) assert lat is not None assert lon is not None cml.plot_map(ds)
def test_plot(): for s in load_source("file", "docs/examples/test.grib"): plot_map(s) # test.grib fields endStep is 0, so datetime == valid_datetime assert s.datetime() == s.valid_datetime() # test shape assert s.shape == (11, 19)
def test_plot_1(): s = cml.load_source("file", climetlab_file("docs/examples/test.grib")) assert cml.plot_map(s) is None assert cml.plot_map(s[0]) is None p = cml.new_plot() p.plot_map(s[0]) p.plot_map(s[1]) assert p.show() is None with pytest.raises(TypeError): cml.plot_map(s, unknown=42)
def dont_test_wrapper_xarray_plot_map(coords): source = load_source( "dummy-source", kind="netcdf", dims=coords.split(","), ) ds = source.to_xarray() if "custom_lat" in ds.keys(): ds["custom_lat"].attrs["long_name"] = "latitude" if "custom_lon" in ds.keys(): ds["custom_lon"].attrs["standard_name"] = "longitude" lat, lon = find_lat_lon(ds) assert lat is not None assert lon is not None cml.plot_map(ds)
def checksum_of_plot_map(ds): with temp_file(extension=".png") as filename: cml.plot_map(ds, path=filename) with open(filename, "rb") as f: return f.read()
def test_numpy_xarray(): s = cml.load_source("file", climetlab_file("docs/examples/test.grib")) x = s.to_xarray() cml.plot_map(x.msl.values, metadata=x.msl)
def test_numpy_xarray(): s = cml.load_source("file", "docs/examples/test.nc") x = s.to_xarray() cml.plot_map(x.msl.values, metadata=x.msl)
import climetlab as cml data = cml.load_source( "url", ("https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs" "/v04r00/access/csv/ibtracs.SP.list.v04r00.csv"), ) pd = data.to_pandas() uma = pd[pd.NAME == "UMA:VELI"] cml.plot_map(uma, style="cyclone-track")
from climetlab import load_source, plot_map s = load_source("file", "docs/examples/test.grib") plot_map(s[0], path="x.png") plot_map(s[1], path="y.png") # plot_map(s)
def plot_layer(name, path): print("plot_layer", name, file=sys.stderr) climetlab.plot_map(None, background=False, foreground=name, path=path) print("done", name, file=sys.stderr)
def plot_projection(name, path): print("plot_projection", name, file=sys.stderr) climetlab.plot_map(None, projection=name, background="land-sea", path=path) print("done", name, file=sys.stderr)
import climetlab as cml # cml.settings.set("plotting-options", {'dump_yaml': True}) dataset = cml.load_dataset("example-dataset") data = dataset[0] cml.plot_map(data, foreground=False) cml.plot_map(data, foreground=True) cml.plot_map(data, foreground="example-foreground") cml.plot_map( data, foreground=dict( map_grid=False, map_label=False, map_grid_frame=True, map_grid_frame_thickness=5, map_boundaries=True, ), ) # Partial update of the current `foreground` # How to do is still to be decided # Option 1 cml.plot_map( data, foreground={
def test_numpy_1(): ds = cml.load_dataset("weather-bench") z500 = ds.to_xarray() z = z500.sel({"time": "1979-01-01"}).z.values cml.plot_map(z[0], metadata=z500.z)
def dont_test_plot_map_grib(): source = load_source("dummy-source", kind="grib", date=20000101) cml.plot_map(source)
def plot(): bbox = BoundingBox(north=90, west=0, east=360, south=-90) cml.plot_map(bounding_box=bbox, projection="polar-north")
import climetlab as cml data = cml.load_dataset("hurricane-database", "atlantic") print(data.home_page) irma = data.to_pandas(name="irma", year=2017) cml.plot_map(irma)
def test_netcdf(): for s in load_source("file", "docs/examples/test.nc"): plot_map(s)
def test_netcdf(): for s in load_source("file", climetlab_file("docs/examples/test.nc")): plot_map(s)