예제 #1
0
            meta_data = {
                'latitude': float('%.6f' % float(latitude)),
                'longitude': float('%.6f' % float(longitude)),
                'model': target_model, 'method': method,
                'grid_id': 'discharge_{}'.format(station_name)
            }

            tms_id = TS.get_timeseries_id_if_exists(meta_data=meta_data)

            if tms_id is None:
                tms_id = TS.generate_timeseries_id(meta_data=meta_data)
                meta_data['id'] = tms_id
                TS.insert_run(meta_data=meta_data)

            existing_ts_end = TS.get_obs_end(id_=tms_id)

            processed_discharge_ts = []

            if existing_ts_end is None:
                fcst_start = datetime.now() - timedelta(days=10)
            else:
                fcst_start = existing_ts_end + timedelta(hours=1)

            if method in ('SF'): # process fcst ts from statistical forecasts
                try:
                    timeseries = read_csv('{}/{}.csv'.format(INPUT_DIR, station_name))
                    processed_discharge_ts = process_fcsts_from_csv(timeseries=timeseries, fcst_start=fcst_start)
                except FileNotFoundError as fe:
                    print("File not found: {}/{}.csv".format(INPUT_DIR, station_name))
                    continue
예제 #2
0
        if start_time is None:
            start_time = (datetime.now() - timedelta(days=3)).strftime('%Y-%m-%d 00:00:00')
        else:
            check_time_format(time=start_time)

        if end_time is None:
            end_time = (datetime.now() + timedelta(days=2)).strftime('%Y-%m-%d 00:00:00')
        else:
            check_time_format(time=end_time)

        pool = get_Pool(host=con_params.CURW_SIM_HOST, port=con_params.CURW_SIM_PORT, user=con_params.CURW_SIM_USERNAME,
                        password=con_params.CURW_SIM_PASSWORD,
                        db=con_params.CURW_SIM_DATABASE)
        TS = Timeseries(pool)

        latest_fgt = TS.get_obs_end(dis_id)

        if output_dir is None:
            output_dir = os.path.join(OUTPUT_DIRECTORY, (datetime.utcnow() + timedelta(hours=5, minutes=30)).strftime('%Y-%m-%d_%H-00-00'))
        if file_name is None:
            file_name = 'mike_dis.txt'  #.format(latest_fgt.strftime('%Y-%m-%d_%H-%M-00'))

        mike_dis_file_path = os.path.join(output_dir, file_name)

        if not os.path.isfile(mike_dis_file_path):
            makedir_if_not_exist_given_filepath(mike_dis_file_path)
            print("{} start preparing mike discharge input".format(datetime.now()))
            mike_discharge = prepare_mike_dis_input(TS=TS, start=start_time, end=end_time, dis_id=dis_id)
            mike_discharge.to_csv(mike_dis_file_path, header=False, index=True)
            print("{} completed preparing mike discharge input".format(datetime.now()))
            print("Mike input discharge file is available at {}".format(mike_dis_file_path))
예제 #3
0
                continue

            end_time = (datetime.now() + timedelta(
                hours=5, minutes=30)).strftime(COMMON_DATE_TIME_FORMAT)

            timeseries = []

            if tms_id is None:
                tms_id = discharge_TS.generate_timeseries_id(
                    meta_data=meta_data)
                meta_data['id'] = tms_id
                discharge_TS.insert_run(meta_data=meta_data)
                start = (datetime.now() -
                         timedelta(days=10)).strftime(COMMON_DATE_TIME_FORMAT)
            else:
                obs_end = discharge_TS.get_obs_end(id_=tms_id)
                if obs_end is None:
                    start = (
                        datetime.now() -
                        timedelta(days=10)).strftime(COMMON_DATE_TIME_FORMAT)
                else:
                    start = (
                        obs_end -
                        timedelta(days=1)).strftime(COMMON_DATE_TIME_FORMAT)

            wl_timeseries = waterlevel_TS.get_timeseries(id_=wl_tms_id,
                                                         start_date=start,
                                                         end_date=end_time)

            estimated_discharge_ts = []