For COPYING and LICENSE details, please refer to the LICENSE file
"""
"""
This is an example that should illustrate how you can scale
a dataset by the length of the month
"""

from pycmbs.examples import download
from pycmbs.data import Data
from pycmbs.mapping import map_plot
import matplotlib.pyplot as plt

plt.close('all')

# read some data as Data object
filename = download.get_sample_file(name='air', return_object=False)
air = Data(filename, 'air', read=True)

# this dataset has the following times
print air.date

# obviously the different months have different numbers of days.
# Let's say you want now to perform a proper averaging of the data
# taking into account the different lengths of the months
#
# the way how you would do it is like
# y = sum(w[i] * x[i])
# whereas w is a weighting factor for each timestep and 'x' is the input data

# how can you easily do that with the Data object?
# -*- coding: utf-8 -*-

"""
This file is part of pyCMBS.
(c) 2012- Alexander Loew
For COPYING and LICENSE details, please refer to the LICENSE file
"""

"""
Basic plotting in pyCMBS
"""

from pycmbs.mapping import map_plot
import matplotlib.pyplot as plt
from pycmbs.examples import download

air = download.get_sample_file(name='air')
air.label = 'air temperature'
f1 = map_plot(air, show_timeseries=False, use_basemap=True, title='show_timeseries=True')
f2 = map_plot(air, show_zonal=True, use_basemap=True, title='show_zonal=True')
f3 = map_plot(air, show_histogram=True, use_basemap=True, title='show_histogram=True')
plt.show()
Beispiel #3
0
# -*- coding: utf-8 -*-
"""
This file is part of pyCMBS.
(c) 2012- Alexander Loew
For COPYING and LICENSE details, please refer to the LICENSE file
"""
"""
Basic plotting in pyCMBS
"""

from pycmbs.mapping import map_plot
import matplotlib.pyplot as plt
from pycmbs.examples import download

# Read some sample data ...
air = download.get_sample_file(name='air')
air.label = 'air temperature'

# a quick plot as well as a projection plot
f1 = map_plot(air)  # unprojected
f2 = map_plot(air, use_basemap=True)  # projected
plt.show()
"""
This is an example that should illustrate how you can scale
a dataset by the length of the month
"""

from pycmbs.examples import download
from pycmbs.data import Data
from pycmbs.mapping import map_plot
import matplotlib.pyplot as plt

plt.close('all')

# read some data as Data object
filename = download.get_sample_file(name='air', return_object=False)
air = Data(filename, 'air', read=True)

# this dataset has the following times
print air.date

# obviously the different months have different numbers of days.
# Let's say you want now to perform a proper averaging of the data
# taking into account the different lengths of the months
#
# the way how you would do it is like
# y = sum(w[i] * x[i])
# whereas w is a weighting factor for each timestep and 'x' is the input data

# how can you easily do that with the Data object?

# 1) calculate the weights ...
#     these are dependent on the number of days  which you get as ...
Beispiel #5
0
 def setUp(self):
     self.D = download.get_sample_file(name='air')
     self.file = download.get_sample_file(name='air', return_object=False)  # filename only
     self.areafile = self.file[:-3] + '_cell_area.nc'
     self._tmpdir = tempfile.mkdtemp()
import os
import numpy as np
import matplotlib.pyplot as plt

from pycmbs.examples import download

plt.close('all')

#~ file='./example_data/air.mon.mean.nc'
#~ if not os.path.exists(file):
    #~ raise ValueError('Sample file not existing: see example-01.py')

# read data
#~ D = Data('./example_data/air.mon.mean.nc', 'air',read=True)
D = download.get_sample_file(name='air')
D.label = 'air temperature'

#~ P = Data('./example_data/pr_wtr.eatm.mon.mean.nc','pr_wtr',read=True)
P = download.get_sample_file(name='rain')

# some analysis
print 'Temporal stdv. ...'
t = D.timstd(return_object=True)
map_plot(t,use_basemap=True,title='Temporal stdv.',show_stat=True)


print 'Some LinePlot'
L=LinePlot(regress=True, title='This is a LinePlot with regression')
L.plot(D, label='2m air temperature')
L.plot(P, label='Precipitable water', ax=L.ax.twinx(), color='green')  # use secondary axis for plotting here
"""
This file is part of pyCMBS.
(c) 2012- Alexander Loew
For COPYING and LICENSE details, please refer to the LICENSE file
"""

from pycmbs.data import Data
from pycmbs.examples import download
import matplotlib.pyplot as plt

plt.close('all')

# load some sample data

# filename = '<THEINPUTFILE>'
filename = download.get_sample_file(name='<VARNAME>', return_object=False)

thevar =  '<VARNAME>'
if thevar == 'rain':
    thevar = 'pr_wtr'

x = Data(filename, thevar, read=True)
print 'Data dimensions: ', x.shape

# calculate global mean temperature timeseries
t = x.fldmean()

# plot results as a figure
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(x.date, t, label='global mean')
Beispiel #8
0
 def setUp(self):
     self.D = download.get_sample_file(name='air')
     self.file = download.get_sample_file(
         name='air', return_object=False)  # filename only
     self.areafile = self.file[:-3] + '_cell_area.nc'
     self._tmpdir = tempfile.mkdtemp()
Beispiel #9
0
from pycmbs.data import Data
from pycmbs.examples import download
import matplotlib.pyplot as plt

plt.close('all')

# load some sample data

# filename = '<THEINPUTFILE>'
filename = download.get_sample_file(name='<VARNAME>', return_object=False)

thevar = '<VARNAME>'
if thevar == 'rain':
    thevar = 'pr_wtr'

x = Data(filename, thevar, read=True)
print 'Data dimensions: ', x.shape

# calculate global mean temperature timeseries
t = x.fldmean()

# plot results as a figure
f = plt.figure()
ax = f.add_subplot(111)
ax.plot(x.date, t, label='global mean')
ax.set_xlabel('Years')
ax.set_ylabel('Temperature [degC]')

# perhaps you also want to calculate some statistics like the temperature trend
from scipy import stats
import numpy as np
import os
import numpy as np
import matplotlib.pyplot as plt

from pycmbs.examples import download

plt.close('all')

#~ file='./example_data/air.mon.mean.nc'
#~ if not os.path.exists(file):
#~ raise ValueError('Sample file not existing: see example-01.py')

# read data
#~ D = Data('./example_data/air.mon.mean.nc', 'air',read=True)
D = download.get_sample_file(name='air')
D.label = 'air temperature'

#~ P = Data('./example_data/pr_wtr.eatm.mon.mean.nc','pr_wtr',read=True)
P = download.get_sample_file(name='rain')

# some analysis
print 'Temporal stdv. ...'
t = D.timstd(return_object=True)
map_plot(t, use_basemap=True, title='Temporal stdv.', show_stat=True)

print 'Some LinePlot'
L = LinePlot(regress=True, title='This is a LinePlot with regression')
L.plot(D, label='2m air temperature')
L.plot(P, label='Precipitable water', ax=L.ax.twinx(),
       color='green')  # use secondary axis for plotting here