Skip to content

Commit

Permalink
add example file
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormccaffrey committed Jun 15, 2021
1 parent ead31a6 commit 88d6a7f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 130 deletions.
76 changes: 11 additions & 65 deletions .ipynb_checkpoints/example-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "markdown",
"id": "9c9d36a7",
"id": "955e0f44",
"metadata": {},
"source": [
"Example code for "
"### Example code for computing CIV distance."
]
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 2,
"id": "2da2635f",
"metadata": {},
"outputs": [],
Expand All @@ -20,78 +20,24 @@
"import matplotlib.patches as patches\n",
"import numpy as np\n",
"import richardsplot as rplot\n",
"from sklearn.preprocessing import scale"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "f7f83e67",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from sklearn.preprocessing import scale\n",
"\n",
"def project(data, fit):\n",
" #Use: Project scattered data (data) onto a line of best fit (fit)\n",
" #Returns: 2-D array of (x,y) locations on the line of your orthogonal projection\n",
" \n",
" #data: 2-D (N by 2) array of your data in some x-y space\n",
" #fit: 2-D (N by 2) array of coordinates along your line of best fit\n",
" \n",
" locs = [] #this will contain xy locations along the best-fit curve corresponding to each data point's orthogonal projection onto said curve - python list faster than numpy array\n",
" \n",
" #Loop through each data point and compare with locations along fit\n",
" for scat in data: \n",
" r2 = (scat[0]-fit[:,0])**2 + (scat[1]-fit[:,1])**2 #dist^2 of scat from each point along fit\n",
" delta = [fit[np.argmin(r2), 0], fit[np.argmin(r2), 1]] #save point along fit where dist^2 was minimum\n",
" locs.append(delta) \n",
" \n",
" return np.array(locs)\n",
"\n",
"\n",
"def CIV_distance(data_original, fit_original):\n",
" #fit: N-by-2 array containing coordinates of points along best fit line \n",
" #data: N-by-2 [[x,y]] array of data \n",
" #NOTE: This really just caters to this situation (assumes monotonically decreasing fit_original)\n",
" \n",
" #1) Scale all the data equally\n",
" xscale = scale(np.concatenate((fit_original[:,0], data_original[:,0]))) #add ``good`` mask to lofar to remove \"bad\" reconstructions\n",
" yscale = scale(np.concatenate((fit_original[:,1], data_original[:,1])))\n",
" fit = np.array([xscale[0:len(fit_original)], yscale[0:len(fit_original)]]).T\n",
" data = np.array([xscale[len(fit_original):len(fit_original)+len(data_original)], yscale[len(fit_original):len(fit_original)+len(data_original)]]).T\n",
" \n",
" #2) data is now each point's orthogonal projection onto fit\n",
" data = project(data, fit) \n",
" \n",
" darr = [] #list to fill with distances along best-fit line for each point\n",
"\n",
" #3) Loop through each data point- start at tip of line and sum dist traveled until passing data point\n",
" for scat in data:\n",
" d = 0 #start at beginning of the line\n",
" for i in range(fit.shape[0]-1):\n",
" xp, x = fit[i,0], fit[i+1,0]\n",
" yp, y = fit[i,1], fit[i+1,1] \n",
" d += np.sqrt((x-xp)**2 + (y-yp)**2)\n",
" if yp >= scat[1] > y: #if we pass the projected y-coord, save the distance traveled\n",
" darr.append(d)\n",
" break\n",
" \n",
" return np.array(darr)"
"from CIVfunctions import project, CIV_distance"
]
},
{
"cell_type": "markdown",
"id": "80b6d000",
"metadata": {},
"source": [
"---\n",
"\n",
"Load in example file with CIV EW+Blueshift already computed."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "70c80012",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -297,7 +243,7 @@
"[5 rows x 342 columns]"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -309,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "7f6eb57e",
"metadata": {},
"outputs": [],
Expand All @@ -323,7 +269,7 @@
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": 5,
"id": "928bfdf1",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -372,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 6,
"id": "946351e7",
"metadata": {},
"outputs": [],
Expand Down
Binary file added __pycache__/CIVfunctions.cpython-36.pyc
Binary file not shown.
76 changes: 11 additions & 65 deletions example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "markdown",
"id": "9c9d36a7",
"id": "955e0f44",
"metadata": {},
"source": [
"Example code for "
"### Example code for computing CIV distance."
]
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 2,
"id": "2da2635f",
"metadata": {},
"outputs": [],
Expand All @@ -20,78 +20,24 @@
"import matplotlib.patches as patches\n",
"import numpy as np\n",
"import richardsplot as rplot\n",
"from sklearn.preprocessing import scale"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "f7f83e67",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from sklearn.preprocessing import scale\n",
"\n",
"def project(data, fit):\n",
" #Use: Project scattered data (data) onto a line of best fit (fit)\n",
" #Returns: 2-D array of (x,y) locations on the line of your orthogonal projection\n",
" \n",
" #data: 2-D (N by 2) array of your data in some x-y space\n",
" #fit: 2-D (N by 2) array of coordinates along your line of best fit\n",
" \n",
" locs = [] #this will contain xy locations along the best-fit curve corresponding to each data point's orthogonal projection onto said curve - python list faster than numpy array\n",
" \n",
" #Loop through each data point and compare with locations along fit\n",
" for scat in data: \n",
" r2 = (scat[0]-fit[:,0])**2 + (scat[1]-fit[:,1])**2 #dist^2 of scat from each point along fit\n",
" delta = [fit[np.argmin(r2), 0], fit[np.argmin(r2), 1]] #save point along fit where dist^2 was minimum\n",
" locs.append(delta) \n",
" \n",
" return np.array(locs)\n",
"\n",
"\n",
"def CIV_distance(data_original, fit_original):\n",
" #fit: N-by-2 array containing coordinates of points along best fit line \n",
" #data: N-by-2 [[x,y]] array of data \n",
" #NOTE: This really just caters to this situation (assumes monotonically decreasing fit_original)\n",
" \n",
" #1) Scale all the data equally\n",
" xscale = scale(np.concatenate((fit_original[:,0], data_original[:,0]))) #add ``good`` mask to lofar to remove \"bad\" reconstructions\n",
" yscale = scale(np.concatenate((fit_original[:,1], data_original[:,1])))\n",
" fit = np.array([xscale[0:len(fit_original)], yscale[0:len(fit_original)]]).T\n",
" data = np.array([xscale[len(fit_original):len(fit_original)+len(data_original)], yscale[len(fit_original):len(fit_original)+len(data_original)]]).T\n",
" \n",
" #2) data is now each point's orthogonal projection onto fit\n",
" data = project(data, fit) \n",
" \n",
" darr = [] #list to fill with distances along best-fit line for each point\n",
"\n",
" #3) Loop through each data point- start at tip of line and sum dist traveled until passing data point\n",
" for scat in data:\n",
" d = 0 #start at beginning of the line\n",
" for i in range(fit.shape[0]-1):\n",
" xp, x = fit[i,0], fit[i+1,0]\n",
" yp, y = fit[i,1], fit[i+1,1] \n",
" d += np.sqrt((x-xp)**2 + (y-yp)**2)\n",
" if yp >= scat[1] > y: #if we pass the projected y-coord, save the distance traveled\n",
" darr.append(d)\n",
" break\n",
" \n",
" return np.array(darr)"
"from CIVfunctions import project, CIV_distance"
]
},
{
"cell_type": "markdown",
"id": "80b6d000",
"metadata": {},
"source": [
"---\n",
"\n",
"Load in example file with CIV EW+Blueshift already computed."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "70c80012",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -297,7 +243,7 @@
"[5 rows x 342 columns]"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -309,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "7f6eb57e",
"metadata": {},
"outputs": [],
Expand All @@ -323,7 +269,7 @@
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": 5,
"id": "928bfdf1",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -372,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 6,
"id": "946351e7",
"metadata": {},
"outputs": [],
Expand Down

0 comments on commit 88d6a7f

Please sign in to comment.