sys.argv[9]), int(sys.argv[10]) MODEL_NAME = str(sys.argv[11]) ENS_NUM = int(sys.argv[12]) LEAD_FINAL = int(sys.argv[13]) MONTH_NAME_TEMPLATE = '{}01' MONTH_NAME = MONTH_NAME_TEMPLATE.format(calendar.month_abbr[INIT_FCST_MON]) print(f"*** LEAD FINAL: {LEAD_FINAL}") BC_FCST_SYR, BC_FCST_EYR = int(sys.argv[14]), int(sys.argv[15]) if FCST_VAR == 'PRECTOT': MASK_FILE = str(sys.argv[16]) else: MASK_FILE = str(sys.argv[17]) MASK = read_nc_files(MASK_FILE, 'mask') print(f"MASK: {MASK.shape}") MONTHLY_BC_FCST_DIR = str(sys.argv[18]) MONTHLY_RAW_FCST_DIR = str(sys.argv[19]) SUBDAILY_RAW_FCST_DIR = str(sys.argv[20]) BASE_OUTDIR = str(sys.argv[21]) OUTDIR_TEMPLATE = '{}/{:04d}/ens{:01d}' # All file formats MONTHLY_BC_INFILE_TEMPLATE = '{}/{}.{}.{}_{:04d}_{:04d}.nc' MONTHLY_RAW_INFILE_TEMPLATE = '{}/{:04d}/ens{:01d}/{}.cfsv2.{:04d}{:02d}.nc' SUBDAILY_INFILE_TEMPLATE = '{}/{:04d}/ens{:01d}/{}.cfsv2.{:04d}{:02d}.nc' SUBDAILY_OUTFILE_TEMPLATE = '{}/{}.{:04d}{:02d}.nc4' MONTHLY_NMME_INFILE_TEMPLATE = '{}/{:04d}/ens{:01d}/{}.nmme.monthly.{:04d}{:02d}.nc'
MONTH_NAME, ens+1) if op.isdir(OUTDIR): pass else: MAKEDIR(OUTDIR) print(f"OUTDIR is {OUTDIR}") for LEAD_NUM in range(0, LEAD_FINAL): ## Loop from lead =0 to Final Lead FCST_DATE = datetime(INIT_FCST_YEAR, INIT_FCST_MON, 1) + \ relativedelta(months=LEAD_NUM) FCST_YEAR, FCST_MONTH = FCST_DATE.year, FCST_DATE.month for VAR_NUM, VAR_VALUE in enumerate(VAR_NAME_LIST): VAR = VAR_NAME_LIST[VAR_NUM] INFILE = INFILE_TEMPLATE.format(INDIR, VAR, FCST_YEAR, \ FCST_MONTH) TEMP = read_nc_files(INFILE, VAR) if VAR == VAR_NAME_LIST[0]: LATS, LONS = read_nc_files(INFILE, 'lat'), \ read_nc_files(INFILE, 'lon') IN_DATA = np.empty((len(VAR_NAME_LIST), TEMP.shape[0], \ len(LATS), len(LONS))) IN_DATA[VAR_NUM, ] = TEMP ### Finished reading all files now writing combined output OUTFILE = OUTFILE_TEMPLATE.format(OUTDIR, FCST_YEAR, FCST_MONTH) print(f"Now writing {OUTFILE}") SDATE = datetime(FCST_YEAR, FCST_MONTH, 1, 6) NUM_DAYS = TEMP.shape[0] DATES = [ SDATE + relativedelta(hours=n * 6) for n in range(NUM_DAYS) ]
DIR = DIRA + DIRB INFILE_TEMP = '{}/{}/{}/ens{}/{}.cfsv2.{:04d}{:02d}.nc' DIRA1 = '/discover/nobackup/projects/fame/FORECASTS/GEOS5/BCSD_Test/' DIRB1 = 'EXPERIMENTS/NMME/data/AF/PRECTOT_Monthly/' DIR1 = DIRA1 + DIRB1 OUTFILE_TEMPLATE = '{}/{:04d}/{}/ens{}/nmme/{}.nmme.monthly.{:04d}{:02d}.nc' OUTDIR_TEMPLATE = '{}/{:04d}/{}/ens{}/nmme/' if not os.path.exists(DIR1): os.makedirs(DIR1) #reads sample file for lat and lon values GEA1 = '/discover/nobackup/projects/usaf_lis/razamora/GHI_S2S/AFRICOM/' GEB1 = 'data/CFSv2/RAW_CFSv2/Monthly/jan01/2008/ens10/jan01.cfsv2.200801.nc' GE1 = GEA1 + GEB1 LONS = read_nc_files(GE1, 'lon') LATS = read_nc_files(GE1, 'lat') print("Read coarse res lat lon") for mm in range(2, len(MONTH)): YR1 = 2007 for YR in range(0, 13): YR1 = YR1+1 for ens in range(1, 13): for ld in range(0, 9): mm1 = mm+1+ld xpreci = np.empty([1, 720, 1440]) print("Processing: Year=", YR1) print("MONTH=", MONTH[mm]) print("ens=", ens)
cmdargs = str(sys.argv) VAR_NAME = str( sys.argv[1] ) ## this is the name of the variable to create the observational climatology for (precip or tmp) lat1, lat2, lon1, lon2 = int(sys.argv[2]), int(sys.argv[3]), int( sys.argv[4]), int(sys.argv[5]) #lat1, lat2, lon1, lon2 = 5, 19, 30, 41 INDIR = str( sys.argv[6] ) ## This is the location of observed data, that is on the same grid as the NMME data INFILE_template = '{}/all_forc_var_{:04d}{:02d}.nc4' CLIM_SYR, CLIM_EYR = int(sys.argv[7]), int(sys.argv[8]) MASK_FILE = str(sys.argv[9]) LATS = read_nc_files(MASK_FILE, 'lat') LONS = read_nc_files(MASK_FILE, 'lon') OUTDIR = str(sys.argv[10]) if not os.path.exists(OUTDIR): os.makedirs(OUTDIR) #MAKEDIR(OUTDIR) OUTFILE_template = '{}/{}_obs_clim.nc' #print(VAR_NAME) #print(lat1) #print(lat2) #print(lon1) #print(lon2) #print(INDIR) #print(MASK_FILE) #print(OUTDIR)
# Directory and file addresses FCST_CLIM_INDIR = str(sys.argv[18]) OBS_CLIM_INDIR = str(sys.argv[19]) FCST_INDIR = str(sys.argv[20]) # Observation climatology filename templates: OBS_CLIM_FILE_TEMPLATE = '{}/{}_obs_clim.nc' FCST_CLIM_FILE_TEMPLATE = '{}/{}/{}_fcst_clim.nc' MONTH_NAME_TEMPLATE = '{}01' # GEOS5 filename TEMPLATE: FCST_INFILE_TEMPLATE = '{}/{:04d}/ens{:01d}/{}.nmme.monthly.{:04d}{:02d}.nc' # Input mask MASK_FILE = str(sys.argv[21]) MASK = read_nc_files(MASK_FILE, 'mask')[0, ] LATS = read_nc_files(MASK_FILE, 'lat') LONS = read_nc_files(MASK_FILE, 'lon') ### Output directory OUTFILE_TEMPLATE = '{}/{}.{}.{}_{:04d}_{:04d}.nc' OUTDIR = str(sys.argv[22]) if not os.path.exists(OUTDIR): os.makedirs(OUTDIR) ENSS = int(sys.argv[23]) ENSF = int(sys.argv[24]) print(f"Ensemble number is {ENS_NUMF}") NUM_YRS = (CLIM_EYR - CLIM_SYR) + 1 TINY = ((1 / (NUM_YRS)) / ENS_NUMF) / 2
MODEL_NAME = str(sys.argv[11]) ENS_NUM = int(sys.argv[12]) LEAD_FINAL = int(sys.argv[13]) MONTH_NAME_template = '{}01' MONTH_NAME = MONTH_NAME_template.format(calendar.month_abbr[INIT_FCST_MON]) BC_FCST_SYR, BC_FCST_EYR = int(sys.argv[14]), int(sys.argv[15]) # NEED TO MODIFY THE BELOW PATHS ... if (FCST_VAR == 'PRECTOT'): # MASK_FILE='/discover/nobackup/sshukla2/scripts/BCSD/CHIRPS_0.25_MASK.nc' MASK_FILE = str(sys.argv[16]) else: # MASK_FILE = '/discover/nobackup/sshukla2/scripts/BCSD/CHIRPS_MASK.nc' MASK_FILE = str(sys.argv[17]) MASK = read_nc_files(MASK_FILE, 'mask')[0, ] #Directory and file addresses # In[14]: # NEED TO MODIFY THE BELOW PATHS ... ##BASEDIR='/discover/nobackup/sshukla2/Misc' ##DAILY_RAW_FCST_DIR='/discover/nobackup/projects/fame/FORECASTS/GEOS5/Shrad_BCSD' # FORCEDIR='/discover/nobackup/projects/fame/FORECASTS/GEOS5/BCSD_Test/FAME_May_data' # INDIR2=${FORCEDIR}'/' # DAILY_RAW_FCST_DIR=${FORCEDIR}'/RAW_'${fcstdatatype} # OUTDIR2=${FORCEDIR}'/'${fcstdatatype}'/BCSD_DATA' BASEDIR = str(sys.argv[18]) #$INDIR2 DAILY_RAW_FCST_DIR = str(sys.argv[19]) #$DAILY_RAW_FCST_DIR BASEDIR1 = str(sys.argv[20]) #$OUTDIR2 OUTDIR_template = '{}/Daily/{:04d}/ens{:01d}'
if k >= 13: k = k - 12 KY = 1 LEADS1[i, j] = k LDYR[i, j] = KY INFILE_TEMP = '{}/{}/prec.{}.mon_{}.{:04d}.nc' OUTDIR_TEMPLATE = '{}/{}/{:04d}/ens{}/' OUTFILE_TEMPLATE = '{}/{}.nmme.monthly.{:04d}{:02d}.nc' if not os.path.exists(NMME_OUTPUT_DIR): os.makedirs(NMME_OUTPUT_DIR) ## Read in example fine spatial resolution file for lat and lon over AFRICOM EX_FCST_FILENAME = '/ex_raw_fcst_download.nc' GE = SUPPLEMENTARY_DIR + EX_FCST_FILENAME LONS = read_nc_files(GE, 'lon') LATS = read_nc_files(GE, 'lat') ## Read in example coarse spatial resolution file for lat and lon over Globe EX_NMME_FILENAME = '/ex_raw_nmme_download.nc' GE1 = SUPPLEMENTARY_DIR + EX_NMME_FILENAME LONI = read_nc_files(GE1, 'X') LATI = read_nc_files(GE1, 'Y') LON1 = LONI.copy() for n, l in enumerate(LON1): if l >= 180: LON1[n] = LON1[n] - 360. LONI = LON1 LON1 = LONI[0:180] LON2 = LONI[180:] LONI = np.hstack((LON2, LON1))
FCST_SYR, FCST_EYR = int(sys.argv[7]), int(sys.argv[8]) LEAD_FINAL = int(sys.argv[9]) ENS_NUM = int(sys.argv[10]) MONTH_NAME = calendar.month_abbr[INIT_FCST_MON].lower() + "01" print("month name is:", MONTH_NAME) CLIM_SYR, CLIM_EYR = int(sys.argv[11]), int(sys.argv[12]) ## Both FCST_SYR and CLIM_SYR, and FCST_EYR and CLIM_EYR ## will be the same since we are using the entire hindcast for # Directory and file addresses INDIR = str(sys.argv[13]) INFILE_TEMPLATE = '{}/{}/{:04d}/ens{:01d}/{}.cfsv2.{:04d}{:02d}.nc' # OUTFILE_TEMPLATE = '{}/{}_fcst_clim.nc' # MASK_FILE = str(sys.argv[14]) LATS = read_nc_files(MASK_FILE, 'lat') LONS = read_nc_files(MASK_FILE, 'lon') OUTDIR = str(sys.argv[15]) if not os.path.exists(OUTDIR): os.makedirs(OUTDIR) print("Ready to create climatology for Variable {}".format(VAR)) print("Forecast Initialization month is {}".format(MONTH_NAME)) ### First read all forecast data FCST_TS = np.empty( (LEAD_FINAL, ((CLIM_EYR - CLIM_SYR) + 1) * ENS_NUM, len(LATS), len(LONS))) ## Storing climatology of forecast for all years and ensemble members for LEAD_NUM in range(0, LEAD_FINAL): ## Loop from lead =0 to Final Lead
SYR1 = 1982 SYR2 = 1991 SYR3 = 2019 SYR4 = 2011 SYR5 = 2017 SYR6 = 2018 EYR1 = 2020 EYR2 = 2010 EYR3 = 2018 EYR4 = 2017 EYR5 = 2016 GEA = '/discover/nobackup/projects/nca/razamora/GHI_S2S/AFRICOM/data/CFSv2/' GEB = 'RAW_CFSv2/Monthly/jan01/2008/ens10/jan01.cfsv2.200801.nc' GE = GEA + GEB LONS = read_nc_files(GE, 'lon') LATS = read_nc_files(GE, 'lat') print("Read fine res lat lon") GEA1 = '/discover/nobackup/projects/fame/FORECASTS/GEOS5/BCSD_Test/EXPERIMENTS/' GEB1 = 'NMME/data/GEM-NEMO/prec.GEM-NEMO.mon_Dec_2019_2020.nc' GE1 = GEA1 + GEB1 LONI = read_nc_files(GE1, 'X') LATI = read_nc_files(GE1, 'Y') LON1 = LONI.copy() for n, l in enumerate(LON1): if l >= 180: LON1[n] = LON1[n] - 360. LONI = LON1 LON1 = LONI[0:180] LON2 = LONI[180:]