Skip to content

Commit 456965a

Browse files
Merge pull request #86 from falconstryker/devel
Devel
2 parents a3c958c + ea3cc78 commit 456965a

File tree

9 files changed

+193
-50
lines changed

9 files changed

+193
-50
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: MarsFormat Test Workflow
2+
3+
on:
4+
# Trigger the workflow on push to devel branch
5+
push:
6+
branches: [ devel ]
7+
paths:
8+
- 'bin/MarsFormat.py'
9+
- 'tests/test_marsformat.py'
10+
- '.github/workflows/marsformat_test.yml'
11+
# Allow manual triggering of the workflow
12+
workflow_dispatch:
13+
# Trigger on pull requests that modify MarsFormat or tests
14+
pull_request:
15+
branches: [ devel ]
16+
paths:
17+
- 'bin/MarsFormat.py'
18+
- 'tests/test_marsformat.py'
19+
- '.github/workflows/marsformat_test.yml'
20+
21+
jobs:
22+
test:
23+
# Run on multiple OS and Python versions for comprehensive testing
24+
strategy:
25+
matrix:
26+
os: [ubuntu-latest, macos-latest, windows-latest]
27+
python-version: ['3.9', '3.10', '3.11']
28+
29+
runs-on: ${{ matrix.os }}
30+
31+
steps:
32+
# Checkout the repository
33+
- uses: actions/checkout@v3
34+
35+
# Set up the specified Python version
36+
- name: Set up Python ${{ matrix.python-version }}
37+
uses: actions/setup-python@v3
38+
with:
39+
python-version: ${{ matrix.python-version }}
40+
41+
# Install dependencies
42+
- name: Install dependencies
43+
shell: bash
44+
run: |
45+
python -m pip install --upgrade pip
46+
pip install numpy xarray netCDF4 matplotlib scipy
47+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
48+
49+
# Install the package in editable mode
50+
- name: Install package
51+
run: pip install -e .
52+
53+
# Set HOME for Windows since it might be used by the script
54+
- name: Set HOME environment variable for Windows
55+
if: runner.os == 'Windows'
56+
shell: pwsh
57+
run: |
58+
echo "HOME=$env:USERPROFILE" >> $env:GITHUB_ENV
59+
60+
# Set up AmesCAP configuration - handle platform differences
61+
- name: Set up AmesCAP configuration
62+
shell: bash
63+
run: |
64+
mkdir -p $HOME/.amescap
65+
cp mars_templates/amescap_profile $HOME/.amescap_profile
66+
67+
# Print out environment info
68+
- name: Show environment info
69+
run: |
70+
python -c "import os, sys, numpy, netCDF4, xarray; print(f'Python: {sys.version}, NumPy: {numpy.__version__}, NetCDF4: {netCDF4.__version__}, xarray: {xarray.__version__}')"
71+
echo "Working directory: $(pwd)"
72+
echo "Home directory: $HOME"
73+
echo "Environment variables: $(env)"
74+
75+
# Run the tests
76+
- name: Run MarsFormat tests
77+
run: python -m unittest -v tests/test_marsformat.py

.github/workflows/marspull_test.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ on:
88
- 'bin/MarsPull.py'
99
- 'tests/test_marspull.py'
1010
- '.github/workflows/marspull_test.yml'
11-
1211
# Allow manual triggering of the workflow
1312
workflow_dispatch:
14-
15-
# Trigger on pull requests that modify MarsPull or tests
13+
# Trigger on pull requests that modify MarsFormat or tests
1614
pull_request:
1715
branches: [ devel ]
1816
paths:
@@ -25,7 +23,7 @@ jobs:
2523
# Run on multiple OS and Python versions for comprehensive testing
2624
strategy:
2725
matrix:
28-
os: [ubuntu-latest, macos-latest]
26+
os: [ubuntu-latest, macos-latest, windows-latest]
2927
python-version: ['3.9', '3.10', '3.11']
3028

3129
runs-on: ${{ matrix.os }}
@@ -42,6 +40,7 @@ jobs:
4240

4341
# Install dependencies
4442
- name: Install dependencies
43+
shell: bash
4544
run: |
4645
python -m pip install --upgrade pip
4746
pip install requests numpy
@@ -53,5 +52,4 @@ jobs:
5352

