Skip to content

Commit a094c37

Browse files
committed
change mintpy template to dictionary. add checks if files exist and separate inputs
1 parent d29ea63 commit a094c37

File tree

1 file changed

+104
-41
lines changed

1 file changed

+104
-41
lines changed

prep/ARIA_prep.ipynb

Lines changed: 104 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"outputs": [],
9696
"source": [
9797
"# Specify a calval location ID from my_sites.txt\n",
98-
"site = 'test' \n",
98+
"site = 'CalVal_S1_LosAngelesA64' \n",
9999
"\n",
100100
"# Choose the requirement to validate\n",
101101
"# Options: 'Secular' 'Coseismic' 'Transient'\n",
@@ -108,7 +108,7 @@
108108
"aria_gunw_version = '3_0_1'\n",
109109
"\n",
110110
"# The date and version of this Cal/Val run\n",
111-
"rundate = '20250415'\n",
111+
"rundate = '20250417'\n",
112112
"version = '1'\n",
113113
"\n",
114114
"# Provide the file where you keep your customized list of sites.\n",
@@ -355,11 +355,11 @@
355355
" if sitedata['sites'][site]['maskWater'] != 'False':\n",
356356
" command = 'ariaTSsetup.py -f ' + product_file + ' -b ' + \\\n",
357357
" sitedata['sites'][site]['analysis_region'] + \\\n",
358-
" ' --mask Download -l \"ionosphere, troposphereTotal, solidEarthTide\" --croptounion -nt 8'\n",
358+
" ' --mask Download -l \"ionosphere, troposphereTotal, solidEarthTide\" --croptounion -nt 8 --log-level info'\n",
359359
" mask_file = '../mask/watermask.msk'\n",
360360
" else: # skip slow mask download when we don't need to mask water\n",
361361
" command = 'ariaTSsetup.py -f ' + product_file + ' -b ' + \\\n",
362-
" sitedata['sites'][site]['analysis_region'] + ' -l \"ionosphere, troposphereTotal, solidEarthTide\" --croptounion -nt 8'\n",
362+
" sitedata['sites'][site]['analysis_region'] + ' -l \"ionosphere, troposphereTotal, solidEarthTide\" --croptounion -nt 8 --log-level info'\n",
363363
" # Crop and prepare stack\n",
364364
" process = subprocess.run(command, text = True, shell = True)\n",
365365
" print('Finished preparing GUNWs for MintPy!!')\n",
@@ -405,45 +405,39 @@
405405
"source": [
406406
"os.chdir(mintpy_dir)\n",
407407
"\n",
408-
"# Write smallbaseline.py config file\n",
409-
"config_file_content = \"\"\"\n",
410-
"mintpy.load.processor = aria\n",
411-
"mintpy.compute.cluster = local\n",
412-
"mintpy.compute.numWorker = auto\n",
413-
"mintpy.load.unwFile = {wd}/stack/unwrapStack.vrt\n",
414-
"mintpy.load.corFile = {wd}/stack/cohStack.vrt\n",
415-
"mintpy.load.connCompFile = {wd}/stack/connCompStack.vrt\n",
416-
"mintpy.load.demFile = {wd}/DEM/glo_90.dem\n",
417-
"mintpy.load.incAngleFile = {wd}/incidenceAngle/*.vrt\n",
418-
"mintpy.load.azAngleFile = {wd}/azimuthAngle/*.vrt\n",
419-
"mintpy.load.waterMaskFile = {mask_file}\n",
420-
"mintpy.topographicResidual.pixelwiseGeometry = no\n",
421-
"mintpy.troposphericDelay.method = no\n",
422-
"mintpy.topographicResidual = no\n",
423-
"mintpy.network.tempBaseMax = {tempmax}\n",
424-
"mintpy.network.startDate = {startdatenet}\n",
425-
"mintpy.network.endDate = {enddatenet}\n",
426-
"mintpy.velocity.startDate = {startdatevel}\n",
427-
"mintpy.velocity.endDate = {enddatevel}\n",
428-
"mintpy.reference.lalo = {reference_lalo}\n",
429-
"mintpy.network.excludeIfgIndex = {excludeIfg}\"\"\".format(wd = work_dir,\n",
430-
" mask_file = mask_file,\n",
431-
" tempmax=sitedata['sites'][site]['tempBaseMax'],\n",
432-
" excludeIfg=sitedata['sites'][site]['ifgExcludeList'],\n",
433-
" startdatenet=sitedata['sites'][site]['download_start_date'],\n",
434-
" enddatenet=sitedata['sites'][site]['download_end_date'],\n",
435-
" startdatevel=sitedata['sites'][site]['download_start_date'],\n",
436-
" enddatevel=sitedata['sites'][site]['download_end_date'],\n",
437-
" reference_lalo=sitedata['sites'][site]['reference_lalo'])\n",
438-
"\n",
439-
"# Write the config file\n",
408+
"# Build config as a dictionary first\n",
409+
"config_file_content = {\n",
410+
" \"mintpy.load.processor\": \"aria\",\n",
411+
" \"mintpy.compute.cluster\": \"local\",\n",
412+
" \"mintpy.compute.numWorker\": \"auto\",\n",
413+
" \"mintpy.load.unwFile\": f\"{work_dir}/stack/unwrapStack.vrt\",\n",
414+
" \"mintpy.load.corFile\": f\"{work_dir}/stack/cohStack.vrt\",\n",
415+
" \"mintpy.load.connCompFile\": f\"{work_dir}/stack/connCompStack.vrt\",\n",
416+
" \"mintpy.load.demFile\": f\"{work_dir}/DEM/glo_90.dem\",\n",
417+
" \"mintpy.load.incAngleFile\": f\"{work_dir}/incidenceAngle/*.vrt\",\n",
418+
" \"mintpy.load.azAngleFile\": f\"{work_dir}/azimuthAngle/*.vrt\",\n",
419+
" \"mintpy.load.waterMaskFile\": mask_file,\n",
420+
" \"mintpy.topographicResidual.pixelwiseGeometry\": \"no\",\n",
421+
" \"mintpy.troposphericDelay.method\": \"no\",\n",
422+
" \"mintpy.topographicResidual\": \"no\",\n",
423+
" \"mintpy.network.tempBaseMax\": sitedata['sites'][site]['tempBaseMax'],\n",
424+
" \"mintpy.network.startDate\": sitedata['sites'][site]['download_start_date'],\n",
425+
" \"mintpy.network.endDate\": sitedata['sites'][site]['download_end_date'],\n",
426+
" \"mintpy.velocity.startDate\": sitedata['sites'][site]['download_start_date'],\n",
427+
" \"mintpy.velocity.endDate\": sitedata['sites'][site]['download_end_date'],\n",
428+
" \"mintpy.reference.lalo\": sitedata['sites'][site]['reference_lalo'],\n",
429+
" \"mintpy.network.excludeIfgIndex\": sitedata['sites'][site]['ifgExcludeList'],\n",
430+
"}\n",
431+
"\n",
432+
"# Write dictionary to a config text file\n",
440433
"with open(config_file, \"w\") as file:\n",
441-
" file.write(config_file_content)\n",
434+
" for key, value in config_file_content.items():\n",
435+
" file.write(f\"{key} = {value}\\n\")\n",
442436
"\n",
443-
"# Print the results\n",
437+
"# Print results\n",
444438
"print(f'MintPy config file:\\n {config_file}')\n",
445439
"with open(config_file, \"r\") as file:\n",
446-
" print(file.read())"
440+
" print(file.read())\n"
447441
]
448442
},
449443
{
@@ -464,10 +458,18 @@
464458
"metadata": {},
465459
"source": [
466460
"<div class=\"alert alert-block alert-info\">\n",
467-
" <b>Note:</b> If you plan to use one or more ARIA GUNW correction layers — such as <b>troposphere</b>, <b>ionosphere</b>, or <b>solid Earth tides</b> — run the <code>prep_aria.py</code> command in the second cell below.\n",
461+
" <b>Note:</b> If you plan to use one or more ARIA GUNW correction layers — such as <b>troposphere</b>, <b>ionosphere</b>, or <b>solid Earth tides</b> — run <b>Section 1.4.2</b> <code>prep_aria.py</code> command in the second cell below.\n",
468462
"</div>"
469463
]
470464
},
465+
{
466+
"cell_type": "markdown",
467+
"id": "50ad69da-bd51-4f40-9975-16863a131cac",
468+
"metadata": {},
469+
"source": [
470+
"#### 1.4.1 Use `smallbaselineApp.py` to generate MintPy stacks"
471+
]
472+
},
471473
{
472474
"cell_type": "code",
473475
"execution_count": null,
@@ -484,6 +486,58 @@
484486
"[x for x in os.listdir('inputs') if x.endswith('.h5')]"
485487
]
486488
},
489+
{
490+
"cell_type": "markdown",
491+
"id": "42cf2c62-6f47-4922-bc25-659645380d56",
492+
"metadata": {},
493+
"source": [
494+
"#### 1.4.2 Use `prep_aria.py` to generate MintPy stacks, including optional corrections"
495+
]
496+
},
497+
{
498+
"cell_type": "code",
499+
"execution_count": null,
500+
"id": "671415cf-b6b5-412a-af67-c94358d4bf6c",
501+
"metadata": {},
502+
"outputs": [],
503+
"source": [
504+
"# Get paths from MintPy config file content\n",
505+
"stack_dir = config_file_content['mintpy.load.unwFile'].split('/unwrapStack.vrt')[0]\n",
506+
"dem_f = config_file_content['mintpy.load.demFile']\n",
507+
"incAngle_f = config_file_content['mintpy.load.incAngleFile']\n",
508+
"azAngle_f = config_file_content['mintpy.load.azAngleFile']"
509+
]
510+
},
511+
{
512+
"cell_type": "code",
513+
"execution_count": null,
514+
"id": "d5f3a44c-8ea0-4bb6-970e-704581ef107a",
515+
"metadata": {},
516+
"outputs": [],
517+
"source": [
518+
"# Set optional correction file paths\n",
519+
"solidearthtides_f = f\"{stack_dir}/setStack.vrt\"\n",
520+
"troposphere_f = f\"{stack_dir}/troposphereTotal/HRRRStack.vrt\"\n",
521+
"ionosphere_f = f\"{stack_dir}/ionoStack.vrt\""
522+
]
523+
},
524+
{
525+
"cell_type": "code",
526+
"execution_count": null,
527+
"id": "093f314a-8f13-4cfd-a809-4c29cafe3baa",
528+
"metadata": {},
529+
"outputs": [],
530+
"source": [
531+
"# Check if optional corrections files exist\n",
532+
"cor_files = [solidearthtides_f, troposphere_f, ionosphere_f]\n",
533+
"\n",
534+
"for file in cor_files:\n",
535+
" if os.path.isfile(file):\n",
536+
" print(f\"Found: {file}\")\n",
537+
" else:\n",
538+
" print(f\"File Not Found: {file}\")"
539+
]
540+
},
487541
{
488542
"cell_type": "code",
489543
"execution_count": null,
@@ -493,11 +547,20 @@
493547
},
494548
"outputs": [],
495549
"source": [
496-
"command = f'prep_aria.py -s {work_dir}/stack -d {work_dir}/DEM/glo_90.dem -i {work_dir}/incidenceAngle/*.vrt -a {work_dir}/azimuthAngle/*.vrt --set {work_dir}/stack/setStack.vrt --tropo {work_dir}/stack/troposphereTotal/HRRRStack.vrt --iono {work_dir}/stack/ionoStack.vrt'\n",
550+
"command = f\"prep_aria.py -s {stack_dir} -d {dem_f} -i {incAngle_f} -a {azAngle_f} --set {solidearthtides_f} --tropo {troposphere_f} --iono {ionosphere_f}\"\n",
497551
"process = subprocess.run(command, shell=True)\n",
552+
"\n",
498553
"print('Mintpy input files:')\n",
499554
"[x for x in os.listdir('inputs') if x.endswith('.h5')]"
500555
]
556+
},
557+
{
558+
"cell_type": "code",
559+
"execution_count": null,
560+
"id": "2f337891-567f-4509-a041-a219b8790390",
561+
"metadata": {},
562+
"outputs": [],
563+
"source": []
501564
}
502565
],
503566
"metadata": {

0 commit comments

Comments
 (0)