Skip to content

Instantly share code, notes, and snippets.

@nghia1991ad
Created December 5, 2023 08:35
Show Gist options
  • Save nghia1991ad/1358ed5b548b87acb8ba32a27c125bdc to your computer and use it in GitHub Desktop.
Save nghia1991ad/1358ed5b548b87acb8ba32a27c125bdc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "d1ef3806",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7d8165b9",
"metadata": {},
"outputs": [],
"source": [
"stadf = pd.read_json(\"station_list.json\").T.reset_index()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "11542f8a",
"metadata": {},
"outputs": [],
"source": [
"def decimal_to_degrees_minutes(decimal_degree): #ChatGPT write for me\n",
" degrees = int(decimal_degree)\n",
" minutes = (decimal_degree - degrees) * 60\n",
"\n",
" return degrees, minutes\n",
"\n",
"def add_zero_if_less_than_10(number):\n",
" number = \"{:.2f}\".format(number)\n",
" if float(number) < 10:\n",
" return \"0\" + str(number)\n",
" else:\n",
" return str(number)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "754f7e5d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" BUMT2732.86N 9045.98E2772\n",
" CHUK2704.96N 8933.02E2263\n",
" DOCH2729.53N 8938.61E3093\n",
" PARO2734.04N 8919.23E2566\n",
" TASH2744.95N 8943.85E1614\n"
]
}
],
"source": [
"# UPP 5951.50N 1737.60E 14\n",
"\n",
"for i in range(0,len(stadf)): # loop through all the stations\n",
" latde, latmi = decimal_to_degrees_minutes(stadf.coords[i][0])\n",
" londe, lonmi = decimal_to_degrees_minutes(stadf.coords[i][1])\n",
" latmi = add_zero_if_less_than_10(latmi)\n",
" lonmi = add_zero_if_less_than_10(lonmi)\n",
" ele = int(stadf.coords[i][2])\n",
" sta = stadf['index'][i]\n",
" print(\" {}{}{}N {}{}E{}\".format(sta,latde,latmi,londe,lonmi,ele))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "580c26e0",
"metadata": {},
"outputs": [],
"source": [
"# Y2000.phs"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment