Example #1
0
    def execute(input=None, context=None, config=None, params=None, state=None):
        """
        Dependencies
        ------------
        PRACSAL, PRESWAT_L1, longitude, latitude, TEMPWAT_L1

        Algorithms used
        ------------
        1. PRACSAL = gsw_SP_from_C((CONDWAT_L1 * 10),TEMPWAT_L1,PRESWAT_L1)
        2. absolute_salinity = gsw_SA_from_SP(PRACSAL,PRESWAT_L1,longitude,latitude)
        3. conservative_temperature = gsw_CT_from_t(absolute_salinity,TEMPWAT_L1,PRESWAT_L1)
        4. DENSITY = gsw_rho(absolute_salinity,conservative_temperature,PRESWAT_L1)

        Reference
        ------------
        The calculations below are based on the following spreadsheet document:
        https://docs.google.com/spreadsheet/ccc?key=0Au7PUzWoCKU4dDRMeVI0RU9yY180Z0Y5U0hyMUZERmc#gid=0

        """
        lat = params['lat']
        lon = params['lon']
        stream_def_id = params['stream_def']


        rdt = RecordDictionaryTool.load_from_granule(input)
        out_rdt = RecordDictionaryTool(stream_definition_id=stream_def_id)

        out_rdt['time'] = rdt['time']

        conductivity = rdt['conductivity']
        pressure = rdt['pressure']
        temperature = rdt['temp']
        log.debug('L2 transform using L1 values: temp %s, pressure %s, conductivity %s',
                  temperature, pressure, conductivity)

        latitude = np.ones(conductivity.shape) * lat
        longitude = np.ones(conductivity.shape) * lon

        log.debug("Using latitude: %s, longitude: %s", latitude, longitude)

        # Doing: PRACSAL = gsw_SP_from_C((CONDWAT_L1 * 10),TEMPWAT_L1,PRESWAT_L1)
        pracsal = gsw.sp_from_c(conductivity * 10, temperature, pressure)
        old_pracsal = SP_from_cndr(conductivity * 10, t=temperature, p=pressure)

        log.debug("CTDBP Density algorithm calculated the pracsal (practical salinity) values: %s (old: %s)", pracsal, old_pracsal)

        # Doing: absolute_salinity = gsw_SA_from_SP(PRACSAL,PRESWAT_L1,longitude,latitude)
        absolute_salinity = gsw.sa_from_sp(pracsal, pressure, longitude, latitude)
        old_absolute_salinity = SA_from_SP(old_pracsal, pressure, longitude, latitude)
        log.debug('absolute_salinity = SA_from_SP(pracsal=%s, pressure=%s, longitude=%s, latitude=%s)=%s (old value: %s)',
                  pracsal, pressure, longitude, latitude, absolute_salinity, old_absolute_salinity)

        log.debug("CTDBP Density algorithm calculated the absolute_salinity (actual salinity) values: %s", absolute_salinity)

        conservative_temperature = gsw.ct_from_t(absolute_salinity, temperature, pressure)
        old_conservative_temperature = conservative_t(old_absolute_salinity, temperature, pressure)
        log.debug("CTDBP Density algorithm calculated the conservative temperature values: %s (old value: %s)",
                  conservative_temperature, old_conservative_temperature)

        # Doing: DENSITY = gsw_rho(absolute_salinity,conservative_temperature,PRESWAT_L1)
        dens_value = gsw.rho(absolute_salinity, conservative_temperature, pressure)
        old_dens_value = rho(old_absolute_salinity, old_conservative_temperature, pressure)
        log.debug("Calculated density values: %s (old: %s)", dens_value, old_dens_value)

        for key, value in rdt.iteritems():
            if key in out_rdt:
                if key=='conductivity' or key=='temp' or key=='pressure':
                    continue
                out_rdt[key] = value[:]

        out_rdt['density'] = dens_value

        return out_rdt.to_granule()
    def execute(input=None, context=None, config=None, params=None, state=None):
        """
        Dependencies
        ------------
        PRACSAL, PRESWAT_L1, longitude, latitude, TEMPWAT_L1

        Algorithms used
        ------------
        1. PRACSAL = gsw_SP_from_C((CONDWAT_L1 * 10),TEMPWAT_L1,PRESWAT_L1)
        2. absolute_salinity = gsw_SA_from_SP(PRACSAL,PRESWAT_L1,longitude,latitude)
        3. conservative_temperature = gsw_CT_from_t(absolute_salinity,TEMPWAT_L1,PRESWAT_L1)
        4. DENSITY = gsw_rho(absolute_salinity,conservative_temperature,PRESWAT_L1)

        Reference
        ------------
        The calculations below are based on the following spreadsheet document:
        https://docs.google.com/spreadsheet/ccc?key=0Au7PUzWoCKU4dDRMeVI0RU9yY180Z0Y5U0hyMUZERmc#gid=0

        """
        lat = params['lat']
        lon = params['lon']
        stream_def_id = params['stream_def']


        rdt = RecordDictionaryTool.load_from_granule(input)
        out_rdt = RecordDictionaryTool(stream_definition_id=stream_def_id)

        out_rdt['time'] = rdt['time']

        conductivity = rdt['conductivity']
        pressure = rdt['pressure']
        temperature = rdt['temp']
        log.debug('L2 transform using L1 values: temp %s, pressure %s, conductivity %s',
                  temperature, pressure, conductivity)

        latitude = np.ones(conductivity.shape) * lat
        longitude = np.ones(conductivity.shape) * lon

        log.debug("Using latitude: %s, longitude: %s", latitude, longitude)

        # Doing: PRACSAL = gsw_SP_from_C((CONDWAT_L1 * 10),TEMPWAT_L1,PRESWAT_L1)
        pracsal = gsw.sp_from_c(conductivity * 10, temperature, pressure)
        old_pracsal = SP_from_cndr(conductivity * 10, t=temperature, p=pressure)

        log.debug("CTDBP Density algorithm calculated the pracsal (practical salinity) values: %s (old: %s)", pracsal, old_pracsal)

        # Doing: absolute_salinity = gsw_SA_from_SP(PRACSAL,PRESWAT_L1,longitude,latitude)
        absolute_salinity = gsw.sa_from_sp(pracsal, pressure, longitude, latitude)
        old_absolute_salinity = SA_from_SP(old_pracsal, pressure, longitude, latitude)
        log.debug('absolute_salinity = SA_from_SP(pracsal=%s, pressure=%s, longitude=%s, latitude=%s)=%s (old value: %s)',
                  pracsal, pressure, longitude, latitude, absolute_salinity, old_absolute_salinity)

        log.debug("CTDBP Density algorithm calculated the absolute_salinity (actual salinity) values: %s", absolute_salinity)

        conservative_temperature = gsw.ct_from_t(absolute_salinity, temperature, pressure)
        old_conservative_temperature = conservative_t(old_absolute_salinity, temperature, pressure)
        log.debug("CTDBP Density algorithm calculated the conservative temperature values: %s (old value: %s)",
                  conservative_temperature, old_conservative_temperature)

        # Doing: DENSITY = gsw_rho(absolute_salinity,conservative_temperature,PRESWAT_L1)
        dens_value = gsw.rho(absolute_salinity, conservative_temperature, pressure)
        old_dens_value = rho(old_absolute_salinity, old_conservative_temperature, pressure)
        log.debug("Calculated density values: %s (old: %s)", dens_value, old_dens_value)

        for key, value in rdt.iteritems():
            if key in out_rdt:
                if key=='conductivity' or key=='temp' or key=='pressure':
                    continue
                out_rdt[key] = value[:]

        out_rdt['density'] = dens_value

        return out_rdt.to_granule()
Example #3
0
gsw_cv.long_chck_cast = np.float64(gsw_cv.long_chck_cast)

""" Absolute Salinity (SA) and Preformed Salinity (Sstar) """

SA_chck_cast = gsw.SA_from_SP(gsw_cv.SP_chck_cast, gsw_cv.p_chck_cast, gsw_cv.long_chck_cast, gsw_cv.lat_chck_cast)
test_print("SA_chck_cast", "SA_from_SP")

Sstar_from_SP = gsw.Sstar_from_SP(gsw_cv.SP_chck_cast, gsw_cv.p_chck_cast, gsw_cv.long_chck_cast, gsw_cv.lat_chck_cast)
test_print("Sstar_from_SP")

SA_SA_Sstar_from_SP, Sstar_SA_Sstar_from_SP = gsw.SA_Sstar_from_SP(gsw_cv.SP_chck_cast, gsw_cv.p_chck_cast, gsw_cv.long_chck_cast, gsw_cv.lat_chck_cast)[0:2]
test_print("SA_SA_Sstar_from_SP")
test_print("Sstar_SA_Sstar_from_SP")

""" Conservative Temperature (CT) """
CT_chck_cast = gsw.conservative_t(SA_chck_cast, gsw_cv.t_chck_cast, gsw_cv.p_chck_cast)
test_print("CT_chck_cast", "CT_from_t")

""" other conversions between temperatures, salinities, pressure and height """
t_from_CT =  gsw.t_from_CT(SA_chck_cast, CT_chck_cast, gsw_cv.p_chck_cast)
test_print("t_from_CT", "t_chck_cast") #NOTE: diffs are also found in the original

pt = gsw.potential_t(SA_chck_cast, gsw_cv.t_chck_cast, gsw_cv.p_chck_cast,gsw_cv.pr)
#test_print("pt", "pt_from_t")

CT_from_pt = gsw.CT_from_pt(SA_chck_cast, pt)
#test_print("CT_from_pt") #NOTE: diffs are also found in the original

pot_enthalpy = gsw.pot_enthalpy_from_pt(SA_chck_cast, pt)
test_print("pot_enthalpy") #NOTE: diffs are also found in the original