Examples

Some examples on working with p4tools
import pandas as pd
from p4tools.io import (
    get_blotch_catalog,
    get_blotches_for_tile,
    get_fan_catalog,
    get_fans_for_tile,
    get_region_names,
)
from p4tools.plotting import plot_blotches_for_tile, plot_fans_for_tile
from p4tools.markings import Fan, Blotch
blotches = get_blotch_catalog('v1')
fans = get_fans_for_tile('80s', 'v1')  # v3 for this
get_blotches_for_tile('80s', 'v3')
obsid marking_id angle tile_id image_x image_y n_votes radius_1 radius_2 vote_ratio ... l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
9380 ESP_011448_0950 B0024a4 26.06 APF000080s 369.5 18362.0 4.0 512.08 384.06 1.0 ... 185.552 1.0 138.82556 127.680593 279.889716 -3367.51901 -84.780277 -84.84121 65.478392 29

1 rows × 24 columns

fans.head()
obsid marking_id angle distance tile_id image_x image_y n_votes spread version ... l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
137158 ESP_011448_0950 F025909 84.48 168.80 APF000080s 26.91 18140.73 18 20.93 1 ... 185.552 1.0 138.825539 127.358295 280.193080 -3367.505762 -84.777851 -84.838813 65.556417 29
137159 ESP_011448_0950 F02590a 85.14 97.54 APF000080s 49.08 18258.54 6 25.92 1 ... 185.552 1.0 138.825539 127.482002 280.203359 -3367.496453 -84.776815 -84.837788 65.536248 29
137160 ESP_011448_0950 F02590b 82.90 58.67 APF000080s 111.50 18205.77 18 28.49 1 ... 185.552 1.0 138.825539 127.447992 280.122584 -3367.504162 -84.778305 -84.839261 65.535784 29
137161 ESP_011448_0950 F02590c 79.00 83.67 APF000080s 139.47 18145.31 10 17.41 1 ... 185.552 1.0 138.825539 127.396216 280.075757 -3367.511393 -84.779397 -84.840341 65.540949 29
137162 ESP_011448_0950 F02590d 75.80 70.94 APF000080s 169.71 18280.73 13 21.39 1 ... 185.552 1.0 138.825539 127.540728 280.080872 -3367.507926 -84.778303 -84.839259 65.516853 29

5 rows × 25 columns

Blotch.from_marking_id("B0024a4").plot()

fans['area'] = [Fan(row).area for _, row in fans.iterrows()]
fans.query("marking_id == 'F025910'").squeeze()
obsid                     ESP_011448_0950
marking_id                        F025910
angle                               84.78
distance                           227.48
tile_id                        APF000080s
image_x                            673.95
image_y                          18328.19
n_votes                                20
spread                              22.13
version                                 1
vote_ratio                            1.0
x                                  673.95
y                                  244.19
x_angle                              0.09
y_angle                               1.0
l_s                               185.552
map_scale                             1.0
north_azimuth                  138.825539
BodyFixedCoordinateX           127.739446
BodyFixedCoordinateY           279.560121
BodyFixedCoordinateZ         -3367.544491
PlanetocentricLatitude         -84.784963
PlanetographicLatitude         -84.845842
Longitude                        65.44291
MY                                     29
area                          9254.575622
Name: 137165, dtype: object
fan = Fan.from_marking_id("F025910", version='v1')  # don't forget to use version here, if you need to get to old catalog!
fan
Fan.from_marking_id('F025910')  # tile_id='APF000080s', area=9254.575622432452
fan.area
np.float64(9254.575622432452)
fan.plot()

fan.to_shapely().area  # using the shapely object's area calculation
9254.1279
fan.radius
np.float64(37.20899726662801)
areas = [Fan(row).area for _, row in fans.iterrows()]
pd.Series(areas).sort_values(ascending=False).head(10)
7     9254.575622
48    6580.655978
0     4837.742642
8     4388.099137
11    3676.285708
21    3333.388541
6     3310.657326
15    2426.634151
10    2373.369482
5     2258.073369
dtype: float64
plot_fans_for_tile('80s')

