|
@@ -14,15 +14,19 @@ from functools import partial
|
|
|
|
|
|
|
|
|
class MaterialLoader:
|
|
|
- def __init__(self, base_path, lazy_load=True):
|
|
|
- self.base_path = Path(base_path)
|
|
|
+ def __init__(self, input_file, lazy_load=True):
|
|
|
self.lazy_load = lazy_load
|
|
|
self._data_cache = {}
|
|
|
self.opt = parser.parse_args_and_yaml()
|
|
|
+ self.base_path = Path(self.opt.dqyc_base_path)
|
|
|
+ self.base_path_cdq = Path(self.opt.cdqyc_base_path)
|
|
|
|
|
|
def wrapper_path(self, station_id, spec):
|
|
|
return f"{self.base_path/station_id/spec}.txt"
|
|
|
|
|
|
+ def wrapper_path_cdq(self, area_id, spec):
|
|
|
+ return f"{self.base_path_cdq/area_id/spec}.txt"
|
|
|
+
|
|
|
def _load_material(self, station_id):
|
|
|
"""核心数据加载方法"""
|
|
|
# 根据您的原始代码逻辑简化的加载流程
|
|
@@ -76,6 +80,56 @@ class MaterialLoader:
|
|
|
print(f"Error loading {station_id}: {str(e)}")
|
|
|
return None
|
|
|
|
|
|
+ def _load_material_cdq(self, area_id, moment):
|
|
|
+ """核心数据加载方法"""
|
|
|
+ # 根据您的原始代码逻辑简化的加载流程
|
|
|
+ try:
|
|
|
+ basic = pd.read_csv(self.wrapper_path_cdq(area_id, self.opt.doc_cdq_mapping['basic']), sep=r'\s+', header=0)
|
|
|
+ basic_area = pd.read_csv(self.wrapper_path_cdq(area_id, self.opt.doc_cdq_mapping['basic_area']), sep=r'\s+', header=0)
|
|
|
+ plant_type = int(basic.loc[basic['PropertyID'].tolist().index('PlantType'), 'Value'])
|
|
|
+ assert plant_type == 0 or plant_type == 1
|
|
|
+ # 根据电站类型加载数据
|
|
|
+
|
|
|
+ if self.opt.switch_nwp_owner:
|
|
|
+ nwp_v, nwp_v_h = nwp_own, nwp_own_h
|
|
|
+ # 如果是风电
|
|
|
+ if plant_type == 0:
|
|
|
+ station_info = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['station_info_w']), sep=r'\s+', header=0)
|
|
|
+ station_info_d = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['station_info_d_w']), sep=r'\s+', header=0)
|
|
|
+ nwp = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['nwp_w']), sep=r'\s+', header=0)
|
|
|
+ nwp_h = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['nwp_w_h']), sep=r'\s+', header=0)
|
|
|
+ cap = float(station_info.loc[0, 'PlantCap'])
|
|
|
+ if Path(self.wrapper_path(station_id, self.opt.doc_mapping['env_wf'])).exists():
|
|
|
+ env = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['env_wf']), sep=r'\s+', header=0)
|
|
|
+ else:
|
|
|
+ env = None
|
|
|
+ # 如果是光伏
|
|
|
+ else:
|
|
|
+ station_info = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['station_info_s']), sep=r'\s+', header=0)
|
|
|
+ station_info_d = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['station_info_d_s']), sep=r'\s+', header=0)
|
|
|
+ nwp = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['nwp_s']), sep=r'\s+', header=0)
|
|
|
+ nwp_h = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['nwp_s_h']), sep=r'\s+', header=0)
|
|
|
+ cap = float(station_info.loc[0, 'PlantCap'])
|
|
|
+ if Path(self.wrapper_path(station_id, self.opt.doc_mapping['env_sf'])).exists():
|
|
|
+ env = pd.read_csv(self.wrapper_path(station_id, self.opt.doc_mapping['env_sf']), sep=r'\s+', header=0)
|
|
|
+ else:
|
|
|
+ env = None
|
|
|
+
|
|
|
+ return types.SimpleNamespace(**{
|
|
|
+ 'station_info': station_info,
|
|
|
+ 'station_info_d': station_info_d,
|
|
|
+ 'nwp': nwp,
|
|
|
+ 'nwp_h': nwp_h,
|
|
|
+ 'power': power,
|
|
|
+ 'nwp_v': nwp_v,
|
|
|
+ 'nwp_v_h': nwp_v_h,
|
|
|
+ 'env': env,
|
|
|
+ 'cap': cap
|
|
|
+ })
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error loading {station_id}: {str(e)}")
|
|
|
+ return None
|
|
|
+
|
|
|
def get_material(self, station_id):
|
|
|
if self.lazy_load:
|
|
|
if station_id not in self._data_cache:
|
|
@@ -120,8 +174,8 @@ class MaterialLoader:
|
|
|
|
|
|
def get_material_region(self):
|
|
|
try:
|
|
|
- basic = pd.read_csv(os.path.join(self.base_path, self.opt.doc_area_mapping['basic']+'.txt'), sep=r'\s+', header=0)
|
|
|
- power = pd.read_csv(os.path.join(self.base_path, self.opt.doc_area_mapping['power']+'.txt'), sep=r'\s+', header=0)
|
|
|
+ basic = pd.read_csv(os.path.join(self.base_path, self.opt.doc_mapping['basic_area']+'.txt'), sep=r'\s+', header=0)
|
|
|
+ power = pd.read_csv(os.path.join(self.base_path, self.opt.doc_mapping['power_area']+'.txt'), sep=r'\s+', header=0)
|
|
|
plant_type = int(basic.loc[basic['PropertyID'].tolist().index('PlantType'), 'Value'])
|
|
|
area_id = int(basic.loc[basic['PropertyID'].tolist().index('AreaId'), 'Value'])
|
|
|
assert plant_type == 0 or plant_type == 1
|
|
@@ -135,5 +189,7 @@ class MaterialLoader:
|
|
|
print(f"Region Error loading: {str(e)}")
|
|
|
return None
|
|
|
|
|
|
+ def get_material_cdq(self):
|
|
|
+ pass
|
|
|
if __name__ == "__main__":
|
|
|
run_code = 0
|