Changeset 5b5ea20 in sasmodels for explore/jitter.py


Ignore:
Timestamp:
Oct 30, 2017 10:55:42 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
904cd9c
Parents:
87a6591
Message:

[possibly] correct weighting for the azimuthal equidistant projection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • explore/jitter.py

    r87a6591 r5b5ea20  
    197197            return Rz(longitude)*Ry(latitude) 
    198198        def weight(theta_i, phi_j, wi, wj): 
     199            # Weighting for each point comes from the integral: 
     200            #     \int\int I(q, lat, log) sin(lat) dlat dlog 
     201            # We are doing a conformal mapping from disk to sphere, so we need 
     202            # a change of variables g(theta, phi) -> (lat, long): 
     203            #     lat, long = sqrt(theta^2 + phi^2), arctan(phi/theta) 
     204            # giving: 
     205            #     dtheta dphi = det(J) dlat dlong 
     206            # where J is the jacobian from the partials of g. Using 
     207            #     R = sqrt(theta^2 + phi^2), 
     208            # then 
     209            #     J = [[x/R, Y/R], -y/R^2, x/R^2]] 
     210            # and 
     211            #     det(J) = 1/R 
     212            # with the final integral being: 
     213            #    \int\int I(q, theta, phi) sin(R)/R dtheta dphi 
     214            # 
     215            # This does approximately the right thing, decreasing the weight 
     216            # of each point as you go farther out on the disk, but it hasn't 
     217            # yet been checked against the 1D integral results. Prior 
     218            # to declaring this "good enough" and checking that integrals 
     219            # work in practice, we will examine alternative mappings. 
     220            # 
     221            # The issue is that the mapping does not support the case of free 
     222            # rotation about a single axis correctly, with a small deviation 
     223            # in the orthogonal axis independent of the first axis.  Like the 
     224            # usual polar coordiates integration, the integrated sections 
     225            # form wedges, though at least in this case the wedge cuts through 
     226            # the entire sphere, and treats theta and phi identically. 
    199227            latitude = sqrt(theta_i**2 + phi_j**2) 
    200             w = wi*wj if latitude < 180 else 0 
    201             return w 
     228            w = sin(radians(latitude))/latitude if latitude != 0 else 1 
     229            return w*wi*wj if latitude < 180 else 0 
    202230    elif PROJECTION == 'azimuthal_equal_area': 
    203231        # https://en.wikipedia.org/wiki/Lambert_azimuthal_equal-area_projection 
     
    209237            return Rz(longitude)*Ry(latitude) 
    210238        def weight(theta_i, phi_j, wi, wj): 
    211             R = sqrt(theta_i**2 + phi_j**2) 
    212             return wi*wj if R <= 180 else 0 
    213             #return wi*wj if latitude <= 180 else 0 
     239            latitude = sqrt(theta_i**2 + phi_j**2) 
     240            w = sin(radians(latitude))/latitude if latitude != 0 else 1 
     241            return w*wi*wj if latitude < 180 else 0 
    214242    elif SCALED_PHI == 10:  # random thrashing 
    215243        def rotate(theta_i, phi_j): 
     
    234262                  for wi, theta_i in zip(weights, dtheta*t) 
    235263                  for wj, phi_j in zip(weights, dphi*t)]) 
     264    #print(max(w), min(w), min(w[w>0])) 
    236265    points = points[:, w>0] 
    237266    w = w[w>0] 
     267    w /= max(w) 
    238268 
    239269    if 0: # Kent distribution 
     
    504534 
    505535    ## use gaussian distribution unless testing integration 
    506     #dist = 'rectangle' 
    507     dist = 'gaussian' 
     536    dist = 'rectangle' 
     537    #dist = 'gaussian' 
    508538 
    509539    ## initial view 
Note: See TracChangeset for help on using the changeset viewer.