pd.options.display.max_columns = None
blotches.head()
obsid marking_id angle tile_id image_x image_y n_votes radius_1 radius_2 vote_ratio x y x_angle y_angle l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
0 ESP_012079_0945 B000000 2.28 APF0000cia 3330.27 5573.00 4 22.13 15.78 1.00 370.27 93.00 0.50 0.10 214.785 0.25 126.856883 -67.239204 257.001479 -3370.630963 -85.493625 -85.546304 104.661641 29
1 ESP_012079_0945 B000001 1.38 APF0000cia 3593.60 5706.40 5 25.55 15.73 0.55 633.60 226.40 0.20 0.05 214.785 0.25 126.856883 -67.166591 257.008699 -3370.633997 -85.493821 -85.546498 104.646095 29
2 ESP_012079_0945 B000004 7.16 APF0000cic 98.10 34394.70 10 84.54 48.33 1.00 98.10 418.70 0.58 0.18 214.785 0.25 126.856883 -65.402430 263.908435 -3370.353989 -85.387847 -85.441752 103.918757 29
3 ESP_012079_0945 B000005 81.00 APF0000cic 825.58 34203.38 8 51.92 35.12 1.00 825.58 227.38 0.16 0.97 214.785 0.25 126.856883 -65.252200 263.799557 -3370.366323 -85.390259 -85.444136 103.893535 29
4 ESP_012079_0945 B000006 14.66 APF0000cic 152.67 34155.33 3 184.94 71.25 1.00 152.67 179.33 0.93 0.25 214.785 0.25 126.856883 -65.411364 263.848867 -3370.358955 -85.388794 -85.442688 103.923605 29
def get_area_m2(row):
    """Compute area in square meters for a blotch row."""
    return Blotch(row).area * (row['map_scale'] ** 2)
blotches['area_m2'] = blotches.apply(get_area_m2, axis=1)
blotches.sort_values(by='area_m2', ascending=False).head(5).T
247015 151122 213497 247017 217096
obsid ESP_011420_0930 ESP_020568_0950 ESP_020049_0985 ESP_011420_0930 ESP_020321_0935
marking_id B044091 B02b30d B03aeca B044093 B03bda7
angle 0.65 176.24 17.56 90.89 169.78
tile_id APF0000ftb APF0000pqj APF0000jcv APF0000ftb APF0000tde
image_x 445.72 406.17 656.06 287.17 444.79
image_y 12310.0 28843.33 7894.17 12381.33 16118.0
n_votes 3 3 13 3 4
radius_1 307.83 450.63 190.52 165.95 335.92
radius_2 231.66 356.56 144.14 133.42 251.94
vote_ratio 1.0 1.0 1.0 1.0 1.0
x 445.72 406.17 656.06 287.17 444.79
y 254.0 347.33 222.17 325.33 226.0
x_angle 0.33 -0.33 0.94 0.07 -0.98
y_angle 0.03 0.39 0.3 0.84 0.18
l_s 184.304 199.362 176.075 184.304 188.091
map_scale 1.0 0.5 1.0 1.0 0.5
north_azimuth 157.311404 122.217013 107.843834 157.311404 136.913825
BodyFixedCoordinateX -108.319074 -292.548434 218.993402 -108.419596 -33.483452
BodyFixedCoordinateY 138.086757 -0.475303 -451.601655 138.223638 210.518459
BodyFixedCoordinateZ -3377.673253 -3368.925447 -3343.091928 -3377.663493 -3374.783449
PlanetocentricLatitude -87.025617 -85.037032 -81.461947 -87.022737 -86.385774
PlanetographicLatitude -87.060467 -85.094998 -81.56071 -87.057621 -86.428085
Longitude 128.111619 180.093088 295.869955 128.109861 99.037327
MY 29 30 30 29 30
area_m2 224032.934242 126195.132302 86273.012533 69558.156881 66469.569807
Blotch.from_marking_id("B0024a4", with_center=True, color='green').plot()

