Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satellite plotting fix, OMPS pairing fix, and some additional time interval looping #284

Merged
merged 11 commits into from
Oct 7, 2024
27 changes: 20 additions & 7 deletions melodies_monet/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,21 @@ def open_sat_obs(self, time_interval=None, control_dict=None):
else: flst = self.file

self.obj = mio.sat._omps_nadir_mm.read_OMPS_nm(flst)

# couple of changes to move to reader
self.obj = self.obj.swap_dims({'x':'time'}) # indexing needs
self.obj = self.obj.sortby('time') # enforce time in order.
# restrict observation data to time_interval if using
# additional development to deal with files crossing intervals needed (eg situtations where orbit start at 23hrs, ends next day).
if time_interval is not None:
self.obj = self.obj.sel(time=slice(time_interval[0],time_interval[-1]))

elif self.sat_type == 'mopitt_l3':
print('Reading MOPITT')
self.obj = mio.sat._mopitt_l3_mm.open_dataset(self.file, ['column','pressure_surf','apriori_col',
if time_interval is not None:
flst = tsub.subset_mopitt_l3(self.file,time_interval)
else: flst = self.file
self.obj = mio.sat._mopitt_l3_mm.open_dataset(flst, ['column','pressure_surf','apriori_col',
'apriori_surf','apriori_prof','ak_col'])
elif self.sat_type == 'modis_l2':
# from monetio import modis_l2
Expand Down Expand Up @@ -599,12 +602,22 @@ def open_model_files(self, time_interval=None, control_dict=None):
#self.obj.monet.scrip = self.obj_scrip
elif "camx" in self.model.lower():
self.mod_kwargs.update({"var_list": list_input_var})
self.mod_kwargs.update({"surf_only": control_dict['model'][self.label].get('surf_only', False)})
self.mod_kwargs.update({"fname_met_3D": control_dict['model'][self.label].get('files_vert', None)})
self.mod_kwargs.update({"fname_met_2D": control_dict['model'][self.label].get('files_met_surf', None)})
self.obj = mio.models._camx_mm.open_mfdataset(self.files, **self.mod_kwargs)
elif 'raqms' in self.model.lower():
if len(self.files) > 1:
self.obj = mio.raqms.open_mfdataset(self.files,**self.mod_kwargs)
if time_interval is not None:
# fill filelist with subset
print('subsetting model files to interval')
file_list = tsub.subset_model_filelist(self.files,'%m_%d_%Y_%HZ','6H',time_interval)
else:
file_list = self.files
if len(file_list) > 1:
self.obj = mio.models.raqms.open_mfdataset(file_list,**self.mod_kwargs)
else:
self.obj = mio.raqms.open_dataset(self.files,**self.mod_kwargs)
self.obj = mio.models.raqms.open_dataset(file_list)

else:
print('**** Reading Unspecified model output. Take Caution...')
if len(self.files) > 1:
Expand Down Expand Up @@ -1779,7 +1792,7 @@ def plotting(self):
if filter_criteria and 'altitude' in filter_criteria:
vmin_y2, vmax_y2 = filter_criteria['altitude']['value']
elif filter_criteria is None:
#if 'altitude' in pairdf.columns: # pairdf is dataset object, don't have columns

if 'altitude' in pairdf:
vmin_y2 = pairdf['altitude'].min()
vmax_y2 = pairdf['altitude'].max()
Expand Down
6 changes: 3 additions & 3 deletions melodies_monet/plots/satplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def make_spatial_overlay(df, vmodel, column_o=None, label_o=None, column_m=None,
cax.tick_params(labelsize=text_kwargs['fontsize']*0.8,length=10.0,width=2.0,grid_linewidth=2.0)

#plt.tight_layout(pad=0)
savefig(outname + '.png',loc=4, height=100, decorate=True, bbox_inches='tight', dpi=150)
savefig(outname + '.png',loc=4, logo_height=100, decorate=True, bbox_inches='tight', dpi=150)
return ax

def calculate_boxplot(df, df_reg=None,column=None, label=None, plot_dict=None, comb_bx = None, label_bx = None):
Expand Down Expand Up @@ -671,7 +671,7 @@ def make_boxplot(comb_bx, label_bx, ylabel = None, vmin = None, vmax = None, out
ax.set_ylim(ymin = vmin, ymax = vmax)

plt.tight_layout()
savefig(outname + '.png',loc=4, height=100, decorate=True, bbox_inches='tight', dpi=200)
savefig(outname + '.png',loc=4, logo_height=100, decorate=True, bbox_inches='tight', dpi=200)

def make_spatial_bias_gridded(df, column_o=None, label_o=None, column_m=None,
label_m=None, ylabel = None, vmin=None,
Expand Down Expand Up @@ -777,5 +777,5 @@ def make_spatial_bias_gridded(df, column_o=None, label_o=None, column_m=None,
cax.tick_params(labelsize=text_kwargs['fontsize']*0.8,length=10.0,width=2.0,grid_linewidth=2.0)

#plt.tight_layout(pad=0)
savefig(outname + '.png',loc=4, height=100, decorate=True, bbox_inches='tight', dpi=150)
savefig(outname + '.png',loc=4, logo_height=100, decorate=True, bbox_inches='tight', dpi=150)
return ax
5 changes: 2 additions & 3 deletions melodies_monet/util/satellite_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ def omps_l3_daily_o3_pairing(model_data,obs_data,ozone_ppbv_varname):
grid_adjust = xe.Regridder(model_data[['latitude','longitude']],obs_data[['latitude','longitude']],'bilinear')
mod_col_obsgrid = grid_adjust(column)
# Aggregate time-step to daily means
daily_mean = mod_col_obsgrid.groupby('time.date').mean(numeric_only=True).compute()

daily_mean = mod_col_obsgrid.resample(time='1D').mean()
zmoon marked this conversation as resolved.
Show resolved Hide resolved
# change dimension name for date to time
daily_mean = daily_mean.rename({'date':'time'})
daily_mean = daily_mean.rename(ozone_ppbv_varname)

return xr.merge([daily_mean,obs_data])

def space_and_time_pairing(model_data,obs_data,pair_variables):
Expand Down
26 changes: 25 additions & 1 deletion melodies_monet/util/time_interval_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def subset_model_filelist(all_files,timeformat,timestep,timeinterval):

def subset_OMPS_l2(file_path,timeinterval):
'''Dependent on filenaming convention
OMPS-satelliteid_NMTO3-L2_version_startingtimestamp_orbitnumber_endingtimestamp.h5
'''
import pandas as pd
from glob import glob
Expand All @@ -29,7 +30,30 @@ def subset_OMPS_l2(file_path,timeinterval):
subset_interval = pd.date_range(start=timeinterval[0],end=timeinterval[-1],freq='D',inclusive='left')

for i in subset_interval:
fst = fnmatch.filter(all_files,'*OMPS-NPP_NMTO3-L2_v*_{}*_o*'.format(i.strftime('%Ym%m%d')))
fst = fnmatch.filter(all_files,'*OMPS-*_NMTO3-L2_v*_{}*_o*'.format(i.strftime('%Ym%m%d')))
fst.sort()
for j in fst:
interval_files.append(j)
return interval_files

def subset_mopitt_l3(file_path,timeinterval):
'''Dependent on filenaming conventions
MOP03J-YYYYMMDD-
MOP03JM-201909-
'''
import pandas as pd
from glob import glob
import fnmatch
all_files = glob(file_path)
interval_files = []
if 'MOP03JM-' in all_files[0]:
subset_interval = pd.date_range(start=timeinterval[0],end=timeinterval[-1],freq='M')
strfmt = '%Y%m'
else:
subset_interval = pd.date_range(start=timeinterval[0],end=timeinterval[-1],freq='D')
strfmt = '%Y%m%d'
for i in subset_interval:
fst = fnmatch.filter(all_files,'*MOP*-{}*'.format(i.strftime(strfmt)))
fst.sort()
for j in fst:
interval_files.append(j)
Expand Down