Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to scan OceanCurrent Current Meters folder #1209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions ARGO/oceancurrent/argo_oceancurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,51 @@

# Specify the directory path
PROFILES_PATH = "/mnt/oceancurrent/website/profiles/"
CURRENT_METERS_PATH = "/mnt/oceancurrent/website/timeseries/ANMN_P48/"


def parse_filename(filename):
# Extract the part before the extension (if any)
base_name = filename.split('.')[0]
# Split the parts before any underscore (to safely ignore _zt or _xyz suffixes)
main_parts = base_name.split('_')[0]
parts = main_parts.split('-')

if len(parts) >= 5: # Check there are enough parts to parse
date = parts[1] # Assume the second element is the date
identifier = '-'.join(parts[2:-1]) # Join the identifier parts
nominal_depth = parts[-1] # The last part before _zt or _xyz is the nominal depth
return identifier, nominal_depth, date
return None, None, None

def scan_subdirectory(subdir_path):
result = []
if os.path.exists(subdir_path) and os.path.isdir(subdir_path):
for filename in os.listdir(subdir_path):
# Skip HTML files
if filename.endswith('.html'):
continue
identifier, nominal_depth, date = parse_filename(filename)
if identifier and nominal_depth and date: # Ensure all parts were correctly parsed
result.append({
'currentMeterIdentifier': identifier,
'instrumentNominalDepth': nominal_depth,
'date': date,
'filename': filename
})
else:
print("Directory not found or is not a directory:", subdir_path)
return result

def scan_current_meters():
result = {}
# Scan each subdirectory in the specified path
for subdir_name in os.listdir(CURRENT_METERS_PATH):
subdir_path = os.path.join(CURRENT_METERS_PATH, subdir_name)
if os.path.isdir(subdir_path):
result[subdir_name] = scan_subdirectory(subdir_path)
return result

def main():

platform_codes = os.listdir(PROFILES_PATH)
Expand Down Expand Up @@ -49,3 +92,8 @@ def main():

if __name__ == '__main__':
main()
data = scan_current_meters()
print("Final result:", json.dumps(data, indent=4))
# Optionally, write to a file
with open(os.path.join(CURRENT_METERS_PATH, 'current_meters.json'), 'w') as f:
json.dump(data, f, indent=4)
46 changes: 46 additions & 0 deletions ARGO/oceancurrent/test_argo_oceancurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,52 @@
from unittest.mock import patch

from argo_oceancurrent import main, PROFILES_PATH
from argo_oceancurrent import scan_current_meters, CURRENT_METERS_PATH

class TestCurrentMeterScanning(unittest.TestCase):
def setUp(self):
# Create a temporary directory
self.test_dir = tempfile.mkdtemp()

# Set up a structure for the test
os.makedirs(os.path.join(self.test_dir, 'xyz'))
os.makedirs(os.path.join(self.test_dir, 'zt'))

# Example test files for 'xyz' and 'zt' directories
self.test_files = {
'xyz': ["SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif", "SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif"],
'zt': ["SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif"]
}

# Create test files in the respective directories
for subdir, files in self.test_files.items():
for file in files:
with open(os.path.join(self.test_dir, subdir, file), 'w') as f:
f.write("Dummy content")

def tearDown(self):
# Remove the temporary directory and all its contents
shutil.rmtree(self.test_dir)

def test_current_meters_scanning(self):
with patch('argo_oceancurrent.CURRENT_METERS_PATH', new=self.test_dir):
# Run the scan_current_meters to generate the results
result = scan_current_meters()

# Define the expected result based on the test files
expected_result = {
'xyz': [
{'currentMeterIdentifier': 'Long-Ranger-Workhorse-ADCP', 'instrumentNominalDepth': '485p8', 'date': '0812', 'filename': 'SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif'},
{'currentMeterIdentifier': 'Long-Ranger-Workhorse-ADCP', 'instrumentNominalDepth': '509p9', 'date': '0902', 'filename': 'SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif'}
],
'zt': [
{'currentMeterIdentifier': 'Long-Ranger-Workhorse-ADCP', 'instrumentNominalDepth': '485p8', 'date': '0812', 'filename': 'SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif'}
]
}

