def test_find_ifs_exp_output(): ofiles = find_ifs_output( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy"), "ok") assert len(ofiles) == 1 assert os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy", "ICMSHok+004321") in ofiles
def select_files(path, expname, start, length): allfiles = cmor_utils.find_ifs_output(path, expname) start_date = cmor_utils.make_datetime(start).date() end_date = cmor_utils.make_datetime(start + length).date() return [ f for f in allfiles if f.endswith(expname + "+000000") or ( end_date > cmor_utils.get_ifs_date(f) >= start_date) ]
def test_find_ifs_exp_output(self): ofiles = find_ifs_output( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy"), "ok") eq_(len(ofiles), 1) ok_( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy", "ICMSHok+004321") in ofiles)
def test_find_ifs_output(): ofiles = find_ifs_output( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy")) assert len(ofiles) == 3 assert os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy", "ICMGGGbla+003456") in ofiles assert os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy", "ICMSHok+004321") in ofiles
def test_find_ifs_output(self): ofiles = find_ifs_output( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy")) eq_(len(ofiles), 3) ok_( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy", "ICMGGGbla+003456") in ofiles) ok_( os.path.join(os.path.dirname(__file__), "test_data", "ifs_dummy", "ICMSHok+004321") in ofiles)
def get_prev_files(gpfile): log.info("Searching for previous month file of %s" % gpfile) date = cmor_utils.get_ifs_date(gpfile) prevdate = date - relativedelta.relativedelta(months=1) ifsoutputdir = os.path.abspath( os.path.join(os.path.dirname(gridpoint_file), "..")) expname = os.path.basename(gpfile)[5:9] inigpfile, inishfile = None, None prevgpfiles, prevshfiles = [], [] for f in cmor_utils.find_ifs_output(ifsoutputdir, expname=expname): if f.endswith("+000000"): if os.path.basename(f).startswith("ICMGG"): inigpfile = f if os.path.basename(f).startswith("ICMSH"): inishfile = f elif cmor_utils.get_ifs_date(f) == prevdate: if os.path.basename(f).startswith("ICMGG"): prevgpfiles.append(f) if os.path.basename(f).startswith("ICMSH"): prevshfiles.append(f) if not any(prevgpfiles) or not any(prevshfiles): log.info( "No regular previous month files found, taking initial state files..." ) if not inigpfile: log.warning("No initial gridpoint file found in %s" % ifsoutputdir) if not inishfile: log.warning("No initial spectral file found in %s" % ifsoutputdir) return inigpfile, inishfile if len(prevgpfiles) > 1: log.warning( "Multiple previous month gridpoint files found: %s. Taking first match" % ",".join(prevgpfiles)) elif len(prevshfiles) > 1: log.warning( "Multiple previous month spectral files found: %s. Taking first match" % ",".join(prevshfiles)) else: log.info( "Found previous month gridpoint file %s and spectral file %s" % (prevgpfiles[0], prevshfiles[0])) return prevgpfiles[0], prevshfiles[0]
def get_prev_file(grb_file): fname = os.path.basename(grb_file) exp, year, mon = fname[5:9], int(fname[10:14]), int(fname[14:16]) if mon == 1: prev_year, prev_mon = year - 1, 12 else: prev_year, prev_mon = year, mon - 1 output_dir = os.path.abspath(os.path.join(os.path.dirname(grb_file), "..")) output_files = cmor_utils.find_ifs_output(output_dir, exp) ini_path = None for output_path in output_files: output_name = os.path.basename(output_path) if output_name == fname[:9] + "+000000": ini_path = output_path if output_name[:10] == fname[:10] and int(output_name[10:14]) == prev_year and \ int(output_name[14:]) == prev_mon: log.info("Found previous month file for %s: %s" % (grb_file, output_path)) return output_path ece_leg = os.path.split(os.path.dirname(grb_file))[-1] if re.match(r"^0*\d1$", ece_leg): # First leg if ini_path is None: log.error( "Previous month file for %s could not be found because the initial state file hasn't been found" % grb_file) else: log.info("Assumed previous month file for %s: %s" % (grb_file, ini_path)) else: if ini_path is None: log.error("Previous month file for %s could not be found" % grb_file) else: log.error( "Assumed previous month file for %s: %s, this is probably not correct!" % (grb_file, ini_path)) return ini_path