In [1]:
import xarray as xr
import numpy as np
import netCDF4 as nc

Many of this is borrowed from Kayla Besong's GettingData_XR.ipynb notebook from previous lunch byte


In [7]:
min_temps = []
date_range = np.arange(1999,2018+1,1) 

for i in date_range:
    url_t1 = 'https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.'+str(i)+'.nc' 
    print(url_t1)
    t1 = xr.open_dataset(url_t1)
    min_temps.append(t1)


https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.1999.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2000.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2001.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2002.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2003.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2004.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2005.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2006.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2007.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2008.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2009.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2010.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2011.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2012.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2013.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2014.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2015.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2016.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2017.nc
https://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/cpc_global_temp/tmin.2018.nc

In [8]:
latbnds,lonbnds = [32,24],[360-88,360-79]
for i in range(len(min_temps)):
    min_temps[i] = min_temps[i].sel(lat = slice(*latbnds), lon = slice(*lonbnds))

In [9]:
min_temps = xr.concat(min_temps,dim='time')

In [10]:
min_temps.to_netcdf('tmin_99_18.nc')

In [11]:
min_temps


Out[11]:
<xarray.Dataset>
Dimensions:  (lat: 16, lon: 18, time: 7305)
Coordinates:
  * lat      (lat) float32 31.75 31.25 30.75 30.25 ... 25.75 25.25 24.75 24.25
  * lon      (lon) float32 272.25 272.75 273.25 273.75 ... 279.75 280.25 280.75
  * time     (time) datetime64[ns] 1999-01-01 1999-01-02 ... 2018-12-31
Data variables:
    tmin     (time, lat, lon) float32 1.1301223 0.7896629 0.6621582 ... nan nan
Attributes:
    Conventions:                     CF-1.0
    version:                         V1.0
    history:                         created 9/2016 by CAS NOAA/ESRL PSD
    title:                           CPC GLOBAL TEMP V1.0
    dataset_title:                   CPC GLOBAL TEMP
    Source:                          ftp://ftp.cpc.ncep.noaa.gov/precip/wd52w...
    References:                      https://www.esrl.noaa.gov/psd/data/gridd...
    DODS_EXTRA.Unlimited_Dimension:  time

In [ ]: