Commit 96e47871 authored by CEVAER's avatar CEVAER

Added ORM dependencies, added extract file date, finding track points for that date.

parent bbc02554
# smap_cyclones # smap_cyclones
Package used to adapt SMAP data for a cyclone oriented usage.
Provide scripts to extract cyclone data from SMAP NetCDF files. Provide scripts to extract cyclone data from SMAP NetCDF files.
\ No newline at end of file
#!/usr/bin/env python
import argparse import argparse
import logging import logging
import datetime
import os
import sys
from sqlalchemy import create_engine, and_
from sqlalchemy.orm import sessionmaker
from cyclobs_orm import SimpleTrack
logging.basicConfig() logging.basicConfig()
logger = logging.getLogger(os.path.basename(__file__)) logger = logging.getLogger(os.path.basename(__file__))
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
def extractDateFromFilename(filename):
datePart = "-".join(filename.split("_")[4:7])
return datetime.datetime.strptime(datePart, "%Y-%m-%d")
def getTrackPointsFromDatabase(session, smapDate):
reqTracks = session.query(SimpleTrack).filter(and_( >= smapDate, < smapDate + datetime.timedelta(days=1))).all()
return reqTracks
def processSmapFile(session, file):
logger.debug(f"Processing {file}...")
fileDate = extractDateFromFilename(os.path.basename(file))
logger.debug(f"File date {fileDate}")
trackPoints = getTrackPointsFromDatabase(session, fileDate)
trakcPointsPerSid = {trackPoint.sid: trackPoint for trackPoint in trackPoints}
if __name__ == "__main__": if __name__ == "__main__":
pass description = """
\ No newline at end of file Read SMAP netCDF files from a directory, extract the wind data of cyclones and save it into a new netCDF file.
parser = argparse.ArgumentParser(description=description)
parser.add_argument("--dbd", action="store", type=str, required=True, help='database (postgresql://user:pass@host:5432/base_name)')
parser.add_argument("--debug", action="store_true", default=False, help="Run in debug mode (verbose output)")
args = parser.parse_args()
if sys.gettrace():
if args.debug:
engine = create_engine(args.dbd)
Session = sessionmaker(bind=engine)
smapTests = ["/home/datawork-cersat-public/provider/remss/satellite/l3/smap/smap/wind/v1.0/daily/2020/110/",
for f in smapTests:
processSmapFile(Session(), f)
...@@ -5,11 +5,13 @@ from pathlib import Path ...@@ -5,11 +5,13 @@ from pathlib import Path
import glob import glob
install_requires = [ install_requires = [
] ]
setup(name='smap_cyclones', setup(name='smap_cyclones',
description='cyclobs web server', description='Package used to adapt SMAP data for a cyclone oriented usage.',
url='', url='',
author = "Théo CEVAER", author = "Théo CEVAER",
author_email = "", author_email = "",
...@@ -18,7 +20,7 @@ setup(name='smap_cyclones', ...@@ -18,7 +20,7 @@ setup(name='smap_cyclones',
include_package_data=True, include_package_data=True,
scripts=glob.glob('bin/**'), scripts=glob.glob('bin/**'),
use_scm_version=True, use_scm_version=True,
setup_requires=['setuptools_scm'ss], setup_requires=['setuptools_scm'],
install_requires=install_requires, install_requires=install_requires,
data_files=[ (os.path.dirname(p) , [p] ) for p in glob.glob('etc/**',recursive=True) if not os.path.isdir(p) ], data_files=[ (os.path.dirname(p) , [p] ) for p in glob.glob('etc/**',recursive=True) if not os.path.isdir(p) ],
zip_safe = False zip_safe = False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment