not finished

This commit is contained in:
Jianshun Gao 2023-06-09 18:59:56 +02:00
parent eb924fa05e
commit c20e37f4e6
5 changed files with 92120 additions and 1261 deletions

View File

@ -1,5 +1,6 @@
import numpy as np
import xarray as xr
import copy
class ImageAnalyser():
@ -70,7 +71,9 @@ class ImageAnalyser():
return mean / 4
def substract_offset(self, dataArray, **kwargs):
return dataArray - self.get_offset_from_corner(dataArray, **kwargs)
res = dataArray - self.get_offset_from_corner(dataArray, **kwargs)
res.attrs = copy.copy(dataArray.attrs)
return res
def crop_image(self, dataSet, center=None, span=None):
@ -138,6 +141,8 @@ class ImageAnalyser():
self._image_name['OD']: xr.apply_ufunc(self.get_OD, dataSet[self._image_name['atoms']], dataSet[self._image_name['background']], dataSet[self._image_name['dark']], **kwargs)
}
)
dataSet[self._image_name['OD']].attrs.update(dataSet.attrs)
return dataSet

View File

@ -0,0 +1,131 @@
import pymongo
import xarray_mongodb
import bson
import builtins
from ToolFunction.ToolFunction import get_date
npTypeDict = {v: getattr(builtins, k) for k, v in np.sctypeDict.items() if k in vars(builtins)}
npArrayType = type(np.array([0]))
class MongoDB:
def __init__(self, mongoClient, mongoDB, date=None) -> None:
self.mongoClient = mongoClient
self.mongoDB = mongoDB
self.xdb = xarray_mongodb.XarrayMongoDB(mongoDB)
if date is None:
date= get_date()
self.set_date(date)
def _convert_numpy_type(self, data):
for key in data:
typeKey = type(data[key])
if typeKey in npTypeDict:
data[key] = data[key].item()
elif typeKey == npArrayType:
data[key] = data[key].tolist()
else:
try:
data[key] = data[key].item()
except:
pass
return data
def set_date(self, date):
date = date.split("/")
self.year = int(date[0])
self.month = int(date[1])
self.day = int(date[2])
def create_global(self, shotNum, dataSet=None, date=None):
if not date is None:
self.set_date(date)
data = {
'year': self.year,
'month': self.month,
'day': self.day,
'shotNum': shotNum,
'global_parameters' : {},
}
global_parameters = self._convert_numpy_type(dataSet.attrs)
if not dataSet is None:
data['global_parameters'].update(global_parameters)
data = self._convert_numpy_type(data)
self.mongoDB['global'].insert_one(data)
def _add_data_normal(self, shotNum, data):
filter = {
'year': self.year,
'month': self.month,
'day': self.day,
'shotNum': shotNum,
}
self.mongoDB['global'].update_one(filter, {"$set": data}, upsert=False)
def _add_data_xarray_dataArray(self, shotNum, dataArray):
filter = {
'year': self.year,
'month': self.month,
'day': self.day,
'shotNum': shotNum,
}
dataArray.attrs = self._convert_numpy_type(dataArray.attrs)
mongoID, _ = self.xdb.put(dataArray)
data_label = {
dataArray.name:
{
'name': dataArray.name,
'mongoID': mongoID,
'engine': 'xarray',
'dtype': 'dataArray',
}
}
self.mongoDB['global'].update_one(filter, {"$set": data_label}, upsert=False)
def _add_data_xarray_dataSet(self, shotNum, dataSet, name):
filter = {
'year': self.year,
'month': self.month,
'day': self.day,
'shotNum': shotNum,
}
dataSet.attrs = self._convert_numpy_type(dataSet.attrs)
for key in list(dataSet.data_vars):
dataSet[key].attrs = self._convert_numpy_type(dataSet[key].attrs)
print(key)
mongoID, _ = self.xdb.put(dataSet)
data_label = {
name:
{
'name': name,
'mongoID': mongoID,
'engine': 'xarray',
'dtype': 'dataSet',
}
}
self.mongoDB['global'].update_one(filter, {"$set": data_label}, upsert=False)
def add_data(self, shotNum, data, date=None, name=None, engine='normal'):
pass
def read_data(self, shotNum, data=None):
pass

View File

@ -325,6 +325,8 @@ def read_hdf5_global(filePath, preprocess=None, join="outer", combine="nested",
datesetOfGlobal = xr.open_mfdataset(fullFilePath, **kwargs)
datesetOfGlobal.attrs['scanAxis'] = np.setdiff1d(datesetOfGlobal.attrs['scanAxis'], excludeAxis)
datesetOfGlobal.
return datesetOfGlobal

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long