get_blotches_for_tile("80s", version='v1')
obsid marking_id angle tile_id image_x image_y n_votes radius_1 radius_2 vote_ratio x y x_angle y_angle l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
177822 ESP_011448_0950 B031fa6 0.0 APF000080s 146.33 18533.0 3 10.0 10.0 1.0 146.33 449.0 0.67 0.33 185.552 1.0 138.825539 127.786289 280.175948 -3367.493077 -84.775102 -84.836095 65.482603 29
blotches = get_blotches_for_tile('ftb')
collection = [
            Blotch(blotch, with_center=False, color='green')
            for _, blotch in blotches.iterrows()
        ]
[b.area for b in collection]
[8527.599417483081,
 462.9796509521814,
 1351.0356374909834,
 454.60353661918026,
 555.9104749194903,
 588.2757907553031,
 1078.194598712017,
 1524.9139944077483,
 410.4179784242359,
 383.47379487145776,
 338.12584739468514,
 314.1592653589793,
 558.7388507855172,
 566.640270468561,
 882.7341285836209,
 356.0115626901025,
 347.2741652019387,
 538.3323215448594,
 659.3624926836716,
 394.86803726676254,
 461.63819088909855,
 381.75440121214797,
 364.82373008342194,
 366.42028746997624,
 344.0043955680823,
 370.0698756556515,
 1961.7226077592,
 4867.553812341817,
 1799.3597587141685,
 655.2074222400337,
 320.7566099315179,
 530.0466850802817,
 394.1206523744735,
 1049.0955967581415,
 806.0723563321919,
 373.86931781090294,
 314.1592653589793,
 341.80528071056955,
 404.7250983766658,
 621.4598056366414,
 727.8630355396049,
 384.4351222234562,
 590.7601622257619,
 453.9500853472336,
 69558.15688117163,
 3649.2749688876993,
 3076.005623760799,
 224032.93424202612]
rois = get_region_names()
rois.roi_name.unique()
array(['Macclesfield', 'unknown', 'Starburst', 'Manhattan_Classic',
       'Wellington', 'Albany', 'Bilbao', 'Ithaca', 'Portsmouth', 'Pisaq',
       'Manhattan_Frontinella', 'BuenosAires', 'Inca_City_Ridges',
       'Inca_City', 'Giza', 'Potsdam', 'Troy', 'Oswego_Edge', 'Halifax',
       'Caterpillar', 'Rochester', 'Manhattan_Cracks', 'Schenectady',
       'Binghamton', 'Atka', 'Cortland', 'Geneseo', 'Manhattan2'],
      dtype=object)
rois.query("roi_name=='Giza'").describe()
lat_IND lon_IND minimal_distance lat_WORD lon_WORD MY
count 35.000000 35.000000 35.000000 3.500000e+01 3.500000e+01 35.000000
mean -84.829069 66.071666 6.318094 -8.482000e+01 6.570000e+01 29.057143
std 0.066423 0.991527 11.242504 2.883665e-14 1.441832e-14 1.027357
min -84.979100 65.637800 0.720371 -8.482000e+01 6.570000e+01 28.000000
25% -84.834950 65.736450 1.254355 -8.482000e+01 6.570000e+01 28.000000
50% -84.812200 65.774200 1.487853 -8.482000e+01 6.570000e+01 29.000000
75% -84.809350 65.799750 4.005964 -8.482000e+01 6.570000e+01 30.000000
max -84.581900 69.890400 44.631912 -8.482000e+01 6.570000e+01 31.000000
fans = get_fan_catalog()
blotches = get_blotch_catalog()
fansperobsid = fans.groupby("obsid").size()
fansperobsid.head()
obsid
ESP_011296_0975    4500
ESP_011341_0980     457
ESP_011348_0950       6
ESP_011350_0945    1108
ESP_011351_0945    1643
dtype: int64
blotchesperobsid = blotches.groupby("obsid").size()
blotchesperobsid.head()
obsid
ESP_011296_0975    1012
ESP_011341_0980     281
ESP_011348_0950     198
ESP_011350_0945     626
ESP_011351_0945    1279
dtype: int64
df = fansperobsid.to_frame()
df["blotches counts"] = blotchesperobsid
df.columns = ["fan_count_per_obsid", "blotch_count_per_obsid"]
df.head()
fan_count_per_obsid blotch_count_per_obsid
obsid
ESP_011296_0975 4500 1012.0
ESP_011341_0980 457 281.0
ESP_011348_0950 6 198.0
ESP_011350_0945 1108 626.0
ESP_011351_0945 1643 1279.0
fan_counts_per_tile = fans.groupby("tile_id").size()
fan_counts_per_tile.head()
tile_id
APF0000001    3
APF0000006    4
APF0000009    1
APF000000c    4
APF000000f    1
dtype: int64
blotch_counts_per_tile = blotches.groupby("tile_id").size()
blotch_counts_per_tile.head()
tile_id
APF0000001    1
APF0000002    2
APF0000004    4
APF0000005    5
APF0000006    7
dtype: int64
fan_counts_per_tile.name = "fans"
blotch_counts_per_tile.name = "blotches"
df = pd.DataFrame(fan_counts_per_tile)
df["blotches"] = blotch_counts_per_tile
df.head()
fans blotches
tile_id
APF0000001 3 1.0
APF0000006 4 7.0
APF0000009 1 26.0
APF000000c 4 3.0
APF000000f 1 32.0
df[(df.fans + df.blotches) > 100].head()
fans blotches
tile_id
APF00002zj 99 4.0
APF000061m 133 52.0
APF00006mg 98 7.0
APF00006mt 118 2.0
APF00006mv 95 19.0

