コード例 #1
0
    def adjusted_zgrad_snow(self,int_length=0.5,ice_cond=2.03,snow_cond=0.33,\
            mean_salinity=1.):
        import data_series as ds
        import numpy as np
        import tprof

        series_names = [
            'surface_temp_' + '{:6.3f}'.format(0. - int_length), 'sftemp_0.000'
        ]
        if set(series_names) & set(self.data.keys()) == set(series_names):
            boundary_vars = series_names
        else:
            boundary_vars = None

        tdates = self.temp.dates()
        varname = 'zgrad_top_snow_adjusted_' + '{:6.3f}'.format(0. -
                                                                int_length)
        zgrad_adjust_series = ds.data_series(self.name, '', varname)
        for tdate in tdates:
            snowpos = self.snowpos_rt(tdate)
            if snowpos is not None:
                zint = [snowpos[1] - int_length, snowpos[1]]

                complete_zprof = tprof.complete_zprof(self,tdate,zint,\
                    boundary_vars = boundary_vars, adjust_for_snow=True,\
                    salinity = mean_salinity)

                if complete_zprof is not None:
                    zgrad_adjust = np.polyfit(complete_zprof[0],
                                              complete_zprof[1], 1)[0]
                    zgrad_adjust_series.data_list[tdate] = zgrad_adjust

        self.data[varname] = zgrad_adjust_series
        self.data[varname].type = 'regular_temp'
コード例 #2
0
ファイル: drivers.py プロジェクト: zhaobin74/IMBS_MO
def zgrad_top_snow_adjusted(blist=None,force_new=False,quiet=True,\
        int_length = 0.5, mean_salinity = 1):
    import buoys
    import numpy as np
    import data_series as ds
    import tprof

    buoy_list = buoys.buoylist()

    if not blist is None:
        buoy_list = [bb for bb in buoy_list if bb in blist]

    for buoy_name in buoy_list:
        if not quiet:
            print 'Calculating top gradient for buoy ' + buoy_name

        buoy = buoys.buoy(buoy_name)
        buoy.update_series()
        buoy.process_temp()

        series_names = [
            'sftemp_' + '{:6.3f}'.format(0. - int_length), 'sftemp_0.000'
        ]
        if set(series_names) & set(buoy.data.keys()) == set(series_names):
            boundary_vars = series_names
        else:
            boundary_vars = None

        tdates = buoy.temp.dates()
        varname = 'zgrad_top_snow_adjusted_' + '{:6.3f}'.format(0. -
                                                                int_length)
        zgrad_adjust_series = ds.data_series(buoy.name, '', varname)
        for tdate in tdates:
            snowpos = buoy.snowpos_rt(tdate)
            if snowpos is not None:
                zint = [snowpos[1] - int_length, snowpos[1]]

                complete_zprof = tprof.complete_zprof(buoy,tdate,zint,\
                    boundary_vars = boundary_vars, adjust_for_snow=True,\
                    salinity = mean_salinity)

                if complete_zprof is not None:
                    zgrad_adjust = np.polyfit(complete_zprof[0],
                                              complete_zprof[1], 1)[0]
                    zgrad_adjust_series.data_list[tdate] = zgrad_adjust

        buoy.data[varname] = zgrad_adjust_series
        buoy.data[varname].type = 'regular_temp'
        buoy.save_series()
コード例 #3
0
    def average_ice_temp(self, layer=1, nlayer=4, restrict_hour=None):
        '''Returns data series of the average temperature of given sections of 
          the ice layer, with times-of-observation equal to those of the 
          temperature.
          e.g. layer=1, nlayer=1 returns the average temp of the whole ice layer
               layer=1, nlayer=4 returns the average temp of the top 
               quarter of the ice layer
               layer=4, nlayer=4 returns the average temp of the bottom quarter
               of the ice layer'''
        import tprof
        import data_series as ds
        import numpy as np
        tdates = self.temp.dates()
        varname = 'average_ice_temp.ilayer.' + str(layer) + '.nlayer.' + str(
            nlayer)
        self.data[varname] = ds.data_series(self.name, '', varname)
        if not 'bottom_rt' in list(self.data.keys()) and \
           not 'interface_rt' in list(self.data.keys()):
            print('Not enough information provided')
            return self.data[varname]

        if self.data['bottom_rt'].period() is None or \
           self.data['interface_rt'].period() is None:
            return self.data[varname]

        for tdate in tdates:
            if restrict_hour is None or tdate.hour == restrict_hour:
                if tdate >= max([self.data['bottom_rt'].period()[0],\
                                 self.data['interface_rt'].period()[0]]) and \
                   tdate <= min([self.data['bottom_rt'].period()[1],\
                                 self.data['interface_rt'].period()[1]]):
                    zint_f = np.array([self.data['interface_rt'].data_list[tdate],\
                            self.data['bottom_rt'].data_list[tdate]])
                    prop_start = float(layer - 1) / float(nlayer)
                    prop_end = float(layer) / float(nlayer)
                    zint = [zint_f[0] + prop_start * (zint_f[1] - zint_f[0]),\
                            zint_f[0] + prop_end * (zint_f[1] - zint_f[0])]

                    zprof = tprof.complete_zprof(self, tdate, zint)
                    if zprof is not None:
                        weights = tprof.zpt_weights(zprof[0])
                        mean_temp = np.sum(
                            zprof[1] * weights) / np.sum(weights)
                        self.data[varname].data_list[tdate] = mean_temp

        self.data[varname].type = 'regular'
        return self.data[varname]
コード例 #4
0
    def temp_statistics(self, layer_calc=[0, 0.4], mode='interface'):
        import tprof
        import data_series as ds
        import numpy as np
        if mode == 'base':
            icepos_index = 0
            prefix = 'base_'
            boundary_vars = [
                'basal_temp_{:4.3f}'.format(zpos) for zpos in layer_calc
            ]
        elif mode == 'interface':
            icepos_index = 1
            prefix = 'interface_'
            boundary_vars = None

        statistics = ['zmean', 'zgrad', 'z_recip_mean', 'z_recip_sq_mean']
        layer_label = '{:4.3f}_{:4.3f}'.format(*layer_calc)
        varnames = [prefix + layer_label + '_' + stat for stat in statistics]
        for varname in varnames:
            self.data[varname] = ds.data_series(self.name, '', varname)
            self.data[varname].type = 'regular_temp'

        tdates = self.temp.dates()
        for tdate in tdates:
            icepos = self.icepos_rt(tdate)
            if not icepos is None:
                layer_calc_transform = [
                    zi + icepos[icepos_index] for zi in layer_calc
                ]
                zprof = tprof.complete_zprof(self,tdate,layer_calc_transform,\
                    boundary_vars=boundary_vars)
                if not zprof is None:
                    zweights = tprof.zpt_weights(zprof[0])

                    zgrad = np.polyfit(zprof[0], zprof[1], 1)[0]
                    zmean = np.sum(zweights * zprof[1])
                    z_recip_mean = np.sum(zweights * 1. / zprof[1])
                    z_recip_sq_mean = np.sum(zweights * 1. / (zprof[1])**2.)

                    data_series = [zmean,zgrad,z_recip_mean,\
                                       z_recip_sq_mean]
                    for (ii, varname) in enumerate(varnames):
                        self.data[varname].data_list[tdate] = \
                           data_series[ii]

        return self.data[varname]
コード例 #5
0
    def average_snow_temp(self, restrict_hour=None):
        '''Returns data series of the average temperature of the snow layer,
           with times-of-observation equal to those of the temperature'''
        import tprof
        import data_series as ds
        import numpy as np
        tdates = self.temp.dates()
        varname = 'average_snow_temp'
        self.data[varname] = ds.data_series(self.name, '', varname)
        if not 'surface_rt' in list(self.data.keys()) and \
           not 'interface_rt' in list(self.data.keys()):
            print('Not enough information provided')
            return self.data[varname]

        if self.data['surface_rt'].period() is None or \
           self.data['interface_rt'].period() is None:
            return self.data[varname]

        for tdate in tdates:
            if restrict_hour is None or tdate.hour == restrict_hour:
                if tdate >= max([self.data['surface_rt'].period()[0],\
                                 self.data['interface_rt'].period()[0]]) and \
                   tdate <= min([self.data['surface_rt'].period()[1],\
                                 self.data['interface_rt'].period()[1]]):
                    zint = [self.data['surface_rt'].data_list[tdate],\
                            self.data['interface_rt'].data_list[tdate]]

                    zprof = tprof.complete_zprof(self, tdate, zint)
                    if zprof is not None:
                        weights = tprof.zpt_weights(zprof[0])
                        mean_temp = np.sum(
                            zprof[1] * weights) / np.sum(weights)
                        self.data[varname].data_list[tdate] = mean_temp

        self.data[varname].type = 'regular'
        return self.data[varname]
コード例 #6
0
ファイル: drivers.py プロジェクト: zhaobin74/IMBS_MO
def lei_statistics(zint=None,quiet=True,blist=None,force_new=False,\
       relative_position = 'bottom'):
    import buoys
    import tprof
    import data_series as ds
    import numpy as np

    if relative_position == 'bottom':
        icepos_index = 0
        prefix = ''
        boundary_vars = ['temp_{:4.3f}'.format(zpos) for zpos in zint]
    elif relative_position == 'interface':
        icepos_index = 1
        prefix = 'int_'
        boundary_vars = None

    statistics = ['zmean', 'zgrad', 'z_recip_mean', 'z_recip_sq_mean']
    if zint is None:
        print 'Please specify z-interval'

    layer_label = '{:4.3f}_{:4.3f}'.format(*zint)
    varnames = [prefix + layer_label + '_' + stat for stat in statistics]

    buoy_list = buoys.buoylist()

    if not blist is None:
        buoy_list = [bb for bb in buoy_list if bb in blist]

    for buoy_name in buoy_list:
        if not quiet:
            print ' '
            print 'Calculating Lei statistics of '+\
                  str(zint[0])+'-'+str(zint[1])+' heat storage series '+\
                  'for buoy '+buoy_name
            print '----------------------------'

        buoy = buoys.buoy(buoy_name)
        not_there_log = np.array([(not buoy.is_series(varname)) \
                                      for varname in varnames])
        if np.sum(not_there_log) > 0 or force_new:
            buoy.update_series()
            buoy.process_temp()

            for varname in varnames:
                buoy.data[varname] = ds.data_series(buoy.name, '', varname)
                buoy.data[varname].type = 'regular_temp'

            tdates = buoy.temp.dates()
            for tdate in tdates:
                if tdate.day == 1 and tdate.hour == 1:
                    print tdate

                icepos = buoy.icepos_rt(tdate)
                if not icepos is None:
                    zint_transform = [zi + icepos[icepos_index] for zi in zint]
                    zprof = tprof.complete_zprof(buoy,tdate,zint_transform,\
                        boundary_vars=boundary_vars)
                    if not zprof is None:
                        zweights = tprof.zpt_weights(zprof[0])

                        zgrad = np.polyfit(zprof[0], zprof[1], 1)[0]
                        zmean = np.sum(zweights * zprof[1])
                        z_recip_mean = np.sum(zweights * 1. / zprof[1])
                        z_recip_sq_mean = np.sum(zweights * 1. /
                                                 (zprof[1])**2.)

                        data_series = [zmean,zgrad,z_recip_mean,\
                                           z_recip_sq_mean]
                        for (ii, varname) in enumerate(varnames):
                            buoy.data[varname].data_list[tdate] = \
                               data_series[ii]

            result = 1
            buoy.save_series()
        else:
            result = 2

        if not quiet:
            print result