Best Python code snippet using avocado_python
master.cfg
Source:master.cfg
1# -*- python -*-2# Task Coach - Your friendly task manager3# Copyright (C) 2004-2016 Task Coach developers <developers@taskcoach.org>4#5# Task Coach is free software: you can redistribute it and/or modify6# it under the terms of the GNU General Public License as published by7# the Free Software Foundation, either version 3 of the License, or8# (at your option) any later version.9#10# Task Coach is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU General Public License for more details.14#15# You should have received a copy of the GNU General Public License16# along with this program. If not, see <http://www.gnu.org/licenses/>.17c = BuildmasterConfig = {}18REPOURL = 'http://hg.code.sf.net/p/taskcoach/repo'19PASSWORD = file('.passwd', 'rb').readlines()[0].strip()20USERPASSWORD = file('.userpasswd', 'rb').readlines()[0].strip()21# Warning: put release branch first.22BRANCHES = [23 ('Release1_4_Branch', 'LastRelease', 'rel'),24 ('trunk', 'Trunk', 'trunk'),25 ]26####### BUILDSLAVES27from buildbot.buildslave import BuildSlave28from buildbot.steps.trigger import Trigger29from buildbot.schedulers.forcesched import ForceScheduler30c['slaves'] = [BuildSlave("WinXPSP3", PASSWORD, max_builds=1),31 BuildSlave("Ubuntu10", PASSWORD, max_builds=1),32 BuildSlave("Fedora14", PASSWORD, max_builds=1),33 BuildSlave("OpenSuse", PASSWORD, max_builds=1),34 BuildSlave("MacOS", PASSWORD, max_builds=1),35 BuildSlave("Release", PASSWORD, max_builds=1)]36c['slavePortnum'] = 998937####### CHANGESOURCES38# SourceForge does not (yet) provide a buildbot notification39# post-commit hook. There is a feature request for this though40# (https://sourceforge.net/tracker/?func=detail&aid=1633682&group_id=1&atid=350001)41#from buildbot.changes.pb import PBChangeSource42#c['change_source'] = PBChangeSource()43from buildbot.changes.hgpoller import HgPoller44c['change_source'] = []45####### SCHEDULERS46from buildbot.scheduler import Triggerable47from buildbot.schedulers.basic import SingleBranchScheduler48c['schedulers'] = []49forceBuilders = ['Release']50for branchName, longName, shortName in BRANCHES:51 branch = None if branchName == 'trunk' else branchName52 for platform in ['Win32', 'Ubuntu10', 'Fedora14', 'OpenSuse', 'MacOS']:53 c['schedulers'].append(SingleBranchScheduler(name='%s%s' % (longName, platform),54 branch=branch,55 treeStableTimer=0,56 builderNames=['%s-%s' % (platform.lower(), shortName)]))57 forceBuilders.append('%s-%s' % (platform.lower(), shortName))58# Release schedulers59c['schedulers'].append(Triggerable(name="Release",60 builderNames=['macos-release', 'windows-release', 'ubuntu10-release', 'fedora14-release', 'opensuse-release']))61c['schedulers'].append(Triggerable(name="PPARelease",62 builderNames=['ubuntu10-pparelease']))63# Force schedulers64c['schedulers'].append(ForceScheduler(name="Force", builderNames=forceBuilders))65####### BUILDERS66import os, sys67sys.path.insert(0, os.getcwd())68import tcbuild69reload(tcbuild)70from buildbot.process import factory71from buildbot.steps.source import Mercurial72from buildbot.steps.shell import Compile, SetPropertyFromCommand73c['builders'] = []74# For each branch, all platforms should at least make cleanup,75# revision, integration, the platform-specific package or the generic76# package used on this platform, and distribution tests. Unit tests77# are skipped for some platforms (MacOS) due to unknown circumstances78# making them crash randomly.79# Each generic package format may be used by several platforms, but80# only one build is uploaded to the master: the Fedora 14 build for81# RPM and SRPM and the Ubuntu 10 build for DEB.82# Coverage tests must only be run on different OSes (no need to run83# them on Fedora if they are run on Ubuntu), so they run only on84# Ubuntu 10 and Win32 (not MacOS since the unit tests can't be85# launched from the slave there).86# Language tests, documentation generation and source (tar.gz and zip)87# need only be run on one platform; this would be Ubuntu 10.88def addCommonStartSteps(f, skipUnitTests=False, skipIntegrationTests=False, **kwargs):89 f.addStep(tcbuild.Revert(**kwargs))90 f.addStep(tcbuild.Cleanup(**kwargs))91 f.addStep(SetPropertyFromCommand(command='hg identify -n', property='got_revision_number'))92 f.addStep(tcbuild.Revision(**kwargs))93 if not skipUnitTests:94 f.addStep(tcbuild.UnitTests(**kwargs))95 if not skipIntegrationTests:96 f.addStep(tcbuild.IntegrationTests(**kwargs))97def addCommonEndSteps(f, **kwargs):98 f.addStep(tcbuild.DistributionTests(**kwargs))99# Main release builder100f = factory.BuildFactory()101f.addStep(tcbuild.CleanupReleaseStep())102f.addStep(Trigger(schedulerNames=['Release'], waitForFinish=True, set_properties=dict(release=True)))103f.addStep(tcbuild.ZipReleaseStep())104c['builders'].append(dict(name='Release', slavename='Release',105 builddir='release', factory=f))106for branchName, longName, shortName in BRANCHES:107 hgargs = dict(repourl=REPOURL, branchType='inrepo')108 workdir = 'build/taskcoach'109 branch = 'default' if branchName == 'trunk' else branchName110 source = HgPoller(REPOURL,111 pollinterval=10*60,112 workdir='hgpoller-%s' % branch,113 branch=branch)114 source.setName('poller-%s' % branch)115 c['change_source'].append(source)116 # Win32117 f = factory.BuildFactory()118 f.addStep(Mercurial(**hgargs))119 addCommonStartSteps(f, workdir=workdir, skipUnitTests=True)120 f.addStep(tcbuild.BuildSourceZip(workdir=workdir))121 f.addStep(tcbuild.UploadSourceZip(workdir=workdir))122 f.addStep(tcbuild.BuildEXE(workdir=workdir))123 f.addStep(tcbuild.UploadEXE(workdir=workdir))124 f.addStep(tcbuild.BuildWinPenPack(workdir=workdir))125 f.addStep(tcbuild.UploadWinPenPack(workdir=workdir))126 f.addStep(tcbuild.BuildPortableApps(workdir=workdir))127 f.addStep(tcbuild.UploadPortableApps(workdir=workdir))128 addCommonEndSteps(f, workdir=workdir)129 f.addStep(tcbuild.KillEXE(workdir=workdir))130 c['builders'].append(dict(name='win32-%s' % shortName,131 slavename='WinXPSP3',132 builddir='%s-win32' % shortName,133 factory=f))134 # Ubuntu 10135 f = factory.BuildFactory()136 f.addStep(Mercurial(**hgargs))137 addCommonStartSteps(f, workdir=workdir)138 if shortName == 'rel':139 f.addStep(tcbuild.LanguageTests(workdir=workdir))140 f.addStep(tcbuild.Epydoc(workdir=workdir))141 f.addStep(tcbuild.UploadDoc(workdir=workdir))142 f.addStep(tcbuild.Cleanup(workdir=workdir))143 f.addStep(tcbuild.Revision(workdir=workdir))144 f.addStep(tcbuild.BuildSourceTar(workdir=workdir))145 f.addStep(tcbuild.UploadSourceTar(workdir=workdir))146 f.addStep(tcbuild.BuildSourceRaw(workdir=workdir))147 f.addStep(tcbuild.UploadSourceRaw(workdir=workdir))148 f.addStep(tcbuild.BuildDEB(workdir=workdir))149 f.addStep(tcbuild.UploadDEB(workdir=workdir))150 f.addStep(tcbuild.UploadChangelog(workdir=workdir))151 if shortName == 'rel':152 f.addStep(tcbuild.PPA(name='rel', workdir=workdir))153 elif branchName == 'trunk':154 f.addStep(tcbuild.PPA(name='relnext', workdir=workdir))155 f.addStep(tcbuild.PylintStep(workdir=workdir))156 f.addStep(tcbuild.PylintUploadStep(workdir=workdir))157 f.addStep(tcbuild.Coverage(workdir=workdir))158 f.addStep(tcbuild.UploadCoverage(workdir=workdir))159 addCommonEndSteps(f, workdir=workdir)160 c['builders'].append(dict(name='ubuntu10-%s' % shortName,161 slavename='Ubuntu10',162 builddir='%s-ubuntu10' % shortName,163 factory=f))164 # Fedora 14165 f = factory.BuildFactory()166 f.addStep(Mercurial(**hgargs))167 addCommonStartSteps(f, workdir=workdir)168 f.addStep(tcbuild.BuildRPM(workdir=workdir))169 f.addStep(tcbuild.UploadRPM(workdir=workdir))170 f.addStep(tcbuild.Cleanup(workdir=workdir))171 f.addStep(tcbuild.Revision(workdir=workdir))172 f.addStep(tcbuild.BuildSRPM(workdir=workdir))173 f.addStep(tcbuild.UploadSRPM(workdir=workdir))174 f.addStep(tcbuild.Cleanup(workdir=workdir))175 f.addStep(tcbuild.Revision(workdir=workdir))176 f.addStep(tcbuild.BuildFedora14(workdir=workdir))177 f.addStep(tcbuild.UploadFedora14(workdir=workdir))178 addCommonEndSteps(f, workdir=workdir)179 c['builders'].append(dict(name='fedora14-%s' % shortName,180 slavename='Fedora14',181 builddir='%s-fedora14' % shortName,182 factory=f))183 # OpenSuse184 f = factory.BuildFactory()185 f.addStep(Mercurial(**hgargs))186 addCommonStartSteps(f, skipUnitTests=True, skipIntegrationTests=True, workdir=workdir)187 f.addStep(tcbuild.BuildOpenSuse(workdir=workdir))188 f.addStep(tcbuild.UploadOpenSuse(workdir=workdir))189 c['builders'].append(dict(name='opensuse-%s' % shortName,190 slavename='OpenSuse',191 builddir='%s-opensuse' % shortName,192 factory=f))193 # MacOS194 f = factory.BuildFactory()195 f.addStep(Mercurial(**hgargs))196 addCommonStartSteps(f, skipUnitTests=True, skipIntegrationTests=True, workdir=workdir)197 f.addStep(tcbuild.BuildDMG(workdir=workdir))198 f.addStep(tcbuild.UploadDMG(workdir=workdir))199 addCommonEndSteps(f, workdir=workdir)200 c['builders'].append(dict(name='macos-%s' % shortName,201 slavename='MacOS',202 builddir='%s-macos' % shortName,203 factory=f))204####### Release205f = factory.BuildFactory()206f.addStep(Mercurial(repourl=REPOURL, defaultBranch=BRANCHES[0][0], branchType='inrepo'))207f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))208f.addStep(tcbuild.BuildDMG(workdir='build/taskcoach'))209f.addStep(tcbuild.UploadDMG(workdir='build/taskcoach'))210c['builders'].append(dict(name='macos-release', slavename='MacOS',211 builddir='release-macos', factory=f))212f = factory.BuildFactory()213f.addStep(Mercurial(repourl=REPOURL, defaultBranch=BRANCHES[0][0], branchType='inrepo'))214f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))215f.addStep(tcbuild.BuildEXE(workdir='build/taskcoach'))216f.addStep(tcbuild.UploadEXE(workdir='build/taskcoach'))217f.addStep(tcbuild.BuildSourceZip(workdir='build/taskcoach'))218f.addStep(tcbuild.UploadSourceZip(workdir='build/taskcoach'))219f.addStep(tcbuild.BuildWinPenPack(workdir='build/taskcoach'))220f.addStep(tcbuild.UploadWinPenPack(workdir='build/taskcoach'))221f.addStep(tcbuild.BuildPortableApps(workdir='build/taskcoach'))222f.addStep(tcbuild.UploadPortableApps(workdir='build/taskcoach'))223c['builders'].append(dict(name='windows-release', slavename='WinXPSP3',224 builddir='release-windows', factory=f))225f = factory.BuildFactory()226f.addStep(Mercurial(repourl=REPOURL, defaultBranch=BRANCHES[0][0], branchType='inrepo'))227f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))228f.addStep(tcbuild.BuildDEB(workdir='build/taskcoach'))229f.addStep(tcbuild.UploadDEB(workdir='build/taskcoach'))230f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))231f.addStep(tcbuild.BuildSourceTar(workdir='build/taskcoach'))232f.addStep(tcbuild.UploadSourceTar(workdir='build/taskcoach'))233f.addStep(tcbuild.BuildSourceRaw(workdir=workdir))234f.addStep(tcbuild.UploadSourceRaw(workdir='build/taskcoach'))235f.addStep(tcbuild.ReleaseTests(workdir=workdir))236f.addStep(Trigger(schedulerNames=['PPARelease'], waitForFinish=False))237c['builders'].append(dict(name='ubuntu10-release', slavename='Ubuntu10',238 builddir='release-ubuntu10', factory=f))239f = factory.BuildFactory()240f.addStep(Mercurial(repourl=REPOURL, defaultBranch=BRANCHES[0][0], branchType='inrepo'))241f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))242f.addStep(tcbuild.BuildRPM(workdir='build/taskcoach'))243f.addStep(tcbuild.UploadRPM(workdir='build/taskcoach'))244f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))245f.addStep(tcbuild.BuildSRPM(workdir='build/taskcoach'))246f.addStep(tcbuild.UploadSRPM(workdir='build/taskcoach'))247f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))248f.addStep(tcbuild.BuildFedora14(workdir='build/taskcoach'))249f.addStep(tcbuild.UploadFedora14(workdir='build/taskcoach'))250c['builders'].append(dict(name='fedora14-release', slavename='Fedora14',251 builddir='release-fedora14', factory=f))252f = factory.BuildFactory()253f.addStep(Mercurial(repourl=REPOURL, defaultBranch=BRANCHES[0][0], branchType='inrepo'))254f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))255f.addStep(tcbuild.BuildOpenSuse(workdir='build/taskcoach'))256f.addStep(tcbuild.UploadOpenSuse(workdir='build/taskcoach'))257c['builders'].append(dict(name='opensuse-release', slavename='OpenSuse',258 builddir='release-opensuse', factory=f))259f = factory.BuildFactory()260f.addStep(Mercurial(repourl=REPOURL, defaultBranch=BRANCHES[0][0], branchType='inrepo'))261f.addStep(tcbuild.Cleanup(workdir='build/taskcoach'))262f.addStep(tcbuild.PPA(workdir='build/taskcoach', name='release'))263c['builders'].append(dict(name='ubuntu10-pparelease', slavename='Ubuntu10',264 builddir='ubuntu10-pparelease', factory=f))265####### STATUS TARGETS266c['status'] = []267from buildbot.status import html268from buildbot.status.web.authz import Authz269from buildbot.status.web.auth import BasicAuth270c['status'].append(html.WebStatus(http_port=8010,271 authz=Authz(auth=BasicAuth([('fraca7', USERPASSWORD), ('frank', USERPASSWORD), ('aaron', USERPASSWORD)]), forceBuild='auth', cancelPendingBuild='auth')))272from buildbot.status import mail273c['status'].append(mail.MailNotifier(fromaddr="fraca7@free.fr",274 sendToInterestedUsers=True,275 mode='failing',276 relayhost='smtp.free.fr',277 lookup=tcbuild.TaskCoachEmailLookup()))278c['status'].append(mail.MailNotifier(fromaddr='fraca7@free.fr',279 sendToInterestedUsers=False,280 mode='all',281 relayhost='smtp.free.fr',282 extraRecipients=('fraca7@free.fr', 'frank@niessink.com'),283 builders=['Release']))284from buildbot.status.client import PBListener285c['status'].append(PBListener(port=8011, user='taskcoach', passwd=PASSWORD))286from buildbot.process.users import manual287c['user_managers'] = []288c['user_managers'].append(manual.CommandlineUserManager(username="taskcoach",289 passwd=PASSWORD,290 port=9990))291####### PROJECT IDENTITY292c['projectName'] = "TaskCoach"293c['projectURL'] = "http://www.taskcoach.org/"...
Convert_for_NEMO.py
Source:Convert_for_NEMO.py
1from cdo import *2cdo=Cdo()3import shutil4import os5import glob6import sys7# What needs to be done with the raw data?8# 1. Reduce the domain to fit the Baltic/North Sea.9# 2. Change some units.10# a) humidity: from relative [%] to specific [kg/kg]11# b) wind: from speed and direction to u and v12# c) precipitation: from kg/m^2 to kg/m^2/s13def precipitation(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finaldir):14 """15 Prepare precipitation for NEMO-Nordic. Both rain and snow.16 Extract area, make 12h values (24fc-12fc), change the unit from kg/m^2 to kg/m^2/s.17 Merge all data for one year.18 """19 for year in list(range(yearStart, yearEnd + 1)):20 print "Working on precipitation, year: " , year21# for month in list(range(monthStart, monthEnd + 1)):22 for month in list(range(monthStart, 13)):23 print "month: ", month24 if year == yearStart and month < monthStart:25 # Before the start date.26 continue27# 1. Reduce the domain to fit the Baltic/North Sea.28 outfile3= workdir+"UERRA_precip_diff_%04d%02d.grb" % (year, month)29 infile2 = downdir+"RR24-12_UERRA_%04d%02d_fc.grb" % (year, month)30 cdo.selindexbox("200,405,280,470", 31 input=" -setgridtype,curvilinear "+infile2, 32 output=outfile3, options = '-f nc')33 if year == yearEnd and month == monthEnd:34 # Done with the last month.35 break36# Merge monthly files to a yearly file.37 outfile4=workdir+"UERRA_precip_diff_%04d.grb" % (year)38 cdo.mergetime(input=workdir+"UERRA_precip_diff_%04d??.grb" % (year), 39 output=outfile4)40 41# Split up rain and snow and change the units. Copy to final destination.42 cdo.splitname(input=outfile4, output=workdir+"UERRA_precip_")43 outfile =workdir+"rain_y"+str(year)+".nc"44 cdo.setname("RAIN", input=" -divc,43200 "+workdir+"UERRA_precip_tp.nc", output=outfile)45 shutil.copy(outfile, finaldir+"Precip")46 snowfile=workdir+"snow_y"+str(year)+".nc"47 cdo.setname("SNOW", input=" -divc,43200 "+workdir+"UERRA_precip_sf.nc", output=snowfile)48 shutil.copy(snowfile, finaldir+"Snow")49# Clean up50 for fl in glob.glob(workdir+"UERRA*.nc"):51 os.remove(fl)52 for fl in glob.glob(workdir+"UERRA*.grb"):53 os.remove(fl)54def param_with_analysis(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finaldir):55 """56 Prepare all parameters which are avail for the analysis; T2m, SLP, wind.57 Extract area, merge analysis and forecasts. Change the units for wind.58 From wind speed and direction to u/v components in m/s.59 Merge all data for one year for each parameter.60 """61 for year in list(range(yearStart, yearEnd + 1)):62 print "Working on temperature, SLP and wind, year: " , year63# for month in list(range(monthStart, monthEnd + 1)):64 for month in list(range(monthStart, 13)):65 print "month: ", month66 sys.stdout.flush()67 if year == yearStart and month < monthStart:68 # Before the start date.69 continue70# 1. Reduce the domain to fit the Baltic/North Sea.71 infile1 =downdir+"UERRA_an_%04d%02d.grb" % (year, month)72 outfile1=workdir+"UERRA_an_%04d%02d.nc" % (year, month)73 cdo.selindexbox("200,405,280,470", 74 input=" -setgridtype,curvilinear "+infile1, 75 output=outfile1, options = '-f nc')76 infile2 =downdir+"UERRA_fc_%04d%02d.grb" % (year, month)77 outfile2=workdir+"UERRA_fc_%04d%02d.nc" % (year, month)78# For parameters available at the analysis time, forecasts valid at 0, 6, 12, and 18 are not needed.79 cdo.selindexbox("200,405,280,470", 80 input=" -setgridtype,curvilinear -selhour,1,2,3,4,5,7,8,9,10,11,13,14,15,16,17,19,20,21,22,23 -selname,wdir,10si,msl,2t "+infile2, 81 output=outfile2, options = '-f nc')82 if year == yearEnd and month == monthEnd:83 # Done with the last month.84 break85# Merge monthly files to a yearly file.86 print "Merge ", year, "and finalize the preparation."87 sys.stdout.flush()88 outfile3=workdir+"UERRA_analysis_%04d.nc" % (year)89 cdo.mergetime(input=workdir+"UERRA_fc_%04d??.nc" % (year)+" "+workdir+"UERRA_an_%04d??.nc" % (year), 90 output=outfile3, options = '-O')91# Make sure it is really only one year.92 yearfile=workdir+"UERRA_exact_one_year_%04d.nc" % (year)93 cdo.selyear(year, input=outfile3, output=yearfile, options = '-O')94 95 cdo.splitname(input=yearfile, output=workdir+"UERRA_analysis_%04d_" % (year))96### T2m97# Change the parameter name and copy to final destination.98 infile=workdir+"UERRA_analysis_%04d_2t.nc" % (year)99 tfile =workdir+"tair_y"+str(year)+".nc"100 cdo.setname("TAIR", input=infile, output=tfile)101 shutil.copy(tfile, finaldir+"T2m/")102### MSLP103# Change the parameter name and copy to final destination.104 infile=workdir+"UERRA_analysis_%04d_msl.nc" % (year)105 pfile =workdir+"pres_y"+str(year)+".nc"106 cdo.setname("PRES", input=infile, output=pfile)107 shutil.copy(pfile, finaldir+"MSLP/")108### Wind109# Convertion from speed and direction into u+v components110# Then, copy to final destination.111 infile1=workdir+"UERRA_analysis_%04d_10si.nc" % (year)112 infile2=workdir+"UERRA_analysis_%04d_wdir.nc" % (year)113 cdo.chname("10si,speed", input=infile1, output=workdir+"UERRA_analysis_%04d_speed.nc" % (year))114 wfile =workdir+"speedy_y"+str(year)+".nc"115 cdo.merge(input=infile2+" "+workdir+"UERRA_analysis_%04d_speed.nc" % (year), output=wfile)116 zzfile =workdir+"uv_y"+str(year)+".nc"117 cdo.expr('\'U=(-1)*speed*sin(0.01745329252*wdir);V=(-1)*speed*cos(0.01745329252*wdir);\'', 118 input=wfile, output=zzfile)119 shutil.copy(zzfile, finaldir+"Wind/")120 sys.stdout.flush()121 for fl in glob.glob(workdir+"UERRA*.nc"):122 os.remove(fl)123def radiation(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finaldir):124 """125 Prepare long and shortwave radiation.126 Change the unit from J/m2 to W/m2 by dividing with 3600s.127 """128 for year in list(range(yearStart, yearEnd + 1)):129 print "Working on radiation, year: " , year130 for month in list(range(monthStart, 13)):131# for month in list(range(monthStart, monthEnd + 1)):132 print "month: ", month133 sys.stdout.flush()134 if year == yearStart and month < monthStart:135 # Before the start date.136 continue137 infile2 =downdir+"UERRA_fc_%04d%02d.grb" % (year, month)138 outfile2=workdir+"UERRA_fc_%04d%02d.nc" % (year, month)139 cdo.selindexbox("200,405,280,470", 140 input=" -setgridtype,curvilinear -selname,ssrd,strd "+infile2, 141 output=outfile2, options = '-f nc')142 cdo.splithour(input=outfile2, output=workdir+"hour_")143 cdo.sub(input=workdir+"hour_02.nc"+" "+workdir+"hour_01.nc", output=workdir+"hourly_02.nc")144 cdo.sub(input=workdir+"hour_03.nc"+" "+workdir+"hour_02.nc", output=workdir+"hourly_03.nc")145 cdo.sub(input=workdir+"hour_04.nc"+" "+workdir+"hour_03.nc", output=workdir+"hourly_04.nc")146 cdo.sub(input=workdir+"hour_05.nc"+" "+workdir+"hour_04.nc", output=workdir+"hourly_05.nc")147 cdo.sub(input=workdir+"hour_06.nc"+" "+workdir+"hour_05.nc", output=workdir+"hourly_06.nc")148 cdo.sub(input=workdir+"hour_08.nc"+" "+workdir+"hour_07.nc", output=workdir+"hourly_08.nc")149 cdo.sub(input=workdir+"hour_09.nc"+" "+workdir+"hour_08.nc", output=workdir+"hourly_09.nc")150 cdo.sub(input=workdir+"hour_10.nc"+" "+workdir+"hour_09.nc", output=workdir+"hourly_10.nc")151 cdo.sub(input=workdir+"hour_11.nc"+" "+workdir+"hour_10.nc", output=workdir+"hourly_11.nc")152 cdo.sub(input=workdir+"hour_12.nc"+" "+workdir+"hour_11.nc", output=workdir+"hourly_12.nc")153 cdo.sub(input=workdir+"hour_14.nc"+" "+workdir+"hour_13.nc", output=workdir+"hourly_14.nc")154 cdo.sub(input=workdir+"hour_15.nc"+" "+workdir+"hour_14.nc", output=workdir+"hourly_15.nc")155 cdo.sub(input=workdir+"hour_16.nc"+" "+workdir+"hour_15.nc", output=workdir+"hourly_16.nc")156 cdo.sub(input=workdir+"hour_17.nc"+" "+workdir+"hour_16.nc", output=workdir+"hourly_17.nc")157 cdo.sub(input=workdir+"hour_18.nc"+" "+workdir+"hour_17.nc", output=workdir+"hourly_18.nc")158 cdo.sub(input=workdir+"hour_20.nc"+" "+workdir+"hour_19.nc", output=workdir+"hourly_20.nc")159 cdo.sub(input=workdir+"hour_21.nc"+" "+workdir+"hour_20.nc", output=workdir+"hourly_21.nc")160 cdo.sub(input=workdir+"hour_22.nc"+" "+workdir+"hour_21.nc", output=workdir+"hourly_22.nc")161 cdo.sub(input=workdir+"hour_23.nc"+" "+workdir+"hour_22.nc", output=workdir+"hourly_23.nc")162 cdo.sub(input=workdir+"hour_00.nc"+" "+workdir+"hour_23.nc", output=workdir+"hourly_00.nc")163 os.rename(workdir+"hour_01.nc", workdir+"hourly_01.nc")164 os.rename(workdir+"hour_07.nc", workdir+"hourly_07.nc")165 os.rename(workdir+"hour_13.nc", workdir+"hourly_13.nc")166 os.rename(workdir+"hour_19.nc", workdir+"hourly_19.nc")167 outfile2=workdir+"hourly_%04d%02d.nc" % (year, month)168 cdo.mergetime(input=workdir+"hourly_??.nc", output=outfile2)169 if year == yearEnd and month == monthEnd:170 # Done with the last month.171 break172 print ("Almost done... merge and then copy.")173 sys.stdout.flush()174 175 infile=workdir+"hourly_%04d??.nc" % (year)176 allrad=cdo.mergetime(input=infile)177 # Make sure it is really only one year.178 yearfile=workdir+"UERRA_exact_one_year_%04d.nc" % (year)179 cdo.selyear(year, input=allrad, output=yearfile, options = '-O')180 181 solfile =workdir+"solrad_y"+str(year)+".nc"182 lonfile =workdir+"lwdrad_y"+str(year)+".nc"183 cdo.setname("SOLRAD", input=" -divc,3600 -selname,ssrd "+yearfile, output=solfile)184 cdo.setname("LWRAD_DN", input=" -divc,3600 -selname,strd "+yearfile, output=lonfile)185 shutil.copy(solfile, finaldir+"Radiation/")186 shutil.copy(lonfile, finaldir+"Radiation/")187def humidity(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finaldir):188 """189 Prepare specific humidity.190 Change from relative to specific humidity based on the August-Roche-Magnus formula.191 https://en.wikipedia.org/wiki/Clausius-Clapeyron_relation, 2017-08-10192 with e_s(T) saturation vapor pressure [in hPa]193 e_s(T) = 6.1094*exp((17.625*TAIR)/(243.04+TAIR)) !temperature in Celsius194 and vapor pressure [e]195 e = e_s(T) * RH !RH=0...1196 and specific humidity s197 s = 0.622*e / (p-0.378*e)198 """199 for year in list(range(yearStart, yearEnd + 1)):200 print "Working on humidity, year: " , year201 # T2m and MSLP are needed for computation202 # copy these files from the final destination.203 # Hence, these parameters need to be prepare before!!!204 cpfile=finaldir+"T2m/tair_y%04d.nc" % (year)205 shutil.copy(cpfile, workdir)206 split_file=workdir+"tair_y%04d.nc" % (year)207 outfile=workdir+"tair_y%04d_" % (year)208 cdo.splitmon(input=split_file, output=outfile)209 cpfile=finaldir+"MSLP/pres_y%04d.nc" % (year)210 shutil.copy(cpfile, workdir)211 split_file=workdir+"pres_y%04d.nc" % (year)212 outfile=workdir+"pres_y%04d_" % (year)213 cdo.splitmon(input=split_file, output=outfile)214 for month in list(range(monthStart, 13)):215 print "month: ", month216 if year == yearStart and month < monthStart:217 # Before the start date.218 continue219# 1. Reduce the domain to fit the Baltic/North Sea.220 fc_infile =downdir+"UERRA_fc_%04d%02d.grb" % (year, month)221 outfile2 =workdir+"UERRA_fc_%04d%02d.nc" % (year, month)222 cdo.selindexbox("200,405,280,470", 223 input=" -setgridtype,curvilinear -selname,r "+fc_infile, 224 output=outfile2, options = '-f nc')225 cdo.merge(input=workdir+"pres_y%04d_%02d.nc" % (year, month) + " " 226 +workdir+"tair_y%04d_%02d.nc" % (year, month) + " " + outfile2,227 output=workdir+"all_param_%04d_%02d.nc" % (year, month), 228 options = ' -O')229 230 cdo.expr('\'SHUMID=0.622*(6.1094*exp((17.625*(TAIR-273.15))/(243.04+(TAIR-273.15)))*r/100)/(PRES/100-0.377*(6.1094*exp((17.625*(TAIR-273.15))/(243.04+(TAIR-273.15)))*r/100));\'' , 231 input= workdir+"all_param_%04d_%02d.nc" % (year, month), 232 output=workdir+"shum_%04d_%02d.nc" % (year, month))233 if year == yearEnd and month == monthEnd:234 # Done with the last month.235 break236# Merge all monthly files into a yearly file and copy to final destination237 cdo.mergetime(input=workdir+"shum_%04d_??.nc" % (year), 238 output=workdir+"shumid_y%04d.nc" % (year)) ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!