Пример #1
0
def ReadBenchmark(filname, variable_name, alternate_vars="", study_limits=[]):
    obs = Variable(filename       = filname,
                variable_name  = variable_name,
                alternate_vars = alternate_vars,
                t0 = None if len(study_limits) != 2 else study_limits[0],
                tf = None if len(study_limits) != 2 else study_limits[1])
    if obs.time is None: raise il.NotTemporalVariable()
    return obs
Пример #2
0
    def stageData(self, m):

        energy_threshold = float(self.keywords.get("energy_threshold", 20.))
        sh = Variable(filename=os.path.join(os.environ["ILAMB_ROOT"],
                                            "DATA/sh/GBAF/sh_0.5x0.5.nc"),
                      variable_name="sh")
        le = Variable(filename=os.path.join(os.environ["ILAMB_ROOT"],
                                            "DATA/le/GBAF/le_0.5x0.5.nc"),
                      variable_name="le")
        obs = Variable(name=self.variable,
                       unit="1",
                       data=np.ma.masked_array(
                           le.data / (le.data + sh.data),
                           mask=((le.data < 0) + (sh.data < 0) +
                                 ((le.data + sh.data) < energy_threshold))),
                       lat=sh.lat,
                       lat_bnds=sh.lat_bnds,
                       lon=sh.lon,
                       lon_bnds=sh.lon_bnds,
                       time=sh.time,
                       time_bnds=sh.time_bnds)

        if obs.time is None: raise il.NotTemporalVariable()
        self.pruneRegions(obs)

        sh = m.extractTimeSeries("hfss",
                                 initial_time=obs.time_bnds[0, 0],
                                 final_time=obs.time_bnds[-1, 1],
                                 lats=None if obs.spatial else obs.lat,
                                 lons=None if obs.spatial else obs.lon)
        le = m.extractTimeSeries("hfls",
                                 initial_time=obs.time_bnds[0, 0],
                                 final_time=obs.time_bnds[-1, 1],
                                 lats=None if obs.spatial else obs.lat,
                                 lons=None if obs.spatial else obs.lon)
        mod = Variable(name=self.variable,
                       unit="1",
                       data=np.ma.masked_array(
                           le.data / (le.data + sh.data),
                           mask=((le.data < 0) + (sh.data < 0) +
                                 ((le.data + sh.data) < energy_threshold))),
                       lat=sh.lat,
                       lat_bnds=sh.lat_bnds,
                       lon=sh.lon,
                       lon_bnds=sh.lon_bnds,
                       time=sh.time,
                       time_bnds=sh.time_bnds)

        obs, mod = il.MakeComparable(obs,
                                     mod,
                                     mask_ref=True,
                                     clip_ref=True,
                                     logstring="[%s][%s]" %
                                     (self.longname, m.name))

        return obs, mod
Пример #3
0
    def stageData(self, m):

        obs = Variable(filename=self.source,
                       variable_name=self.variable,
                       alternate_vars=self.alternate_vars,
                       convert_calendar=False)
        if obs.time is None: raise il.NotTemporalVariable()
        self.pruneRegions(obs)

        # Try to extract a commensurate quantity from the model
        mod = m.extractTimeSeries(self.variable,
                                  alt_vars=self.alternate_vars,
                                  expression=self.derived,
                                  convert_calendar=False,
                                  lats=None if obs.spatial else obs.lat,
                                  lons=None if obs.spatial else obs.lon)

        # When we make things comparable, sites can get pruned, we
        # also need to prune the site labels
        lat = np.copy(obs.lat)
        lon = np.copy(obs.lon)
        obs, mod = il.MakeComparable(obs,
                                     mod,
                                     clip_ref=False,
                                     prune_sites=True,
                                     allow_diff_times=True)

        # Some datasets / models return data in UTC, others are local
        # time. Try to correct by looking at the time of maximum
        # incident radiation.
        try:
            inc = Variable(filename=self.source,
                           variable_name="LW_IN",
                           convert_calendar=False)
            obs.tmax = getTimeOfDailyMaximum(inc)
        except:
            obs.tmax = 12.
        try:
            inc = m.extractTimeSeries("FSDS",
                                      convert_calendar=False,
                                      lats=None if obs.spatial else obs.lat,
                                      lons=None if obs.spatial else obs.lon)
            mod.tmax = getTimeOfDailyMaximum(inc)
        except:
            mod.tmax = 12.

        return obs, mod
Пример #4
0
    def stageData(self, m):

        obs = Variable(filename=self.source,
                       variable_name=self.variable,
                       alternate_vars=self.alternate_vars)
        if obs.time is None: raise il.NotTemporalVariable()
        self.pruneRegions(obs)

        # Try to extract a commensurate quantity from the model
        mod = m.extractTimeSeries(
            self.variable,
            alt_vars=self.alternate_vars,
            expression=self.derived,
            initial_time=obs.time_bnds[0, 0],
            final_time=obs.time_bnds[-1, 1],
            lats=None if obs.spatial else obs.lat,
            lons=None if obs.spatial else obs.lon).convert(obs.unit)
        return obs, mod
Пример #5
0
    def stageData(self, m):

        energy_threshold = float(self.keywords.get("energy_threshold", 10))

        # Handle obs data
        dn_obs = Variable(filename=self.source.replace("albedo", "rsds"),
                          variable_name="rsds")
        up_obs = Variable(filename=self.source.replace("albedo", "rsus"),
                          variable_name="rsus")
        dn_obs, up_obs, obs = _albedo(dn_obs, up_obs, self.variable,
                                      energy_threshold)

        # Prune out uncovered regions
        if obs.time is None: raise il.NotTemporalVariable()
        self.pruneRegions(obs)

        # Handle model data
        dn_mod = m.extractTimeSeries("rsds",
                                     initial_time=obs.time_bnds[0, 0],
                                     final_time=obs.time_bnds[-1, 1],
                                     lats=None if obs.spatial else obs.lat,
                                     lons=None if obs.spatial else obs.lon)
        up_mod = m.extractTimeSeries("rsus",
                                     initial_time=obs.time_bnds[0, 0],
                                     final_time=obs.time_bnds[-1, 1],
                                     lats=None if obs.spatial else obs.lat,
                                     lons=None if obs.spatial else obs.lon)
        dn_mod, up_mod, mod = _albedo(dn_mod, up_mod, self.variable,
                                      energy_threshold)

        # Make variables comparable
        obs, mod = il.MakeComparable(obs,
                                     mod,
                                     mask_ref=True,
                                     clip_ref=True,
                                     logstring="[%s][%s]" %
                                     (self.longname, m.name))
        dn_obs, dn_mod = il.MakeComparable(dn_obs,
                                           dn_mod,
                                           mask_ref=True,
                                           clip_ref=True,
                                           logstring="[%s][%s]" %
                                           (self.longname, m.name))
        up_obs, up_mod = il.MakeComparable(up_obs,
                                           up_mod,
                                           mask_ref=True,
                                           clip_ref=True,
                                           logstring="[%s][%s]" %
                                           (self.longname, m.name))

        # Compute the mean albedo
        dn_obs = dn_obs.integrateInTime(mean=True)
        up_obs = up_obs.integrateInTime(mean=True)
        np.seterr(over='ignore', under='ignore')
        obs_timeint = np.ma.masked_array(up_obs.data / dn_obs.data,
                                         mask=(dn_obs.data.mask +
                                               up_obs.data.mask))
        np.seterr(over='warn', under='warn')
        obs_timeint = Variable(name=self.variable,
                               unit="1",
                               data=obs_timeint,
                               lat=dn_obs.lat,
                               lat_bnds=dn_obs.lat_bnds,
                               lon=dn_obs.lon,
                               lon_bnds=dn_obs.lon_bnds)
        dn_mod = dn_mod.integrateInTime(mean=True)
        up_mod = up_mod.integrateInTime(mean=True)
        np.seterr(over='ignore', under='ignore')
        mod_timeint = np.ma.masked_array(up_mod.data / dn_mod.data,
                                         mask=(dn_mod.data.mask +
                                               up_mod.data.mask))
        np.seterr(over='warn', under='warn')
        mod_timeint = Variable(name=self.variable,
                               unit="1",
                               data=mod_timeint,
                               lat=dn_mod.lat,
                               lat_bnds=dn_mod.lat_bnds,
                               lon=dn_mod.lon,
                               lon_bnds=dn_mod.lon_bnds)

        return obs, mod, obs_timeint, mod_timeint
