def initialize(outputformat='netcdf', merge=False, statistics=None, synoptic=None, ensemble=True, pressurelevels=None, threads=2, period='hourly', area=None, variables=['total_precipitation'], years=[2008, 2009], months=list(range(1, 13)), days=list(range(1, 32)), hours=list(range(0, 24)), prelimbe=False, land=False): """Initializer of the class.""" era5 = fetch.Fetch(years=years, months=months, days=days, hours=hours, area=area, variables=variables, outputformat=outputformat, outputprefix='era5', period=period, ensemble=ensemble, statistics=statistics, synoptic=synoptic, pressurelevels=pressurelevels, merge=merge, threads=threads, prelimbe=prelimbe, land=land) return era5
def _execute(args): """Call to ERA-5 cli library.""" # the info subroutine if args.command == "info": _run_info(args) # the fetching subroutines else: years = _construct_year_list(args) synoptic, statistics, days, hours = _set_period_args(args) # try to build and send download request era5 = efetch.Fetch(years, months=args.months, days=days, hours=hours, variables=args.variables, area=args.area, outputformat=args.format, outputprefix=args.outputprefix, period=args.command, ensemble=args.ensemble, synoptic=synoptic, statistics=statistics, pressurelevels=args.levels, threads=args.threads, merge=args.merge, prelimbe=args.prelimbe, land=args.land) era5.fetch(dryrun=args.dryrun) return True
def _execute(args): """Call to ERA-5 cli library.""" # the info subroutine if args.command == "info": _run_info(args) # the fetching subroutines else: # make list of years to be downloaded if not args.endyear: years = [args.startyear] else: assert (args.endyear >= args.startyear), ('endyear should be >= startyear or None') years = list(range(args.startyear, args.endyear + 1)) synoptic, statistics, days, hours = _set_period_args(args) # try to build and send download request era5 = efetch.Fetch(years, months=args.months, days=days, hours=hours, variables=args.variables, outputformat=args.format, outputprefix=args.outputprefix, period=args.command, ensemble=args.ensemble, synoptic=synoptic, statistics=statistics, pressurelevels=args.levels, threads=args.threads, merge=args.merge) era5.fetch(dryrun=args.dryrun) return True
def test_init(): """Test init function of Fetch class.""" era5 = fetch.Fetch(years=[2008, 2009], months=list(range(1, 13)), days=list(range(1, 32)), hours=list(range(0, 24)), variables=['total_precipitation'], outputformat='netcdf', outputprefix='era5', period='hourly', ensemble=True, statistics=None, synoptic=None, pressurelevels=None, merge=False, threads=2, prelimbe=False) valid_months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] assert era5.months == valid_months valid_days = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'] assert era5.days == valid_days valid_hours = ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'] assert era5.hours == valid_hours assert era5.variables == ['total_precipitation'] assert era5.outputformat == 'netcdf' assert era5.outputprefix == 'era5' assert era5.period == 'hourly' assert era5.ensemble assert era5.statistics is None assert era5.synoptic is None assert era5.pressure_levels is None assert not era5.merge assert era5.threads == 2 assert not era5.prelimbe assert not era5.land # initializing hourly variable with days=None should result in ValueError with pytest.raises(TypeError): era5 = initialize(variables=['temperature'], period='hourly', days=None) # initializing monthly variable with days=None returns fetch.Fetch object era5 = initialize(variables=['temperature'], period='monthly', days=None) assert isinstance(era5, fetch.Fetch)
def _execute(args): """Call to ERA-5 cli library.""" # the info subroutine if args.command == "info": # List dataset information era5info = einfo.Info(args.name) if era5info.infotype == "list": era5info.list() return True else: era5info.vars() return True # the fetching subroutines else: # make list of years to be downloaded if not args.endyear: years = [args.startyear] else: assert (args.endyear >= args.startyear), ('endyear should be >= startyear or None') years = list(range(args.startyear, args.endyear + 1)) # set subroutine specific arguments for monthly and hourly fetch if args.command == "monthly": synoptic = args.synoptic statistics = None elif args.command == "hourly": statistics = args.statistics synoptic = None else: raise AttributeError('The command "{}" is not valid.'.format( args.command)) # try to build and send download request era5 = efetch.Fetch(years, months=args.months, days=args.days, hours=args.hours, variables=args.variables, outputformat=args.format, outputprefix=args.outputprefix, period=args.command, ensemble=args.ensemble, synoptic=synoptic, statistics=statistics, pressurelevels=args.levels, threads=args.threads, split=args.split) era5.fetch() return True