1 #ifndef MHO_PyScanStoreInterface_HH__
2 #define MHO_PyScanStoreInterface_HH__
12 #include "pybind11_json/pybind11_json.hpp"
13 #include <pybind11/embed.h>
14 #include <pybind11/pybind11.h>
15 namespace py = pybind11;
16 namespace nl = nlohmann;
17 using namespace pybind11::literals;
59 fScanStore->SetDirectory(dir);
65 fInitialized = fScanStore->Initialize();
69 bool IsValid()
const {
return fScanStore->IsValid(); };
73 bool IsStationPresent(std::string st)
const {
return fScanStore->IsStationPresent(st); }
75 bool IsFringePresent(std::string fr)
const {
return fScanStore->IsFringePresent(fr); }
77 std::size_t
GetNBaselines()
const {
return fScanStore->GetNBaselines(); }
79 std::size_t
GetNStations()
const {
return fScanStore->GetNStations(); }
81 std::size_t
GetNFringes()
const {
return fScanStore->GetNFringes(); }
85 std::vector< std::string >
GetStationsPresent()
const {
return fScanStore->GetStationsPresent(); }
87 std::vector< std::string >
GetFringesPresent()
const {
return fScanStore->GetFringesPresent(); }
96 std::string
GetStationFilename(std::string station)
const {
return fScanStore->GetStationFilename(station); }
112 auto it = fBaselineContainers.find(
baseline);
113 if(it != fBaselineContainers.end())
119 fScanStore->LoadBaseline(
baseline, con);
121 fBaselineContainers[
baseline] = std::make_pair(con, inter);
131 auto it = fBaselineContainers.find(
baseline);
132 if(it != fBaselineContainers.end())
146 if(!IsStationPresent(station))
151 auto it = fStationContainers.find(station);
152 if(it != fStationContainers.end())
158 fScanStore->LoadStation(station, con);
160 fStationContainers[station] = std::make_pair(con, inter);
170 auto it = fStationContainers.find(station);
171 if(it != fStationContainers.end())
185 if(!IsFringePresent(
fringe))
190 auto it = fFringeContainers.find(
fringe);
191 if(it != fFringeContainers.end())
197 fScanStore->LoadFringe(
fringe, con);
199 fFringeContainers[
fringe] = std::make_pair(con, inter);
209 auto it = fFringeContainers.find(
fringe);
210 if(it != fFringeContainers.end())
219 std::vector< std::string > baselines;
220 for(
auto it = fBaselineContainers.begin(); it != fBaselineContainers.end(); it++)
222 baselines.push_back(it->first);
229 std::vector< std::string >
stations;
230 for(
auto it = fStationContainers.begin(); it != fStationContainers.end(); it++)
239 std::vector< std::string > fringes;
240 for(
auto it = fFringeContainers.begin(); it != fFringeContainers.end(); it++)
242 fringes.push_back(it->first);
249 auto it = fBaselineContainers.find(
baseline);
250 if(it != fBaselineContainers.end())
252 return *(it->second.second);
256 py::print(
"could not find baseline: ",
baseline,
", returning empty container ");
257 return fEmptyContainer;
262 auto it = fStationContainers.find(station);
263 if(it != fStationContainers.end())
265 return *(it->second.second);
269 py::print(
"could not find station: ", station,
", returning empty container ");
270 return fEmptyContainer;
275 auto it = fFringeContainers.find(
fringe);
276 if(it != fFringeContainers.end())
278 return *(it->second.second);
282 py::print(
"could not find fringe: ",
fringe,
", returning empty container ");
283 return fEmptyContainer;
289 for(
auto it = fBaselineContainers.begin(); it != fBaselineContainers.end(); it++)
291 delete it->second.second;
292 delete it->second.first;
294 for(
auto it = fStationContainers.begin(); it != fStationContainers.end(); it++)
296 delete it->second.second;
297 delete it->second.first;
299 for(
auto it = fFringeContainers.begin(); it != fFringeContainers.end(); it++)
301 delete it->second.second;
302 delete it->second.first;
304 fBaselineContainers.clear();
305 fStationContainers.clear();
306 fFringeContainers.clear();
307 fInitialized =
false;
319 std::map< std::string, std::pair< MHO_ContainerStore*, MHO_PyContainerStoreInterface* > > fBaselineContainers;
320 std::map< std::string, std::pair< MHO_ContainerStore*, MHO_PyContainerStoreInterface* > > fStationContainers;
321 std::map< std::string, std::pair< MHO_ContainerStore*, MHO_PyContainerStoreInterface* > > fFringeContainers;
326 py::class_< MHO_PyScanStoreInterface >(m, pyclass_name.c_str())
329 "specify the path to the directory of the scan to be loaded", py::arg(
"directory"))
331 "initialize the scan storage container after setting the directory")
334 "check if baseline (2-char code) is present in this scan", py::arg(
"baseline"))
336 "check if station (1-char code) is present in this scan", py::arg(
"station"))
338 "check if fringe file (file basename) is present in this scan", py::arg(
"fringe_file_basename"))
340 "check if baseline has been loaded into memory, must be true before get_baseline_data can be called",
343 "check if station has been loaded into memory, must be true before get_station_data can be called",
346 "check if fringe has been loaded into memory, must be true before get_fringe_data can be called",
347 py::arg(
"fringe_file_basename"))
349 "get the number of baselines in the current scan")
353 "get the list of baselines in the current scan")
355 "get the list of stations in the current scan")
357 "get the list of fringe files available in the current scan")
359 "get the root/ovex file data object as a dictionary")
361 "get the file basename of the root/ovex file")
363 "get the filename associated with the baseline 2-char code", py::arg(
"baseline"))
365 "get the filename associated with the station 1-char code", py::arg(
"station"))
367 "get the filename associated with the fringe basename", py::arg(
"fringe"))
375 "get the list of baseline container objects that have been loaded into memory")
377 "get the list of station container objects that have been loaded into memory")
379 "get the list of fringe container objects that have been loaded into memory")
385 return py::cast(m.GetBaselineData(baseline));
387 py::print(
"data for baseline ",
baseline,
" either has not been loaded or it does not exist in this scan.");
388 return py::object(py::cast(
nullptr));
390 py::return_value_policy::reference,
"get the baseline data container that has been loaded into memory",
395 if(m.IsStationLoaded(station))
397 return py::cast(m.GetStationData(station));
399 py::print(
"data for station ", station,
" either has not been loaded or it does not exist in this scan.");
400 return py::object(py::cast(
nullptr));
402 py::return_value_policy::reference,
"get the station data container that has been loaded into memory",
407 if(m.IsFringeLoaded(
fringe))
409 return py::cast(m.GetFringeData(
fringe));
411 py::print(
"data for fringe ",
fringe,
" either has not been loaded or it does not exist in this scan.");
412 return py::object(py::cast(
nullptr));
414 py::return_value_policy::reference,
"get the fringe data container that has been loaded into memory",
417 "clear memory of the current scan contents and reset to uninitialized state");
Class MHO_ContainerStore.
Definition: MHO_ContainerStore.hh:32
python binding to the MHO_ContainerStore
Definition: MHO_PyContainerStoreInterface.hh:30
python bindings for the MHO_ScanDataStore
Definition: MHO_PyScanStoreInterface.hh:31
bool Initialize()
Definition: MHO_PyScanStoreInterface.hh:63
std::vector< std::string > GetStationsLoaded() const
Definition: MHO_PyScanStoreInterface.hh:227
MHO_PyContainerStoreInterface & GetStationData(std::string station)
Definition: MHO_PyScanStoreInterface.hh:260
py::dict GetRootFileData() const
Definition: MHO_PyScanStoreInterface.hh:90
MHO_PyContainerStoreInterface & GetFringeData(std::string fringe)
Definition: MHO_PyScanStoreInterface.hh:273
std::string GetRootFileBasename() const
Definition: MHO_PyScanStoreInterface.hh:92
void Clear()
Definition: MHO_PyScanStoreInterface.hh:287
virtual ~MHO_PyScanStoreInterface()
Definition: MHO_PyScanStoreInterface.hh:48
int LoadBaseline(std::string baseline)
Definition: MHO_PyScanStoreInterface.hh:100
std::string GetStationFilename(std::string station) const
Definition: MHO_PyScanStoreInterface.hh:96
std::vector< std::string > GetBaselinesLoaded() const
Definition: MHO_PyScanStoreInterface.hh:217
std::vector< std::string > GetFringesLoaded() const
Definition: MHO_PyScanStoreInterface.hh:237
std::size_t GetNStations() const
Definition: MHO_PyScanStoreInterface.hh:79
bool IsBaselinePresent(std::string bl) const
Definition: MHO_PyScanStoreInterface.hh:71
std::vector< std::string > GetFringesPresent() const
Definition: MHO_PyScanStoreInterface.hh:87
MHO_PyScanStoreInterface()
Definition: MHO_PyScanStoreInterface.hh:41
bool IsFringePresent(std::string fr) const
Definition: MHO_PyScanStoreInterface.hh:75
bool IsStationPresent(std::string st) const
Definition: MHO_PyScanStoreInterface.hh:73
MHO_PyScanStoreInterface(MHO_ScanDataStore *scan_store)
Definition: MHO_PyScanStoreInterface.hh:34
MHO_PyContainerStoreInterface & GetBaselineData(std::string baseline)
Definition: MHO_PyScanStoreInterface.hh:247
std::vector< std::string > GetBaselinesPresent() const
Definition: MHO_PyScanStoreInterface.hh:83
std::size_t GetNFringes() const
Definition: MHO_PyScanStoreInterface.hh:81
bool IsStationLoaded(std::string station) const
Definition: MHO_PyScanStoreInterface.hh:164
void SetDirectory(std::string dir)
Definition: MHO_PyScanStoreInterface.hh:57
bool IsFringeLoaded(std::string fringe) const
Definition: MHO_PyScanStoreInterface.hh:203
int LoadFringe(std::string fringe)
Definition: MHO_PyScanStoreInterface.hh:178
std::size_t GetNBaselines() const
Definition: MHO_PyScanStoreInterface.hh:77
std::string GetBaselineFilename(std::string baseline) const
Definition: MHO_PyScanStoreInterface.hh:94
int LoadStation(std::string station)
Definition: MHO_PyScanStoreInterface.hh:139
std::string GetFringeFilename(std::string fringe) const
Definition: MHO_PyScanStoreInterface.hh:98
bool IsValid() const
Definition: MHO_PyScanStoreInterface.hh:69
bool IsBaselineLoaded(std::string baseline) const
Definition: MHO_PyScanStoreInterface.hh:125
std::vector< std::string > GetStationsPresent() const
Definition: MHO_PyScanStoreInterface.hh:85
Class to catalog and organize data files that are associated with a single scan, and handle retrieval...
Definition: MHO_ScanDataStore.hh:28
Definition: difx2mark4.h:102
struct mk4_fringe fringe
Definition: fourfit3.c:54
int baseline
Definition: fourfit3.c:62
Definition: MHO_ChannelLabeler.hh:17
void Clear()
Definition: MHO_OpenCLFastFourierTransformPlan.cc:83
void DeclarePyScanStoreInterface(py::module &m, std::string pyclass_name)
Definition: MHO_PyScanStoreInterface.hh:324