# Check if the results match the expected output
self.assertEqual(result, expected_result, "The scanned output does not match the expected output.")



class TestProfilesJsonGeneration(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html> <title> SAM1DS</title> <BODY BGCOLOR = "#FFFFFF">
<a href=../../../><em>OceanCurrent</em></a> - <a href=../../>Current meters</a>
- <a href=../mapst/01_Aust_vrms_1.html>Aust</a>
- <a href=../mapst/08_SA_vrms_1.html>SA</a>
<h3> SAM1DS</h3>
<p><a href="xyz/"> <b>layer-average velocity vector scatter plots</b></a><br>
<a href="xyz/latest.html"> <img src="xyz/latest.gif" width=30% align="top"></a></p>
<p><a href="zt/"> <b>depth-time plots</b></a><br>
<a href="zt/latest.html"> <img src="zt/latest.gif" width=30% align="top"></a></p>
<p><a href="../ANMNtable.html#SAM1DS"> <b>Deployment metadata and tidal constituents</b></a><br>
<p><a href="https://thredds.aodn.org.au/thredds/catalog/IMOS/ANMN/SA/SAM1DS/Velocity/catalog.html" target="blank"> <b>data download from AODN</b></a></p>
Updated: 17-Aug-2024 19:40:21</body></html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html> <title> SAM1DS/xyz </title>
<BODY BGCOLOR = "#FFFFFF">
<a href=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.html>[PREV]</a>
<a href=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.html>[NEXT]</a>
<a href=index.html>[LIST]</a><br>
<IMG src=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif><BR>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html> <title> SAM1DS/xyz </title>
<BODY BGCOLOR = "#FFFFFF">
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html>[PREV]</a>
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html>[NEXT]</a>
<a href=index.html>[LIST]</a><br>
<IMG src=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif><BR>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html> <title> SAM1DS/xyz </title>
<BODY BGCOLOR = "#FFFFFF">
<a href="../">[up]</a> <a href="../index.html">[index.html]</a>
<UL>
<li><a href="SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html">SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.gif</a>
<li><a href="SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.html">SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif</a>
</UL>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html> <title> SAM1DS/xyz </title>
<BODY BGCOLOR = "#FFFFFF">
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html>[PREV]</a>
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_xyz.html>[NEXT]</a>
<a href=index.html>[LIST]</a><br>
<IMG src=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_xyz.gif><BR>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html> <title> SAM1DS/zt </title>
<BODY BGCOLOR = "#FFFFFF">
<a href=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.html>[PREV]</a>
<a href=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.html>[NEXT]</a>
<a href=index.html>[LIST]</a><br>
<IMG src=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif><BR>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html> <title> SAM1DS/zt </title>
<BODY BGCOLOR = "#FFFFFF">
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html>[PREV]</a>
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html>[NEXT]</a>
<a href=index.html>[LIST]</a><br>
<IMG src=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.gif><BR>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html> <title> SAM1DS/zt </title>
<BODY BGCOLOR = "#FFFFFF">
<a href="../">[up]</a> <a href="../index.html">[index.html]</a>
<UL>
<li><a href="SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html">SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.gif</a>
<li><a href="SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.html">SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.gif</a>
</UL>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html> <title> SAM1DS/zt </title>
<BODY BGCOLOR = "#FFFFFF">
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html>[PREV]</a>
<a href=SAM1DS-0812-Long-Ranger-Workhorse-ADCP-485p8_zt.html>[NEXT]</a>
<a href=index.html>[LIST]</a><br>
<IMG src=SAM1DS-0902-Long-Ranger-Workhorse-ADCP-509p9_zt.gif><BR>
<P><CENTER>&copy;<FONT SIZE="-1"> Copyright 2017, CSIRO Australia<BR>

Use of this web site and information available from it is
subject to our<BR> </FONT>

<FONT SIZE="-1"><A HREF="http://www.csiro.au/en/About/Footer/Legal-notice">
Legal Notice and Disclaimer</A></FONT></CENTER></P>
</BODY> </html>
Loading