Skip to content

Commit

Permalink
Moved generate_obs_grid to analysis class.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwfncar committed Jul 13, 2024
1 parent 467b450 commit 1e02e30
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
7 changes: 5 additions & 2 deletions examples/process_swath_data/control_modis_l2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ analysis:
debug: True

obs_grid:
start_time: '2020-09-09'
end_time: '2020-09-11'
ntime: 72
nlat: 180
nlon: 360

obs:
Terra_MODIS:
# MOD04_L2.AYYYYDDD.HHMM.0XX.timestamp.hdf
debug: True
debug: False
obs_type: 'sat_swath_clm'
sat_type: 'modis_l2'
filename: $HOME/Data/MODIS/Terra/C61/2020/*/MOD04_L2.*.hdf
Expand All @@ -25,7 +28,7 @@ obs:

Aqua_MODIS:
# MYD04_L2.AYYYYDDD.HHMM.0XX.timestamp.hdf
debug: True
debug: False
obs_type: 'sat_swath_clm'
sat_type: 'modis_l2'
filename: $HOME/Data/MODIS/Aqua/C61/2020/*/MYD04_L2.*.hdf
Expand Down
6 changes: 4 additions & 2 deletions examples/process_swath_data/process_modis_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
an.control = 'control_modis_l2.yaml'
an.read_control()

an.generate_obs_grid()
print(an.obs_grid)

for time_interval in an.time_intervals:

print(time_interval)

an.open_obs(time_interval=time_interval)

for obs in an.obs:
print(an.obs[obs].obj)
# for obs in an.obs:
# print(an.obs[obs].obj)
26 changes: 13 additions & 13 deletions melodies_monet/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def __init__(self):
self.variable_dict = None
self.resample = None
self.time_var = None
self.obs_grid = None
self.obs_edges = None

def __repr__(self):
return (
Expand Down Expand Up @@ -241,7 +239,7 @@ def rename_vars(self):
self.obj = self.obj.rename({v:d['rename']})
self.variable_dict[d['rename']] = self.variable_dict.pop(v)

def open_sat_obs(self,time_interval=None):
def open_sat_obs(self, time_interval=None, control_dict=None):
"""Methods to opens satellite data observations.
Uses in-house python code to open and load observations.
Alternatively may use the satpy reader.
Expand Down Expand Up @@ -302,15 +300,6 @@ def open_sat_obs(self,time_interval=None):
print('something happened opening file:', e)
return

def generate_obs_grid(self, control_dict=None):
from .util import grid_util
self.obs_grid, self.obs_edges = grid_util.generate_uniform_grid(
control_dict['obs_grid']['start'],
control_dict['obs_grid']['end'],
control_dict['obs_grid']['ntime'],
control_dict['obs_grid']['nlat'],
control_dict['obs_grid']['nlon'])

def filter_obs(self):
"""Filter observations based on filter_dict.
Expand Down Expand Up @@ -663,6 +652,8 @@ def __init__(self):
self.target_grid = None
self.obs_regridders = None
self.model_regridders = None
self.obs_grid = None
self.obs_edges = None

def __repr__(self):
return (
Expand Down Expand Up @@ -834,6 +825,15 @@ def setup_regridders(self):
self.obs_regridders = regrid_util.setup_regridder(self.control_dict, config_group='obs')
self.model_regridders = regrid_util.setup_regridder(self.control_dict, config_group='model')

def generate_obs_grid(self):
from .util import grid_util
self.obs_grid, self.obs_edges = grid_util.generate_uniform_grid(
self.control_dict['obs_grid']['start_time'],
self.control_dict['obs_grid']['end_time'],
self.control_dict['obs_grid']['ntime'],
self.control_dict['obs_grid']['nlat'],
self.control_dict['obs_grid']['nlon'])

def open_models(self, time_interval=None,load_files=True):
"""Open all models listed in the input yaml file and create a :class:`model`
object for each of them, populating the :attr:`models` dict.
Expand Down Expand Up @@ -969,7 +969,7 @@ def open_obs(self, time_interval=None, load_files=True):
if load_files:
if o.obs_type in ['sat_swath_sfc', 'sat_swath_clm', 'sat_grid_sfc',\
'sat_grid_clm', 'sat_swath_prof']:
o.open_sat_obs(time_interval=time_interval)
o.open_sat_obs(time_interval=time_interval, control_dict=self.control_dict)
else:
o.open_obs(time_interval=time_interval, control_dict=self.control_dict)
self.obs[o.label] = o
Expand Down

0 comments on commit 1e02e30

Please sign in to comment.