Sun Rising/Setting Azimuths for Equinox/Solstice using Observer points in PyEphem - pyephem

Essentially what I am trying to do is:
Take an Observer point (using lat/lon)
Calculate the dates for the next equinox and solstice given a starting date
Find the Sunset Azimuth for each
Find the Sunrise Azimuth for each
*Please note, I am working in ArcGIS, so some of my values are pulling from an outside table
Here is kind of what I have:
sun = ephem.Sun()
final = ephem.Observer()
final.lon = row[1]
final.lat = row[2]
final.elevation = row[3]
equinoxDate = ephem.next_equinox('0001/01/01')
equinoxSetDate = final.next_setting(ephem.Sun(), start=equinoxDate, use_center=True)
final.date = equinoxSetDate
sun.compute(final)
print sun.az
I keep getting hung up on the "next_setting" part. I get NeverUpError... if I switch it to previous_setting, next_rising, previous_rising... it doesn't matter. I always get a NeverUpError or AlwaysUpError.
If someone can help me get it to find the Azimuth for an Equinox Sunset (on any date) then I can figure out the rest I am sure.
Let me know if something isn't clear.
THANKS!

I figured it out. I was getting errors because: final.lon, final.lat are treated as strings by pyephem. So I switched it by saying final.lon = str(row[1]) and went from there. Works great now! Brandon, you were on the right track with the values.
sun = ephem.Sun()
final = ephem.Observer()
final.lon = str(row[1])
final.lat = str(row[2])
final.elevation = row[3]
equinoxDate = ephem.next_equinox('0001/01/01')
equinoxSetDate = final.next_setting(ephem.Sun(), start=equinoxDate, use_center=True)
final.date = equinoxSetDate
sun.compute(final)
print sun.az

Related

Ironpython script in Ansys Customization tool

I'm a beginner in Python and I'm working with the Ansys Customization Tool (ACT) to add my own extension.
Is there a direct way to fill a file with every node's coordinates after deformation?
hopefully in 3 lines or columns: x , y , z
So far I only found the GetNodeValue object but it only gives me the displacement and I need the deformed coordinates for the entire model.
My first idea was to add the displacements to the initial coordinates but I didn't manage to do it.
Many thanks for your help
Lara
APDL Snippet
Add an APDL Snippet in the solution part of the tree:
/prep7
UPGEOM,1,1,1,file,rst ! adds the displacements to the nodal coordinates.
cdwrite,geom,nodesAndelements,geom ! Writes node and element data to nodesAndelement.geom
I'm not sure if you can work with the output format from cdwrite, but this is the quickest solution i can think of.
If you want to automate you have to insert the command snippet via
solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution
fullPath = "path//to//snippet"
snippet = solution.AddCommandSnippet()
snippet.ImportTextFile(fullPath)
ACT
If you want to stay in ACT it could be done like this:
global nodeResults
import units
analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
mesh = analysis.MeshData
# Get nodes
allNodes = mesh.Nodes
# get the result data
reader = analysis.GetResultsData()
# get the deformation result
myDeformation = reader.GetResult("U")
nodeResultsTemp = []
result_unit = myDeformation.GetComponentInfo("X").Unit
for node in allNodes:
# get node deformation and convert values in meter
deformationNode1 = myDeformation.GetNodeValues(node.Id)
deformationNode1[0] = units.ConvertUnit(deformationNode1[0],result_unit,"m","Length")
deformationNode1[1] = units.ConvertUnit(deformationNode1[1],result_unit,"m","Length")
deformationNode1[2] = units.ConvertUnit(deformationNode1[2],result_unit,"m","Length")
# add node coordinates (in meter) to the displacement
mesh_unit = mesh.Unit
node1 = mesh.NodeById(node.Id)
node1CoorX = units.ConvertUnit(node1.X,mesh_unit,"m","Length")
node1CoorY = units.ConvertUnit(node1.Y,mesh_unit,"m","Length")
node1CoorZ = units.ConvertUnit(node1.Z,mesh_unit,"m","Length")
deformationNode1[0] = deformationNode1[0]+node1CoorX
deformationNode1[1] = deformationNode1[1]+node1CoorY
deformationNode1[2] = deformationNode1[2]+node1CoorZ
nodeResultsTemp.append([node1.X,node1.Y,node1.Z,deformationNode1[0],deformationNode1[1],deformationNode1[2]])
nodeResults = nodeResultsTemp

How do i exclude some elements of a list from further calculations

