SPB Git
20.2 KB · 248 lines python
1"""Chapitre 38 — tests des fonctions de traite.geo et des chiffres cités dans manuscript/chapters/ch38.tex et solutions/ch38.tex.2Tolérances : distances ±1 m sauf indication, coefficients ±0,0005, parts ±0,001, GVF ±0,001."""3import sys, pathlib4import numpy as np, pytest5sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "cases"))6from traite import geo7import ch38_sig as c3889pytestmark = pytest.mark.filterwarnings("ignore")101112@pytest.fixture(scope="module")13def r():14    return c38.tout()1516# ----------------------------------------------------------------------------- fonctions génériques (traite.geo)1718def test_haversine_et_equirectangulaire():19    # un degré de latitude ≈ 111,19 km sur la sphère de rayon 6371,0088 km ; méridien et équateur20    assert geo.haversine_km(0, 0, 1, 0) == pytest.approx(np.pi / 180 * geo.R_TERRE_KM, rel=1e-9)21    assert geo.haversine_km(0, 0, 0, 90) == pytest.approx(np.pi / 2 * geo.R_TERRE_KM, rel=1e-9)22    # antipodes et point identique23    assert geo.haversine_km(10, 20, -10, -160) == pytest.approx(np.pi * geo.R_TERRE_KM, rel=1e-6)24    assert float(geo.haversine_km(45.0, -75.0, 45.0, -75.0)) == 0.025    xy = geo.equirectangulaire_km([45.0, 46.0], [-75.0, -75.0], 45.0, -75.0)26    assert xy[1, 1] == pytest.approx(np.pi / 180 * geo.R_TERRE_KM, rel=1e-9) and xy[1, 0] == 0.0272829def test_facteur_echelle_tm():30    assert float(geo.facteur_echelle_tm(45.0, -76.5, -76.5)) == pytest.approx(0.9999)          # méridien central31    k = float(geo.facteur_echelle_tm(45.4215, -75.7395, -76.5)); assert k == pytest.approx(0.999943, abs=1e-6)32    # croissant avec l'écart au méridien, décroissant avec la latitude33    assert geo.facteur_echelle_tm(45, -75.0, -76.5) > geo.facteur_echelle_tm(45, -76.0, -76.5)34    assert geo.facteur_echelle_tm(60, -75.0, -76.5) < geo.facteur_echelle_tm(45, -75.0, -76.5)353637def test_point_dans_polygone_carre_et_concave():38    carre = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], float)39    pts = np.array([(0.5, 0.5), (1.5, 0.5), (-0.1, 0.2), (0.99, 0.01)])40    assert list(geo.point_dans_polygone(pts, carre)) == [True, False, False, True]41    poly = np.array([(0, 0), (4, 0), (4, 3), (2, 1), (0, 3)], float)                             # exercice 342    assert list(geo.point_dans_polygone(np.array([(1, 1), (2, 2), (3, 2.5)]), poly)) == [True, False, False]43    # cohérence avec shapely sur des points aléatoires44    from shapely.geometry import Polygon, Point45    rng = np.random.default_rng(1); P = rng.uniform(-1, 5, (500, 2)); sp = Polygon(poly)46    assert np.array_equal(geo.point_dans_polygone(P, poly), np.array([sp.contains(Point(*p)) for p in P]))474849def test_idw_exact_et_moyenne():50    co = np.array([(0, 0), (1, 0), (0, 1)], float); z = np.array([1.0, 2.0, 3.0])51    assert geo.idw(co, z, co)[1] == 2.0                                                          # valeur exacte aux observations52    assert float(geo.idw(co[:2], z[:2], np.array([[0.5, 0.0]]))[0]) == pytest.approx(1.5)       # équidistant : moyenne53    # un point plus proche de (1, 0) tire vers 254    assert geo.idw(co[:2], z[:2], np.array([[0.9, 0.0]]), puissance=2)[0] > 1.9555657def test_grille_hexagonale_couvre_et_aire():58    cells = geo.grille_hexagonale(0, 0, 10, 10, 1.0)59    from shapely.geometry import Polygon, Point60    polys = [Polygon(c) for c in cells]61    assert polys[0].area == pytest.approx(3 * np.sqrt(3) / 2, rel=1e-9)62    rng = np.random.default_rng(2); P = rng.uniform(0, 10, (300, 2))63    assert all(any(p.contains(Point(*q)) for p in polys) for q in P)                            # chaque point tombe dans une cellule64    # pavage : aires d'intersection nulles entre cellules distinctes65    assert polys[0].intersection(polys[1]).area < 1e-9666768def test_classifications_et_gvf():69    z = np.array([1, 2, 3, 10, 11, 12, 30, 31, 32], float)70    bj = geo.bornes_jenks(z, 3)71    assert list(geo.classer(z, bj)) == [0, 0, 0, 1, 1, 1, 2, 2, 2] and geo.gvf(z, bj) > 0.9972    be = geo.bornes_intervalles_egaux(z, 3); assert be[0] == 1 and be[-1] == 32 and len(be) == 473    bq = geo.bornes_quantiles(z, 3); assert np.bincount(geo.classer(z, bq)).tolist() == [3, 3, 3]74    assert geo.gvf(z, bj) >= geo.gvf(z, be) - 1e-9 and geo.gvf(z, bj) >= geo.gvf(z, bq) - 1e-9    # Jenks optimal75    assert geo.gvf(z, np.array([1.0, 32.0])) == pytest.approx(0.0)767778def test_gravite_annuelle_emd():79    A = geo.accessibilite_gravitaire(np.array([[0.0, 0.0]]), np.array([[1.5, 0.0], [6.0, 0.0], [9.0, 0.0]]), [100, 40, 30], 0.25)80    assert float(A[0]) == pytest.approx(80.816, abs=0.001)                                      # exercice 481    assert geo.probabilite_annuelle(0.70) == pytest.approx(0.04702, abs=1e-5)82    assert geo.probabilite_annuelle(0.20) == pytest.approx(0.00889, abs=1e-5)83    assert geo.probabilite_annuelle(0.07) == pytest.approx(0.00290, abs=1e-5)84    assert geo.probabilite_annuelle(1 - 0.5 ** 25) == pytest.approx(0.5)85    assert geo.effet_minimal_detectable(1.0) == pytest.approx(2.8016, abs=1e-3)8687# ----------------------------------------------------------------------------- chiffres du chapitre (cas 1)8889def test_projection_et_distances(r):90    b = r["base"]91    assert b["crs_nom"] == "NAD83 / MTM zone 9"92    assert b["xs"] == pytest.approx(364315.8, abs=0.5) and b["ys"] == pytest.approx(5031566.3, abs=0.5)93    assert b["k_sujet"] == pytest.approx(0.999943, abs=1e-6)94    assert b["etendue_km"][0] == pytest.approx(42.2, abs=0.05) and b["etendue_km"][1] == pytest.approx(27.5, abs=0.05)95    e = b["ecarts"]96    assert e["mtm9"]["max_m"] < 1.5 and e["equirect"]["max_m"] == pytest.approx(82.8, abs=0.5) and e["haversine"]["max_m"] == pytest.approx(70.8, abs=0.5)97    assert e["equirect"]["max_rel_pct"] == pytest.approx(0.51, abs=0.01) and e["haversine"]["max_rel_pct"] == pytest.approx(0.28, abs=0.01)98    m = b["manhattan"]; assert m["moyenne_ratio"] == pytest.approx(1.33, abs=0.005) and m["mediane_ratio"] == pytest.approx(1.37, abs=0.005) and m["max_ratio"] <= np.sqrt(2) + 1e-999100101def test_geometries_et_jointure(r):102    a = r["geom"]["aires_km2"]; L = r["geom"]["longueurs_km"]103    assert a["A"] == pytest.approx(31.0, abs=0.05) and a["B"] == pytest.approx(50.3, abs=0.05) and a["corridor_300"] == pytest.approx(15.0, abs=0.05)104    assert L["cours_eau"] == pytest.approx(43.8, abs=0.05) and L["corridor"] == pytest.approx(24.5, abs=0.05)105    s = r["secteurs"]106    assert s.loc["Total", "zone_A"] == 31 and s.loc["Total", "zone_B"] == 57 and s.loc["Total", "corridor_300"] == 17107    assert s.loc["Hull", "zone_A"] == 14 and s.loc["Aylmer", "zone_A"] == 17 and s.loc["Hull", "zone_B"] == 19 and s.loc["Aylmer", "zone_B"] == 38108    assert s.loc["Hull", "corridor_300"] == 14 and s.loc["Gatineau", "zone_A"] == 0109    assert s.loc["Hull", "dist_corr_med_km"] == pytest.approx(2.0, abs=0.05) and s.loc["Buckingham", "dist_corr_med_km"] == pytest.approx(16.8, abs=0.05)110    assert s.loc["Hull", "acces_moy"] == pytest.approx(74.3, abs=0.1) and s.loc["Aylmer", "acces_moy"] == pytest.approx(26.4, abs=0.1)111    v = r["ventes"]; assert (v["zone_A"] == v["zone_A_rayon"]).all()                           # lancer de rayon = shapely112    assert int(v["zone_A"].sum() + v["zone_B"].sum()) == 88113114115def test_grille_classification_et_surfacique(r):116    g = r["grille"]117    assert (g["n_cellules"], g["n_occupees"], g["n_cartographiees"]) == (374, 69, 30) and g["aire_cellule_km2"] == pytest.approx(3.74, abs=0.005)118    cl = g["classif"]119    assert np.allclose(np.round(cl["Jenks"]["bornes"]), [2546, 3004, 3358, 3548, 3925, 4106]) and cl["Jenks"]["effectifs"].tolist() == [4, 5, 8, 9, 4]120    assert np.allclose(np.round(cl["quantiles"]["bornes"]), [2546, 3165, 3441, 3555, 3650, 4106]) and cl["quantiles"]["effectifs"].tolist() == [6, 6, 6, 6, 6]121    assert cl["intervalles égaux"]["effectifs"].tolist() == [4, 2, 9, 11, 4]122    assert cl["Jenks"]["gvf"] == pytest.approx(0.964, abs=0.001) and cl["intervalles égaux"]["gvf"] == pytest.approx(0.952, abs=0.001) and cl["quantiles"]["gvf"] == pytest.approx(0.909, abs=0.001)123    ps = g["pond_surf"]; assert ps["total_exact"] == 600 and ps["eam"] == pytest.approx(2.95, abs=0.01) and ps["max"] == pytest.approx(14.9, abs=0.05) and ps["total_est"] == pytest.approx(598.3, abs=0.05)124    ok = g["cartographiees"]; assert np.abs(ok["residu_moy"]).max() < 0.051125126127def test_idw_sujet(r):128    i = r["idw"]129    assert i[1.0]["sujet"] == pytest.approx(-0.054, abs=0.0005) and i[2.0]["sujet"] == pytest.approx(-0.060, abs=0.0005) and i[3.0]["sujet"] == pytest.approx(-0.066, abs=0.0005)130    assert i[1.0]["eqm_loo"] == pytest.approx(0.086, abs=0.0005) and i[2.0]["eqm_loo"] == pytest.approx(0.090, abs=0.0005) and i[3.0]["eqm_loo"] == pytest.approx(0.095, abs=0.0005)131    assert i["eqm_sans_correction"] == pytest.approx(0.103, abs=0.0005)132133134def test_modeles_augmentes(r):135    m = r["modeles"]; ref = m["référence"]; ss = m["sans secteur"]; sn = m["sans secteur ni gradient"]136    c = ref["coef"]137    assert c.loc["zone_A", "coef"] == pytest.approx(0.0054, abs=0.0005) and c.loc["zone_A", "t"] == pytest.approx(0.31, abs=0.01)138    assert c.loc["zone_B", "coef"] == pytest.approx(-0.0181, abs=0.0005) and c.loc["corr_300", "coef"] == pytest.approx(-0.0306, abs=0.0005)139    assert c.loc["ln_dist_corridor", "coef"] == pytest.approx(-0.0065, abs=0.0005) and c.loc["ln_acces", "coef"] == pytest.approx(0.0106, abs=0.0005)140    assert (c["p"] > 0.05).all() and ref["F"] == pytest.approx(0.84, abs=0.01) and ref["p_F"] == pytest.approx(0.52, abs=0.01)141    assert ref["r2_base"] == pytest.approx(0.8530, abs=0.0001) and ref["r2"] == pytest.approx(0.8541, abs=0.0001)142    assert ref["mde"]["zone_A"] == pytest.approx(0.049, abs=0.001) and ref["mde"]["zone_B"] == pytest.approx(0.038, abs=0.001) and ref["mde"]["corr_300"] == pytest.approx(0.062, abs=0.001)143    assert ref["mde"]["ln_acces"] == pytest.approx(0.059, abs=0.001) and ref["mde"]["ln_dist_corridor"] == pytest.approx(0.020, abs=0.001)144    c2 = ss["coef"]145    assert c2.loc["zone_A", "coef"] == pytest.approx(0.0614, abs=0.0005) and c2.loc["zone_A", "t"] == pytest.approx(3.78, abs=0.01)146    assert c2.loc["zone_B", "coef"] == pytest.approx(0.0424, abs=0.0005) and c2.loc["zone_B", "t"] == pytest.approx(2.99, abs=0.01)147    assert c2.loc["ln_dist_corridor", "t"] == pytest.approx(-1.98, abs=0.01) and c2.loc["ln_acces", "coef"] == pytest.approx(0.1359, abs=0.0005) and c2.loc["ln_acces", "t"] == pytest.approx(10.9, abs=0.05)148    assert ss["F"] == pytest.approx(33.4, abs=0.05) and ss["r2_base"] == pytest.approx(0.7661, abs=0.0001) and ss["r2"] == pytest.approx(0.8182, abs=0.0001)149    c3 = sn["coef"]150    assert c3.loc["zone_A", "coef"] == pytest.approx(0.0578, abs=0.0005) and c3.loc["zone_B", "coef"] == pytest.approx(0.0502, abs=0.0005)151    assert c3.loc["ln_acces", "coef"] == pytest.approx(0.0596, abs=0.0005) and c3.loc["ln_acces", "t"] == pytest.approx(14.1, abs=0.05) and sn["F"] == pytest.approx(99.4, abs=0.05)152    assert sn["r2_base"] == pytest.approx(0.6372, abs=0.0001) and sn["r2"] == pytest.approx(0.8040, abs=0.0001)153    # effets en pourcentage cités : +0,5, −1,8, −3,0 (référence) ; +6,3, +4,3, +14,6 (sans secteur) ; +5,8, +5,2, +6,0154    assert c.loc["zone_A", "effet_pct"] == pytest.approx(0.5, abs=0.05) and c.loc["zone_B", "effet_pct"] == pytest.approx(-1.8, abs=0.05) and c.loc["corr_300", "effet_pct"] == pytest.approx(-3.0, abs=0.05)155    assert c2.loc["zone_A", "effet_pct"] == pytest.approx(6.3, abs=0.05) and c2.loc["zone_B", "effet_pct"] == pytest.approx(4.3, abs=0.05) and c2.loc["ln_acces", "effet_pct"] == pytest.approx(14.6, abs=0.05)156    assert c3.loc["zone_A", "effet_pct"] == pytest.approx(6.0, abs=0.06) and c3.loc["zone_B", "effet_pct"] == pytest.approx(5.2, abs=0.06) and c3.loc["ln_acces", "effet_pct"] == pytest.approx(6.1, abs=0.06)157158159def test_sensibilite_tampon(r):160    t = r["tampon"]; ref = t[t["spec"] == "référence"].set_index("rayon_m"); ss = t[t["spec"] == "sans secteur"].set_index("rayon_m")161    assert ref["n_dans_tampon"].loc[[100, 300, 1000]].tolist() == [4, 17, 57]162    assert (ref["t"].abs() < 1.96).all()                                                         # jamais significatif dans la référence163    assert ref.loc[100, "coef"] == pytest.approx(-0.054, abs=0.0005) and ref.loc[400, "coef"] == pytest.approx(0.002, abs=0.0005)164    assert 1.96 * ref.loc[100, "se"] == pytest.approx(0.072, abs=0.001) and 1.96 * ref.loc[1000, "se"] == pytest.approx(0.022, abs=0.001)165    assert ss.loc[300, "t"] == pytest.approx(-2.13, abs=0.01) and ss.loc[750, "t"] == pytest.approx(-2.72, abs=0.01) and ss.loc[1000, "t"] == pytest.approx(-3.56, abs=0.01)166    assert ss.loc[300, "coef"] == pytest.approx(-0.039, abs=0.0005) and ss.loc[1000, "coef"] == pytest.approx(-0.045, abs=0.0005) and (ss["coef"] < 0).all()167168169def test_faux_positifs(r):170    tab = r["faux_positifs"]["tableau"].set_index(["rayon_km", "spec", "erreur_type"])171    assert tab.loc[(0.5, "référence", "classique"), "n_polygones"] == 107 and tab.loc[(1.0, "référence", "classique"), "n_polygones"] == 346 and tab.loc[(2.0, "référence", "classique"), "n_polygones"] == 484172    g = lambda r_, s_, e_, col="part_5pct": float(tab.loc[(r_, s_, e_), col])173    assert g(1.0, "référence", "classique") == pytest.approx(0.029, abs=0.001) and g(2.0, "référence", "classique") == pytest.approx(0.035, abs=0.001) and g(0.5, "référence", "classique") == pytest.approx(0.112, abs=0.001)174    assert g(0.5, "référence", "HC1") == pytest.approx(0.262, abs=0.001) and g(1.0, "référence", "HC1") == pytest.approx(0.072, abs=0.001)175    assert g(1.0, "sans secteur", "classique") == pytest.approx(0.364, abs=0.001) and g(2.0, "sans secteur", "classique") == pytest.approx(0.736, abs=0.001)176    assert g(2.0, "sans secteur", "classique", "part_bonferroni") == pytest.approx(0.293, abs=0.001) and g(2.0, "référence", "classique", "part_bonferroni") == 0.0177    assert g(1.0, "référence", "classique", "ecart_type_t") == pytest.approx(1.01, abs=0.005) and g(2.0, "sans secteur", "classique", "ecart_type_t") == pytest.approx(4.42, abs=0.005)178    assert g(2.0, "sans secteur ni gradient", "classique") == pytest.approx(0.483, abs=0.001)179180# ----------------------------------------------------------------------------- cas 4 et capitalisation181182def test_cas4(r):183    c4 = r["cas4"]; par = c4["par_rmr"]184    assert c4["total"]["part_zone_inondable"] == pytest.approx(0.0666, abs=0.0001) and c4["n_inond"] == 3 and c4["n_sol"] == 2185    assert par.loc["Québec", "part_inond_rmr"] == pytest.approx(0.288, abs=0.001) and par.loc["Saguenay", "part_inond_rmr"] == pytest.approx(0.185, abs=0.001) and par.loc["Montréal", "part_inond_rmr"] == pytest.approx(0.026, abs=0.001)186    assert par.loc["Québec", "part_inond_total"] == pytest.approx(0.050, abs=0.001) and par["val_inond"].sum() == 9546000 and par["valeur"].sum() == 143363000187    assert par.loc["Québec", "val_inond"] == 7229000 and par.loc["Montréal", "n"] == 17 and par.loc["Gatineau", "n"] == 8188    assert c4["coef_inondable"] == pytest.approx(0.0756, abs=0.0005) and c4["se_inondable"] == pytest.approx(0.0347, abs=0.0005) and c4["effet_pct_inondable"] == pytest.approx(7.9, abs=0.05)189    assert c4["effet_pct_sol"] == pytest.approx(5.5, abs=0.05)190    assert abs(c4["coef_inondable"] - np.log(1.05)) < c4["se_inondable"]                       # à moins d'une erreur-type du générateur191    d = c4["distances_km"]192    assert d.loc["Montréal", "Québec"] == pytest.approx(236, abs=0.5) and d.loc["Québec", "Trois-Rivières"] == pytest.approx(116, abs=0.5) and d.loc["Gatineau", "Saguenay"] == pytest.approx(478, abs=0.5)193    assert c4["etendue_km"][0] == pytest.approx(379, abs=1) and c4["etendue_km"][1] == pytest.approx(343, abs=1)194195196def test_capitalisation(r):197    cap = r["capitalisation"]198    assert np.allclose(cap["p_annuelle"] * 100, [4.70, 0.89, 0.29], atol=0.005)199    assert np.allclose(cap["decote_pct"] * 100, [12.82, 1.29, 0.16], atol=0.005)200    assert np.allclose(cap["decote_dollars"], [81805, 8246, 1009], atol=0.6)201    # identité : décote = p1 × D / R202    assert np.allclose(cap["decote_pct"], cap["p_annuelle"] * cap["dommage_pct"] / 0.055)203204# ----------------------------------------------------------------------------- solutions des exercices205206def test_solutions_1_a_5():207    # ex. 1 : fuseaux et facteurs d'échelle208    k = {v: float(geo.facteur_echelle_tm(la, lo, l0)) for v, (la, lo, l0) in {"Mtl": (45.51, -73.60, -73.5), "Qc": (46.82, -71.19, -70.5), "Gat": (45.42, -75.74, -76.5), "Sag": (48.38, -71.10, -70.5)}.items()}209    assert k["Mtl"] == pytest.approx(0.999901, abs=1e-6) and k["Qc"] == pytest.approx(0.999934, abs=1e-6) and k["Gat"] == pytest.approx(0.999943, abs=1e-6) and k["Sag"] == pytest.approx(0.999924, abs=1e-6)210    assert (k["Mtl"] - 1) * 10000 == pytest.approx(-0.99, abs=0.01)211    # ex. 2 : trois distances212    xy = geo.equirectangulaire_km([45.4620], [-75.6612], 45.4215, -75.7395)[0]213    assert xy[0] == pytest.approx(6.111, abs=0.001) and xy[1] == pytest.approx(4.503, abs=0.001) and np.hypot(*xy) == pytest.approx(7.591, abs=0.001)214    assert float(geo.haversine_km(45.4215, -75.7395, 45.4620, -75.6612)) == pytest.approx(7.589, abs=0.001)215    assert np.hypot(45.4620 - 45.4215, -75.6612 + 75.7395) * 111 == pytest.approx(9.785, abs=0.001)216    # ex. 3 : aire, périmètre et tampon217    from shapely.geometry import Polygon218    sp = Polygon([(0, 0), (4, 0), (4, 3), (2, 1), (0, 3)])219    assert sp.area == 8.0 and sp.length == pytest.approx(15.657, abs=0.001)220    assert sp.buffer(0.5, quad_segs=64).area == pytest.approx(16.560, abs=0.001) and sp.area + 0.5 * sp.length + np.pi * 0.25 == pytest.approx(16.614, abs=0.001)221    # ex. 4 : indice gravitaire222    for lam, a1, a2 in [(0.25, 80.816, 62.54), (0.5, 49.561, 23.007)]:223        A1 = 100 * np.exp(-lam * 1.5) + 40 * np.exp(-lam * 6) + 30 * np.exp(-lam * 9); A2 = 170 * np.exp(-lam * 4)224        assert A1 == pytest.approx(a1, abs=0.001) and A2 == pytest.approx(a2, abs=0.001)225    assert np.log(80.816) == pytest.approx(4.392, abs=0.001) and np.log(62.54) == pytest.approx(4.136, abs=0.001)226    # ex. 5 : capitalisation et EMD227    p1 = geo.probabilite_annuelle(0.35); assert p1 == pytest.approx(0.01708, abs=1e-5)228    assert p1 * 0.10 / 0.05 == pytest.approx(0.0342, abs=0.0001) and p1 * 0.10 / 0.05 * 520000 == pytest.approx(17767, abs=1) and p1 * 0.2 / 0.05 * 520000 == pytest.approx(35534, abs=1)229    se = 0.09 / np.sqrt(500 * 0.048 * 0.952 * 0.9); assert se == pytest.approx(0.0199, abs=0.0001) and geo.effet_minimal_detectable(se) == pytest.approx(0.0556, abs=0.0001)230231232def test_solutions_6_et_7():233    e6 = c38.exercice_6(); t = e6["tableau_3km"].set_index(["spec", "erreur_type"])234    assert int(t.loc[("référence", "classique"), "n_polygones"]) == 995235    assert float(t.loc[("référence", "classique"), "part_5pct"]) == pytest.approx(0.045, abs=0.001) and float(t.loc[("référence", "HC1"), "part_5pct"]) == pytest.approx(0.053, abs=0.001)236    assert float(t.loc[("sans secteur", "classique"), "part_5pct"]) == pytest.approx(0.892, abs=0.001) and float(t.loc[("sans secteur", "classique"), "part_bonferroni"]) == pytest.approx(0.505, abs=0.001)237    assert float(t.loc[("sans secteur ni gradient", "classique"), "part_5pct"]) == pytest.approx(0.601, abs=0.001) and float(t.loc[("sans secteur ni gradient", "classique"), "part_bonferroni"]) == pytest.approx(0.325, abs=0.001)238    assert float(t.loc[("référence", "classique"), "ecart_type_t"]) == pytest.approx(0.98, abs=0.005) and float(t.loc[("sans secteur", "classique"), "ecart_type_t"]) == pytest.approx(6.28, abs=0.005)239    c = e6["comparaison_05km"]240    assert c["classique"]["n"] == 107 and c["classique"]["part_5pct"] == pytest.approx(0.112, abs=0.001) and c["HC1"]["part_5pct"] == pytest.approx(0.262, abs=0.001) and c["HC3"]["part_5pct"] == pytest.approx(0.234, abs=0.001)241    assert c["HC3"]["ecart_type"] == pytest.approx(1.42, abs=0.005)242    e7 = c38.exercice_7().set_index("grille")243    assert e7.loc["hexagones R = 800 m", ["cellules", "occupees", "n_min5"]].tolist() == [813, 123, 43] and e7.loc["hexagones R = 800 m", "gvf"] == pytest.approx(0.962, abs=0.001)244    assert e7.loc["hexagones R = 2000 m", ["cellules", "occupees", "n_min5"]].tolist() == [154, 34, 19] and e7.loc["hexagones R = 2000 m", "gvf"] == pytest.approx(0.975, abs=0.001)245    assert e7.loc["carrés de 2 km", ["cellules", "occupees", "n_min5"]].tolist() == [368, 64, 36] and e7.loc["carrés de 2 km", "gvf"] == pytest.approx(0.962, abs=0.001)246    assert np.allclose(e7["part_inter"].values, [0.356, 0.286, 0.250, 0.302], atol=0.001)247    assert np.allclose(e7.loc["hexagones R = 800 m", "bornes_jenks"], [2407, 2981, 3388, 3602, 3970, 4207])248
Files · main
Menu

Theme