Skip to content

Commit

Permalink
Merge pull request #12 from ideaconsult/updates_pyambit
Browse files Browse the repository at this point in the history
Updates pyambit
  • Loading branch information
kerberizer authored Aug 20, 2024
2 parents 53fba8c + 2ff4c89 commit 7717d10
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 1,495 deletions.
146 changes: 91 additions & 55 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ requests = "^2.31.0"
xlsxwriter = "^3.1.9"
measurement = "^3.2.2"
openpyxl = "^3.1.2"
pyambit = {git = "https://github.com/ideaconsult/pyambit.git"}

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/ideaconsult/pynanomapper/issues"
Expand Down
3 changes: 2 additions & 1 deletion src/pynanomapper/aa.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self, token=None):
self.token = token

def __call__(self, r):
r.headers['Authorization'] = "Bearer {}".format(self.token)
if self.token != None:
r.headers['Authorization'] = "Bearer {}".format(self.token)
return r

def setKey(self, token):
Expand Down
4 changes: 3 additions & 1 deletion src/pynanomapper/clients/authservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def logout(self):
def getHeaders(self):
headers = {}
headers["Accept"] = "application/json"
headers["Authorization"] = "Bearer {}".format(self.token['access_token'])
_token = self.token['access_token']
if _token != None:
headers["Authorization"] = "Bearer {}".format(_token)
return headers


Expand Down
10 changes: 5 additions & 5 deletions src/pynanomapper/clients/datamodel_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self, investigation, provider, parameters, filename, spectrum_embed
self.spectrum_embedding = spectrum_embedding

@staticmethod
def x4search():
return np.linspace(140,3*1024+140,num=1024)
def x4search(dim=1024):
return np.linspace(140,3*1024+140,num=dim)
#return np.linspace(140,140+2048,num=1024)

@staticmethod
Expand Down Expand Up @@ -79,16 +79,16 @@ def xy2embedding(x,y,xlinspace = None,remove_baseline=True,window=16):
if xlinspace is None:
xlinspace = StudyRaman.x4search()
spe = rc2.spectrum.Spectrum(x=x, y=y, metadata={})
(spe,hist_dist,index) = StudyRaman.spectra2dist(spe,xcrop = [xlinspace[0],xlinspace[-1]],remove_baseline=True,window=window)
(spe,hist_dist,index) = StudyRaman.spectra2dist(spe,xcrop = [xlinspace[0],xlinspace[-1]],remove_baseline=remove_baseline,window=window)
return (hist_dist.cdf(xlinspace),hist_dist.pdf(xlinspace))

@staticmethod
def h52embedding(h5,dataset="raw",xlinspace = None):
def h52embedding(h5,dataset="raw",xlinspace = None,remove_baseline=True,window=16):
if xlinspace is None:
xlinspace = StudyRaman.x4search()
x = h5[dataset][0]
y = h5[dataset][1]
return StudyRaman.xy2embedding(x,y,xlinspace)
return StudyRaman.xy2embedding(x,y,xlinspace,remove_baseline=remove_baseline,window=window)

def to_solr_json(self):
_solr = {}
Expand Down
15 changes: 10 additions & 5 deletions src/pynanomapper/clients/service_charisma.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ def dict2figure(pm,figsize):

def solrquery_get(self,solr_url, params):
headers = {}
headers["Authorization"] = "Bearer {}".format(self.tokenservice.api_key());
_token = self.tokenservice.api_key()
if _token != None:
headers["Authorization"] = "Bearer {}".format(_token);
return requests.get(solr_url, params = params, headers= headers)

def solrquery_post(self,solr_url, json):
headers = {}
headers["Authorization"] = "Bearer {}".format(self.tokenservice.api_key());
_token = self.tokenservice.api_key()
if _token != None:
headers["Authorization"] = "Bearer {}".format(_token);
return requests.get(solr_url, json = json, headers= headers)

def thumbnail(self,solr_url,domain,figsize=(6,4),extraprm=""):
Expand Down Expand Up @@ -197,14 +201,15 @@ def image(self,domain,dataset="raw",figsize=(6,4),extraprm=""):
except Exception as err:
return self.empty_figure(figsize,"Error","{}".format(domain.split("/")[-1]))

def knnquery(self,domain,dataset="raw"):
def knnquery(self,domain,dataset="raw",dim=1024):
try:
with self.File(domain,mode="r") as h5:
x = h5[dataset][0]
y = h5[dataset][1]
(cdf,pdf) = StudyRaman.h52embedding(h5,dataset="raw",xlinspace = StudyRaman.x4search())
(cdf,pdf) = StudyRaman.h52embedding(h5,dataset="raw",xlinspace = StudyRaman.x4search(dim=dim))
result_json = {}
result_json["cdf"] = compress(cdf.tolist(),precision=6)
result_json["cdf"] = compress(cdf.tolist(),precision=4)
result_json["pdf"] = compress(pdf.tolist(),precision=4)
#return ','.join(map(str, cdf))
try:
px = 1/plt.rcParams['figure.dpi'] # pixel in inches
Expand Down
Loading

0 comments on commit 7717d10

Please sign in to comment.