So I have a list of stars and their respective distances. My assignment is to find which stars are in a certain distance (+- 10parsec). I want to exclude some of them from further calculations in the program. The thing is I don't want to remove them completely so remove, pop etc isn't helping me. I still want those stars on the list to be present in my output csv. I just want a line saying something like those stars which don't support the if statement, don't use them in this calculation. So i guess the output would be blank for those.
I suppose it is an if or for statement, to mark those bad stars as False and then down the line use calculation that excludes those faulty stars.
I'm a physics student and this is my first python program ever! Please be cool about my ignorance...
Edit: forgive me if i include useless stuff i don't really know what's important. I also use uncertainties library if its of any use
column_names = ['id','pi','s_pi','v_r' ,'s_v', 'dis', 'X',
'ra_h', 'ra_m', 'ra_s','dec_d', 'dec_m',
'dec_s', 'ma', 's_ma', 'md', 's_md']
data = pd.read_csv("hyades_data.dat", skiprows=2, sep='\s+',
names=column_names)
calculations with all
v_r = unumpy.uarray(data['v_r'], data['s_v'])
ma = unumpy.uarray(data['ma'], data['s_ma'])
md = unumpy.uarray(data['md'], data['s_md'])
mi = unumpy.sqrt(ma**2+md**2)
r_m = v_r*unumpy.tan(th)/(4.74*mi/1000)
diff = np.abs(r_pc - r_m)
'''
if np.abs(dist-46.43) <=10:
r_m=True
else r_m=False
at this point i want to make the distiction
'''
mean_diff = diff.mean()
print("Mean : ")
print(mean_diff)
print(a_ref,d_ref)
df_va=pd.DataFrame(v_r)
df_mi = pd.DataFrame(mi)
df_rm = pd.DataFrame(r_m)
df_rpc = pd.DataFrame(r_pc)
df_diff = pd.DataFrame(diff)
#df_mean_diff = pd.DataFrame(mean_diff)
ve = v_r*np.tan(th)
output = pd.concat([data['id'], ra, dec, th_d, df_mi, df_rm, df_rpc,
df_diff,df_va], axis=1)
output.columns = ['id','ra', 'dec', 'th_d','mi', 'r_m', 'r_pc',
'dist_diff','va']
output.to_csv('results.csv', index=False)

Large inaccuracies with Ruby Geocoder and/or OpenStreetMap

I'm using the geocoder gem in rails to get latitude & longitude for addresses and then display them in OpenStreetMap.
When I search for my old address:
>> results = Geocoder.search("1000 Mount Curve Ave E, Altadena, CA 91001")
I get:
>> results.first.coordinates
=> [34.1976645, -118.1278219]
Mount Curve Address Discrepancy
Those coordinates are perhaps a thousand feet off. (See image.) The resulting accurate coordinates from Google Maps are [34.200503,-118.1310407].
I've tried another address and it was much farther off, perhaps a mile. (1346 E Woodbury Rd, Pasadena, CA 91104)
I've tried yet another address, and it was pretty much dead-accurate. (922 E Brockton Ave, Redlands, CA 92374)
Does anyone know what might be causing these inaccuracies and how to get accurate results consistently?
Because of the inaccuracies and/or limitations with OSM/Nominatim, I switched to Google maps service. At the top of my controller I added:
require 'google_maps_service'
And in my controller's show routine I ended up with this, which yields accurate results:
source = Property.find(params[:id])
#property = PropertyDecorator.new(source)
gmaps = GoogleMapsService::Client.new(key: '[removed, put in your own key here]')
results = gmaps.geocode("#{#property.address1} #{#property.address2}")
if results[0] == nil
#lat = 0
#lng = 0
else
#lat = results[0][:geometry][:location][:lat]
#lng = results[0][:geometry][:location][:lng]
end

How can I get current date and time in swift with out Foundation

I am trying to do the equivalent of NSDate() but with out importing Foundation.
Does the Darwin module have a way to do this?
I was looking at this answer but no dice
How can I get a precise time, for example in milliseconds in Objective-C?
I am not sure if this is what you are looking for, but the BSD library
function
let t = time(nil)
gives the number of seconds since the Unix epoch as an integer, so this is almost the same as
let t = NSDate().timeIntervalSince1970
only that the latter returns the time as a Double with higher
precision. If you need this higher precision then you could use
gettimeofday():
var tv = timeval()
gettimeofday(&tv, nil)
let t = Double(tv.tv_sec) + Double(tv.tv_usec) / Double(USEC_PER_SEC)
If you are looking for the time broken down to years, month, days, hours etc according to your local time zone, then use
var t = time(nil)
var tmValue = tm()
localtime_r(&t, &tmValue)
let year = tmValue.tm_year + 1900
let month = tmValue.tm_mon + 1
let day = tmValue.tm_mday
let hour = tmValue.tm_hour
// ...
tmValue is a struct tm, and the fields are described in
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/localtime.3.html.

how to check the date using internet in matlab?

when using date command in matlab, i get the system current date. is there a way to get the current date using internet in matlab? the link i've given is similar to this question but that question was asked for vb, and i'm trying to do this thing in matlab.
https://stackoverflow.com/questions/21198527/how-to-check-the-real-date-time-through-an-internet-connection]
MATLAB Code based on urlread to get current date using internet (URL) and with couple of bounding keys (to find the date string) -
URL = 'http://time.is/';
key1 = 'title="Click for calendar">';
key2 = '</h2>';
data = urlread(URL);
start_ind = strfind(data,key1);
data1 = data(start_ind:end);
off_stop_ind = strfind(data1,key2);
current_date = data(start_ind+ numel(key1):start_ind + off_stop_ind(1)-2)
Output at my location -
current_date =
Saturday, September 6, 2014, week 36
If you would like to have it in the DD-MM-YYYY format, use this -
date_split = strsplit(current_date,',')
current_date1 = datestr(strcat(date_split(2),date_split(3)))
Output -
current_date1 =
06-Sep-2014