The input data products for the P4 project are the `COLOR products one can find on the uahirise.org website!

buffalo = "ESP_011486_0980_COLOR ESP_011987_0975_COLOR ESP_012198_0975_COLOR ESP_012277_0975_COLOR ESP_012620_0975_COLOR".split()
buffalo = [i.rstrip("_COLOR") for i in buffalo]
p4_buffalo = fans[fans.obsid.isin(buffalo)].obsid.unique()
fans[fans.obsid.isin(p4_buffalo)].groupby("obsid").size()
obsid
ESP_011486_0980    261
ESP_012277_0975     20
ESP_012620_0975     30
dtype: int64
fans[fans.obsid.isin(p4_buffalo)][["l_s", "obsid"]].drop_duplicates()
l_s obsid
15583 187.254 ESP_011486_0980
48242 224.333 ESP_012277_0975
85398 241.144 ESP_012620_0975
fans[fans.tile_id.str.contains("r8y")]
obsid marking_id angle distance tile_id image_x image_y n_votes spread version vote_ratio x y x_angle y_angle l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
106534 ESP_020242_0945 F01a026 34.16 171.27 APF0000r8y 505.45 13038.68 19.0 41.85 1 1.0 505.45 434.68 0.82 0.56 184.557 1.0 143.67511 -63.562264 265.129449 -3370.242420 -85.375019 -85.429073 103.481673 30
106535 ESP_020242_0945 F01a027 33.30 90.38 APF0000r8y 249.21 12781.71 14.0 25.57 1 1.0 249.21 177.71 0.83 0.55 184.557 1.0 143.67511 -63.936682 265.103685 -3370.250040 -85.373975 -85.428040 103.559434 30
106536 ESP_020242_0945 F01a028 38.19 86.92 APF0000r8y 387.19 12617.75 16.0 33.44 1 1.0 387.19 13.75 0.78 0.62 184.557 1.0 143.67511 -63.932326 264.882174 -3370.272468 -85.377659 -85.431682 103.569463 30
106537 ESP_020242_0945 F01a029 39.19 54.32 APF0000r8y 73.62 13114.42 12.0 30.04 1 1.0 73.62 510.42 0.77 0.63 184.557 1.0 143.67511 -63.860251 265.482502 -3370.212467 -85.368005 -85.422140 103.525207 30
106538 ESP_020242_0945 F01a02a 36.11 106.09 APF0000r8y 30.86 13128.72 18.0 36.90 1 1.0 30.86 524.72 0.81 0.59 184.557 1.0 143.67511 -63.885407 265.522804 -3370.208488 -85.367238 -85.421382 103.528361 30
106539 ESP_020242_0945 F01a02b 76.52 63.91 APF0000r8y 32.33 13128.33 3.0 46.96 1 1.0 32.33 524.33 0.23 0.96 184.557 1.0 143.67511 -63.884475 265.521496 -3370.208625 -85.367264 -85.421407 103.528235 30
106540 ESP_020242_0945 F01a02c 32.72 77.35 APF0000r8y 204.00 13205.53 15.0 36.85 1 1.0 204.00 601.53 0.84 0.54 184.557 1.0 143.67511 -63.695785 265.464328 -3370.212856 -85.368953 -85.423077 103.492539 30
plot_fans_for_tile("r8y")

blotches = get_blotches_for_tile("ftb")  # no blotches, that's why below plot is empty
blotches.head()
obsid marking_id angle tile_id image_x image_y n_votes radius_1 radius_2 vote_ratio x y x_angle y_angle l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
7600 ESP_011420_0930 B001db0 65.97 APF0000ftb 694.83 12074.33 3.0 60.16 45.12 1.00 694.83 18.33 0.34 0.84 184.304 1.0 157.311464 -108.219785 137.763762 -3377.691341 -87.030969 -87.065756 128.151268 29
7601 ESP_011420_0930 B001db1 76.61 APF0000ftb 495.83 12276.83 6.0 12.95 11.38 1.00 495.83 220.83 0.40 0.63 184.304 1.0 157.311464 -108.291561 138.031307 -3377.676832 -87.026646 -87.061484 128.115726 29
7602 ESP_011420_0930 B001db2 50.11 APF0000ftb 284.75 12448.50 4.0 24.16 17.80 1.00 284.75 392.50 0.60 0.64 184.304 1.0 157.311464 -108.388342 138.278643 -3377.662577 -87.022330 -87.057219 128.090771 29
7603 ESP_011420_0930 B001db3 39.37 APF0000ftb 236.70 12400.62 8.0 13.06 11.08 1.00 236.70 344.62 0.63 0.53 184.304 1.0 157.311464 -108.452364 138.261137 -3377.660639 -87.021893 -87.056787 128.110721 29
7604 ESP_011420_0930 B001db4 51.89 APF0000ftb 214.67 12296.33 6.0 14.54 12.17 0.66 214.67 240.33 0.57 0.60 184.304 1.0 157.311464 -108.521524 138.183271 -3377.662441 -87.022209 -87.057098 128.144138 29
plot_blotches_for_tile("ftb")

get_fans_for_tile("APF0000r8y")
obsid marking_id angle distance tile_id image_x image_y n_votes spread version vote_ratio x y x_angle y_angle l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
106534 ESP_020242_0945 F01a026 34.16 171.27 APF0000r8y 505.45 13038.68 19.0 41.85 1 1.0 505.45 434.68 0.82 0.56 184.557 1.0 143.67511 -63.562264 265.129449 -3370.242420 -85.375019 -85.429073 103.481673 30
106535 ESP_020242_0945 F01a027 33.30 90.38 APF0000r8y 249.21 12781.71 14.0 25.57 1 1.0 249.21 177.71 0.83 0.55 184.557 1.0 143.67511 -63.936682 265.103685 -3370.250040 -85.373975 -85.428040 103.559434 30
106536 ESP_020242_0945 F01a028 38.19 86.92 APF0000r8y 387.19 12617.75 16.0 33.44 1 1.0 387.19 13.75 0.78 0.62 184.557 1.0 143.67511 -63.932326 264.882174 -3370.272468 -85.377659 -85.431682 103.569463 30
106537 ESP_020242_0945 F01a029 39.19 54.32 APF0000r8y 73.62 13114.42 12.0 30.04 1 1.0 73.62 510.42 0.77 0.63 184.557 1.0 143.67511 -63.860251 265.482502 -3370.212467 -85.368005 -85.422140 103.525207 30
106538 ESP_020242_0945 F01a02a 36.11 106.09 APF0000r8y 30.86 13128.72 18.0 36.90 1 1.0 30.86 524.72 0.81 0.59 184.557 1.0 143.67511 -63.885407 265.522804 -3370.208488 -85.367238 -85.421382 103.528361 30
106539 ESP_020242_0945 F01a02b 76.52 63.91 APF0000r8y 32.33 13128.33 3.0 46.96 1 1.0 32.33 524.33 0.23 0.96 184.557 1.0 143.67511 -63.884475 265.521496 -3370.208625 -85.367264 -85.421407 103.528235 30
106540 ESP_020242_0945 F01a02c 32.72 77.35 APF0000r8y 204.00 13205.53 15.0 36.85 1 1.0 204.00 601.53 0.84 0.54 184.557 1.0 143.67511 -63.695785 265.464328 -3370.212856 -85.368953 -85.423077 103.492539 30
get_blotches_for_tile("5g")
obsid marking_id angle tile_id image_x image_y n_votes radius_1 radius_2 vote_ratio x y x_angle y_angle l_s map_scale north_azimuth BodyFixedCoordinateX BodyFixedCoordinateY BodyFixedCoordinateZ PlanetocentricLatitude PlanetographicLatitude Longitude MY
69911 ESP_012254_1065 B011117 37.88 APF000005g 407.47 26519.18 61.0 21.72 16.57 1.00 407.47 215.18 0.69 0.59 223.218 0.25 100.857783 900.773236 -336.044800 -3241.529659 -73.480014 -73.663520 339.541336 29
69912 ESP_012254_1065 B011118 37.20 APF000005g 462.80 26382.70 54.0 21.64 15.34 0.85 462.80 78.70 0.72 0.57 223.218 0.25 100.857783 900.738239 -336.039608 -3241.539736 -73.480625 -73.664125 339.540897 29
69913 ESP_012254_1065 B011119 35.34 APF000005g 542.32 26364.61 59.0 19.22 14.75 1.00 542.32 60.61 0.65 0.54 223.218 0.25 100.857783 900.724423 -336.054456 -3241.542130 -73.480763 -73.664261 339.539780 29
69914 ESP_012254_1065 B01111a 41.62 APF000005g 134.61 26914.31 55.0 22.07 15.63 1.00 134.61 610.31 0.69 0.62 223.218 0.25 100.857783 900.888886 -336.035590 -3241.498827 -73.478158 -73.661682 339.544259 29
69915 ESP_012254_1065 B01111b 15.11 APF000005g 424.85 26942.25 35.0 14.20 11.73 1.00 424.85 638.25 0.73 0.31 223.218 0.25 100.857783 900.857708 -336.101545 -3241.501188 -73.478269 -73.661792 339.539928 29
69916 ESP_012254_1065 B01111c 21.95 APF000005g 755.74 26755.94 53.0 15.90 12.94 1.00 755.74 451.94 0.68 0.39 223.218 0.25 100.857783 900.777473 -336.149418 -3241.518687 -73.479303 -73.662815 339.535583 29
69917 ESP_012254_1065 B01111d 4.13 APF000005g 313.37 26945.62 26.0 14.23 12.12 1.00 313.37 641.62 0.58 0.23 223.218 0.25 100.857783 900.872572 -336.077977 -3241.499324 -73.478168 -73.661692 339.541553 29