5453
# Run the tests
5554
- name: Run MarsPull tests
56-
run: |
57-
python -m unittest tests/test_marspull.py
55+
run: python -m unittest -v tests/test_marspull.py

bin/MarsFiles.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def wrapper(*args, **kwargs):
177177
f" - ``daily`` : instantaneous data\n"
178178
f" - ``diurn`` : 5-sol averages binned by time of day\n"
179179
f" - ``average``: 5-sol averages\n"
180+
f"Works on 'fort.11' files only.\n"
180181
f"{Green}Example:\n"
181182
f"> MarsFiles fort.11_* -bin fixed daily diurn average\n"
182183
f"> MarsFiles fort.11_* -bin fixed diurn"
@@ -187,7 +188,7 @@ def wrapper(*args, **kwargs):
187188
parser.add_argument('-c', '--concatenate', action='store_true',
188189
help=(
189190
f"Combine sequential files of the same type into one file.\n"
190-
f"and ``diurn``).\n"
191+
f"Works on 'daily', 'diurn', and 'average' files.\n"
191192
f"{Green}Example:\n"
192193
f"> ls\n"
193194
f"00334.atmos_average.nc 00668.atmos_average.nc\n"
@@ -214,6 +215,7 @@ def wrapper(*args, **kwargs):
214215
f"Defaults to ``areo`` (Ls) unless otherwise specified using "
215216
f"-dim.\nIf a file contains multiple Mars Years of data, the "
216217
f"function splits the file in the first Mars Year.\n"
218+
f"Works on 'daily', 'diurn', and 'average' files.\n"
217219
f"{Green}Example:\n"
218220
f"> MarsFiles 01336.atmos_average.nc --split 0 90\n"
219221
f"> MarsFiles 01336.atmos_average.nc --split 270\n"
@@ -232,6 +234,7 @@ def wrapper(*args, **kwargs):
232234
f"time.\nUseful for comparing data at a specific time of day "
233235
f"across all longitudes.\nWorks on vertically interpolated "
234236
f"files.\n"
237+
f"Works on 'diurn' files only.\n"
235238
f"{Yellow}Generates a new file ending in ``_T.nc``{Nclr}\n"
236239
f"{Green}Example:\n"
237240
f"> MarsFiles 01336.atmos_diurn.nc -t"
@@ -253,7 +256,7 @@ def wrapper(*args, **kwargs):
253256
f"{Yellow}Generates a new file ending in ``_to_average.nc``\n"
254257
f"{Green}Example:\n"
255258
f"> MarsFiles 01336.atmos_daily.nc -ba {Blue}(5-sol bin){Green}\n"
256-
f"> MarsFiles 01336.atmos_daily_pstd.nc -ba 10 {Blue}(10-sol bin)"
259+
f"> MarsFiles 01336.atmos_daily.nc -ba 10 {Blue}(10-sol bin)"
257260
f"{Nclr}\n\n"
258261
)
259262
)
@@ -270,9 +273,9 @@ def wrapper(*args, **kwargs):
270273
f"{Yellow}Generates a new file ending in ``_to_diurn.nc``\n"
271274
f"{Green}Example:\n"
272275
f"> MarsFiles 01336.atmos_daily.nc -bd {Blue}(5-sol bin){Green}\n"
273-
f"> MarsFiles 01336.atmos_daily_pstd.nc -bd -ba 10 "
276+
f"> MarsFiles 01336.atmos_daily.nc -bd -ba 10 "
274277
f"{Blue}(10-sol bin){Green}\n"
275-
f"> MarsFiles 01336.atmos_daily_pstd.nc -bd -ba 1 "
278+
f"> MarsFiles 01336.atmos_daily.nc -bd -ba 1 "
276279
f"{Blue}(no binning, mimics raw Legacy output)"
277280
f"{Nclr}\n\n"
278281
)
@@ -284,9 +287,9 @@ def wrapper(*args, **kwargs):
284287
nargs='+', type=float,
285288
help=(
286289
f"Temporal high-pass filtering: removes low-frequencies \n"
287-
f"Only works with 'daily' or 'average' files. Requires a cutoff frequency "
288-
f"in Sols.\n"
289-
f"Data is detrended before filtering. Use ``--add_trend`` \n"
290+
f"Only works with 'daily' or 'average' files. Requires a cutoff "
291+
f"frequency in Sols.\n"
292+
f"Data is detrended before filtering. Use ``-add_trend`` \n"
290293
f"to add the original linear trend to the amplitudes \n"
291294
f"\n{Yellow}Generates a new file ending in ``_hpt.nc``\n"
292295
f"{Green}Example:\n"
@@ -301,9 +304,9 @@ def wrapper(*args, **kwargs):
301304
nargs='+', type=float,
302305
help=(
303306
f"Temporal low-pass filtering: removes high-frequencies \n"
304-
f"Only works with 'daily' or 'average' files. Requires a cutoff frequency "
305-
f"in Sols.\n"
306-
f"Data is detrended before filtering. Use ``--add_trend`` \n"
307+
f"Only works with 'daily' or 'average' files. Requires a cutoff "
308+
f"frequency in Sols.\n"
309+
f"Data is detrended before filtering. Use ``-add_trend`` \n"
307310
f"to add the original linear trend to the amplitudes \n"
308311
f"\n{Yellow}Generates a new file ending in ``_lpt.nc``\n"
309312
f"{Green}Example:\n"
@@ -320,7 +323,7 @@ def wrapper(*args, **kwargs):
320323
f"Temporal band-pass filtering"
321324
f"specified by user.\nOnly works with 'daily' or 'average' "
322325
f"files. Requires two cutoff frequencies in Sols.\n"
323-
f"Data is detrended before filtering. Use ``--add_trend`` \n"
326+
f"Data is detrended before filtering. Use ``-add_trend`` \n"
324327
f"to add the original linear trend to the amplitudes \n"
325328
f"\n{Yellow}Generates a new file ending in ``bpt.nc``\n"
326329
f"{Green}Example:\n"
@@ -340,7 +343,7 @@ def wrapper(*args, **kwargs):
340343
f"in Sols.\n"
341344
f"{Yellow}Generates a new file ending in ``_hps.nc``\n"
342345
f"{Green}Example:\n"
343-
f"> MarsFiles 01336.atmos_daily.nc -hps 10 --add_trend\n"
346+
f"> MarsFiles 01336.atmos_daily.nc -hps 10 -add_trend\n"
344347
f"{Nclr}\n\n"
345348
)
346349
)
@@ -355,7 +358,7 @@ def wrapper(*args, **kwargs):
355358
f"cutoff frequency in Sols.\n"
356359
f"{Yellow}Generates a new file ending in ``_lps.nc``\n"
357360
f"{Green}Example:\n"
358-
f"> MarsFiles 01336.atmos_daily.nc -lps 20 --add_trend\n"
361+
f"> MarsFiles 01336.atmos_daily.nc -lps 20 -add_trend\n"
359362
f"{Nclr}\n\n"
360363
)
361364
)
@@ -370,7 +373,7 @@ def wrapper(*args, **kwargs):
370373
f"cutoff frequency in Sols.\nData detrended before filtering.\n"
371374
f"{Yellow}Generates a new file ending in ``_bps.nc``\n"
372375
f"{Green}Example:\n"
373-
f"> MarsFiles 01336.atmos_daily.nc -bps 10 20 --add_trend\n"
376+
f"> MarsFiles 01336.atmos_daily.nc -bps 10 20 -add_trend\n"
374377
f"{Nclr}\n\n"
375378
)
376379
)
@@ -384,6 +387,7 @@ def wrapper(*args, **kwargs):
384387
f"harmonics.\nOnly works with 'diurn' files.\nReturns the phase "
385388
f"and amplitude of the variable.\n"
386389
f"N = 1 diurnal tide, N = 2 semi-diurnal, etc.\n"
390+
f"Works on 'diurn' files only.\n"
387391
f"{Yellow}Generates a new file ending in ``_tide_decomp.nc``\n"
388392
f"{Green}Example:\n"
389393
f"> MarsFiles 01336.atmos_diurn.nc -tide 2 -incl ps temp\n"
@@ -402,6 +406,7 @@ def wrapper(*args, **kwargs):
402406
f"user-provided source file.\nBoth files must have the same "
403407
f"vertical dimensions (i.e., should be vertically\ninterpolated "
404408
f"to the same standard grid [zstd, zagl, pstd, etc.].\n"
409+
f"Works on 'daily', 'diurn', and 'average' files.\n"
405410
f"{Yellow}Generates a new file ending in ``_regrid.nc``\n"
406411
f"{Green}Example:\n"
407412
f"> MarsFiles 01336.atmos_average_pstd.nc -regrid "
@@ -421,6 +426,7 @@ def wrapper(*args, **kwargs):
421426
f"Zonally average the entire file over the longitudinal "
422427
f"dimension.\nDoes not work if the longitude dimension has "
423428
f"length <= 1.\n"
429+
f"Works on 'daily', 'diurn', and 'average' files.\n"
424430
f"{Yellow}Generates a new file ending in ``_zavg.nc``\n"
425431
f"{Green}Example:\n"
426432
"> MarsFiles 01336.atmos_diurn.nc -zavg"
@@ -435,6 +441,7 @@ def wrapper(*args, **kwargs):
435441
f"Must be used with [-split --split]. Flag indicates the "
436442
f"dimension on which to trim the file.\nAcceptable values are "
437443
f"'areo', 'lev', 'lat', 'lon'. Default = 'areo'.\n"
444+
f"Works on 'daily', 'diurn', and 'average' files.\n"
438445
f"{Green}Example:\n"
439446
f"> MarsFiles 01336.atmos_average.nc --split 0 90 -dim areo\n"
440447
f"> MarsFiles 01336.atmos_average.nc --split -70 -dim lat"
@@ -450,6 +457,7 @@ def wrapper(*args, **kwargs):
450457
f"For use with ``-tide``: Returns the result in percent "
451458
f"amplitude.\n"
452459
f"N = 1 diurnal tide, N = 2 semi-diurnal, etc.\n"
460+
f"Works on 'diurn' files only.\n"
453461
f"{Yellow}Generates a new file ending in ``_norm.nc``\n"
454462
f"{Green}Example:\n"
455463
f"> MarsFiles 01336.atmos_diurn.nc -tide 6 -incl ps "
@@ -482,6 +490,7 @@ def wrapper(*args, **kwargs):
482490
nargs=0,
483491
help=(
484492
f"Reconstructs the first N harmonics.\n"
493+
f"Works on 'diurn' files only.\n"
485494
f"{Yellow}Generates a new file ending in ``_reconstruct.nc``\n"
486495
f"{Green}Example:\n"
487496
f"> MarsFiles 01336.atmos_diurn.nc -tide 6 -incl ps temp "
@@ -495,8 +504,7 @@ def wrapper(*args, **kwargs):
495504
f"Flag to use only the variables specified in a calculation.\n"
496505
f"All dimensional and 1D variables are ported to the new file "
497506
f"automatically.\n"
498-
f"{Yellow}Overwrites existing target file. To override, use "
499-
f"-ext.{Nclr}\n"
507+
f"Works on 'daily', 'diurn', and 'average' files.\n"
500508
f"{Green}Example:\n"
501509
f"> MarsFiles 01336.atmos_daily.nc -ba -incl ps temp ts"
502510
f"{Nclr}\n\n"
@@ -510,8 +518,8 @@ def wrapper(*args, **kwargs):
510518
f"CAP to create a new file with the extension name specified "
511519
f"here.\n"
512520
f"{Green}Example:\n"
513-
f"> MarsFiles 00334.atmos_average.nc -c -ext _comb\n"
514-
f"{Blue}(Produces 00334.atmos_average_comb.nc and "
521+
f"> MarsFiles 01336.atmos_average.nc -c -ext _my_concat\n"
522+
f"{Blue}(Produces 01336.atmos_average_my_concat.nc and "
515523
f"preserves all other files)"
516524
f"{Nclr}\n\n"
517525
)

