Skip to content

Commit

Permalink
Merge pull request #38 from PCMDI/37_pjg_specsupdateA
Browse files Browse the repository at this point in the history
working again
  • Loading branch information
gleckler1 authored Feb 27, 2025
2 parents e4a20e7 + 74b91ef commit 7f18da9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 71 deletions.
10 changes: 10 additions & 0 deletions DataPreparationExamples/LOCA2/LOCA2-0_CMIP6_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"activity_id": "DRCDP",
"source_id": "LOCA2-0",
"driving_activity_id": "CMIP",
"driving_experiment_id": "historical",
"driving_mip_era": "CMIP6",
"driving_source_id": "ACCESS-CM2",
"driving_variant_label": "r1i1p1f1",
"outpath":"/global/cfs/projectdirs/m3522/project_downscale/"
}
11 changes: 11 additions & 0 deletions DataPreparationExamples/LOCA2/LOCA2-1_CMIP6_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"activity_id": "DRCDP",
"source_id": "LOCA2-1",
"driving_activity_id": "CMIP",
"driving_experiment_id": "historical",
"driving_mip_era": "CMIP6",
"driving_source_id": "ACCESS-CM2",
"driving_variant_label": "r1i1p1f1",
"outpath":"/global/cfs/projectdirs/m3522/project_downscale/"
}

37 changes: 0 additions & 37 deletions DataPreparationExamples/LOCA2/LOCA2_CMIP6_input.json

This file was deleted.

33 changes: 20 additions & 13 deletions DataPreparationExamples/LOCA2/LOCA2_CMIP6_runCMOR.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@
# PJG 11052024 added inputs to run via GNU parallel
# PJG 02052025 added if for LOCA2-1 version of 'pr'

# %% Get current script path, append src dir
current_dir = os.path.dirname(os.path.abspath(__file__))
new_path = os.path.join(current_dir, "..", "..", "src")
sys.path.append(new_path)
from DRCDPLib import writeUserJson

cmorTable = '../../Tables/DRCDP_APday.json'
inputJson = 'LOCA2-0_CMIP6_input.json'

multi = True
if multi == True:
expi = sys.argv[1]
modi = sys.argv[3]
vari = sys.argv[2]
inputVarName = vari
outputVarName = vari
if vari == 'pr': outputUnits = 'kg m-2 s-1'

if vari == 'pr':
outputUnits = 'kg m-2 s-1'
inputJson = 'LOCA2-1_CMIP6_input.json'

if vari == 'tasmax': outputUnits = 'K'
if vari == 'tasmin': outputUnits = 'K'

cmorTable = '../Tables/Downscaling_Aday.json'
inputJson = 'LOCA2_CMIP6_input.json'

inputFilePath = '/global/cfs/projectdirs/m3522/cmip6/LOCA2/*/0p0625deg/r1i1p1f1/historical/' + vari + '/*v2022*.nc' #v20220519.nc'

if vari == 'pr': # LOCA2.1
Expand All @@ -51,7 +61,7 @@ def extract_date(ds): # preprocessing function when opening multiple files
lst = glob.glob(infile)
mods = []
for l in lst:
mod = l.split('/')[7]
mod = l.split('.')[1]
if mod not in mods: mods.append(mod)
mod_runs[exp] = {}
for mod in mods:
Expand Down Expand Up @@ -107,33 +117,30 @@ def extract_date(ds): # preprocessing function when opening multiple files

##### CMOR setup
cmor.setup(inpath='./',netcdf_file_action=cmor.CMOR_REPLACE_4,logfile= exp + '-' + mod + '-' + ri + '-'+'cmorLog.txt')
cmor.dataset_json(inputJson)
# cmor.dataset_json(inputJson)
cmor.dataset_json(writeUserJson(inputJson, cmorTable))
cmor.load_table(cmorTable)

# SET CMIP MODEL SPECIFIC ATTRIBUTES
cmor.set_cur_dataset_attribute("source_id","LOCA2--" + mod)
# cmor.set_cur_dataset_attribute("source_id","LOCA2--" + mod)
cmor.set_cur_dataset_attribute("driving_source_id",mod)
cmor.set_cur_dataset_attribute("driving_variant_label",ri)
cmor.set_cur_dataset_attribute("driving_experiment_id",exp)

# Create CMOR axes
cmorLat = cmor.axis("latitude", coord_vals=lat[:], cell_bounds=f.lat_bnds.values, units="degrees_north")
cmorLon = cmor.axis("longitude", coord_vals=lon[:], cell_bounds=f.lon_bnds.values, units="degrees_east")
cmorTime = cmor.axis("time", coord_vals=cftime.date2num(time,tunits), cell_bounds=cftime.date2num(f.time_bnds.values,tunits), units= tunits)
tbds = cftime.date2num(f.time_bnds.values[:],tunits).astype(np.float64)
cmorTime = cmor.axis("time", coord_vals=cftime.date2num(time,tunits), cell_bounds=tbds, units=tunits)
cmoraxes = [cmorTime,cmorLat, cmorLon]

# Setup units and create variable to write using cmor - see https://cmor.llnl.gov/mydoc_cmor3_api/#cmor_set_variable_attribute
varid = cmor.variable(outputVarName,outputUnits,cmoraxes,missing_value=1.e20)
values = np.array(d[:],np.float32)

cmor.set_variable_attribute(varid,'valid_min','f',2.0)
cmor.set_variable_attribute(varid,'valid_max','f',3.0)

cmor.set_deflate(varid,1,1,1) ; # shuffle=1,deflate=1,deflate_level=1 - Deflate options compress file data
cmor.write(varid,values,len(time)) ; # Write variable with time axis
cmor.close()
f.close()
fc.close()
end_time = datetime.now()
print('done cmorizing ',mod,exp, ri, yr[0],'-',yr[1],' process time: {}'.format(end_time-start_time))

42 changes: 21 additions & 21 deletions DataPreparationExamples/LOCA2/jobs.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
python LOCA2_CMIP6_runCMOR.py ssp585 pr AWI-CM-1-1-MR
python LOCA2_CMIP6_runCMOR.py ssp585 pr IPSL-CM6A-LR
python LOCA2_CMIP6_runCMOR.py ssp585 pr ACCESS-CM2
python LOCA2_CMIP6_runCMOR.py ssp585 pr INM-CM5-0
python LOCA2_CMIP6_runCMOR.py ssp585 pr KACE-1-0-G
python LOCA2_CMIP6_runCMOR.py ssp585 pr MPI-ESM1-2-LR
python LOCA2_CMIP6_runCMOR.py ssp585 pr NorESM2-LM
python LOCA2_CMIP6_runCMOR.py ssp585 pr CanESM5
python LOCA2_CMIP6_runCMOR.py ssp585 pr GFDL-ESM4
python LOCA2_CMIP6_runCMOR.py ssp585 pr ACCESS-ESM1-5
python LOCA2_CMIP6_runCMOR.py ssp585 pr GFDL-CM4
python LOCA2_CMIP6_runCMOR.py ssp585 pr INM-CM4-8
python LOCA2_CMIP6_runCMOR.py ssp585 pr EC-Earth3
python LOCA2_CMIP6_runCMOR.py ssp585 pr BCC-CSM2-MR
python LOCA2_CMIP6_runCMOR.py ssp585 pr MPI-ESM1-2-HR
python LOCA2_CMIP6_runCMOR.py ssp585 pr TaiESM1
python LOCA2_CMIP6_runCMOR.py ssp585 pr EC-Earth3-Veg
python LOCA2_CMIP6_runCMOR.py ssp585 pr FGOALS-g3
python LOCA2_CMIP6_runCMOR.py ssp585 pr MIROC6
python LOCA2_CMIP6_runCMOR.py ssp585 pr NorESM2-MM
python LOCA2_CMIP6_runCMOR.py ssp585 pr MRI-ESM2-0
python LOCA2_CMIP6_runCMOR.py historical tasmax AWI-CM-1-1-MR
python LOCA2_CMIP6_runCMOR.py historical tasmax IPSL-CM6A-LR
python LOCA2_CMIP6_runCMOR.py historical tasmax ACCESS-CM2
python LOCA2_CMIP6_runCMOR.py historical tasmax INM-CM5-0
python LOCA2_CMIP6_runCMOR.py historical tasmax KACE-1-0-G
python LOCA2_CMIP6_runCMOR.py historical tasmax MPI-ESM1-2-LR
python LOCA2_CMIP6_runCMOR.py historical tasmax NorESM2-LM
python LOCA2_CMIP6_runCMOR.py historical tasmax CanESM5
python LOCA2_CMIP6_runCMOR.py historical tasmax GFDL-ESM4
python LOCA2_CMIP6_runCMOR.py historical tasmax ACCESS-ESM1-5
python LOCA2_CMIP6_runCMOR.py historical tasmax GFDL-CM4
python LOCA2_CMIP6_runCMOR.py historical tasmax INM-CM4-8
python LOCA2_CMIP6_runCMOR.py historical tasmax EC-Earth3
python LOCA2_CMIP6_runCMOR.py historical tasmax BCC-CSM2-MR
python LOCA2_CMIP6_runCMOR.py historical tasmax MPI-ESM1-2-HR
python LOCA2_CMIP6_runCMOR.py historical tasmax TaiESM1
python LOCA2_CMIP6_runCMOR.py historical tasmax EC-Earth3-Veg
python LOCA2_CMIP6_runCMOR.py historical tasmax FGOALS-g3
python LOCA2_CMIP6_runCMOR.py historical tasmax MIROC6
python LOCA2_CMIP6_runCMOR.py historical tasmax NorESM2-MM
python LOCA2_CMIP6_runCMOR.py historical tasmax MRI-ESM2-0

0 comments on commit 7f18da9

Please sign in to comment.