if len(args) ==2: target_date = datetime.date.today() else: target_date = datetime.date(int(args[2]), int(args[3]), int(args[4])) ndfd_factory = NDFDProjectFactory() ndfd = ndfd_factory.sourceConfig('ndfd') temps_factory = TempextsProjectFactory() region = temps_factory.regionConfig(region_key) source = temps_factory.sourceConfig(source_key) print 'updating % source file with NDFD forecast' % source.tag # need indexes from static file for source reader = ndfd_factory.staticFileReader(source, region) source_shape = reader.datasetShape('ndfd.x_indexes') ndfd_indexes = [ reader.getData('ndfd.y_indexes').flatten(), reader.getData('ndfd.x_indexes').flatten() ] reader.close() del reader reader = temps_factory.tempextsFileReader(target_date.year, source, region) last_obs_date = reader.dateAttribute('temps.mint', 'last_obs_date')) print ' last obs date', last_obs_date del reader # create a template for the NDFD grib file path file_template = ndfd_factory.forecastGribFilepath(ndfd,target_date,'%s','%s') # in case the daily download hasn't occurred yet - go back one day if not os.path.exists(filepath_template % ('001-003', 'mint')):
factory = NDFDProjectFactory() if dev_mode: factory.useDirpathsForMode('dev') project = factory.getProjectConfig() ndfd_config = factory.getSourceConfig('ndfd') if region_key is None: region_key = factory.project.region grid_region = factory.regionConfig(region_key) print 'region =', grid_region.description if source_key is None: source_key = factory.project.source grid_source = factory.sourceConfig(source_key) print 'source =', grid_source.description reader = factory.staticFileReader(grid_source, grid_region) grid_shape, grib_indexes = reader.gribSourceIndexes('ndfd') data_mask = reader.getData('cus_mask') reader.close() grid = N.empty((num_hours, ) + grid_shape, dtype=float) grid.fill(N.nan) grib_times = [] grib_filepath = factory.forecastGribFilepath(factory.sourceConfig('ndfd'), fcast_date, timespan, variable) print '\nreading gribs from', grib_filepath gribs = pygrib.open(grib_filepath) for grib in gribs.select():