first working version for DB
This commit is contained in:
parent
f454776242
commit
d0d90f8f7d
@ -1,3 +1,6 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
import numpy as np
|
||||
import pymongo
|
||||
import xarray_mongodb
|
||||
import bson
|
||||
@ -273,6 +276,94 @@ class MongoDB:
|
||||
|
||||
return self.mongoDB['global'].find_one(filter)
|
||||
|
||||
def read_global_all(self, shotNum, date=None):
|
||||
|
||||
from xarray.core.utils import equivalent
|
||||
|
||||
if not date is None:
|
||||
self.set_date(date)
|
||||
|
||||
filter = {
|
||||
'year': self.year,
|
||||
'month': self.month,
|
||||
'day': self.day,
|
||||
'shotNum': shotNum,
|
||||
}
|
||||
|
||||
result = {}
|
||||
dropped_attrs = OrderedDict()
|
||||
|
||||
docs = self.mongoDB['global'].find(filter)
|
||||
|
||||
for doc in docs:
|
||||
|
||||
global_parameters = doc['global_parameters']
|
||||
|
||||
result.update(
|
||||
{
|
||||
key: value
|
||||
for key, value in global_parameters.items()
|
||||
if key not in result and key not in dropped_attrs.keys()
|
||||
}
|
||||
)
|
||||
|
||||
result = {
|
||||
key: value
|
||||
for key, value in result.items()
|
||||
if key not in global_parameters or equivalent(global_parameters[key], value)
|
||||
}
|
||||
|
||||
dropped_attrs.update(
|
||||
{
|
||||
key: []
|
||||
for key in global_parameters if key not in result
|
||||
}
|
||||
)
|
||||
|
||||
for doc in docs:
|
||||
|
||||
global_parameters = doc['global_parameters']
|
||||
|
||||
dropped_attrs.update(
|
||||
{
|
||||
key: np.append(dropped_attrs[key], global_parameters[key])
|
||||
for key in dropped_attrs.keys()
|
||||
}
|
||||
)
|
||||
|
||||
scan_attrs = OrderedDict()
|
||||
scan_length = []
|
||||
for attrs_key in dropped_attrs.keys():
|
||||
flag = True
|
||||
for key in scan_attrs.keys():
|
||||
if equivalent(scan_attrs[key], dropped_attrs[attrs_key]):
|
||||
flag = False
|
||||
|
||||
result.update({attrs_key: key})
|
||||
|
||||
break
|
||||
if flag:
|
||||
scan_attrs.update({
|
||||
attrs_key: dropped_attrs[attrs_key]
|
||||
})
|
||||
scan_length = np.append(scan_length, len(dropped_attrs[attrs_key]))
|
||||
|
||||
result.update(
|
||||
{
|
||||
key: value
|
||||
for key, value in scan_attrs.items()
|
||||
}
|
||||
)
|
||||
|
||||
result.update(
|
||||
{
|
||||
"scanAxis": list(scan_attrs.keys()),
|
||||
"scanAxisLength": scan_length,
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
def _load_data_single(self, mongoID, engine):
|
||||
if engine == 'xarray':
|
||||
return self.xdb.get(mongoID)
|
||||
|
@ -16,11 +16,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 172,
|
||||
"execution_count": 178,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mongoClient = pymongo.MongoClient('mongodb://userAdmin:DyLab2021userAdmin@127.0.0.1:27017/?authMechanism=DEFAULT')\n",
|
||||
"mongoClient = pymongo.MongoClient('mongodb://control:DyLab2021@127.0.0.1:27017/?authMechanism=DEFAULT')\n",
|
||||
"mongoDB = mongoClient.testDB\n",
|
||||
"mongoCollection = mongoDB.testCollection"
|
||||
]
|
||||
@ -5474,7 +5474,149 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 170,
|
||||
"execution_count": 185,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'TOF_free': 0.022,\n",
|
||||
" 'abs_img_freq': 110.858,\n",
|
||||
" 'absorption_imaging_flag': True,\n",
|
||||
" 'backup_data': True,\n",
|
||||
" 'blink_off_time': 0.001,\n",
|
||||
" 'blink_on_time': 0.001,\n",
|
||||
" 'c_duration': 0.2,\n",
|
||||
" 'carrier_amp': 3,\n",
|
||||
" 'carrier_freq': 0.85,\n",
|
||||
" 'carrier_offset': 0,\n",
|
||||
" 'carrier_phase': 0,\n",
|
||||
" 'channel_in_use': 1,\n",
|
||||
" 'cmot_final_current': 0.65,\n",
|
||||
" 'cmot_hold': 0.06,\n",
|
||||
" 'cmot_initial_current': 0.18,\n",
|
||||
" 'compX_current': 0,\n",
|
||||
" 'compX_current_sg': 0.0,\n",
|
||||
" 'compX_initial_current': 0,\n",
|
||||
" 'compY_current': 0,\n",
|
||||
" 'compY_current_sg': 0.0,\n",
|
||||
" 'compY_final_current': 0,\n",
|
||||
" 'compY_initial_current': 0,\n",
|
||||
" 'compZ_current': 0,\n",
|
||||
" 'compZ_current_sg': 0.189,\n",
|
||||
" 'compZ_final_current': 0.264,\n",
|
||||
" 'compZ_initial_current': 0,\n",
|
||||
" 'default_camera': 0,\n",
|
||||
" 'deltaf': 0.161,\n",
|
||||
" 'evap_1_arm_1_final_pow': 0.35,\n",
|
||||
" 'evap_1_arm_1_mod_depth_final': 0,\n",
|
||||
" 'evap_1_arm_1_mod_depth_initial': 1.0,\n",
|
||||
" 'evap_1_arm_1_mod_ramp_duration': 1.15,\n",
|
||||
" 'evap_1_arm_1_pow_ramp_duration': 1.65,\n",
|
||||
" 'evap_1_arm_1_start_pow': 7,\n",
|
||||
" 'evap_1_arm_2_final_pow': 5,\n",
|
||||
" 'evap_1_arm_2_ramp_duration': 0.5,\n",
|
||||
" 'evap_1_arm_2_start_pow': 0,\n",
|
||||
" 'evap_1_mod_ramp_trunc_value': 1,\n",
|
||||
" 'evap_1_pow_ramp_trunc_value': 1.0,\n",
|
||||
" 'evap_1_rate_constant_1': 0.525,\n",
|
||||
" 'evap_1_rate_constant_2': 0.51,\n",
|
||||
" 'evap_2_arm_1_final_pow': 0.037,\n",
|
||||
" 'evap_2_arm_1_start_pow': 0.35,\n",
|
||||
" 'evap_2_arm_2_final_pow': 0.09,\n",
|
||||
" 'evap_2_arm_2_start_pow': 5,\n",
|
||||
" 'evap_2_ramp_duration': 1.0,\n",
|
||||
" 'evap_2_ramp_trunc_value': 1.0,\n",
|
||||
" 'evap_2_rate_constant_1': 0.37,\n",
|
||||
" 'evap_2_rate_constant_2': 0.71,\n",
|
||||
" 'evap_3_arm_1_final_pow': 0.1038,\n",
|
||||
" 'evap_3_arm_1_mod_depth_final': 0.43,\n",
|
||||
" 'evap_3_arm_1_mod_depth_initial': 0,\n",
|
||||
" 'evap_3_arm_1_start_pow': 0.037,\n",
|
||||
" 'evap_3_ramp_duration': 0.1,\n",
|
||||
" 'evap_3_ramp_trunc_value': 1.0,\n",
|
||||
" 'evap_3_rate_constant_1': -0.879,\n",
|
||||
" 'evap_3_rate_constant_2': -0.297,\n",
|
||||
" 'final_amp': 0.00012,\n",
|
||||
" 'final_freq': 104.0,\n",
|
||||
" 'final_pow_1': 0.1038,\n",
|
||||
" 'final_pow_2': 0.09,\n",
|
||||
" 'gradCoil_current': 0.18,\n",
|
||||
" 'gradCoil_current_sg': 0,\n",
|
||||
" 'imaging_method': 'in_situ_absorption',\n",
|
||||
" 'imaging_pulse_duration': 2.5e-05,\n",
|
||||
" 'imaging_wavelength': 4.21291e-07,\n",
|
||||
" 'initial_amp': 0.62,\n",
|
||||
" 'initial_freq': 102.13,\n",
|
||||
" 'mod_depth_fin': 0.43,\n",
|
||||
" 'mod_depth_ini': 0,\n",
|
||||
" 'mod_depth_initial': 1.0,\n",
|
||||
" 'mot_3d_amp': 0.62,\n",
|
||||
" 'mot_3d_camera_trigger_duration': 0.00025,\n",
|
||||
" 'mot_3d_freq': 102.13,\n",
|
||||
" 'mot_load_duration': 2,\n",
|
||||
" 'odt_axis_camera_trigger_duration': 0.002,\n",
|
||||
" 'odt_hold_time_1': 0.01,\n",
|
||||
" 'odt_hold_time_2': 0.1,\n",
|
||||
" 'odt_hold_time_3': 0.1,\n",
|
||||
" 'odt_hold_time_4': 1.0,\n",
|
||||
" 'odt_hold_time_5': 0.01,\n",
|
||||
" 'operation_mode': 'SWEEP',\n",
|
||||
" 'pow_arm_1': 7,\n",
|
||||
" 'pow_arm_2': 0,\n",
|
||||
" 'pulse_delay': 8e-05,\n",
|
||||
" 'pulse_width': 0.01,\n",
|
||||
" 'push_amp': 0.16,\n",
|
||||
" 'push_freq': 102.66,\n",
|
||||
" 'ramp_duration': 1,\n",
|
||||
" 'recomp_ramp_duration': 0.5,\n",
|
||||
" 'recomp_ramp_pow_fin_arm_1': 0.1038,\n",
|
||||
" 'recomp_ramp_pow_fin_arm_2': 0.09,\n",
|
||||
" 'recomp_ramp_pow_ini_arm_1': 0.1038,\n",
|
||||
" 'recomp_ramp_pow_ini_arm_2': 0.09,\n",
|
||||
" 'save_results': False,\n",
|
||||
" 'sin_mod_amplitude': 0.00519,\n",
|
||||
" 'sin_mod_dc_offset': 0.1038,\n",
|
||||
" 'sin_mod_duration': nan,\n",
|
||||
" 'sin_mod_freq': nan,\n",
|
||||
" 'sin_mod_phase': 0.0,\n",
|
||||
" 'start_pow_1': 0.037,\n",
|
||||
" 'start_pow_2': 0.09,\n",
|
||||
" 'stern_gerlach_duration': 0.001,\n",
|
||||
" 'sweep_duration': 0.4,\n",
|
||||
" 'sweep_start_freq': 0.7695,\n",
|
||||
" 'sweep_stop_freq': 0.9305,\n",
|
||||
" 'tf_meas_ramp_duration': 0.1,\n",
|
||||
" 'wait_after_2dmot_off': 0,\n",
|
||||
" 'wait_time_between_images': 0.22,\n",
|
||||
" 'wavetype': 'SINE',\n",
|
||||
" 'x_offset': 0.0,\n",
|
||||
" 'x_offset_img': 0,\n",
|
||||
" 'y_offset': 0.0,\n",
|
||||
" 'y_offset_img': 0,\n",
|
||||
" 'z_offset': 0.189,\n",
|
||||
" 'z_offset_img': 0.189,\n",
|
||||
" 'compX_final_current': [],\n",
|
||||
" 'scanAxis': ['compX_final_current'],\n",
|
||||
" 'scanAxisLength': array([0.])}"
|
||||
]
|
||||
},
|
||||
"execution_count": 185,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from DataContainer.MongoDB import MongoDB\n",
|
||||
"\n",
|
||||
"DB = MongoDB(mongoClient, mongoDB, date='2023/05/23')\n",
|
||||
"\n",
|
||||
"DB.read_global_all('0069')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 182,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -5772,27 +5914,76 @@
|
||||
" result = {}\n",
|
||||
" dropped_attrs = OrderedDict()\n",
|
||||
" \n",
|
||||
" for doc in self.mongoDB['global'].find(filter):\n",
|
||||
" docs = self.mongoDB['global'].find(filter)\n",
|
||||
" \n",
|
||||
" for doc in docs:\n",
|
||||
" \n",
|
||||
" global_parameters = doc['global_parameters']\n",
|
||||
" \n",
|
||||
" result.update(\n",
|
||||
" {\n",
|
||||
" key: value\n",
|
||||
" for key, value in attrs.items()\n",
|
||||
" for key, value in global_parameters.items()\n",
|
||||
" if key not in result and key not in dropped_attrs.keys()\n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" result = {\n",
|
||||
" key: value\n",
|
||||
" for key, value in result.items()\n",
|
||||
" if key not in attrs or equivalent(attrs[key], value)\n",
|
||||
" if key not in global_parameters or equivalent(global_parameters[key], value)\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" dropped_attrs.update(\n",
|
||||
" {\n",
|
||||
" key: []\n",
|
||||
" for key in attrs if key not in result \n",
|
||||
" for key in global_parameters if key not in result \n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" for doc in docs:\n",
|
||||
" \n",
|
||||
" global_parameters = doc['global_parameters']\n",
|
||||
" \n",
|
||||
" dropped_attrs.update(\n",
|
||||
" {\n",
|
||||
" key: np.append(dropped_attrs[key], global_parameters[key])\n",
|
||||
" for key in dropped_attrs.keys()\n",
|
||||
" }\n",
|
||||
" ) \n",
|
||||
" \n",
|
||||
" scan_attrs = OrderedDict()\n",
|
||||
" scan_length = []\n",
|
||||
" for attrs_key in dropped_attrs.keys():\n",
|
||||
" flag = True\n",
|
||||
" for key in scan_attrs.keys():\n",
|
||||
" if equivalent(scan_attrs[key], dropped_attrs[attrs_key]):\n",
|
||||
" flag = False\n",
|
||||
" \n",
|
||||
" result.update({attrs_key: key})\n",
|
||||
"\n",
|
||||
" break\n",
|
||||
" if flag:\n",
|
||||
" scan_attrs.update({\n",
|
||||
" attrs_key: dropped_attrs[attrs_key]\n",
|
||||
" })\n",
|
||||
" scan_length = np.append(scan_length, len(dropped_attrs[attrs_key]))\n",
|
||||
"\n",
|
||||
" result.update(\n",
|
||||
" {\n",
|
||||
" key: value\n",
|
||||
" for key, value in scan_attrs.items()\n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" result.update(\n",
|
||||
" {\n",
|
||||
" \"scanAxis\": list(scan_attrs.keys()),\n",
|
||||
" \"scanAxisLength\": scan_length,\n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" return result\n",
|
||||
" \n",
|
||||
" def _load_data_single(self, mongoID, engine):\n",
|
||||
" if engine == 'xarray':\n",
|
||||
@ -7001,6 +7192,144 @@
|
||||
"DB.create_global(shotNum, dataSet)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 183,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'TOF_free': 0.022,\n",
|
||||
" 'abs_img_freq': 110.858,\n",
|
||||
" 'absorption_imaging_flag': True,\n",
|
||||
" 'backup_data': True,\n",
|
||||
" 'blink_off_time': 0.001,\n",
|
||||
" 'blink_on_time': 0.001,\n",
|
||||
" 'c_duration': 0.2,\n",
|
||||
" 'carrier_amp': 3,\n",
|
||||
" 'carrier_freq': 0.85,\n",
|
||||
" 'carrier_offset': 0,\n",
|
||||
" 'carrier_phase': 0,\n",
|
||||
" 'channel_in_use': 1,\n",
|
||||
" 'cmot_final_current': 0.65,\n",
|
||||
" 'cmot_hold': 0.06,\n",
|
||||
" 'cmot_initial_current': 0.18,\n",
|
||||
" 'compX_current': 0,\n",
|
||||
" 'compX_current_sg': 0.0,\n",
|
||||
" 'compX_initial_current': 0,\n",
|
||||
" 'compY_current': 0,\n",
|
||||
" 'compY_current_sg': 0.0,\n",
|
||||
" 'compY_final_current': 0,\n",
|
||||
" 'compY_initial_current': 0,\n",
|
||||
" 'compZ_current': 0,\n",
|
||||
" 'compZ_current_sg': 0.189,\n",
|
||||
" 'compZ_final_current': 0.264,\n",
|
||||
" 'compZ_initial_current': 0,\n",
|
||||
" 'default_camera': 0,\n",
|
||||
" 'deltaf': 0.161,\n",
|
||||
" 'evap_1_arm_1_final_pow': 0.35,\n",
|
||||
" 'evap_1_arm_1_mod_depth_final': 0,\n",
|
||||
" 'evap_1_arm_1_mod_depth_initial': 1.0,\n",
|
||||
" 'evap_1_arm_1_mod_ramp_duration': 1.15,\n",
|
||||
" 'evap_1_arm_1_pow_ramp_duration': 1.65,\n",
|
||||
" 'evap_1_arm_1_start_pow': 7,\n",
|
||||
" 'evap_1_arm_2_final_pow': 5,\n",
|
||||
" 'evap_1_arm_2_ramp_duration': 0.5,\n",
|
||||
" 'evap_1_arm_2_start_pow': 0,\n",
|
||||
" 'evap_1_mod_ramp_trunc_value': 1,\n",
|
||||
" 'evap_1_pow_ramp_trunc_value': 1.0,\n",
|
||||
" 'evap_1_rate_constant_1': 0.525,\n",
|
||||
" 'evap_1_rate_constant_2': 0.51,\n",
|
||||
" 'evap_2_arm_1_final_pow': 0.037,\n",
|
||||
" 'evap_2_arm_1_start_pow': 0.35,\n",
|
||||
" 'evap_2_arm_2_final_pow': 0.09,\n",
|
||||
" 'evap_2_arm_2_start_pow': 5,\n",
|
||||
" 'evap_2_ramp_duration': 1.0,\n",
|
||||
" 'evap_2_ramp_trunc_value': 1.0,\n",
|
||||
" 'evap_2_rate_constant_1': 0.37,\n",
|
||||
" 'evap_2_rate_constant_2': 0.71,\n",
|
||||
" 'evap_3_arm_1_final_pow': 0.1038,\n",
|
||||
" 'evap_3_arm_1_mod_depth_final': 0.43,\n",
|
||||
" 'evap_3_arm_1_mod_depth_initial': 0,\n",
|
||||
" 'evap_3_arm_1_start_pow': 0.037,\n",
|
||||
" 'evap_3_ramp_duration': 0.1,\n",
|
||||
" 'evap_3_ramp_trunc_value': 1.0,\n",
|
||||
" 'evap_3_rate_constant_1': -0.879,\n",
|
||||
" 'evap_3_rate_constant_2': -0.297,\n",
|
||||
" 'final_amp': 0.00012,\n",
|
||||
" 'final_freq': 104.0,\n",
|
||||
" 'final_pow_1': 0.1038,\n",
|
||||
" 'final_pow_2': 0.09,\n",
|
||||
" 'gradCoil_current': 0.18,\n",
|
||||
" 'gradCoil_current_sg': 0,\n",
|
||||
" 'imaging_method': 'in_situ_absorption',\n",
|
||||
" 'imaging_pulse_duration': 2.5e-05,\n",
|
||||
" 'imaging_wavelength': 4.21291e-07,\n",
|
||||
" 'initial_amp': 0.62,\n",
|
||||
" 'initial_freq': 102.13,\n",
|
||||
" 'mod_depth_fin': 0.43,\n",
|
||||
" 'mod_depth_ini': 0,\n",
|
||||
" 'mod_depth_initial': 1.0,\n",
|
||||
" 'mot_3d_amp': 0.62,\n",
|
||||
" 'mot_3d_camera_trigger_duration': 0.00025,\n",
|
||||
" 'mot_3d_freq': 102.13,\n",
|
||||
" 'mot_load_duration': 2,\n",
|
||||
" 'odt_axis_camera_trigger_duration': 0.002,\n",
|
||||
" 'odt_hold_time_1': 0.01,\n",
|
||||
" 'odt_hold_time_2': 0.1,\n",
|
||||
" 'odt_hold_time_3': 0.1,\n",
|
||||
" 'odt_hold_time_4': 1.0,\n",
|
||||
" 'odt_hold_time_5': 0.01,\n",
|
||||
" 'operation_mode': 'SWEEP',\n",
|
||||
" 'pow_arm_1': 7,\n",
|
||||
" 'pow_arm_2': 0,\n",
|
||||
" 'pulse_delay': 8e-05,\n",
|
||||
" 'pulse_width': 0.01,\n",
|
||||
" 'push_amp': 0.16,\n",
|
||||
" 'push_freq': 102.66,\n",
|
||||
" 'ramp_duration': 1,\n",
|
||||
" 'recomp_ramp_duration': 0.5,\n",
|
||||
" 'recomp_ramp_pow_fin_arm_1': 0.1038,\n",
|
||||
" 'recomp_ramp_pow_fin_arm_2': 0.09,\n",
|
||||
" 'recomp_ramp_pow_ini_arm_1': 0.1038,\n",
|
||||
" 'recomp_ramp_pow_ini_arm_2': 0.09,\n",
|
||||
" 'save_results': False,\n",
|
||||
" 'sin_mod_amplitude': 0.00519,\n",
|
||||
" 'sin_mod_dc_offset': 0.1038,\n",
|
||||
" 'sin_mod_duration': nan,\n",
|
||||
" 'sin_mod_freq': nan,\n",
|
||||
" 'sin_mod_phase': 0.0,\n",
|
||||
" 'start_pow_1': 0.037,\n",
|
||||
" 'start_pow_2': 0.09,\n",
|
||||
" 'stern_gerlach_duration': 0.001,\n",
|
||||
" 'sweep_duration': 0.4,\n",
|
||||
" 'sweep_start_freq': 0.7695,\n",
|
||||
" 'sweep_stop_freq': 0.9305,\n",
|
||||
" 'tf_meas_ramp_duration': 0.1,\n",
|
||||
" 'wait_after_2dmot_off': 0,\n",
|
||||
" 'wait_time_between_images': 0.22,\n",
|
||||
" 'wavetype': 'SINE',\n",
|
||||
" 'x_offset': 0.0,\n",
|
||||
" 'x_offset_img': 0,\n",
|
||||
" 'y_offset': 0.0,\n",
|
||||
" 'y_offset_img': 0,\n",
|
||||
" 'z_offset': 0.189,\n",
|
||||
" 'z_offset_img': 0.189,\n",
|
||||
" 'compX_final_current': [],\n",
|
||||
" 'scanAxis': ['compX_final_current'],\n",
|
||||
" 'scanAxisLength': array([0.])}"
|
||||
]
|
||||
},
|
||||
"execution_count": 183,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"DB.read_global_all('0069')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 171,
|
||||
|
Loading…
Reference in New Issue
Block a user