bin/MarsFormat.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def wrapper(*args, **kwargs):
125125
help=(
126126
f"Calculate 5-day averages binned by hour from instantaneous "
127127
f"data. Generates MGCM-like 'diurn' files.\n"
128+
f"Works on non-MGCM files only.\n"
128129
f"{Green}Example:\n"
129130
f"> MarsFormat openmars_file.nc -gcm openmars -bd\n"
130131
f"{Blue}(Creates openmars_file_daily.nc; 5-sol bin){Green}\n"
@@ -178,17 +179,22 @@ def main():
178179
print(f"{Yellow}***Notice*** No operation requested. Use '-gcm' and specify openmars, marswrf, pcm, emars")
179180
exit() # Exit cleanly
180181

182+
print(f"Running MarsFormat with args: {args}")
183+
print(f"Current working directory: {os.getcwd()}")
184+
print(f"Files in input_file: {[f.name for f in args.input_file]}")
185+
print(f"File exists check: {all(os.path.exists(f.name) for f in args.input_file)}")
186+
181187
path2data = os.getcwd()
182188

183189
# Load all of the netcdf files
184190
file_list = [f.name for f in args.input_file]
185191
model_type = args.gcm_name # e.g. 'legacy'
186192
for filei in file_list:
187-
# Add path unless full path is provided
188-
if '/' not in filei:
189-
fullnameIN = path2data + '/' + filei
190-
else:
193+
# Use os.path.join for platform-independent path handling
194+
if os.path.isabs(filei):
191195
fullnameIN = filei
196+
else:
197+
fullnameIN = os.path.join(path2data, filei)
192198

193199
print('Processing...')
194200
# Load model variables, dimensions
@@ -536,7 +542,8 @@ def main():
536542
DS_average[model.dim_time].attrs['long_name'] = 'time averaged over %s sols'%(nday)
537543

538544
# Create New File, set time dimension as unlimitted
539-
fullnameOUT = fullnameIN[:-3]+ext+'.nc'
545+
base_name = os.path.splitext(fullnameIN)[0]
546+
fullnameOUT = f"{base_name}{ext}.nc"
540547
DS_average.to_netcdf(fullnameOUT,unlimited_dims=model.dim_time,format='NETCDF4_CLASSIC')
541548

542549

bin/MarsInterp.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ def wrapper(*args, **kwargs):
102102

103103
parser.add_argument('-t', '--interp_type', type=str, default='pstd',
104104
help=(
105-
f"Interpolation interp_: ``pstd``, ``zstd``, or ``zagl``.\n"
105+
f"Interpolation to standard pressure (pstd), standard altitude "
106+
f"(zstd), or altitude above ground level (zagl).\nWorks on "
107+
f"'daily', 'average', and 'diurn' files.\n"
106108
f"{Green}Example:\n"
107109
f"> MarsInterp 01336.atmos_average.nc\n"
108-
f"> MarsInterp 01336.atmos_average.nc -t pstd"
110+
f"> MarsInterp 01336.atmos_average.nc -t pstd\n"
109111
f"{Nclr}\n\n"
110112
)
111113
)
@@ -114,8 +116,11 @@ def wrapper(*args, **kwargs):
114116

115117
parser.add_argument('-v', '--vertical_grid', type=str, default=None,
116118
help=(
117-
f"Layer IDs as defined in ``amescap_profile``.\nFor first "
119+
f"For use with ``-t``. Specify a custom vertical grid to "
120+
f"interpolate to.\n"
121+
f"Custom grids defined in ``amescap_profile``.\nFor first "
118122
f"time use, copy ``amescap_profile`` to your home directory:\n"
123+
f"Works on 'daily', 'diurn', and 'average' files.\n"
119124
f"{Cyan}cp path/to/amesCAP/mars_templates/amescap_profile "
120125
f"~/.amescap_profile\n"
121126
f"{Green}Example:\n"
@@ -126,8 +131,9 @@ def wrapper(*args, **kwargs):
126131

127132
parser.add_argument('-incl', '--include', nargs='+',
128133
help=(
129-
f"Only include the listed variables. Dimensions and 1D "
130-
f"variables are always included.\n"
134+
f"Only include the listed variables in the action. Dimensions "
135+
f"and 1D variables are always included.\n"
136+
f"Works on 'daily', 'diurn', and 'average' files.\n"
131137
f"{Green}Example:\n"
132138
f"> MarsInterp 01336.atmos_daily.nc -incl temp ps ts"
133139
f"{Nclr}\n\n"
@@ -153,8 +159,8 @@ def wrapper(*args, **kwargs):
153159
f"CAP to create a new file with the extension name specified "
154160
f"here.\n"
155161
f"{Green}Example:\n"
156-
f"> MarsInterp 00334.atmos_average.nc -t pstd -ext _dflt_levs\n"
157-
f"{Blue}(Produces 00334.atmos_average_dflt_levs.nc and "
162+
f"> MarsInterp 00334.atmos_average.nc -t pstd -ext _my_pstd\n"
163+
f"{Blue}(Produces 00334.atmos_average_my_pstd.nc and "
158164
f"preserves all other files)"
159165
f"{Nclr}\n\n"
160166
)

0 commit comments

Comments
 (0)