-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: tomvothecoder <[email protected]>
- Loading branch information
1 parent
1fbb46b
commit aedc079
Showing
12 changed files
with
1,337 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
analysis_data_preprocess/fix_units_1.5hr_time_shift_forTRMM.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import cdms2 | ||
from pathlib import Path | ||
import MV2 | ||
|
||
datapath='/p/user_pub/e3sm/e3sm_diags_data/obs_for_e3sm_diags/climatology/TRMM-3B43v-7_3hr/' | ||
for path in Path(datapath).rglob('*.nc'): | ||
print(path.name) | ||
print(path) | ||
filename = path.name.split("/")[-1] | ||
print(filename) | ||
|
||
#filename ='TRMM-3B43v-7_3hr_ANN_199801_201312_climo.nc' | ||
f_in = cdms2.open(datapath+filename) | ||
var0 = f_in('pr') | ||
var = f_in('pr') | ||
lat = var0.getLatitude() | ||
lon = var0.getLongitude() | ||
nlat = len(lat) | ||
var.id = 'pr' | ||
# Fix units problem for obs4mip | ||
#var = var / 3600.0 * 1000 / 1000.0 | ||
|
||
# Manually shift time by 1.5 hour to work around an ncclimo problem: | ||
# The shift may be due to the assumption that ncclimo makes that times are encoded using the CESM/E3SM convention where times refer to the end of the timestep | ||
print('var.time',var.getTime()[:]) | ||
for ilat in range(nlat): | ||
print,'ilat= ',ilat | ||
var[0,ilat,:] = var0[7,ilat,:] | ||
var[1:8,ilat,:] = var0[0:7,ilat,:] | ||
newtime=cdms2.createAxis(MV2.zeros(8)) | ||
newtime.id="time" #name of dimension | ||
newtime.designateTime() # tell cdms to add attributes that make it time | ||
newtime.units = var0.getTime().units | ||
newtime[:] = [x-0.0625 for x in var0.getTime()[:]] | ||
var.setAxis(0,newtime) | ||
print(newtime) | ||
print(var.getTime()) | ||
|
||
|
||
f_out = cdms2.open(filename,'w') | ||
f_out.write(var) | ||
att_keys = list(f_in.attributes.keys()) | ||
att_dic = {} | ||
for i in range(len(att_keys)): | ||
att_dic[i]=att_keys[i],f_in.attributes[att_keys[i]] | ||
to_out = att_dic[i] | ||
setattr(f_out,to_out[0],to_out[1]) | ||
f_in.close() | ||
f_out.close() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.