# # Styling notebook
# from IPython.core.display import HTML
# def css_styling():
# styles = open("/Users/ashokkhosla/.jupyter/custom/custom.css", "r").read()
# return HTML(styles)
# css_styling();Workbench
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import time
import itertools
from collections import Counter
import re
import os
import sys
# Import Khipu classes
sys.path.insert(0, '/Users/ashokkhosla/Desktop/Khipu/fieldguide/code/classes')
# Natural Language Processing Analysis
import math
import statistics
from statistics import mean
import random
import nltk
import scipy
from sklearn import feature_extraction
from sklearn.feature_extraction.text import TfidfVectorizer
from scipy.cluster.hierarchy import ward, dendrogram
from sklearn.cluster import KMeans
from sklearn.metrics.pairwise import cosine_similarity
# Seaborn settings
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(rc={'axes.facecolor':'#dfe7f4', 'figure.facecolor':'#dfe7f4'})
# Plotly
import plotly
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected = True)
import plotly.graph_objs as go
import plotly.express as px
import plotly.figure_factory as ff
#IPython/Jupyter settings
from IPython import get_ipython
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
np.set_printoptions(precision=4, suppress=True)
fig=plt.figure(figsize=(20, 10), dpi= 300, facecolor='w', edgecolor='k')
#import dtale as dtale
def display_dataframe(adataframe):
return adataframe
# Economist style...
def set_economist_style():
params = {"figure.facecolor": "#cad9e1",
"axes.facecolor": "#cad9e1",
"axes.grid" : True,
"axes.grid.axis" : "y",
"grid.color" : "#ffffff",
"grid.linewidth": .75,
"grid.linestyle": 'dotted',
"axes.spines.left" : False,
"axes.spines.right" : False,
"axes.spines.top" : False,
"ytick.major.size": 0,
"ytick.minor.size": 0,
"xtick.direction" : "in",
"xtick.major.size" : 7,
"xtick.color" : "#191919",
"axes.edgecolor" :"#191919",
"axes.prop_cycle" : plt.cycler('color',
['#006767', '#ff7f0e', '#2ca02c', '#d62728',
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
'#bcbd22', '#17becf'])
}
plt.rcParams.update(params)
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = ['Lucida Grande', 'Tahoma', 'Monaco']
mpl.rcParams['figure.dpi']= 120
mpl.rcParams['axes.axisbelow'] = True
set_economist_style();
def prep_plot(aPlotHeight = 5):
set_economist_style()
plt.figure(figsize=(12, aPlotHeight))
plt.grid(linestyle='dotted', linewidth=.75, axis='y')
import khipu_kamayuq as kamayuq # A Khipu Maker is known (in Quechua) as a Khipu Kamayuq
import khipu_qollqa as kq
import khipu_utils as ku<Figure size 6000x3000 with 0 Axes>
import jupyter_core
jupyter_core.paths.jupyter_config_dir()'/Users/ashokkhosla/.jupyter'
#=======================================================
# INITIALIZE
# Read in the Fieldmark and its associated dataframes
#=======================================================
# from fieldmark_ascher_pendant_pendant_sum import Fieldmark_Pendant_Pendant_Sum
# aFieldmark = Fieldmark_Pendant_Pendant_Sum()
# khipu_df = aFieldmark.dataframes[0].dataframe
# sum_cord_df = aFieldmark.dataframes[1].dataframe
from khipu import Khipu
(khipu_dict, all_khipus) = kamayuq.fetch_khipus()
# for index,aName in enumerate(khipu_dict.keys()):
# print(index,aName)
# khipu_dict[aName] = Khipu(aName)
# Initialize plotly
plotly.offline.init_notebook_mode(connected = False);
len(khipu_dict.keys())0: 1000166
25: 1000334
import numpy as np
import matplotlib.pyplot as plt
# Import the MarkovChain class from markovchain.py
from markovchain import MarkovChain
P = np.array([
[0.8, 0.1, 0.1, 0.0],
[0.1, 0.7, 0.0, 0.2],
[0.1, 0.0, 0.7, 0.2],
[0.1, 0.0, 0.7, 0.2]
])
mc = MarkovChain(P, ['1', '2', '3', '4'])
mc.draw("/Users/ashokkhosla/Desktop/markup.png")
cluster_data = """
156.5cm group of 11 pendants (418-428) space of 1.5cm
160.0cm group of 10 pendants (429-438) space of 1.5cm
163.5cm group of 11 pendants (439-449) space of 1.5cm
167.0cm group of 12 pendants (450-461) space of 2.0cm
171.0cm group of 6 pendants (462-467) space of 1.5cm
173.5cm group of 10 pendants (468-477) space of 1.5cm
177.0cm group of 11 pendants (478-488) space of 1.0cm
180.0cm group of 11 pendants (489-499) space of 1.5cm
183.0cm group of 11 pendants (500-510) space of 1.0cm
186.5cm group of 11 pendants (511-521) space of 1.5cm
189.5cm group of 11 pendants (522-532) space of 1.0cm
193.0cm group of 10 pendants (533-542) space of 1.5cm
196.0cm group of 11 pendants (543-553) space of 3.5cm
202.0cm group of 11 pendants (554-564) space of 1.5cm
205.0cm group of 11 pendants (565-575) space of 1.5cm
208.5cm group of 11 pendants (576-586) space of 1.0cm
212.0cm group of 11 pendants (587-597) space of 1.5cm
215.5cm group of 12 pendants (598-609) space of 1.5cm
219.5cm group of 11 pendants (610-620) space of 1.5cm
223.0cm group of 11 pendants (621-631) space of 1.5cm
227.0cm group of 11 pendants (632-642) space of 1.5cm
230.0cm group of 11 pendants (643-653) space of 1.5cm
233.0cm group of 11 pendants (654-664) space of 1.5cm
236.5cm group of 11 pendants (665-675) space of 1.5cm
240.0cm group of 11 pendants (676-686) space of 1.5cm
243.5cm group of 11 pendants (687-697) space of 2.0cm
248.0cm group of 11 pendants (698-708) space of 2.5cm
253.0cm group of 11 pendants (709-719) space of 1.5cm
256.5cm group of 11 pendants (720-730) space of 1.5cm
260.0cm group of 11 pendants (731-741) space of 1.5cm
263.5cm group of 11 pendants (742-752) space of 1.5cm
267.0cm group of 12 pendants (753-764) space of 1.5cm
270.5cm group of 11 pendants (765-775) space of 1.5cm
274.0cm group of 11 pendants (776-786) space of 1.5cm
277.0cm group of 11 pendants (787-797) space of 1.0cm
280.5cm group of 11 pendants (798-808) space of 1.5cm
284.0cm group of 11 pendants (809-819) space of 1.5cm
287.5cm group of 12 pendants (820-831) space of 1.5cm
291.0cm group of 12 pendants (832-843) space of 1.0cm
294.5cm group of 11 pendants (844-854) space of 0.5cm
297.0cm group of 10 pendants (855-864) space of 4.0cm
"""cord_data = """
"p418",
"p419",
"p420",
"p421",
"p422",
"p423",
"p424",
"p425",
"p426",
"p427",
"p428",
"p429",
"p430",
"p431",
"p432",
"p433",
"p434",
"p435",
"p436",
"p437",
"p438",
"p439",
"p440",
"p441",
"p442",
"p443",
"p444",
"p445",
"p446",
"p447",
"p448",
"p449",
"p450",
"p451",
"p452",
"p453",
"p454",
"p455",
"p456",
"p457",
"p458",
"p459",
"p460",
"p461",
"p462",
"p463",
"p464",
"p465",
"p466",
"p467",
"p468",
"p469",
"p470",
"p471",
"p472",
"p473",
"p474",
"p475",
"p476",
"p477",
"p478",
"p479",
"p480",
"p481",
"p482",
"p483",
"p484",
"p485",
"p486",
"p487",
"p488",
"p489",
"p490",
"p491",
"p492",
"p493",
"p494",
"p495",
"p496",
"p497",
"p498",
"p499",
"p500",
"p501",
"p502",
"p503",
"p504",
"p505",
"p506",
"p507",
"p508",
"p509",
"p510",
"p511",
"p511s1",
"p512",
"p512s1",
"p513",
"p513s1",
"p514",
"p514s1",
"p515",
"p515s1",
"p516",
"p516s1",
"p517",
"p517s1",
"p518",
"p518s1",
"p519",
"p519s1",
"p520",
"p520s1",
"p521",
"p521s1",
"p522",
"p523",
"p524",
"p525",
"p526",
"p527",
"p528",
"p529",
"p530",
"p531",
"p532",
"p533",
"p534",
"p535",
"p536",
"p537",
"p538",
"p539",
"p540",
"p541",
"p542",
"p543",
"p544",
"p545",
"p546",
"p547",
"p548",
"p549",
"p550",
"p551",
"p552",
"p553",
"p554",
"p555",
"p556",
"p557",
"p558",
"p559",
"p560",
"p561",
"p562",
"p563",
"p564",
"p565",
"p566",
"p567",
"p568",
"p569",
"p570",
"p571",
"p572",
"p573",
"p574",
"p575",
"p576",
"p577",
"p578",
"p579",
"p580",
"p581",
"p582",
"p583",
"p584",
"p585",
"p586",
"p587",
"p588",
"p589",
"p590",
"p591",
"p592",
"p593",
"p594",
"p595",
"p596",
"p597",
"p598",
"p599",
"p600",
"p601",
"p602",
"p603",
"p604",
"p605",
"p606",
"p607",
"p608",
"p609",
"p610",
"p610s1",
"p611",
"p611s1",
"p612",
"p612s1",
"p613",
"p613s1",
"p614",
"p614s1",
"p615",
"p615s1",
"p616",
"p616s1",
"p617",
"p617s1",
"p618",
"p618s1",
"p619",
"p619s1",
"p620",
"p620s1",
"p621",
"p622",
"p623",
"p624",
"p625",
"p626",
"p627",
"p628",
"p629",
"p630",
"p631",
"p632",
"p633",
"p634",
"p635",
"p636",
"p637",
"p638",
"p639",
"p640",
"p641",
"p642",
"p643",
"p644",
"p645",
"p646",
"p647",
"p648",
"p649",
"p650",
"p651",
"p652",
"p653",
"p654",
"p655",
"p656",
"p657",
"p658",
"p659",
"p660",
"p661",
"p662",
"p663",
"p664",
"p665",
"p665s1",
"p666",
"p666s1",
"p667",
"p667s1",
"p668",
"p668s1",
"p669",
"p669s1",
"p670",
"p670s1",
"p671",
"p671s1",
"p672",
"p672s1",
"p673",
"p673s1",
"p674",
"p674s1",
"p675",
"p675s1",
"p676",
"p677",
"p678",
"p679",
"p680",
"p681",
"p682",
"p683",
"p684",
"p685",
"p686",
"p687",
"p688",
"p689",
"p690",
"p691",
"p692",
"p693",
"p694",
"p695",
"p696",
"p697",
"p698",
"p699",
"p700",
"p701",
"p702",
"p703",
"p704",
"p705",
"p706",
"p707",
"p708",
"p709",
"p710",
"p711",
"p712",
"p713",
"p714",
"p715",
"p716",
"p717",
"p718",
"p719",
"p720",
"p721",
"p722",
"p723",
"p724",
"p725",
"p726",
"p727",
"p728",
"p729",
"p730",
"p731",
"p732",
"p733",
"p734",
"p735",
"p736",
"p737",
"p738",
"p739",
"p740",
"p741",
"p742",
"p743",
"p744",
"p745",
"p746",
"p747",
"p748",
"p749",
"p750",
"p751",
"p752",
"p753",
"p754",
"p755",
"p756",
"p757",
"p758",
"p759",
"p760",
"p761",
"p762",
"p763",
"p764",
"p764s1",
"p765",
"p765s1",
"p766",
"p766s1",
"p767",
"p767s1",
"p768",
"p768s1",
"p769",
"p770",
"p770s1",
"p771",
"p771s1",
"p772",
"p772s1",
"p773",
"p773s1",
"p774",
"p774s1",
"p775",
"p775s1",
"p776",
"p777",
"p778",
"p779",
"p780",
"p781",
"p782",
"p783",
"p784",
"p785",
"p786",
"p787",
"p788",
"p789",
"p790",
"p791",
"p792",
"p793",
"p794",
"p795",
"p796",
"p797",
"p798",
"p799",
"p800",
"p801",
"p802",
"p803",
"p804",
"p805",
"p806",
"p807",
"p808",
"p809",
"p810",
"p811",
"p812",
"p813",
"p814",
"p815",
"p816",
"p817",
"p818",
"p819",
"p820",
"p821",
"p822",
"p823",
"p824",
"p825",
"p826",
"p827",
"p828",
"p829",
"p830",
"p831",
"p832",
"p833",
"p834",
"p835",
"p836",
"p837",
"p838",
"p839",
"p840",
"p841",
"p842",
"p843",
"p844",
"p845",
"p846",
"p847",
"p848",
"p849",
"p850",
"p851",
"p852",
"p853",
"p854",
"p855",
"p856",
"p857",
"p858",
"p859",
"p860",
"p861",
"p862",
"p863",
"p864"
"""cord_lines = [aLine for aLine in cord_data.split('\n') if len(aLine.strip()) > 0]
def shift_pendant_name(aName, delta_pendants):
numbers = re.findall(r'[\d\.]+', aName)
if len(numbers) > 0:
numbers[0] = str(int(numbers[0]) + delta_pendants)
return "p" + "s".join(numbers)
else:
print("!!!! Couldn't process {aName}")
for line in cord_lines:
delta_pendants = -417
print(shift_pendant_name(line, delta_pendants))p1
p2
p3
p4
p5
p6
p7
p8
p9
p10
p11
p12
p13
p14
p15
p16
p17
p18
p19
p20
p21
p22
p23
p24
p25
p26
p27
p28
p29
p30
p31
p32
p33
p34
p35
p36
p37
p38
p39
p40
p41
p42
p43
p44
p45
p46
p47
p48
p49
p50
p51
p52
p53
p54
p55
p56
p57
p58
p59
p60
p61
p62
p63
p64
p65
p66
p67
p68
p69
p70
p71
p72
p73
p74
p75
p76
p77
p78
p79
p80
p81
p82
p83
p84
p85
p86
p87
p88
p89
p90
p91
p92
p93
p94
p94s1
p95
p95s1
p96
p96s1
p97
p97s1
p98
p98s1
p99
p99s1
p100
p100s1
p101
p101s1
p102
p102s1
p103
p103s1
p104
p104s1
p105
p106
p107
p108
p109
p110
p111
p112
p113
p114
p115
p116
p117
p118
p119
p120
p121
p122
p123
p124
p125
p126
p127
p128
p129
p130
p131
p132
p133
p134
p135
p136
p137
p138
p139
p140
p141
p142
p143
p144
p145
p146
p147
p148
p149
p150
p151
p152
p153
p154
p155
p156
p157
p158
p159
p160
p161
p162
p163
p164
p165
p166
p167
p168
p169
p170
p171
p172
p173
p174
p175
p176
p177
p178
p179
p180
p181
p182
p183
p184
p185
p186
p187
p188
p189
p190
p191
p192
p193
p193s1
p194
p194s1
p195
p195s1
p196
p196s1
p197
p197s1
p198
p198s1
p199
p199s1
p200
p200s1
p201
p201s1
p202
p202s1
p203
p203s1
p204
p205
p206
p207
p208
p209
p210
p211
p212
p213
p214
p215
p216
p217
p218
p219
p220
p221
p222
p223
p224
p225
p226
p227
p228
p229
p230
p231
p232
p233
p234
p235
p236
p237
p238
p239
p240
p241
p242
p243
p244
p245
p246
p247
p248
p248s1
p249
p249s1
p250
p250s1
p251
p251s1
p252
p252s1
p253
p253s1
p254
p254s1
p255
p255s1
p256
p256s1
p257
p257s1
p258
p258s1
p259
p260
p261
p262
p263
p264
p265
p266
p267
p268
p269
p270
p271
p272
p273
p274
p275
p276
p277
p278
p279
p280
p281
p282
p283
p284
p285
p286
p287
p288
p289
p290
p291
p292
p293
p294
p295
p296
p297
p298
p299
p300
p301
p302
p303
p304
p305
p306
p307
p308
p309
p310
p311
p312
p313
p314
p315
p316
p317
p318
p319
p320
p321
p322
p323
p324
p325
p326
p327
p328
p329
p330
p331
p332
p333
p334
p335
p336
p337
p338
p339
p340
p341
p342
p343
p344
p345
p346
p347
p347s1
p348
p348s1
p349
p349s1
p350
p350s1
p351
p351s1
p352
p353
p353s1
p354
p354s1
p355
p355s1
p356
p356s1
p357
p357s1
p358
p358s1
p359
p360
p361
p362
p363
p364
p365
p366
p367
p368
p369
p370
p371
p372
p373
p374
p375
p376
p377
p378
p379
p380
p381
p382
p383
p384
p385
p386
p387
p388
p389
p390
p391
p392
p393
p394
p395
p396
p397
p398
p399
p400
p401
p402
p403
p404
p405
p406
p407
p408
p409
p410
p411
p412
p413
p414
p415
p416
p417
p418
p419
p420
p421
p422
p423
p424
p425
p426
p427
p428
p429
p430
p431
p432
p433
p434
p435
p436
p437
p438
p439
p440
p441
p442
p443
p444
p445
p446
p447
cluster_lines['',
'22.0cm group of 6 pendants (40-45) space of 1.5cm',
'26.5cm group of 11 pendants (46-56) space of 1.5cm',
'30.0cm group of 10 pendants (57-66) space of 1.5cm',
'34.0cm group of 11 pendants (67-77) space of 1.5cm',
'37.5cm group of 11 pendants (78-88) space of 1.5cm',
'41.5cm group of 10 pendants (89-98) space of 1.5cm',
'45.5cm group of 11 pendants (99-109) space of 1.5cm',
'49.0cm group of 11 pendants (110-120) space of 4.0cm',
'55.0cm group of 11 pendants (121-131) space of 3.0cm',
'61.0cm group of 11 pendants (132-142) space of 1.0cm',
'64.5cm group of 11 pendants (143-153) space of 1.5cm',
'68.0cm group of 11 pendants (154-164) space of 1.0cm',
'71.0cm group of 11 pendants (165-175) space of 1.0cm',
'74.0cm group of 12 pendants (176-187) space of 1.0cm',
'77.5cm group of 11 pendants (188-198) space of 1.0cm',
'80.5cm group of 11 pendants (199-209) space of 4.5cm',
'87.0cm group of 10 pendants (210-219) space of 1.0cm',
'90.0cm group of 11 pendants (220-230) space of 1.5cm',
'93.5cm group of 11 pendants (231-241) space of 1.0cm',
'96.5cm group of 11 pendants (242-252) space of 3.5cm',
'102.0cm group of 11 pendants (253-263) space of 3.5cm',
'108.5cm group of 11 pendants (264-274) space of 1.0cm',
'111.0cm group of 11 pendants (275-285) space of 1.0cm',
'114.0cm group of 11 pendants (286-296) space of 1.0cm',
'117.5cm group of 11 pendants (297-307) space of 1.0cm',
'120.5cm group of 12 pendants (308-319) space of 1.0cm',
'124.0cm group of 11 pendants (320-330) space of 1.0cm',
'127.5cm group of 10 pendants (331-340) space of 1.5cm',
'130.5cm group of 11 pendants (341-351) space of 1.0cm',
'133.5cm group of 11 pendants (352-362) space of 1.0cm',
'137.0cm group of 8 pendants (363-370) space of 1.0cm',
'140.0cm group of 7 pendants (371-377) space of 1.5cm',
'143.5cm group of 11 pendants (378-388) space of 0.5cm',
'146.0cm group of 11 pendants (389-399) space of 0.5cm',
'148.5cm group of 10 pendants (400-409) space of 3.0cm',
'154.0cm group of 8 pendants (410-417) space of 0.5cm',
'156.5cm group of 11 pendants (418-428) space of 1.5cm',
'160.0cm group of 10 pendants (429-438) space of 1.5cm',
'163.5cm group of 11 pendants (439-449) space of 1.5cm',
'167.0cm group of 12 pendants (450-461) space of 2.0cm',
'171.0cm group of 6 pendants (462-467) space of 1.5cm',
'173.5cm group of 10 pendants (468-477) space of 1.5cm',
'177.0cm group of 11 pendants (478-488) space of 1.0cm',
'180.0cm group of 11 pendants (489-499) space of 1.5cm',
'183.0cm group of 11 pendants (500-510) space of 1.0cm',
'186.5cm group of 11 pendants (511-521) space of 1.5cm',
'189.5cm group of 11 pendants (522-532) space of 1.0cm',
'193.0cm group of 10 pendants (533-542) space of 1.5cm',
'196.0cm group of 11 pendants (543-553) space of 3.5cm',
'202.0cm group of 11 pendants (554-564) space of 1.5cm',
'205.0cm group of 11 pendants (565-575) space of 1.5cm',
'208.5cm group of 11 pendants (576-586) space of 1.0cm',
'212.0cm group of 11 pendants (587-597) space of 1.5cm',
'215.5cm group of 12 pendants (598-609) space of 1.5cm',
'219.5cm group of 11 pendants (610-620) space of 1.5cm',
'223.0cm group of 11 pendants (621-631) space of 1.5cm',
'227.0cm group of 11 pendants (632-642) space of 1.5cm',
'230.0cm group of 11 pendants (643-653) space of 1.5cm',
'233.0cm group of 11 pendants (654-664) space of 1.5cm',
'236.5cm group of 11 pendants (665-675) space of 1.5cm',
'240.0cm group of 11 pendants (676-686) space of 1.5cm',
'243.5cm group of 11 pendants (687-697) space of 2.0cm',
'248.0cm group of 11 pendants (698-708) space of 2.5cm',
'253.0cm group of 11 pendants (709-719) space of 1.5cm',
'256.5cm group of 11 pendants (720-730) space of 1.5cm',
'260.0cm group of 11 pendants (731-741) space of 1.5cm',
'263.5cm group of 11 pendants (742-752) space of 1.5cm',
'267.0cm group of 12 pendants (753-764) space of 1.5cm',
'270.5cm group of 11 pendants (765-775) space of 1.5cm',
'274.0cm group of 11 pendants (776-786) space of 1.5cm',
'277.0cm group of 11 pendants (787-797) space of 1.0cm',
'280.5cm group of 11 pendants (798-808) space of 1.5cm',
'284.0cm group of 11 pendants (809-819) space of 1.5cm',
'287.5cm group of 12 pendants (820-831) space of 1.5cm',
'291.0cm group of 12 pendants (832-843) space of 1.0cm',
'294.5cm group of 11 pendants (844-854) space of 0.5cm',
'297.0cm group of 10 pendants (855-864) space of 4.0cm',
'']
dks = ["AS072",
"AS130 B",
"AS190",
"HP009",
"HP033",
"HP034",
"HP036",
"HP037",
"HP038",
"HP039",
"HP040",
"HP041",
"HP042",
"HP043",
"HP044",
"HP045",
"HP046 A",
"HP046 B",
"HP047",
"HP048",
"HP051 A",
"HP053",
"HP054",
"HP055",
"HP057",
"JC001",
"JC002",
"JC003",
"JC004",
"JC005",
"JC006",
"JC007",
"JC008",
"JC009",
"JC010",
"JC011",
"JC012",
"JC013",
"JC014",
"JC015",
"JC016",
"JC017",
"JC018",
"JC019",
"JC020",
"JC021",
"JC022",
"JC023",
"QU01",
"QU02",
"QU03",
"QU04",
"QU05",
"QU06",
"QU07",
"QU08",
"QU09",
"QU10",
"QU11",
"QU13",
"QU16",
"UR001",
"UR004",
"UR017",
"UR039",
"UR044",
"UR050",
"UR052",
"UR054",
"UR055",
"UR110",
"UR112",
"UR144",
"UR155",
"UR165",
"UR167",
"UR190",
"UR193",
"UR196",
"UR206",
"UR209",
"UR221",
"UR251",
"UR252",
"UR253",
"UR254",
"UR255",
"UR257",
"UR258",
"UR259",
"UR260",
"UR261",
"UR262",
"UR263",
"UR266",
"UR267A",
"UR267B",
"UR268",
"UR269",
"UR270",
"UR271",
"UR272",
"UR273A",
"UR273B",
"UR274A",
"UR275",
"UR276",
"UR277",
"UR278",
"UR279",
"UR280",
"UR281",
"UR284",
"UR288",
"UR292A",
"UR293"]sum_df = pd.read_csv("/Users/ashokkhosla/Desktop/Khipu/fieldguide/data/CSV/khipu_summary.csv")
def khipu_name_to_id(aName):
try:
sum_df[sum_df['kfg_name']==aName]['khipu_id'].values[0]
except:
return f"{aName}ERROR"
for dk in dks:
print(khipu_name_to_id(dk))AS072ERROR
AS130 BERROR
AS190ERROR
1000428
1000562
1000563
HP036ERROR
1000566
1000567
1000593
1000569
HP041ERROR
1000571
1000572
1000573
HP045ERROR
1000575
1000576
HP047ERROR
HP048ERROR
1000581
1000584
1000585
HP055ERROR
1000587
1000625
1000626
1000627
1000628
1000629
1000630
1000631
1000632
1000633
1000634
1000635
1000636
1000637
1000638
1000639
1000640
1000641
1000642
1000643
1000644
1000645
1000646
1000647
QU01ERROR
QU02ERROR
QU03ERROR
QU04ERROR
QU05ERROR
QU06ERROR
QU07ERROR
QU08ERROR
QU09ERROR
QU10ERROR
QU11ERROR
QU13ERROR
QU16ERROR
UR001ERROR
UR004ERROR
UR017ERROR
UR039ERROR
UR044ERROR
UR050ERROR
UR052ERROR
UR054ERROR
UR055ERROR
UR110ERROR
UR112ERROR
UR144ERROR
UR155ERROR
UR165ERROR
UR167ERROR
UR190ERROR
UR193ERROR
1000507
1000517
1000520
UR221ERROR
1000589
1000590
UR253ERROR
1000592
UR255ERROR
1000595
1000599
1000600
1000601
1000602
1000603
1000604
1000607
1000608
1000609
1000610
1000611
1000612
1000613
1000614
1000615
1000616
1000617
1000619
1000620
1000622
1000623
1000621
UR280ERROR
UR281ERROR
1000651
1000655
UR292AERROR
1000660
def as_digitcode_vector(aList, asChars=False):
""" Akin to onehot encoding
>>> list_to_setdict(['a','b','c','a','b','c','d'])
returns a three-tuple
([0, 1, 2, 0, 1, 2, 3], #The encoded result
{0: 'a', 1: 'b', 2: 'c', 3: 'd'}, #The source to target dict
{'a': 0, 'b': 1, 'c': 2, 'd': 3}) #The target to source dict
if asChars is True, then the encoded result is a string, starting with 'A'
if you have more than 52 unique items, you'll need to rethink this
"""
the_values = sorted(set(aList))
if asChars:
source_to_target = {value:chr(ord('A')+index) for index, value in enumerate(the_values)}
target_to_source = {value:key for key,value in source_to_target.items()}
else:
source_to_target = {value:key for key,value in enumerate(the_values)}
target_to_source = dict(enumerate(the_values))
encoded = [source_to_target[aValue] for aValue in aList]
return (encoded, source_to_target, target_to_source)foo = ['ashok', 'bob', 'carlos', 'ashok', 'bob', 'carlos', 'doug']as_digitcode_vector(foo, asString=True)(['A', 'B', 'C', 'A', 'B', 'C', 'D'],
{'ashok': 'A', 'bob': 'B', 'carlos': 'C', 'doug': 'D'},
{'A': 'ashok', 'B': 'bob', 'C': 'carlos', 'D': 'doug'})
ascher_cord_color_df = pd.read_csv(f"/Users/ashokkhosla/Desktop/Khipu/fieldguide/data/CSV/ascher_cord_color.csv")
mixed_colors = [aColor for aColor in ascher_cord_color_df['FULL_COLOR'].tolist() if isinstance(aColor, str)]
mixed_colors[nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan]