Пример #6
0
    def stageData(self, m):

        energy_threshold = float(self.keywords.get("energy_threshold", 20.))

        # Handle obs data
        sh_obs = Variable(filename=os.path.join(os.environ["ILAMB_ROOT"],
                                                "DATA/sh/GBAF/sh_0.5x0.5.nc"),
                          variable_name="sh")
        le_obs = Variable(filename=os.path.join(os.environ["ILAMB_ROOT"],
                                                "DATA/le/GBAF/le_0.5x0.5.nc"),
                          variable_name="le")
        sh_obs, le_obs, obs = _evapfrac(sh_obs, le_obs, self.variable,
                                        energy_threshold)

        # Prune out uncovered regions
        if obs.time is None: raise il.NotTemporalVariable()
        self.pruneRegions(obs)

        # Handle model data
        sh_mod = m.extractTimeSeries("hfss",
                                     initial_time=obs.time_bnds[0, 0],
                                     final_time=obs.time_bnds[-1, 1],
                                     lats=None if obs.spatial else obs.lat,
                                     lons=None if obs.spatial else obs.lon)
        le_mod = m.extractTimeSeries("hfls",
                                     initial_time=obs.time_bnds[0, 0],
                                     final_time=obs.time_bnds[-1, 1],
                                     lats=None if obs.spatial else obs.lat,
                                     lons=None if obs.spatial else obs.lon)
        sh_mod, le_mod, mod = _evapfrac(sh_mod, le_mod, self.variable,
                                        energy_threshold)

        # Make variables comparable
        obs, mod = il.MakeComparable(obs,
                                     mod,
                                     mask_ref=True,
                                     clip_ref=True,
                                     logstring="[%s][%s]" %
                                     (self.longname, m.name))
        sh_obs, sh_mod = il.MakeComparable(sh_obs,
                                           sh_mod,
                                           mask_ref=True,
                                           clip_ref=True,
                                           logstring="[%s][%s]" %
                                           (self.longname, m.name))
        le_obs, le_mod = il.MakeComparable(le_obs,
                                           le_mod,
                                           mask_ref=True,
                                           clip_ref=True,
                                           logstring="[%s][%s]" %
                                           (self.longname, m.name))

        # Compute the mean ef
        sh_obs = sh_obs.integrateInTime(mean=True)
        le_obs = le_obs.integrateInTime(mean=True)
        np.seterr(over='ignore', under='ignore')
        obs_timeint = np.ma.masked_array(
            le_obs.data / (le_obs.data + sh_obs.data),
            mask=(sh_obs.data.mask + le_obs.data.mask))
        np.seterr(over='warn', under='warn')
        obs_timeint = Variable(name=self.variable,
                               unit="1",
                               data=obs_timeint,
                               lat=sh_obs.lat,
                               lat_bnds=sh_obs.lat_bnds,
                               lon=sh_obs.lon,
                               lon_bnds=sh_obs.lon_bnds)
        sh_mod = sh_mod.integrateInTime(mean=True)
        le_mod = le_mod.integrateInTime(mean=True)
        np.seterr(over='ignore', under='ignore')
        mod_timeint = np.ma.masked_array(
            le_mod.data / (le_mod.data + sh_mod.data),
            mask=(sh_mod.data.mask + le_mod.data.mask))
        np.seterr(over='warn', under='warn')
        mod_timeint = Variable(name=self.variable,
                               unit="1",
                               data=mod_timeint,
                               lat=sh_mod.lat,
                               lat_bnds=sh_mod.lat_bnds,
                               lon=sh_mod.lon,
                               lon_bnds=sh_mod.lon_bnds)

        return obs, mod, obs_timeint, mod_timeint