(25, 31), (31, 37), (37, 43), (49, 55), ] # Column names NAMES = ["time", "temp", "dwpt", "pres", "wdir", "wspd", "prcp"] # Create Jasper instance jsp = Jasper(f"import.noaa.hourly.global.{MODE}") # Weather stations stations: Union[pd.DataFrame, None] = None # Get counter value skip = jsp.get_var("station_counter", 0, int) # Get year if MODE == "historical": year = jsp.get_var("year", 1901, int) # Get ISD Lite stations try: stations = pd.read_csv( USAF_WBAN_PATH, dtype="str", skiprows=skip, nrows=STATIONS_PER_CYCLE, names=["id", "usaf", "wban"], ) except pd.errors.EmptyDataError:
# Get task mode # 'historical' or 'recent' MODE = sys.argv[1] # Create Jasper instance jsp = Jasper(f"export.bulk.gridded.daily.{MODE}") # Variables modified: bool = None raw: pd.DataFrame # Get time delta if MODE == "historical": # We'll need to run at least twice a day # Otherwise this is stuck delta = jsp.get_var("date_offset", 0, int) if delta > 18493: jsp.set_var("date_offset", 0) sys.exit() jsp.set_var("date_offset", delta + 1) else: delta = int(sys.argv[2]) # Get date date = datetime.date.today() - datetime.timedelta(days=delta) # Get modification time try: modified = (jsp.bulk().voidcmd(f"""MDTM /gridded/daily/tavg/{ date.strftime("%Y-%m-%d") }.nc""")[4:].strip())
"23": 22, "24": 19, "25": 20, "26": 23, "27": 25, "28": 26, "29": 25, "30": 26, "31": 27, } return condicodes.get(str(code), None) # Get counter value skip = jsp.get_var("station_counter", 0, int) # Get POI stations try: stations = pd.read_csv( POI_PATH, dtype="str", skiprows=skip, nrows=STATIONS_PER_CYCLE, names=["id"], ) except pd.errors.EmptyDataError: pass # Update counter if stations is None or len(stations.index) < STATIONS_PER_CYCLE:
match = matching[0] except BaseException: pass return match # Connect to FTP server ftp = FTP(DWD_FTP_SERVER) ftp.login() ftp.cwd( f"/climate_environment/CDC/observations_global/CLIMAT/monthly/qc/{BASE_DIR}" ) # Get counter value counter = jsp.get_var(f"station_counter_{MODE}", 0, int) skip = 3 if counter == 0 else 3 + counter # Get all files in directory try: endpos = STATIONS_PER_CYCLE + skip stations = ftp.nlst()[skip:endpos] except BaseException: pass # Update counter if stations is None or len(stations) < STATIONS_PER_CYCLE: jsp.set_var("station_counter", 0) sys.exit() else: jsp.set_var("station_counter", counter + STATIONS_PER_CYCLE)