{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### trouble with open_mfdataset with the NORESM1-ME model\n", "* ncrcat works as expected on these two files, but xr.open_mfdataset makes a mess of latitude grid\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import numpy as np\n", "from matplotlib import pyplot as plt\n", "%matplotlib inline\n", "from glob import glob" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['/net/stregone/home/naomi/Raws/histPrcp85/NorESM1-ME/rcp85/atmos/mon/ts/r1i1p1/ts_Amon_NorESM1-ME_rcp85_r1i1p1_200601-204412.nc',\n", " '/net/stregone/home/naomi/Raws/histPrcp85/NorESM1-ME/rcp85/atmos/mon/ts/r1i1p1/ts_Amon_NorESM1-ME_rcp85_r1i1p1_204501-210012.nc']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#scenario ='historical'\n", "scenario ='rcp85'\n", "var = 'ts'\n", "\n", "path = '/net/stregone/home/naomi/Raws/histPrcp85/NorESM1-ME/'+scenario+'/atmos/mon/'+var\n", "\n", "files = glob(path + '/r1i1p1/*.nc')\n", "files" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "dss = xr.open_mfdataset(files)\n", "ds0 = xr.open_dataset(files[0])\n", "ds1 = xr.open_dataset(files[1])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((142,), (96,), (96,))" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dss.lat.shape,ds0.lat.shape,ds1.lat.shape" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.float64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#print(':f.20'.format,dss.lat.values)\n", "type(dss.lat.values[0])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", " 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", " 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])\n", "Coordinates:\n", " * lat (lat) float64 -90.0 -88.11 -86.21 -84.32 -82.42 -80.53 -78.63 ..." ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(ds0.lat - ds1.lat)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(96,)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(dss.lat - ds1.lat).shape" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "dask.array\n", "Coordinates:\n", " * lat (lat) float64 -90.0 -88.11 -86.21 -84.32 -82.42 -80.53 -78.63 ...\n", " * lon (lon) float64 0.0 2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 ...\n", " * time (time) datetime64[ns] 2006-01-16T12:00:00 2006-02-15 ..." ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# could fix latitude problem by:\n", "dss.ts - 0*ds0.ts[0]" ] } ], "metadata": { "gist_info": { "gist_id": null, "gist_url": null }, "kernelspec": { "display_name": "Py3 pangeo", "language": "python", "name": "pangeo" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }