Exemple #1
0
def get_gpp_expected_results():
    land_weights = SURFACE_FRACS * AREA_WEIGHTS
    world_values = np.sum(np.sum(RAW_DATA * land_weights, axis=2),
                          axis=1) / np.sum(land_weights)

    world_land_values = world_values

    nh_area_weights = np.copy(AREA_WEIGHTS)
    nh_area_weights[2, :] = 0
    # we do these by hand: yes they're very slow but that's the point
    world_nh_land_values = np.array([
        (40 * 30 + 60 * 10) * 1.2 + (110 * 80 + 120 * 100 + 260 * 50) * 2,
        (15 * 30 + 90 * 10) * 1.2 + (300 * 80 + 350 * 100 + 270 * 50) * 2,
        (120 * 30 + 60 * 10) * 1.2 + (510 * 80 + 432 * 100 + 280 * 50) * 2,
    ]) / ((30 + 10) * 1.2 + (80 + 100 + 50) * 2)
    world_nh_values = world_nh_land_values

    sh_area_weights = np.copy(AREA_WEIGHTS)
    sh_area_weights[:2, :] = 0
    world_sh_land_values = np.array([
        (3 * 20 + 60 * 10 + 20 * 51 + 40 * 15) * 1.1,
        (10 * 20 + 70 * 10 + 90 * 51 + 130 * 15) * 1.1,
        (50 * 20 + 60 * 10 + 55 * 51 + 60 * 15) * 1.1,
    ]) / ((20 + 10 + 51 + 15) * 1.1)
    world_sh_values = world_sh_land_values

    data = np.vstack([
        world_values,
        world_land_values,
        world_nh_values,
        world_sh_values,
        world_nh_land_values,
        world_sh_land_values,
    ]).T

    exp = ScmDataFrame(
        data=data,
        index=SCMDF_TIME,
        columns={
            "model":
            "unspecified",
            "scenario":
            "experiment",
            "region": [
                "World",
                "World|Land",
                "World|Northern Hemisphere",
                "World|Southern Hemisphere",
                "World|Northern Hemisphere|Land",
                "World|Southern Hemisphere|Land",
            ],
            "variable":
            "gpp",
            "unit":
            "kg m^-2 s^-1",
            "climate_model":
            "model",
            "activity_id":
            "cmip5",
            "member_id":
            "realisation",
            "variable_standard_name":
            "gross_primary_productivity_of_carbon",
            "mip_era":
            "CMIP5",
        },
    )
    exp.metadata = {
        "calendar":
        "gregorian",
        "modeling_realm":
        "land",
        "Conventions":
        "CF-1.5",
        "crunch_source_files":
        "Files: ['/cmip5/experiment/Lmon/gpp/model/realisation/gpp_Lmon_model_experiment_realisation_185001-185003.nc']; sftlf: ['/cmip5/experiment/fx/sftlf/model/r0i0p0/sftlf_fx_model_experiment_r0i0p0.nc']; areacella: ['/cmip5/experiment/fx/areacella/model/r0i0p0/areacella_fx_model_experiment_r0i0p0.nc']",
    }
    exp = _add_land_area_metadata(exp, realm="land")

    return exp
Exemple #2
0
def get_hfds_expected_results():
    sftof_fracs = 100 - SURFACE_FRACS
    ocean_weights = sftof_fracs * AREA_WEIGHTS
    world_values = np.sum(np.sum(RAW_DATA * ocean_weights, axis=2),
                          axis=1) / np.sum(ocean_weights)

    world_ocean_values = world_values

    nh_area_weights = np.copy(AREA_WEIGHTS)
    nh_area_weights[2, :] = 0
    # we do these by hand: yes they're very slow but that's the point
    world_nh_ocean_values = np.array([
        (30 * 100 + 40 * 70 + 50 * 100 + 60 * 90) * 1.2 +
        (110 * 20 + 190 * 100 + 260 * 50) * 2,
        (0 * 100 + 15 * 70 + 45 * 100 + 90 * 90) * 1.2 +
        (300 * 20 + 450 * 100 + 270 * 50) * 2,
        (60 * 100 + 120 * 70 + 60 * 100 + 60 * 90) * 1.2 +
        (510 * 20 + 220 * 100 + 280 * 50) * 2,
    ]) / ((100 + 70 + 100 + 90) * 1.2 + (20 + 100 + 50) * 2)
    world_nh_values = world_nh_ocean_values

    sh_area_weights = np.copy(AREA_WEIGHTS)
    sh_area_weights[:2, :] = 0
    world_sh_ocean_values = np.array([
        (3 * 80 + 60 * 90 + 20 * 49 + 40 * 85) * 1.1,
        (10 * 80 + 70 * 90 + 90 * 49 + 130 * 85) * 1.1,
        (50 * 80 + 60 * 90 + 55 * 49 + 60 * 85) * 1.1,
    ]) / ((80 + 90 + 49 + 85) * 1.1)
    world_sh_values = world_sh_ocean_values

    world_north_atlantic_values = np.array([260, 270, 280])

    world_elnino_values = np.array([190, 450, 220])

    data = np.vstack([
        world_values,
        world_ocean_values,
        world_nh_values,
        world_sh_values,
        world_nh_ocean_values,
        world_sh_ocean_values,
        world_north_atlantic_values,
        world_elnino_values,
    ]).T

    exp = ScmDataFrame(
        data=data,
        index=SCMDF_TIME,
        columns={
            "model":
            "unspecified",
            "scenario":
            "experiment",
            "region": [
                "World",
                "World|Ocean",
                "World|Northern Hemisphere",
                "World|Southern Hemisphere",
                "World|Northern Hemisphere|Ocean",
                "World|Southern Hemisphere|Ocean",
                "World|North Atlantic Ocean",
                "World|El Nino N3.4",
            ],
            "variable":
            "hfds",
            "unit":
            "W m^-2",
            "climate_model":
            "model",
            "activity_id":
            "cmip5",
            "member_id":
            "realisation",
            "variable_standard_name":
            "surface_downward_heat_flux_in_sea_water",
            "mip_era":
            "CMIP5",
        },
    )
    exp.metadata = {
        "calendar":
        "gregorian",
        "modeling_realm":
        "ocean",
        "Conventions":
        "CF-1.5",
        "crunch_source_files":
        "Files: ['/cmip5/experiment/Omon/hfds/model/realisation/hfds_Omon_model_experiment_realisation_185001-185003.nc']; sftof: ['/cmip5/experiment/fx/sftof/model/r0i0p0/sftof_fx_model_experiment_r0i0p0.nc']; areacello: ['/cmip5/experiment/fx/areacello/model/r0i0p0/areacello_fx_model_experiment_r0i0p0.nc']",
    }
    exp = _add_land_area_metadata(exp, realm="ocean")

    return exp
Exemple #3
0
def get_rsdt_expected_results():
    world_values = np.sum(np.sum(RAW_DATA * AREA_WEIGHTS, axis=2),
                          axis=1) / np.sum(AREA_WEIGHTS)

    land_weights = SURFACE_FRACS * AREA_WEIGHTS
    world_land_values = np.sum(np.sum(RAW_DATA * land_weights, axis=2),
                               axis=1) / np.sum(land_weights)

    ocean_weights = (100 - SURFACE_FRACS) * AREA_WEIGHTS
    world_ocean_values = np.sum(np.sum(RAW_DATA * ocean_weights, axis=2),
                                axis=1) / np.sum(ocean_weights)

    nh_area_weights = np.copy(AREA_WEIGHTS)
    nh_area_weights[2, :] = 0
    world_nh_values = np.sum(np.sum(RAW_DATA * nh_area_weights, axis=2),
                             axis=1) / np.sum(nh_area_weights)

    sh_area_weights = np.copy(AREA_WEIGHTS)
    sh_area_weights[:2, :] = 0
    world_sh_values = np.sum(np.sum(RAW_DATA * sh_area_weights, axis=2),
                             axis=1) / np.sum(sh_area_weights)

    # we do these by hand: yes they're very slow but that's the point
    world_nh_land_values = np.array([
        (40 * 30 + 60 * 10) * 1.2 + (110 * 80 + 120 * 100 + 260 * 50) * 2,
        (15 * 30 + 90 * 10) * 1.2 + (300 * 80 + 350 * 100 + 270 * 50) * 2,
        (120 * 30 + 60 * 10) * 1.2 + (510 * 80 + 432 * 100 + 280 * 50) * 2,
    ]) / ((30 + 10) * 1.2 + (80 + 100 + 50) * 2)

    world_sh_land_values = np.array([
        (3 * 20 + 60 * 10 + 20 * 51 + 40 * 15) * 1.1,
        (10 * 20 + 70 * 10 + 90 * 51 + 130 * 15) * 1.1,
        (50 * 20 + 60 * 10 + 55 * 51 + 60 * 15) * 1.1,
    ]) / ((20 + 10 + 51 + 15) * 1.1)

    world_nh_ocean_values = np.array([
        (30 * 100 + 40 * 70 + 50 * 100 + 60 * 90) * 1.2 +
        (110 * 20 + 190 * 100 + 260 * 50) * 2,
        (0 * 100 + 15 * 70 + 45 * 100 + 90 * 90) * 1.2 +
        (300 * 20 + 450 * 100 + 270 * 50) * 2,
        (60 * 100 + 120 * 70 + 60 * 100 + 60 * 90) * 1.2 +
        (510 * 20 + 220 * 100 + 280 * 50) * 2,
    ]) / ((100 + 70 + 100 + 90) * 1.2 + (20 + 100 + 50) * 2)

    world_sh_ocean_values = np.array([
        (3 * 80 + 60 * 90 + 20 * 49 + 40 * 85) * 1.1,
        (10 * 80 + 70 * 90 + 90 * 49 + 130 * 85) * 1.1,
        (50 * 80 + 60 * 90 + 55 * 49 + 60 * 85) * 1.1,
    ]) / ((80 + 90 + 49 + 85) * 1.1)

    world_north_atlantic_values = np.array([260, 270, 280])

    world_elnino_values = np.array([190, 450, 220])

    data = np.vstack([
        world_values,
        world_land_values,
        world_ocean_values,
        world_nh_values,
        world_sh_values,
        world_nh_land_values,
        world_sh_land_values,
        world_nh_ocean_values,
        world_sh_ocean_values,
        world_north_atlantic_values,
        world_elnino_values,
    ]).T

    exp = ScmDataFrame(
        data=data,
        index=SCMDF_TIME,
        columns={
            "model":
            "unspecified",
            "scenario":
            "experiment",
            "region": [
                "World",
                "World|Land",
                "World|Ocean",
                "World|Northern Hemisphere",
                "World|Southern Hemisphere",
                "World|Northern Hemisphere|Land",
                "World|Southern Hemisphere|Land",
                "World|Northern Hemisphere|Ocean",
                "World|Southern Hemisphere|Ocean",
                "World|North Atlantic Ocean",
                "World|El Nino N3.4",
            ],
            "variable":
            "rsdt",
            "unit":
            "W m^-2",
            "climate_model":
            "model",
            "activity_id":
            "cmip5",
            "member_id":
            "realisation",
            "variable_standard_name":
            "toa_incoming_shortwave_flux",
            "mip_era":
            "CMIP5",
        },
    )

    exp.metadata = {
        "calendar":
        "gregorian",
        "land_fraction":
        np.sum(AREA_WEIGHTS * SURFACE_FRACS) / (100 * np.sum(AREA_WEIGHTS)),
        "land_fraction_northern_hemisphere":
        np.sum(nh_area_weights * SURFACE_FRACS) /
        (100 * np.sum(nh_area_weights)),
        "land_fraction_southern_hemisphere":
        np.sum(sh_area_weights * SURFACE_FRACS) /
        (100 * np.sum(sh_area_weights)),
        "modeling_realm":
        "atmos",
        "Conventions":
        "CF-1.5",
        "crunch_source_files":
        "Files: ['/cmip5/experiment/Amon/rsdt/model/realisation/rsdt_Amon_model_experiment_realisation_185001-185003.nc']; areacella: ['/cmip5/experiment/fx/areacella/model/r0i0p0/areacella_fx_model_experiment_r0i0p0.nc']; sftlf: ['/cmip5/experiment/fx/sftlf/model/r0i0p0/sftlf_fx_model_experiment_r0i0p0.nc']",
    }
    exp = _add_land_area_metadata(exp, realm="atmos")

    return exp