Created
July 17, 2019 23:36
-
-
Save andersy005/56d8807442d3915ca2badae7fffd5a8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import xarray as xr" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "<xarray.Dataset>\n", | |
| "Dimensions: (ilev: 31, lat: 192, lev: 30, lon: 288, nbnd: 2, slat: 191, slon: 288, time: 1200)\n", | |
| "Coordinates:\n", | |
| " * ilev (ilev) float64 2.255 5.032 10.16 18.56 ... 967.5 985.1 1e+03\n", | |
| " * lat (lat) float64 -90.0 -89.06 -88.12 -87.17 ... 88.12 89.06 90.0\n", | |
| " * lev (lev) float64 3.643 7.595 14.36 24.61 ... 957.5 976.3 992.6\n", | |
| " * lon (lon) float64 0.0 1.25 2.5 3.75 ... 355.0 356.2 357.5 358.8\n", | |
| " * slat (slat) float64 -89.53 -88.59 -87.64 ... 87.64 88.59 89.53\n", | |
| " * slon (slon) float64 -0.625 0.625 1.875 3.125 ... 355.6 356.9 358.1\n", | |
| " * time (time) float64 2.241e+05 2.242e+05 ... 2.606e+05 2.606e+05\n", | |
| "Dimensions without coordinates: nbnd\n", | |
| "Data variables:\n", | |
| " P0 float64 ...\n", | |
| " TS (time, lat, lon) float32 ...\n", | |
| " ch4vmr (time) float64 ...\n", | |
| " co2vmr (time) float64 ...\n", | |
| " date (time) int32 ...\n", | |
| " date_written (time) |S8 ...\n", | |
| " datesec (time) int32 ...\n", | |
| " f11vmr (time) float64 ...\n", | |
| " f12vmr (time) float64 ...\n", | |
| " gw (lat) float64 ...\n", | |
| " hyai (ilev) float64 ...\n", | |
| " hyam (lev) float64 ...\n", | |
| " hybi (ilev) float64 ...\n", | |
| " hybm (lev) float64 ...\n", | |
| " mdt int32 ...\n", | |
| " n2ovmr (time) float64 ...\n", | |
| " nbdate int32 ...\n", | |
| " nbsec int32 ...\n", | |
| " ndbase int32 ...\n", | |
| " ndcur (time) int32 ...\n", | |
| " nlon (lat) int32 ...\n", | |
| " nsbase int32 ...\n", | |
| " nscur (time) int32 ...\n", | |
| " nsteph (time) int32 ...\n", | |
| " ntrk int32 ...\n", | |
| " ntrm int32 ...\n", | |
| " ntrn int32 ...\n", | |
| " sol_tsi (time) float64 ...\n", | |
| " time_bnds (time, nbnd) float64 ...\n", | |
| " time_written (time) |S8 ...\n", | |
| " w_stag (slat) float64 ...\n", | |
| " wnummax (lat) int32 ...\n", | |
| "Attributes:\n", | |
| " Conventions: CF-1.0\n", | |
| " source: CAM\n", | |
| " case: b.e11.B1850C5CN.f09_g16.005\n", | |
| " title: UNSET\n", | |
| " logname: mai\n", | |
| " host: ys0103\n", | |
| " Version: $Name$\n", | |
| " revision_Id: $Id$\n", | |
| " initial_file: /glade/p/cesm/cseg//inputdata/atm/cam/inic/fv/...\n", | |
| " topography_file: /glade/p/cesm/cseg//inputdata/atm/cam/topo/USG...\n", | |
| " history: Tue Oct 8 16:47:40 2013: /glade/apps/opt/nco/...\n", | |
| " NCO: 4.3.4\n", | |
| " nco_openmp_thread_number: 1" | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "ds = xr.open_dataset(\"/glade/collections/cdg/data/cesmLE/CESM-CAM5-BGC-LE/atm/proc/tseries/monthly/TS/b.e11.B1850C5CN.f09_g16.005.cam.h0.TS.090001-099912.nc\", \n", | |
| " decode_times=False)\n", | |
| "ds" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "t2 = ds['time_bnds'].mean(dim='nbnd')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "<xarray.DataArray 'time_bnds' (time: 1200)>\n", | |
| "array([224125.5, 224155. , 224184.5, ..., 260533.5, 260564. , 260594.5])\n", | |
| "Coordinates:\n", | |
| " * time (time) float64 2.241e+05 2.242e+05 ... 2.606e+05 2.606e+05" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "t2" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "ds['time'].data = t2.data\n", | |
| "ds_new = xr.decode_cf(ds)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "<xarray.Dataset>\n", | |
| "Dimensions: (ilev: 31, lat: 192, lev: 30, lon: 288, nbnd: 2, slat: 191, slon: 288, time: 1200)\n", | |
| "Coordinates:\n", | |
| " * ilev (ilev) float64 2.255 5.032 10.16 18.56 ... 967.5 985.1 1e+03\n", | |
| " * lat (lat) float64 -90.0 -89.06 -88.12 -87.17 ... 88.12 89.06 90.0\n", | |
| " * lev (lev) float64 3.643 7.595 14.36 24.61 ... 957.5 976.3 992.6\n", | |
| " * lon (lon) float64 0.0 1.25 2.5 3.75 ... 355.0 356.2 357.5 358.8\n", | |
| " * slat (slat) float64 -89.53 -88.59 -87.64 ... 87.64 88.59 89.53\n", | |
| " * slon (slon) float64 -0.625 0.625 1.875 3.125 ... 355.6 356.9 358.1\n", | |
| " * time (time) object 0900-01-16 12:00:00 ... 0999-12-16 12:00:00\n", | |
| "Dimensions without coordinates: nbnd\n", | |
| "Data variables:\n", | |
| " P0 float64 ...\n", | |
| " TS (time, lat, lon) float32 ...\n", | |
| " ch4vmr (time) float64 ...\n", | |
| " co2vmr (time) float64 ...\n", | |
| " date (time) int32 ...\n", | |
| " date_written (time) |S8 ...\n", | |
| " datesec (time) int32 ...\n", | |
| " f11vmr (time) float64 ...\n", | |
| " f12vmr (time) float64 ...\n", | |
| " gw (lat) float64 ...\n", | |
| " hyai (ilev) float64 ...\n", | |
| " hyam (lev) float64 ...\n", | |
| " hybi (ilev) float64 ...\n", | |
| " hybm (lev) float64 ...\n", | |
| " mdt int32 ...\n", | |
| " n2ovmr (time) float64 ...\n", | |
| " nbdate int32 ...\n", | |
| " nbsec int32 ...\n", | |
| " ndbase int32 ...\n", | |
| " ndcur (time) int32 ...\n", | |
| " nlon (lat) int32 ...\n", | |
| " nsbase int32 ...\n", | |
| " nscur (time) int32 ...\n", | |
| " nsteph (time) int32 ...\n", | |
| " ntrk int32 ...\n", | |
| " ntrm int32 ...\n", | |
| " ntrn int32 ...\n", | |
| " sol_tsi (time) float64 ...\n", | |
| " time_bnds (time, nbnd) object ...\n", | |
| " time_written (time) |S8 ...\n", | |
| " w_stag (slat) float64 ...\n", | |
| " wnummax (lat) int32 ...\n", | |
| "Attributes:\n", | |
| " Conventions: CF-1.0\n", | |
| " source: CAM\n", | |
| " case: b.e11.B1850C5CN.f09_g16.005\n", | |
| " title: UNSET\n", | |
| " logname: mai\n", | |
| " host: ys0103\n", | |
| " Version: $Name$\n", | |
| " revision_Id: $Id$\n", | |
| " initial_file: /glade/p/cesm/cseg//inputdata/atm/cam/inic/fv/...\n", | |
| " topography_file: /glade/p/cesm/cseg//inputdata/atm/cam/topo/USG...\n", | |
| " history: Tue Oct 8 16:47:40 2013: /glade/apps/opt/nco/...\n", | |
| " NCO: 4.3.4\n", | |
| " nco_openmp_thread_number: 1" | |
| ] | |
| }, | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "ds_new" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python [conda env:analysis]", | |
| "language": "python", | |
| "name": "conda-env-analysis-py" | |
| }, | |
| "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.7.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment